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 {
190190 bool update () {
191191 uint8_t buf[3 ];
192192 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;
196202 last_status[2 ] = buf[2 ];
197203 return ret;
198204 }
205+ void setDeadZone (uint8_t dz_th) {
206+ _dz_threshold = dz_th;
207+ }
199208 PinStatus isPressed () {
200209 return last_status[2 ] ? HIGH : LOW;
201210 }
@@ -213,7 +222,14 @@ class ModulinoJoystick : public Module {
213222 }
214223 return 0xFF ;
215224 }
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+ }
216231private:
232+ uint8_t _dz_threshold = 26 ;
217233 uint8_t last_status[3 ];
218234protected:
219235 uint8_t match[1 ] ={ 0x58 }; // same as fw main.c
You can’t perform that action at this time.
0 commit comments