Add configurable mouse movement and improve HID handling

This commit is contained in:
2026-08-26 20:52:20 +02:00
parent 2a0869743f
commit be37343ec1
6 changed files with 48 additions and 29 deletions
+17 -9
View File
@@ -54,8 +54,10 @@ def ip_address(wlan):
def main():
settings = load()
display = StatusDisplay()
display.update(settings["wifi_ssid"])
display = None
if settings["display_enabled"]:
display = StatusDisplay()
display.update(settings["wifi_ssid"])
hid = get_hid()
wlan = connect_wifi(settings)
volume_requests = []
@@ -72,7 +74,9 @@ def main():
next_mouse = choose_due(now, settings["mouse_min_seconds"], settings["mouse_max_seconds"])
release_at = None
consumer_release_at = None
next_wifi_retry = now
# connect_wifi() already started the first attempt; do not call connect()
# again while the ESP32 station is still in STAT_CONNECTING state.
next_wifi_retry = time.ticks_add(now, 10000)
next_display_refresh = now
while True:
@@ -80,11 +84,13 @@ def main():
server.poll()
# Reconnect without blocking injections or the web server indefinitely.
if not wlan.isconnected() and time.ticks_diff(now, next_wifi_retry) >= 0:
if (not wlan.isconnected() and
time.ticks_diff(now, next_wifi_retry) >= 0 and
wlan.status() != network.STAT_CONNECTING):
wlan.connect(settings["wifi_ssid"], settings["wifi_password"])
next_wifi_retry = time.ticks_add(now, 10000)
if time.ticks_diff(now, next_display_refresh) >= 0:
if display is not None and time.ticks_diff(now, next_display_refresh) >= 0:
address = ip_address(wlan) if wlan.isconnected() else None
display.update(settings["wifi_ssid"], address)
next_display_refresh = time.ticks_add(now, 1000)
@@ -115,10 +121,11 @@ def main():
if (settings["enabled"] and settings["mouse_enabled"] and
time.ticks_diff(now, next_mouse) >= 0):
# Never send (0, 0), so each scheduled jitter is observable.
x = randint(-1, 1)
y = randint(-1, 1)
distance = settings["mouse_distance"]
x = randint(-distance, distance)
y = randint(-distance, distance)
if x == 0 and y == 0:
x = 1
x = distance
hid.move(x, y)
next_mouse = choose_due(
now, settings["mouse_min_seconds"], settings["mouse_max_seconds"]
@@ -128,4 +135,5 @@ def main():
time.sleep_ms(25)
main()
if __name__ == "__main__":
main()