-
Notifications
You must be signed in to change notification settings - Fork 14
/
speed-editor-demo.py
executable file
·63 lines (47 loc) · 1.66 KB
/
speed-editor-demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python3
# Copyright (C) 2021 Sylvain Munaut <[email protected]>
# SPDX-License-Identifier: Apache-2.0
from typing import List
from bmd import SpeedEditorKey, SpeedEditorLed, SpeedEditorJogLed, SpeedEditorJogMode, SpeedEditorHandler, SpeedEditor
class DemoHandler(SpeedEditorHandler):
JOG = {
SpeedEditorKey.SHTL: ( SpeedEditorJogLed.SHTL, SpeedEditorJogMode.RELATIVE_2 ),
SpeedEditorKey.JOG: ( SpeedEditorJogLed.JOG, SpeedEditorJogMode.ABSOLUTE_CONTINUOUS ),
SpeedEditorKey.SCRL: ( SpeedEditorJogLed.SCRL, SpeedEditorJogMode.ABSOLUTE_DEADZERO ),
}
def __init__(self, se):
self.se = se
self.keys = []
self.leds = 0
self.se.set_leds(self.leds)
self._set_jog_mode_for_key(SpeedEditorKey.SHTL)
def _set_jog_mode_for_key(self, key : SpeedEditorKey):
if key not in self.JOG:
return
self.se.set_jog_leds( self.JOG[key][0] )
self.se.set_jog_mode( self.JOG[key][1] )
def jog(self, mode : SpeedEditorJogMode, value):
print(f"Jog mode {mode:d} : {value:d}")
def key(self, keys : List[SpeedEditorKey]):
# Debug message
kl = ', '.join([k.name for k in keys])
if not kl:
kl = 'None'
print(f"Keys held: {kl:s}")
# Find keys being released and toggle led if there is one
for k in self.keys:
if k not in keys:
# Select jog mode
self._set_jog_mode_for_key(k)
# Toggle leds
self.leds ^= getattr(SpeedEditorLed, k.name, 0)
self.se.set_leds(self.leds)
self.keys = keys
def battery(self, charging : bool, level : int):
print(f"Battery {level:d} %{' and charging' if charging else '':s}")
if __name__ == '__main__':
se = SpeedEditor()
se.authenticate()
se.set_handler(DemoHandler(se))
while True:
se.poll()