Skip to content

Commit

Permalink
[python] Slow down keydown
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixNumworks committed Jan 3, 2024
1 parent 1a643c5 commit 1b47415
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions python/port/mod/ion/modion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ mp_obj_t modion_keyboard_keydown(mp_obj_t key_o) {
if (key >= Ion::Keyboard::Key::None) {
return mp_obj_new_bool(false);
}
/* In version 22, scan was greatly sped up. We wait 1 ms after the scan to
* keep the keydown function consistent with older versions.
* WARNING: Do not use Timing::msleep to avoid putting the device to sleep,
* which alters timings (mostly on N120) */
uint64_t currentTime = Ion::Timing::millis();
Ion::Keyboard::State state = Ion::Keyboard::scan();
while (currentTime + 1 > Ion::Timing::millis()) {}
micropython_port_interrupt_if_needed();
return mp_obj_new_bool(state.keyDown(key));
}

0 comments on commit 1b47415

Please sign in to comment.