Browse Source

Rename to ButtonDown, added MFD button info, fixed deadzone.

Thomas Buck 8 years ago
parent
commit
a51cc02516
6 changed files with 30 additions and 23 deletions
  1. 2
    2
      Saitek-X52-PPM.ino
  2. 4
    4
      events.h
  3. 17
    8
      events_buttons.cpp
  4. 3
    3
      events_cppm.cpp
  5. 3
    5
      events_deadzone.cpp
  6. 1
    1
      parser.cpp

+ 2
- 2
Saitek-X52-PPM.ino View File

@@ -19,8 +19,8 @@
19 19
 #include "x52.h"
20 20
 #include "cppm.h"
21 21
 
22
-//#define ENABLE_SERIAL_PORT
23
-//#define DEBUG_OUTPUT
22
+#define ENABLE_SERIAL_PORT
23
+#define DEBUG_OUTPUT
24 24
 //#define DEBUG_INPUT
25 25
 
26 26
 USB usb;

+ 4
- 4
events.h View File

@@ -24,7 +24,7 @@ class JoystickEvents {
24 24
     virtual void OnGamePadChanged(const GamePadEventData& evt) = 0;
25 25
     virtual void OnHatSwitch(uint8_t hat) = 0;
26 26
     virtual void OnButtonUp(uint8_t but_id) = 0;
27
-    virtual void OnButtonDn(uint8_t but_id) = 0;
27
+    virtual void OnButtonDown(uint8_t but_id) = 0;
28 28
     virtual void OnMouseMoved(uint8_t x, uint8_t y) = 0;
29 29
 
30 30
   protected:
@@ -37,7 +37,7 @@ class JoystickEventsDeadZone : public JoystickEvents {
37 37
     virtual void OnGamePadChanged(const GamePadEventData& evt);
38 38
     virtual void OnHatSwitch(uint8_t hat);
39 39
     virtual void OnButtonUp(uint8_t but_id);
40
-    virtual void OnButtonDn(uint8_t but_id);
40
+    virtual void OnButtonDown(uint8_t but_id);
41 41
     virtual void OnMouseMoved(uint8_t x, uint8_t y);
42 42
 
43 43
   private:
@@ -54,7 +54,7 @@ class JoystickEventsCPPM : public JoystickEvents {
54 54
     virtual void OnGamePadChanged(const GamePadEventData& evt);
55 55
     virtual void OnHatSwitch(uint8_t hat);
56 56
     virtual void OnButtonUp(uint8_t but_id);
57
-    virtual void OnButtonDn(uint8_t but_id);
57
+    virtual void OnButtonDown(uint8_t but_id);
58 58
     virtual void OnMouseMoved(uint8_t x, uint8_t y);
59 59
 
60 60
   private:
@@ -68,7 +68,7 @@ class JoystickEventsButtons : public JoystickEvents {
68 68
     virtual void OnGamePadChanged(const GamePadEventData& evt);
69 69
     virtual void OnHatSwitch(uint8_t hat);
70 70
     virtual void OnButtonUp(uint8_t but_id);
71
-    virtual void OnButtonDn(uint8_t but_id);
71
+    virtual void OnButtonDown(uint8_t but_id);
72 72
     virtual void OnMouseMoved(uint8_t x, uint8_t y);
73 73
 
74 74
   private:

+ 17
- 8
events_buttons.cpp View File

@@ -17,9 +17,8 @@
17 17
 
18 18
 #define DEBUG_BUTTON_MFD
19 19
 
20
-JoystickEventsButtons::JoystickEventsButtons(X52* x, JoystickEvents* client) : JoystickEvents(client), x52(x) {
21
-
22
-}
20
+JoystickEventsButtons::JoystickEventsButtons(X52* x, JoystickEvents* client)
21
+        : JoystickEvents(client), x52(x) { }
23 22
 
24 23
 void JoystickEventsButtons::OnGamePadChanged(const GamePadEventData& evt) {
25 24
     if (client) {
@@ -28,22 +27,28 @@ void JoystickEventsButtons::OnGamePadChanged(const GamePadEventData& evt) {
28 27
 }
29 28
 
30 29
 void JoystickEventsButtons::OnHatSwitch(uint8_t hat) {
30
+#ifdef DEBUG_BUTTON_MFD
31
+    String text = "Hat is " + String(hat);
32
+    x52->setMFDText(1, text.c_str());
33
+#endif
34
+
31 35
     if (client) {
32 36
         client->OnHatSwitch(hat);
33 37
     }
34 38
 }
35 39
 
36 40
 void JoystickEventsButtons::OnButtonUp(uint8_t but_id) {
41
+#ifdef DEBUG_BUTTON_MFD
42
+    String text = "Button " + String(but_id) + " up";
43
+    x52->setMFDText(1, text.c_str());
44
+#endif
45
+
37 46
     if (client) {
38 47
         client->OnButtonUp(but_id);
39 48
     }
40 49
 }
41 50
 
42
-void JoystickEventsButtons::OnButtonDn(uint8_t but_id) {
43
-    if (client) {
44
-        client->OnButtonDn(but_id);
45
-    }
46
-
51
+void JoystickEventsButtons::OnButtonDown(uint8_t but_id) {
47 52
 #ifdef DEBUG_BUTTON_MFD
48 53
     String text = "Button " + String(but_id) + " down";
49 54
     x52->setMFDText(1, text.c_str());
@@ -59,6 +64,10 @@ void JoystickEventsButtons::OnButtonDn(uint8_t but_id) {
59 64
         x52->setLEDBrightness(0);
60 65
         x52->setMFDBrightness(0);
61 66
     }
67
+
68
+    if (client) {
69
+        client->OnButtonDown(but_id);
70
+    }
62 71
 }
63 72
 
64 73
 void JoystickEventsButtons::OnMouseMoved(uint8_t x, uint8_t y) {

+ 3
- 3
events_cppm.cpp View File

@@ -34,7 +34,7 @@ JoystickEventsCPPM::JoystickEventsCPPM(JoystickEvents* client) : JoystickEvents(
34 34
 }
35 35
 
36 36
 void JoystickEventsCPPM::OnGamePadChanged(const GamePadEventData& evt) {
37
-    values[CHANNEL_THROTTLE] = map(evt.Z, 0, 0xFF, 1000, 2000);
37
+    values[CHANNEL_THROTTLE] = map(evt.Z, 0, 0xFF, 2000, 1000);
38 38
     values[CHANNEL_PITCH] = map(evt.Y, 0, 0x7FF, 1000, 2000);
39 39
     values[CHANNEL_ROLL] = map(evt.X, 0, 0x7FF, 1000, 2000);
40 40
     values[CHANNEL_YAW] = map(evt.Rz, 0, 0x3FF, 1000, 2000);
@@ -60,9 +60,9 @@ void JoystickEventsCPPM::OnButtonUp(uint8_t but_id) {
60 60
     }
61 61
 }
62 62
 
63
-void JoystickEventsCPPM::OnButtonDn(uint8_t but_id) {
63
+void JoystickEventsCPPM::OnButtonDown(uint8_t but_id) {
64 64
     if (client) {
65
-        client->OnButtonDn(but_id);
65
+        client->OnButtonDown(but_id);
66 66
     }
67 67
 }
68 68
 

+ 3
- 5
events_deadzone.cpp View File

@@ -19,10 +19,8 @@
19 19
 //#define DEBUG_OUTPUT
20 20
 
21 21
 // X, Y, Z, Rx, Ry, Rz, Slider
22
-// As you can see, my controller Rz axis is broken,
23
-// yours may be different, so change these values!
24 22
 const GamePadEventData JoystickEventsDeadZone::deadZone(
25
-    4, 20, 2, 2, 5, 200, 2
23
+    4, 4, 2, 2, 5, 25, 2
26 24
 );
27 25
 const uint8_t JoystickEventsDeadZone::deadZoneMouseX = 1;
28 26
 const uint8_t JoystickEventsDeadZone::deadZoneMouseY = 1;
@@ -170,14 +168,14 @@ void JoystickEventsDeadZone::OnButtonUp(uint8_t but_id) {
170 168
     }
171 169
 }
172 170
 
173
-void JoystickEventsDeadZone::OnButtonDn(uint8_t but_id) {
171
+void JoystickEventsDeadZone::OnButtonDown(uint8_t but_id) {
174 172
 #ifdef DEBUG_OUTPUT
175 173
     Serial.print("Down: ");
176 174
     Serial.println(but_id, DEC);
177 175
 #endif
178 176
 
179 177
     if (client) {
180
-        client->OnButtonDn(but_id);
178
+        client->OnButtonDown(but_id);
181 179
     }
182 180
 }
183 181
 

+ 1
- 1
parser.cpp View File

@@ -99,7 +99,7 @@ void JoystickReportParser::Parse(HID* hid, bool is_rpt_id, uint8_t len, uint8_t*
99 99
             uint64_t mask = (1ull << i);
100 100
             if ((mask & changes) && joyEvents) {
101 101
                 if (buttons & mask) {
102
-                    joyEvents->OnButtonDn(i);
102
+                    joyEvents->OnButtonDown(i);
103 103
                 } else {
104 104
                     joyEvents->OnButtonUp(i);
105 105
                 }

Loading…
Cancel
Save