Browse Source

Tried debugging with TimerOne lib

Thomas Buck 8 years ago
parent
commit
f943e19b31
5 changed files with 43 additions and 25 deletions
  1. 3
    2
      Saitek-X52-PPM.ino
  2. 21
    6
      cppm.cpp
  3. 6
    8
      events_cppm.cpp
  4. 11
    8
      events_deadzone.cpp
  5. 2
    1
      x52.cpp

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

@@ -17,6 +17,7 @@
17 17
 #include "events.h"
18 18
 #include "parser.h"
19 19
 #include "x52.h"
20
+#include "cppm.h"
20 21
 
21 22
 #define ENABLE_SERIAL_PORT
22 23
 #define DEBUG_OUTPUT
@@ -44,11 +45,11 @@ void setup() {
44 45
 #endif
45 46
     }
46 47
 
47
-    delay(200);
48
-
49 48
     if (!hid.SetReportParser(0, &joy)) {
50 49
         ErrorMessage<uint8_t >(PSTR("SetReportParser"), 1);
51 50
     }
51
+
52
+    cppmInit();
52 53
 }
53 54
 
54 55
 void init_joystick() {

+ 21
- 6
cppm.cpp View File

@@ -31,6 +31,9 @@
31 31
 #include <TimerOne.h>
32 32
 #include "cppm.h"
33 33
 
34
+//#define DEBUG_OUTPUT
35
+//#define DEBUG_OUTPUT_ALL
36
+
34 37
 #define CHANNELS 8
35 38
 #define MAX_STATES ((2 * CHANNELS) + 1)
36 39
 #define WHOLE_PULSE_WIDTH 20000
@@ -50,16 +53,23 @@ static void triggerIn(uint16_t us);
50 53
 static void nextState(void);
51 54
 
52 55
 void cppmInit(void) {
56
+#ifdef DEBUG_OUTPUT
57
+    Serial.println("Initializing Timer...");
58
+#endif
59
+
53 60
     pinMode(CPPM_OUTPUT_PIN, OUTPUT);
54 61
     digitalWrite(CPPM_OUTPUT_PIN, LOW);
55
-    Timer1.initialize();
62
+    Timer1.initialize(PULSE_LOW);
56 63
     Timer1.attachInterrupt(&nextState);
57 64
     state = 0;
58 65
     delaySum = MIN_WAIT;
59
-    triggerIn(PULSE_LOW);
60 66
 }
61 67
 
62 68
 void cppmCopy(uint16_t *data) {
69
+#ifdef DEBUG_OUTPUT
70
+    Serial.println("New CPPM data!");
71
+#endif
72
+
63 73
     cli();
64 74
     for (int i = 0; i < CHANNELS; i++) {
65 75
         cppmData[i] = data[i];
@@ -69,18 +79,23 @@ void cppmCopy(uint16_t *data) {
69 79
 
70 80
 static void triggerIn(uint16_t us) {
71 81
     Timer1.setPeriod(us);
72
-    // TODO reset timer?
82
+    //Timer1.start();
73 83
 }
74 84
 
75 85
 static void nextState(void) {
76
-    // TODO stop timer?
86
+    //Timer1.stop();
87
+
88
+#ifdef DEBUG_OUTPUT_ALL
89
+    Serial.print("CPPM state ");
90
+    Serial.println(state, DEC);
91
+#endif
77 92
     
78 93
     state++;
79 94
     if (state > MAX_STATES) {
80 95
         state = 0;
81 96
         delaySum = MIN_WAIT;
82 97
     }
83
-    if ((state % 2) == 0) {
98
+    if (!(state & 0x01)) {
84 99
         // pulse pause
85 100
         digitalWrite(CPPM_OUTPUT_PIN, LOW);
86 101
         triggerIn(PULSE_LOW);
@@ -88,7 +103,7 @@ static void nextState(void) {
88 103
         digitalWrite(CPPM_OUTPUT_PIN, HIGH);
89 104
         if (state <= 15) {
90 105
             // normal ppm pulse
91
-            uint8_t index = state / 2;
106
+            uint8_t index = state >> 1;
92 107
             triggerIn(cppmData[index]);
93 108
             delaySum += PULSE_WIDTH - cppmData[index];
94 109
         } else {

+ 6
- 8
events_cppm.cpp View File

@@ -14,12 +14,9 @@
14 14
 #include "cppm.h"
15 15
 #include "events.h"
16 16
 
17
-//#define DEBUG_OUTPUT_RAW
18
-#define DEBUG_OUTPUT
19
-
20
-#define CHANNEL_THROTTLE 0
21
-#define CHANNEL_PITCH 2
22
-#define CHANNEL_ROLL 1
17
+#define CHANNEL_THROTTLE 2
18
+#define CHANNEL_PITCH 1
19
+#define CHANNEL_ROLL 0
23 20
 #define CHANNEL_YAW 3
24 21
 #define CHANNEL_AUX1 4
25 22
 #define CHANNEL_AUX2 5
@@ -31,8 +28,7 @@ JoystickEventsCPPM::JoystickEventsCPPM(JoystickEvents* client) : JoystickEvents(
31 28
 
32 29
     values[CHANNEL_AUX1] = 200;
33 30
     values[CHANNEL_AUX2] = 200;
34
-    
35
-    cppmInit();
31
+
36 32
     cppmCopy(values);
37 33
 }
38 34
 
@@ -41,6 +37,8 @@ void JoystickEventsCPPM::OnGamePadChanged(const GamePadEventData& evt) {
41 37
     values[CHANNEL_PITCH] = evt.Y;
42 38
     values[CHANNEL_ROLL] = evt.X;
43 39
     values[CHANNEL_YAW] = evt.Rz;
40
+    values[CHANNEL_AUX1] = evt.Ry;
41
+    values[CHANNEL_AUX2] = evt.Slider;
44 42
 
45 43
     cppmCopy(values);
46 44
 }

+ 11
- 8
events_deadzone.cpp View File

@@ -16,20 +16,23 @@
16 16
 #include "events.h"
17 17
 
18 18
 //#define DEBUG_OUTPUT_RAW
19
-#define DEBUG_OUTPUT
19
+//#define DEBUG_OUTPUT
20 20
 
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!
21 24
 const GamePadEventData JoystickEventsDeadZone::deadZone(
22
-    0, 0, 0, 0, 0, 50, 0
25
+    4, 20, 2, 2, 5, 200, 2
23 26
 );
24
-const uint8_t JoystickEventsDeadZone::deadZoneMouseX = 0;
25
-const uint8_t JoystickEventsDeadZone::deadZoneMouseY = 0;
27
+const uint8_t JoystickEventsDeadZone::deadZoneMouseX = 1;
28
+const uint8_t JoystickEventsDeadZone::deadZoneMouseY = 1;
26 29
 
30
+// X, Y, Z, Rx, Ry, Rz, Slider
27 31
 const GamePadEventData JoystickEventsDeadZone::centerValue(
28
-    0x3FF, 0x3FF, 0x7F,
29
-    0x7F, 0x7F, 0x1FF, 0x7F
32
+    0x3FF, 0x3FF, 0x7F, 0x7F, 0x7F, 0x1FF, 0x7F
30 33
 );
31
-const uint8_t JoystickEventsDeadZone::centerMouseX = 0x7F;
32
-const uint8_t JoystickEventsDeadZone::centerMouseY = 0x7F;
34
+const uint8_t JoystickEventsDeadZone::centerMouseX = 0x07;
35
+const uint8_t JoystickEventsDeadZone::centerMouseY = 0x07;
33 36
 
34 37
 void JoystickEventsDeadZone::OnGamePadChanged(const GamePadEventData& evt) {
35 38
 #ifdef DEBUG_OUTPUT_RAW

+ 2
- 1
x52.cpp View File

@@ -12,8 +12,9 @@
12 12
 
13 13
 #include "x52.h"
14 14
 
15
+//#define DEBUG_OUTPUT
16
+
15 17
 #define TIME_24H_FORMAT
16
-#define DEBUG_OUTPUT
17 18
 
18 19
 X52::X52(USB* u, HID* h) : usb(u), hid(h) { }
19 20
 

Loading…
Cancel
Save