Browse Source

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

Thomas Buck 7 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
 #include "x52.h"
19
 #include "x52.h"
20
 #include "cppm.h"
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
 //#define DEBUG_INPUT
24
 //#define DEBUG_INPUT
25
 
25
 
26
 USB usb;
26
 USB usb;

+ 4
- 4
events.h View File

24
     virtual void OnGamePadChanged(const GamePadEventData& evt) = 0;
24
     virtual void OnGamePadChanged(const GamePadEventData& evt) = 0;
25
     virtual void OnHatSwitch(uint8_t hat) = 0;
25
     virtual void OnHatSwitch(uint8_t hat) = 0;
26
     virtual void OnButtonUp(uint8_t but_id) = 0;
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
     virtual void OnMouseMoved(uint8_t x, uint8_t y) = 0;
28
     virtual void OnMouseMoved(uint8_t x, uint8_t y) = 0;
29
 
29
 
30
   protected:
30
   protected:
37
     virtual void OnGamePadChanged(const GamePadEventData& evt);
37
     virtual void OnGamePadChanged(const GamePadEventData& evt);
38
     virtual void OnHatSwitch(uint8_t hat);
38
     virtual void OnHatSwitch(uint8_t hat);
39
     virtual void OnButtonUp(uint8_t but_id);
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
     virtual void OnMouseMoved(uint8_t x, uint8_t y);
41
     virtual void OnMouseMoved(uint8_t x, uint8_t y);
42
 
42
 
43
   private:
43
   private:
54
     virtual void OnGamePadChanged(const GamePadEventData& evt);
54
     virtual void OnGamePadChanged(const GamePadEventData& evt);
55
     virtual void OnHatSwitch(uint8_t hat);
55
     virtual void OnHatSwitch(uint8_t hat);
56
     virtual void OnButtonUp(uint8_t but_id);
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
     virtual void OnMouseMoved(uint8_t x, uint8_t y);
58
     virtual void OnMouseMoved(uint8_t x, uint8_t y);
59
 
59
 
60
   private:
60
   private:
68
     virtual void OnGamePadChanged(const GamePadEventData& evt);
68
     virtual void OnGamePadChanged(const GamePadEventData& evt);
69
     virtual void OnHatSwitch(uint8_t hat);
69
     virtual void OnHatSwitch(uint8_t hat);
70
     virtual void OnButtonUp(uint8_t but_id);
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
     virtual void OnMouseMoved(uint8_t x, uint8_t y);
72
     virtual void OnMouseMoved(uint8_t x, uint8_t y);
73
 
73
 
74
   private:
74
   private:

+ 17
- 8
events_buttons.cpp View File

17
 
17
 
18
 #define DEBUG_BUTTON_MFD
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
 void JoystickEventsButtons::OnGamePadChanged(const GamePadEventData& evt) {
23
 void JoystickEventsButtons::OnGamePadChanged(const GamePadEventData& evt) {
25
     if (client) {
24
     if (client) {
28
 }
27
 }
29
 
28
 
30
 void JoystickEventsButtons::OnHatSwitch(uint8_t hat) {
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
     if (client) {
35
     if (client) {
32
         client->OnHatSwitch(hat);
36
         client->OnHatSwitch(hat);
33
     }
37
     }
34
 }
38
 }
35
 
39
 
36
 void JoystickEventsButtons::OnButtonUp(uint8_t but_id) {
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
     if (client) {
46
     if (client) {
38
         client->OnButtonUp(but_id);
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
 #ifdef DEBUG_BUTTON_MFD
52
 #ifdef DEBUG_BUTTON_MFD
48
     String text = "Button " + String(but_id) + " down";
53
     String text = "Button " + String(but_id) + " down";
49
     x52->setMFDText(1, text.c_str());
54
     x52->setMFDText(1, text.c_str());
59
         x52->setLEDBrightness(0);
64
         x52->setLEDBrightness(0);
60
         x52->setMFDBrightness(0);
65
         x52->setMFDBrightness(0);
61
     }
66
     }
67
+
68
+    if (client) {
69
+        client->OnButtonDown(but_id);
70
+    }
62
 }
71
 }
63
 
72
 
64
 void JoystickEventsButtons::OnMouseMoved(uint8_t x, uint8_t y) {
73
 void JoystickEventsButtons::OnMouseMoved(uint8_t x, uint8_t y) {

+ 3
- 3
events_cppm.cpp View File

34
 }
34
 }
35
 
35
 
36
 void JoystickEventsCPPM::OnGamePadChanged(const GamePadEventData& evt) {
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
     values[CHANNEL_PITCH] = map(evt.Y, 0, 0x7FF, 1000, 2000);
38
     values[CHANNEL_PITCH] = map(evt.Y, 0, 0x7FF, 1000, 2000);
39
     values[CHANNEL_ROLL] = map(evt.X, 0, 0x7FF, 1000, 2000);
39
     values[CHANNEL_ROLL] = map(evt.X, 0, 0x7FF, 1000, 2000);
40
     values[CHANNEL_YAW] = map(evt.Rz, 0, 0x3FF, 1000, 2000);
40
     values[CHANNEL_YAW] = map(evt.Rz, 0, 0x3FF, 1000, 2000);
60
     }
60
     }
61
 }
61
 }
62
 
62
 
63
-void JoystickEventsCPPM::OnButtonDn(uint8_t but_id) {
63
+void JoystickEventsCPPM::OnButtonDown(uint8_t but_id) {
64
     if (client) {
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
 //#define DEBUG_OUTPUT
19
 //#define DEBUG_OUTPUT
20
 
20
 
21
 // X, Y, Z, Rx, Ry, Rz, Slider
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
 const GamePadEventData JoystickEventsDeadZone::deadZone(
22
 const GamePadEventData JoystickEventsDeadZone::deadZone(
25
-    4, 20, 2, 2, 5, 200, 2
23
+    4, 4, 2, 2, 5, 25, 2
26
 );
24
 );
27
 const uint8_t JoystickEventsDeadZone::deadZoneMouseX = 1;
25
 const uint8_t JoystickEventsDeadZone::deadZoneMouseX = 1;
28
 const uint8_t JoystickEventsDeadZone::deadZoneMouseY = 1;
26
 const uint8_t JoystickEventsDeadZone::deadZoneMouseY = 1;
170
     }
168
     }
171
 }
169
 }
172
 
170
 
173
-void JoystickEventsDeadZone::OnButtonDn(uint8_t but_id) {
171
+void JoystickEventsDeadZone::OnButtonDown(uint8_t but_id) {
174
 #ifdef DEBUG_OUTPUT
172
 #ifdef DEBUG_OUTPUT
175
     Serial.print("Down: ");
173
     Serial.print("Down: ");
176
     Serial.println(but_id, DEC);
174
     Serial.println(but_id, DEC);
177
 #endif
175
 #endif
178
 
176
 
179
     if (client) {
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
             uint64_t mask = (1ull << i);
99
             uint64_t mask = (1ull << i);
100
             if ((mask & changes) && joyEvents) {
100
             if ((mask & changes) && joyEvents) {
101
                 if (buttons & mask) {
101
                 if (buttons & mask) {
102
-                    joyEvents->OnButtonDn(i);
102
+                    joyEvents->OnButtonDown(i);
103
                 } else {
103
                 } else {
104
                     joyEvents->OnButtonUp(i);
104
                     joyEvents->OnButtonUp(i);
105
                 }
105
                 }

Loading…
Cancel
Save