File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Expand file tree Collapse file tree 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 {
167167 uint8_t buf[3 ];
168168 auto res = read ((uint8_t *)buf, 3 );
169169 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;
172175 last_status[2 ] = buf[2 ];
173176 return ret;
174177 }
178+ void setDeadZone (uint8_t dz_th) {
179+ _dz_threshold = dz_th;
180+ }
175181 PinStatus isPressed () {
176182 return last_status[2 ] ? HIGH : LOW;
177183 }
@@ -189,6 +195,12 @@ class ModulinoJoystick : public Module {
189195 }
190196 return 0xFF ;
191197 }
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+ }
192204private:
193205 uint8_t last_status[3 ];
194206protected:
You can’t perform that action at this time.
0 commit comments