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 @@ -189,12 +189,21 @@ class ModulinoJoystick : public Module {
189189 bool update () {
190190 uint8_t buf[3 ];
191191 auto res = read ((uint8_t *)buf, 3 );
192- auto ret = res && (buf[0 ] != last_status[0 ] || buf[1 ] != last_status[1 ] || buf[2 ] != last_status[2 ]);
193- last_status[0 ] = buf[0 ];
194- last_status[1 ] = buf[1 ];
192+ auto x = buf[0 ];
193+ auto y = buf[1 ];
194+ map_value (x, y);
195+ auto ret = res && (x != last_status[0 ] || y != last_status[1 ] || buf[2 ] != last_status[2 ]);
196+ if (!ret) {
197+ return false ;
198+ }
199+ last_status[0 ] = x;
200+ last_status[1 ] = y;
195201 last_status[2 ] = buf[2 ];
196202 return ret;
197203 }
204+ void setDeadZone (uint8_t dz_th) {
205+ _dz_threshold = dz_th;
206+ }
198207 PinStatus isPressed () {
199208 return last_status[2 ] ? HIGH : LOW;
200209 }
@@ -212,7 +221,14 @@ class ModulinoJoystick : public Module {
212221 }
213222 return 0xFF ;
214223 }
224+ void map_value (uint8_t &x, uint8_t &y) {
225+ if (x > 128 - _dz_threshold && x < 128 + _dz_threshold && y > 128 - _dz_threshold && y < 128 + _dz_threshold) {
226+ x = 128 ;
227+ y = 128 ;
228+ }
229+ }
215230private:
231+ uint8_t _dz_threshold = 26 ;
216232 uint8_t last_status[3 ];
217233protected:
218234 uint8_t match[1 ] = { 0x58 }; // same as fw main.c
You can’t perform that action at this time.
0 commit comments