File tree 4 files changed +2285
-875
lines changed
4 files changed +2285
-875
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,8 @@ String pinstrapToName(uint8_t pinstrap) {
30
30
switch (pinstrap) {
31
31
case 0x3C :
32
32
return " BUZZER" ;
33
+ case 0x58 :
34
+ return " JOYSTICK" ;
33
35
case 0x7C :
34
36
return " BUTTONS" ;
35
37
case 0x76 :
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ ModulinoKnob encoder;
7
7
ModulinoDistance distance;
8
8
ModulinoMovement imu;
9
9
ModulinoThermo thermo;
10
+ ModulinoJoystick joystick;
10
11
11
12
void setup () {
12
13
@@ -22,6 +23,7 @@ void setup() {
22
23
23
24
imu.begin ();
24
25
thermo.begin ();
26
+ joystick.begin ();
25
27
}
26
28
27
29
int skip = 0 ;
@@ -55,6 +57,10 @@ void loop() {
55
57
Serial.println (" \t Temperature: " + String (thermo.getTemperature ()));
56
58
}
57
59
60
+ if (joystick.update ()) {
61
+ Serial.println (" x: " + String (joystick.getX ()) + " // y: " + String (joystick.getY ()) + " // pressed: " + String (joystick.isPressed ()));
62
+ }
63
+
58
64
if (buttons.update ()) {
59
65
if (buttons.isPressed (0 )) {
60
66
leds.set (1 + skip, RED, 100 );
Original file line number Diff line number Diff line change 1
1
// Copyright (c) 2024 Arduino SA
2
2
// SPDX-License-Identifier: MPL-2.0
3
3
4
+ #include " Arduino.h"
4
5
#include " Wire.h"
5
6
#include < vector>
6
7
#include < vl53l4cd_class.h> // from stm32duino
@@ -155,6 +156,42 @@ class ModulinoButtons : public Module {
155
156
std::vector<uint8_t > match = { 0x7C }; // same as fw main.c
156
157
};
157
158
159
+ class ModulinoJoystick : public Module {
160
+ public:
161
+ ModulinoJoystick (uint8_t address = 0xFF )
162
+ : Module(address, " JOYSTICK" ) {}
163
+ bool update () {
164
+ uint8_t buf[3 ];
165
+ auto res = read ((uint8_t *)buf, 3 );
166
+ auto ret = res && (buf[0 ] != last_status[0 ] || buf[1 ] != last_status[1 ] || buf[2 ] != last_status[2 ]);
167
+ last_status[0 ] = buf[0 ];
168
+ last_status[1 ] = buf[1 ];
169
+ last_status[2 ] = buf[2 ];
170
+ return ret;
171
+ }
172
+ PinStatus isPressed () {
173
+ return last_status[2 ] ? HIGH : LOW;
174
+ }
175
+ int8_t getX () {
176
+ return (last_status[0 ] < 128 ? (128 - last_status[0 ]) : -(last_status[0 ] - 128 ));
177
+ }
178
+ int8_t getY () {
179
+ return (last_status[1 ] < 128 ? (128 - last_status[1 ]) : -(last_status[1 ] - 128 ));
180
+ }
181
+ virtual uint8_t discover () {
182
+ for (int i = 0 ; i < match.size (); i++) {
183
+ if (scan (match[i])) {
184
+ return match[i];
185
+ }
186
+ }
187
+ return 0xFF ;
188
+ }
189
+ private:
190
+ uint8_t last_status[3 ];
191
+ protected:
192
+ std::vector<uint8_t > match = { 0x58 }; // same as fw main.c
193
+ };
194
+
158
195
class ModulinoBuzzer : public Module {
159
196
public:
160
197
ModulinoBuzzer (uint8_t address = 0xFF )
You can’t perform that action at this time.
0 commit comments