Browse code

WIP: lokale wijzigingen vóór pull

Steve Caster authored on18/08/2025 12:23:27
Showing1 changed files
... ...
@@ -1,137 +1,137 @@
1
-
2
-#undef DEBUG
3
-
4
-#define NUM_BUTTONS  40             // you don't need to change this value
5
-#define NUM_AXES  8        // 6 axes to UNO, and 8 to MEGA. If you are using UNO, don't need to change this value.
6
-
7
-typedef struct joyReport_t {
8
- int16_t axis[NUM_AXES];
9
- uint8_t button[(NUM_BUTTONS + 7) / 8]; // 8 buttons per byte
10
-} joyReport_t;
11
-
12
-joyReport_t joyReport;
13
-
14
-uint8_t btn[12];
15
-int fulloff = 0;
16
-void setup(void);
17
-void loop(void);
18
-void setButton(joyReport_t *joy, uint8_t button);
19
-void clearButton(joyReport_t *joy, uint8_t button);
20
-void sendJoyReport(joyReport_t *report);
21
-
22
-
23
-void setup()
24
-{
25
- //set pin to input Button
26
- for ( int portId = 02; portId < 13; portId ++ )
27
- {
28
-   pinMode( portId, INPUT_PULLUP);
29
- }
30
- Serial.begin(115200);
31
- delay(200);
32
-
33
-
34
- for (uint8_t ind = 0; ind < 8; ind++) {
35
-   joyReport.axis[ind] = ind * 1000;
36
- }
37
- for (uint8_t ind = 0; ind < sizeof(joyReport.button); ind++) {
38
-   joyReport.button[ind] = 0;
39
- }
40
-}
41
-
42
-// Send an HID report to the USB interface
43
-void sendJoyReport(struct joyReport_t *report)
44
-{
45
-#ifndef DEBUG
46
- Serial.write((uint8_t *)report, sizeof(joyReport_t));
47
-#else
48
- // dump human readable output for debugging
49
- for (uint8_t ind = 0; ind < NUM_AXES; ind++) {
50
-   Serial.print("axis[");
51
-   Serial.print(ind);
52
-   Serial.print("]= ");
53
-   Serial.print(report->axis[ind]);
54
-   Serial.print(" ");
55
- }
56
- Serial.println();
57
- for (uint8_t ind = 0; ind < NUM_BUTTONS / 8; ind++) {
58
-   Serial.print("button[");
59
-   Serial.print(ind);
60
-   Serial.print("]= ");
61
-   Serial.print(report->button[ind], HEX);
62
-   Serial.print(" ");
63
- }
64
- Serial.println();
65
-#endif
66
-}
67
-
68
-// turn a button on
69
-void setButton(joyReport_t *joy, uint8_t button)
70
-{
71
- uint8_t index = button / 8;
72
- uint8_t bit = button - 8 * index;
73
-
74
- joy->button[index] |= 1 << bit;
75
-}
76
-
77
-// turn a button off
78
-void clearButton(joyReport_t *joy, uint8_t button)
79
-{
80
- uint8_t index = button / 8;
81
- uint8_t bit = button - 8 * index;
82
-
83
- joy->button[index] &= ~(1 << bit);
84
-}
85
-
86
-/*
87
-  Read Digital port for Button
88
-  Read Analog port for axis
89
-*/
90
-void loop()
91
-{
92
- 
93
- for (int bt = 1; bt < 13; bt ++)
94
- {
95
-   // btn[bt] = digitalRead(bt + 1);
96
-   btn[bt] = LOW;
97
- }
98
- 
99
- for (int on = 01; on < 13; on++)
100
- {
101
-   if (btn[on] == LOW)
102
-   {
103
-     setButton(&joyReport, on + 16);
104
-    
105
-     delay(1);
106
-   }
107
-   for (int on = 01; on < 13; on++)
108
-   {
109
-     if (btn[on] == HIGH)
110
-     {
111
-       clearButton(&joyReport, on + 16);
112
-     }
113
-
114
-   }
115
- }
116
-
117
-
118
-//for (uint8_t axis = 0; axis < 1; axis++) {
119
-//  joyReport.axis[axis] = map(analogRead(axis), 0, 1023, -32768, 32767 );
120
-//}
121
-
122
- joyReport.axis[0] = 0;
123
- joyReport.axis[1] = 0;
124
- joyReport.axis[2] = map(analogRead(2), 0, 1023, -32768, 32767 );
125
- joyReport.axis[3] = map(analogRead(3), 0, 1023, -32768, 32767 );
126
- joyReport.axis[4] = map(analogRead(4), 0, 1023, -32768, 32767 );
127
- joyReport.axis[5] = 0;
128
- joyReport.axis[6] = 0;
129
- joyReport.axis[7] = 0;
130
- joyReport.axis[8] = 0;
131
-
132
- //Send Data to HID
133
- sendJoyReport(&joyReport);
134
-
135
- delay(35);
136
- fulloff = 0;
137
-}
1
+
2
+#undef DEBUG
3
+
4
+#define NUM_BUTTONS  40             // you don't need to change this value
5
+#define NUM_AXES  8        // 6 axes to UNO, and 8 to MEGA. If you are using UNO, don't need to change this value.
6
+
7
+typedef struct joyReport_t {
8
+ int16_t axis[NUM_AXES];
9
+ uint8_t button[(NUM_BUTTONS + 7) / 8]; // 8 buttons per byte
10
+} joyReport_t;
11
+
12
+joyReport_t joyReport;
13
+
14
+uint8_t btn[12];
15
+int fulloff = 0;
16
+void setup(void);
17
+void loop(void);
18
+void setButton(joyReport_t *joy, uint8_t button);
19
+void clearButton(joyReport_t *joy, uint8_t button);
20
+void sendJoyReport(joyReport_t *report);
21
+
22
+
23
+void setup()
24
+{
25
+ //set pin to input Button
26
+ for ( int portId = 02; portId < 13; portId ++ )
27
+ {
28
+   pinMode( portId, INPUT_PULLUP);
29
+ }
30
+ Serial.begin(115200);
31
+ delay(200);
32
+
33
+
34
+ for (uint8_t ind = 0; ind < 8; ind++) {
35
+   joyReport.axis[ind] = ind * 1000;
36
+ }
37
+ for (uint8_t ind = 0; ind < sizeof(joyReport.button); ind++) {
38
+   joyReport.button[ind] = 0;
39
+ }
40
+}
41
+
42
+// Send an HID report to the USB interface
43
+void sendJoyReport(struct joyReport_t *report)
44
+{
45
+#ifndef DEBUG
46
+ Serial.write((uint8_t *)report, sizeof(joyReport_t));
47
+#else
48
+ // dump human readable output for debugging
49
+ for (uint8_t ind = 0; ind < NUM_AXES; ind++) {
50
+   Serial.print("axis[");
51
+   Serial.print(ind);
52
+   Serial.print("]= ");
53
+   Serial.print(report->axis[ind]);
54
+   Serial.print(" ");
55
+ }
56
+ Serial.println();
57
+ for (uint8_t ind = 0; ind < NUM_BUTTONS / 8; ind++) {
58
+   Serial.print("button[");
59
+   Serial.print(ind);
60
+   Serial.print("]= ");
61
+   Serial.print(report->button[ind], HEX);
62
+   Serial.print(" ");
63
+ }
64
+ Serial.println();
65
+#endif
66
+}
67
+
68
+// turn a button on
69
+void setButton(joyReport_t *joy, uint8_t button)
70
+{
71
+ uint8_t index = button / 8;
72
+ uint8_t bit = button - 8 * index;
73
+
74
+ joy->button[index] |= 1 << bit;
75
+}
76
+
77
+// turn a button off
78
+void clearButton(joyReport_t *joy, uint8_t button)
79
+{
80
+ uint8_t index = button / 8;
81
+ uint8_t bit = button - 8 * index;
82
+
83
+ joy->button[index] &= ~(1 << bit);
84
+}
85
+
86
+/*
87
+  Read Digital port for Button
88
+  Read Analog port for axis
89
+*/
90
+void loop()
91
+{
92
+ 
93
+ for (int bt = 1; bt < 13; bt ++)
94
+ {
95
+   // btn[bt] = digitalRead(bt + 1);
96
+   btn[bt] = LOW;
97
+ }
98
+ 
99
+ for (int on = 01; on < 13; on++)
100
+ {
101
+   if (btn[on] == LOW)
102
+   {
103
+     setButton(&joyReport, on + 16);
104
+    
105
+     delay(1);
106
+   }
107
+   for (int on = 01; on < 13; on++)
108
+   {
109
+     if (btn[on] == HIGH)
110
+     {
111
+       clearButton(&joyReport, on + 16);
112
+     }
113
+
114
+   }
115
+ }
116
+
117
+
118
+//for (uint8_t axis = 0; axis < 1; axis++) {
119
+//  joyReport.axis[axis] = map(analogRead(axis), 0, 1023, -32768, 32767 );
120
+//}
121
+
122
+ joyReport.axis[0] = 0;
123
+ joyReport.axis[1] = 0;
124
+ joyReport.axis[2] = map(analogRead(2), 0, 1023, -32768, 32767 );
125
+ joyReport.axis[3] = map(analogRead(3), 0, 1023, -32768, 32767 );
126
+ joyReport.axis[4] = map(analogRead(4), 0, 1023, -32768, 32767 );
127
+ joyReport.axis[5] = 0;
128
+ joyReport.axis[6] = 0;
129
+ joyReport.axis[7] = 0;
130
+ joyReport.axis[8] = 0;
131
+
132
+ //Send Data to HID
133
+ sendJoyReport(&joyReport);
134
+
135
+ delay(35);
136
+ fulloff = 0;
137
+}
Browse code

adding new files

countcobolt authored on11/07/2023 15:40:36
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,137 @@
1
+
2
+#undef DEBUG
3
+
4
+#define NUM_BUTTONS  40             // you don't need to change this value
5
+#define NUM_AXES  8        // 6 axes to UNO, and 8 to MEGA. If you are using UNO, don't need to change this value.
6
+
7
+typedef struct joyReport_t {
8
+ int16_t axis[NUM_AXES];
9
+ uint8_t button[(NUM_BUTTONS + 7) / 8]; // 8 buttons per byte
10
+} joyReport_t;
11
+
12
+joyReport_t joyReport;
13
+
14
+uint8_t btn[12];
15
+int fulloff = 0;
16
+void setup(void);
17
+void loop(void);
18
+void setButton(joyReport_t *joy, uint8_t button);
19
+void clearButton(joyReport_t *joy, uint8_t button);
20
+void sendJoyReport(joyReport_t *report);
21
+
22
+
23
+void setup()
24
+{
25
+ //set pin to input Button
26
+ for ( int portId = 02; portId < 13; portId ++ )
27
+ {
28
+   pinMode( portId, INPUT_PULLUP);
29
+ }
30
+ Serial.begin(115200);
31
+ delay(200);
32
+
33
+
34
+ for (uint8_t ind = 0; ind < 8; ind++) {
35
+   joyReport.axis[ind] = ind * 1000;
36
+ }
37
+ for (uint8_t ind = 0; ind < sizeof(joyReport.button); ind++) {
38
+   joyReport.button[ind] = 0;
39
+ }
40
+}
41
+
42
+// Send an HID report to the USB interface
43
+void sendJoyReport(struct joyReport_t *report)
44
+{
45
+#ifndef DEBUG
46
+ Serial.write((uint8_t *)report, sizeof(joyReport_t));
47
+#else
48
+ // dump human readable output for debugging
49
+ for (uint8_t ind = 0; ind < NUM_AXES; ind++) {
50
+   Serial.print("axis[");
51
+   Serial.print(ind);
52
+   Serial.print("]= ");
53
+   Serial.print(report->axis[ind]);
54
+   Serial.print(" ");
55
+ }
56
+ Serial.println();
57
+ for (uint8_t ind = 0; ind < NUM_BUTTONS / 8; ind++) {
58
+   Serial.print("button[");
59
+   Serial.print(ind);
60
+   Serial.print("]= ");
61
+   Serial.print(report->button[ind], HEX);
62
+   Serial.print(" ");
63
+ }
64
+ Serial.println();
65
+#endif
66
+}
67
+
68
+// turn a button on
69
+void setButton(joyReport_t *joy, uint8_t button)
70
+{
71
+ uint8_t index = button / 8;
72
+ uint8_t bit = button - 8 * index;
73
+
74
+ joy->button[index] |= 1 << bit;
75
+}
76
+
77
+// turn a button off
78
+void clearButton(joyReport_t *joy, uint8_t button)
79
+{
80
+ uint8_t index = button / 8;
81
+ uint8_t bit = button - 8 * index;
82
+
83
+ joy->button[index] &= ~(1 << bit);
84
+}
85
+
86
+/*
87
+  Read Digital port for Button
88
+  Read Analog port for axis
89
+*/
90
+void loop()
91
+{
92
+ 
93
+ for (int bt = 1; bt < 13; bt ++)
94
+ {
95
+   // btn[bt] = digitalRead(bt + 1);
96
+   btn[bt] = LOW;
97
+ }
98
+ 
99
+ for (int on = 01; on < 13; on++)
100
+ {
101
+   if (btn[on] == LOW)
102
+   {
103
+     setButton(&joyReport, on + 16);
104
+    
105
+     delay(1);
106
+   }
107
+   for (int on = 01; on < 13; on++)
108
+   {
109
+     if (btn[on] == HIGH)
110
+     {
111
+       clearButton(&joyReport, on + 16);
112
+     }
113
+
114
+   }
115
+ }
116
+
117
+
118
+//for (uint8_t axis = 0; axis < 1; axis++) {
119
+//  joyReport.axis[axis] = map(analogRead(axis), 0, 1023, -32768, 32767 );
120
+//}
121
+
122
+ joyReport.axis[0] = 0;
123
+ joyReport.axis[1] = 0;
124
+ joyReport.axis[2] = map(analogRead(2), 0, 1023, -32768, 32767 );
125
+ joyReport.axis[3] = map(analogRead(3), 0, 1023, -32768, 32767 );
126
+ joyReport.axis[4] = map(analogRead(4), 0, 1023, -32768, 32767 );
127
+ joyReport.axis[5] = 0;
128
+ joyReport.axis[6] = 0;
129
+ joyReport.axis[7] = 0;
130
+ joyReport.axis[8] = 0;
131
+
132
+ //Send Data to HID
133
+ sendJoyReport(&joyReport);
134
+
135
+ delay(35);
136
+ fulloff = 0;
137
+}