File tree 1 file changed +14
-2
lines changed
1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -167,11 +167,17 @@ class ModulinoJoystick : public Module {
167
167
uint8_t buf[3 ];
168
168
auto res = read ((uint8_t *)buf, 3 );
169
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 ];
170
+ auto x = buf[0 ];
171
+ auto y = buf[1 ];
172
+ map_value (x, y);
173
+ last_status[0 ] = x;
174
+ last_status[1 ] = y;
172
175
last_status[2 ] = buf[2 ];
173
176
return ret;
174
177
}
178
+ void setDeadZone (uint8_t dz_th) {
179
+ _dz_threshold = dz_th;
180
+ }
175
181
PinStatus isPressed () {
176
182
return last_status[2 ] ? HIGH : LOW;
177
183
}
@@ -189,6 +195,12 @@ class ModulinoJoystick : public Module {
189
195
}
190
196
return 0xFF ;
191
197
}
198
+ void map_value (uint8_t &x, uint8_t &y) {
199
+ if (x > 128 - _dz_threshold && x < 128 + _dz_threshold && y > 128 - _dz_threshold && y < 128 + _dz_threshold) {
200
+ x = 128 ;
201
+ y = 128 ;
202
+ }
203
+ }
192
204
private:
193
205
uint8_t last_status[3 ];
194
206
protected:
You can’t perform that action at this time.
0 commit comments