1 /*
2 	DS5State.h is part of DualSenseWindows
3 	https://github.com/Ohjurot/DualSense-Windows
4 
5 	Contributors of this file:
6 	11.2020 Ludwig Füchsl
7 
8 	Licensed under the MIT License (To be found in repository root directory)
9 */
10 module ds5w.ds5state;
11 
12 enum DS5W_ISTATE_BTX_SQUARE = 0x10;
13 enum DS5W_ISTATE_BTX_CROSS = 0x20;
14 enum DS5W_ISTATE_BTX_CIRCLE = 0x40;
15 enum DS5W_ISTATE_BTX_TRIANGLE = 0x80;
16 enum DS5W_ISTATE_DPAD_LEFT = 0x01;
17 enum DS5W_ISTATE_DPAD_DOWN = 0x02;
18 enum DS5W_ISTATE_DPAD_RIGHT = 0x04;
19 enum DS5W_ISTATE_DPAD_UP = 0x08;
20 
21 enum DS5W_ISTATE_BTN_A_LEFT_BUMPER = 0x01;
22 enum DS5W_ISTATE_BTN_A_RIGHT_BUMPER = 0x02;
23 enum DS5W_ISTATE_BTN_A_LEFT_TRIGGER = 0x04;
24 enum DS5W_ISTATE_BTN_A_RIGHT_TRIGGER = 0x08;
25 enum DS5W_ISTATE_BTN_A_SELECT = 0x10;
26 enum DS5W_ISTATE_BTN_A_MENU = 0x20;
27 enum DS5W_ISTATE_BTN_A_LEFT_STICK = 0x40;
28 enum DS5W_ISTATE_BTN_A_RIGHT_STICK = 0x80;
29 
30 enum DS5W_ISTATE_BTN_B_PLAYSTATION_LOGO = 0x01;
31 enum DS5W_ISTATE_BTN_B_PAD_BUTTON = 0x02;
32 enum DS5W_ISTATE_BTN_B_MIC_BUTTON = 0x04;
33 
34 enum DS5W_OSTATE_PLAYER_LED_LEFT = 0x01;
35 enum DS5W_OSTATE_PLAYER_LED_MIDDLE_LEFT = 0x02;
36 enum DS5W_OSTATE_PLAYER_LED_MIDDLE = 0x04;
37 enum DS5W_OSTATE_PLAYER_LED_MIDDLE_RIGHT = 0x08;
38 enum DS5W_OSTATE_PLAYER_LED_RIGHT = 0x10;
39 
40 /// <summary>
41 /// Analog stick
42 /// </summary>
43 struct AnalogStick
44 {
45     /// <summary>
46     /// X Position of stick (0 = Center)
47     /// </summary>
48     byte x;
49 
50     /// <summary>
51     /// Y Posistion of stick (0 = Center)
52     /// </summary>
53     byte y;
54 }
55 
56 /// <summary>
57 /// 3 Component vector
58 /// </summary>
59 struct Vec3
60 {
61     short x;
62     short y;
63     short z;
64 }
65 
66 alias Vector3 = Vec3;
67 
68 /// <summary>
69 /// RGB Color
70 /// </summary>
71 struct Color
72 {
73     ubyte r;
74     ubyte g;
75     ubyte b;
76 }
77 
78 /// <summary>
79 /// Touchpad state
80 /// </summary>
81 struct Touch
82 {
83     /// <summary>
84     /// X positon of finger (~ 0 - 2000)
85     /// </summary>
86     uint x;
87 
88     /// <summary>
89     /// Y position of finger (~ 0 - 2048)
90     /// </summary>
91     uint y;
92 
93     /// <summary>
94     /// Touch is down
95     /// </summary>
96     bool down;
97 
98     /// <summary>
99     /// 7-bit ID for touch
100     /// </summary>
101     ubyte id;
102 }
103 
104 struct Battery
105 {
106     /// <summary>
107     /// Charching state of the battery
108     /// </summary>
109     bool chargin;
110 
111     /// <summary>
112     /// Indicates that the battery is fully charged
113     /// </summary>
114     bool fullyCharged;
115 
116     /// <summary>
117     /// Battery charge level 0x0 to 
118     /// </summary>
119     ubyte level;
120 }
121 
122 /// <summary>
123 /// State of the mic led
124 /// </summary>
125 enum MicLed : ubyte
126 {
127     /// <summary>
128     /// Lef is off
129     /// </summary>
130     OFF = 0x00,
131 
132     /// <summary>
133     /// Led is on
134     /// </summary>
135     ON = 0x01,
136 
137     /// <summary>
138     /// Led is pulsing
139     /// </summary>
140     PULSE = 0x02,
141 }
142 
143 /// <summary>
144 /// Type of trigger effect
145 /// </summary>
146 enum TriggerEffectType : ubyte
147 {
148     /// <summary>
149     /// No resistance is applied
150     /// </summary>
151     NoResitance = 0x00,
152 
153     /// <summary>
154     /// Continuous Resitance is applied
155     /// </summary>
156     ContinuousResitance = 0x01,
157 
158     /// <summary>
159     /// Seciton resistance is appleyed
160     /// </summary>
161     SectionResitance = 0x02,
162 
163     /// <summary>
164     /// Extended trigger effect
165     /// </summary>
166     EffectEx = 0x26,
167 
168     /// <summary>
169     /// Calibrate triggers
170     /// </summary>
171     Calibrate = 0xFC,
172 }
173 
174 /// <summary>
175 /// Trigger effect
176 /// </summary>
177 struct TriggerEffect
178 {
179     /// <summary>
180     /// Trigger effect type
181     /// </summary>
182     TriggerEffectType effectType;
183 
184     /// <summary>
185     /// Union for effect parameters
186     /// </summary>
187     union
188     {
189         /// <summary>
190         /// Union one raw data
191         /// </summary>
192         ubyte[6] _u1_raw;
193 
194         /// <summary>
195         /// For type == ContinuousResitance
196         /// </summary>
197         struct TContinuous
198         {
199             /// <summary>
200             /// Start position of resistance
201             /// </summary>
202             ubyte startPosition;
203 
204             /// <summary>
205             /// Force of resistance
206             /// </summary>
207             ubyte force;
208 
209             /// <summary>
210             /// PAD / UNUSED
211             /// </summary>
212             ubyte[4] _pad;
213         }
214 
215         TContinuous Continuous;
216 
217         /// <summary>
218         /// For type == SectionResitance
219         /// </summary>
220         struct TSection
221         {
222             /// <summary>
223             /// Start position of resistance
224             /// </summary>
225             ubyte startPosition;
226 
227             /// <summary>
228             /// End position of resistance (>= start)
229             /// </summary>
230             ubyte endPosition;
231 
232             /// <summary>
233             /// PAD / UNUSED
234             /// </summary>
235             ubyte[4] _pad;
236         }
237 
238         TSection Section;
239         /// <summary>
240         /// For type == EffectEx
241         /// </summary>
242         struct TEffectEx
243         {
244             /// <summary>
245             /// Position at witch the effect starts
246             /// </summary>
247             ubyte startPosition;
248 
249             /// <summary>
250             /// Wher the effect should keep playing when trigger goes beyond 255
251             /// </summary>
252             bool keepEffect;
253 
254             /// <summary>
255             /// Force applied when trigger >= (255 / 2)
256             /// </summary>
257             ubyte beginForce;
258 
259             /// <summary>
260             /// Force applied when trigger <= (255 / 2)
261             /// </summary>
262             ubyte middleForce;
263 
264             /// <summary>
265             /// Force applied when trigger is beyond 255
266             /// </summary>
267             ubyte endForce;
268 
269             /// <summary>
270             /// Vibration frequency of the trigger
271             /// </summary>
272             ubyte frequency;
273         }
274 
275         TEffectEx EffectEx;
276 
277     }
278 }
279 
280 /// <summary>
281 /// Led brightness
282 /// </summary>
283 enum LedBrightness : ubyte
284 {
285     /// <summary>
286     /// Low led brightness
287     /// </summary>
288     LOW = 0x02,
289 
290     /// <summary>
291     /// Medium led brightness
292     /// </summary>
293     MEDIUM = 0x01,
294 
295     /// <summary>
296     /// High led brightness
297     /// </summary>
298     HIGH = 0x00,
299 }
300 
301 /// <summary>
302 /// Player leds values
303 /// </summary>
304 struct PlayerLeds
305 {
306     /// <summary>
307     /// Player indication leds bitflag (You may used them for other features) DS5W_OSTATE_PLAYER_LED_???
308     /// </summary>
309     ubyte bitmask;
310 
311     /// <summary>
312     /// Indicates weather the player leds should fade in
313     /// </summary>
314     bool playerLedFade;
315 
316     /// <summary>
317     /// Brightness of the player leds
318     /// </summary>
319     LedBrightness brightness;
320 }
321 
322 /// <summary>
323 /// Input state of the controler
324 /// </summary>
325 struct DS5InputState
326 {
327     /// <summary>
328     /// Position of left stick
329     /// </summary>
330     AnalogStick leftStick;
331 
332     /// <summary>
333     /// Posisiton of right stick
334     /// </summary>
335     AnalogStick rightStick;
336 
337     /// <summary>
338     /// Left trigger position
339     /// </summary>
340     ubyte leftTrigger;
341 
342     /// <summary>
343     /// Right trigger position
344     /// </summary>
345     ubyte rightTrigger;
346 
347     /// <summary>
348     /// Buttons and dpad bitmask DS5W_ISTATE_BTX_?? and DS5W_ISTATE_DPAD_?? indices check with if(buttonsAndDpad & DS5W_ISTATE_DPAD_??)...
349     /// </summary>
350     ubyte buttonsAndDpad;
351 
352     /// <summary>
353     /// Button bitmask A (DS5W_ISTATE_BTN_A_??)
354     /// </summary>
355     ubyte buttonsA;
356 
357     /// <summary>
358     /// Button bitmask B (DS5W_ISTATE_BTN_B_??)
359     /// </summary>
360     ubyte buttonsB;
361 
362     /// <summary>
363     /// Accelerometer
364     /// </summary>
365     Vector3 accelerometer;
366 
367     /// <summary>
368     /// Gyroscope  (Currently only raw values will be dispayed! Probably needs calibration (Will be done within the lib in the future))
369     /// </summary>
370     Vector3 gyroscope;
371 
372     /// <summary>
373     /// First touch point
374     /// </summary>
375     Touch touchPoint1;
376 
377     /// <summary>
378     /// Second touch point
379     /// </summary>
380     Touch touchPoint2;
381 
382     /// <summary>
383     /// Battery information
384     /// </summary>
385     Battery battery;
386 
387     /// <summary>
388     /// Indicates the connection of headphone
389     /// </summary>
390     bool headPhoneConnected;
391 
392     /// <summary>
393     /// EXPERIMAENTAL: Feedback of the left adaptive trigger (only when trigger effect is active)
394     /// </summary>
395     ubyte leftTriggerFeedback;
396 
397     /// <summary>
398     /// EXPERIMAENTAL: Feedback of the right adaptive trigger (only when trigger effect is active)
399     /// </summary>
400     ubyte rightTriggerFeedback;
401 }
402 
403 struct DS5OutputState
404 {
405     /// <summary>
406     /// Left / Hard rumbel motor
407     /// </summary>
408     ubyte leftRumble;
409 
410     /// <summary>
411     /// Right / Soft rumbel motor
412     /// </summary>
413     ubyte rightRumble;
414 
415     /// <summary>
416     /// State of the microphone led
417     /// </summary>
418     MicLed microphoneLed;
419 
420     /// <summary>
421     /// Diables all leds
422     /// </summary>
423     bool disableLeds;
424 
425     /// <summary>
426     /// Player leds
427     /// </summary>
428     PlayerLeds playerLeds;
429 
430     /// <summary>
431     /// Color of the lightbar
432     /// </summary>
433     Color lightbar;
434 
435     /// <summary>
436     /// Effect of left trigger
437     /// </summary>
438     TriggerEffect leftTriggerEffect;
439 
440     /// <summary>
441     /// Effect of right trigger
442     /// </summary>
443     TriggerEffect rightTriggerEffect;
444 
445 }