summaryrefslogtreecommitdiff
path: root/src/macros/4-move_mouse.py
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@dailly.me>2023-05-22 08:40:47 +0200
committerSébastien Dailly <sebastien@dailly.me>2023-05-22 08:40:47 +0200
commit597b007333d8ec0d9cfd29e6941fcbe57379108a (patch)
tree0cf87e1ac487e7deb91acf7f2bec70bd4dd06703 /src/macros/4-move_mouse.py
Initial commit
Diffstat (limited to 'src/macros/4-move_mouse.py')
-rw-r--r--src/macros/4-move_mouse.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/macros/4-move_mouse.py b/src/macros/4-move_mouse.py
new file mode 100644
index 0000000..ef6ede0
--- /dev/null
+++ b/src/macros/4-move_mouse.py
@@ -0,0 +1,54 @@
+import skeleton
+
+class Color(object):
+ """ Return a color which may change over time.
+ """
+ def __init__(self, code):
+ self.code = code
+
+ def __int__(self):
+ return self.code
+
+class NoIdle(object):
+
+ def __init__(self):
+ self.x = 10
+ self.color = Color(0x000500)
+ self.active = False
+
+ def update(self, macropad):
+ if not self.active:
+ return
+
+ self.x *= -1
+ macropad.mouse.move(
+ self.x,
+ 0,
+ 0)
+ # Update the color in red or blue in order to show that the heartbeat
+ # is active.
+ self.color.code = 0x010000 if self.x > 0 else 0x000001
+ macropad.pixels[4] = int(self.color)
+ macropad.pixels.show()
+
+ def pause(self, macropad, key, pressed):
+ if pressed:
+ self.active = not self.active
+ if self.active:
+ self.update(macropad)
+ else:
+ # Restore the default color (green)
+ self.color.code = 0x000500
+ macropad.pixels[4] = int(self.color)
+ macropad.pixels.show()
+
+
+def build_application():
+ configuration = skeleton.Configuration("NoIdle")
+ actor = NoIdle()
+ configuration.setTick(5000, actor.update)
+ configuration.registerKey(4, "switch", actor.pause, actor.color)
+ return configuration
+
+configuration = build_application()
+