File tree Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -190,12 +190,21 @@ class ModulinoJoystick : public Module {
190
190
bool update () {
191
191
uint8_t buf[3 ];
192
192
auto res = read ((uint8_t *)buf, 3 );
193
- auto ret = res && (buf[0 ] != last_status[0 ] || buf[1 ] != last_status[1 ] || buf[2 ] != last_status[2 ]);
194
- last_status[0 ] = buf[0 ];
195
- last_status[1 ] = buf[1 ];
193
+ auto x = buf[0 ];
194
+ auto y = buf[1 ];
195
+ map_value (x, y);
196
+ auto ret = res && (x != last_status[0 ] || buf[1 ] != y || buf[2 ] != last_status[2 ]);
197
+ if (!ret) {
198
+ return false ;
199
+ }
200
+ last_status[0 ] = x;
201
+ last_status[1 ] = y;
196
202
last_status[2 ] = buf[2 ];
197
203
return ret;
198
204
}
205
+ void setDeadZone (uint8_t dz_th) {
206
+ _dz_threshold = dz_th;
207
+ }
199
208
PinStatus isPressed () {
200
209
return last_status[2 ] ? HIGH : LOW;
201
210
}
@@ -213,7 +222,14 @@ class ModulinoJoystick : public Module {
213
222
}
214
223
return 0xFF ;
215
224
}
225
+ void map_value (uint8_t &x, uint8_t &y) {
226
+ if (x > 128 - _dz_threshold && x < 128 + _dz_threshold && y > 128 - _dz_threshold && y < 128 + _dz_threshold) {
227
+ x = 128 ;
228
+ y = 128 ;
229
+ }
230
+ }
216
231
private:
232
+ uint8_t _dz_threshold = 26 ;
217
233
uint8_t last_status[3 ];
218
234
protected:
219
235
uint8_t match[1 ] ={ 0x58 }; // same as fw main.c
You can’t perform that action at this time.
0 commit comments