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

+ 21
- 6
cppm.cpp View File

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

+ 6
- 8
events_cppm.cpp View File

14
 #include "cppm.h"
14
 #include "cppm.h"
15
 #include "events.h"
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
 #define CHANNEL_YAW 3
20
 #define CHANNEL_YAW 3
24
 #define CHANNEL_AUX1 4
21
 #define CHANNEL_AUX1 4
25
 #define CHANNEL_AUX2 5
22
 #define CHANNEL_AUX2 5
31
 
28
 
32
     values[CHANNEL_AUX1] = 200;
29
     values[CHANNEL_AUX1] = 200;
33
     values[CHANNEL_AUX2] = 200;
30
     values[CHANNEL_AUX2] = 200;
34
-    
35
-    cppmInit();
31
+
36
     cppmCopy(values);
32
     cppmCopy(values);
37
 }
33
 }
38
 
34
 
41
     values[CHANNEL_PITCH] = evt.Y;
37
     values[CHANNEL_PITCH] = evt.Y;
42
     values[CHANNEL_ROLL] = evt.X;
38
     values[CHANNEL_ROLL] = evt.X;
43
     values[CHANNEL_YAW] = evt.Rz;
39
     values[CHANNEL_YAW] = evt.Rz;
40
+    values[CHANNEL_AUX1] = evt.Ry;
41
+    values[CHANNEL_AUX2] = evt.Slider;
44
 
42
 
45
     cppmCopy(values);
43
     cppmCopy(values);
46
 }
44
 }

+ 11
- 8
events_deadzone.cpp View File

16
 #include "events.h"
16
 #include "events.h"
17
 
17
 
18
 //#define DEBUG_OUTPUT_RAW
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
 const GamePadEventData JoystickEventsDeadZone::deadZone(
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
 const GamePadEventData JoystickEventsDeadZone::centerValue(
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
 void JoystickEventsDeadZone::OnGamePadChanged(const GamePadEventData& evt) {
37
 void JoystickEventsDeadZone::OnGamePadChanged(const GamePadEventData& evt) {
35
 #ifdef DEBUG_OUTPUT_RAW
38
 #ifdef DEBUG_OUTPUT_RAW

+ 2
- 1
x52.cpp View File

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

Loading…
Cancel
Save