Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/Modulino.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,17 @@ class ModulinoJoystick : public Module {
uint8_t buf[3];
auto res = read((uint8_t*)buf, 3);
auto ret = res && (buf[0] != last_status[0] || buf[1] != last_status[1] || buf[2] != last_status[2]);
last_status[0] = buf[0];
last_status[1] = buf[1];
auto x = buf[0];
auto y = buf[1];
map_value(x, y);
last_status[0] = x;
last_status[1] = y;
last_status[2] = buf[2];
return ret;
}
void setDeadZone(uint8_t dz_th) {
_dz_threshold = dz_th;
}
PinStatus isPressed() {
return last_status[2] ? HIGH : LOW;
}
Expand All @@ -189,7 +195,14 @@ class ModulinoJoystick : public Module {
}
return 0xFF;
}
void map_value(uint8_t &x, uint8_t &y) {
if (x > 128 - _dz_threshold && x < 128 + _dz_threshold && y > 128 - _dz_threshold && y < 128 + _dz_threshold) {
x = 128;
y = 128;
}
}
private:
uint8_t _dz_threshold = 26;
uint8_t last_status[3];
protected:
uint8_t match[1] ={ 0x58 }; // same as fw main.c
Expand Down