File tree 1 file changed +19
-3
lines changed
1 file changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -166,12 +166,21 @@ class ModulinoJoystick : public Module {
166
166
bool update () {
167
167
uint8_t buf[3 ];
168
168
auto res = read ((uint8_t *)buf, 3 );
169
- auto ret = res && (buf[0 ] != last_status[0 ] || buf[1 ] != last_status[1 ] || buf[2 ] != last_status[2 ]);
170
- last_status[0 ] = buf[0 ];
171
- last_status[1 ] = buf[1 ];
169
+ auto x = buf[0 ];
170
+ auto y = buf[1 ];
171
+ map_value (x, y);
172
+ auto ret = res && (x != last_status[0 ] || buf[1 ] != y || buf[2 ] != last_status[2 ]);
173
+ if (!ret) {
174
+ return false ;
175
+ }
176
+ last_status[0 ] = x;
177
+ last_status[1 ] = y;
172
178
last_status[2 ] = buf[2 ];
173
179
return ret;
174
180
}
181
+ void setDeadZone (uint8_t dz_th) {
182
+ _dz_threshold = dz_th;
183
+ }
175
184
PinStatus isPressed () {
176
185
return last_status[2 ] ? HIGH : LOW;
177
186
}
@@ -189,7 +198,14 @@ class ModulinoJoystick : public Module {
189
198
}
190
199
return 0xFF ;
191
200
}
201
+ void map_value (uint8_t &x, uint8_t &y) {
202
+ if (x > 128 - _dz_threshold && x < 128 + _dz_threshold && y > 128 - _dz_threshold && y < 128 + _dz_threshold) {
203
+ x = 128 ;
204
+ y = 128 ;
205
+ }
206
+ }
192
207
private:
208
+ uint8_t _dz_threshold = 26 ;
193
209
uint8_t last_status[3 ];
194
210
protected:
195
211
uint8_t match[1 ] ={ 0x58 }; // same as fw main.c
You can’t perform that action at this time.
0 commit comments