forked from 1000001101000/Python_buffalo_libmicon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbutton_test.py
More file actions
executable file
·43 lines (34 loc) · 1.11 KB
/
button_test.py
File metadata and controls
executable file
·43 lines (34 loc) · 1.11 KB
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
#!/usr/bin/python3
##simple example of polling one button and taking an action if it is held down.
import libmicon, time
while True:
test = libmicon.micon_api("/dev/ttyS1")
state=int.from_bytes(test.send_read_cmd(0x36),byteorder="big")
##print button number
print(state)
test.port.close()
time.sleep(0.5)
quit()
"""What you could do is use this to read a simple number, for example, the TS-XL models, unpressed is 31, the power button is 30,
the function button is 29, display is 17 and the hidden reset button is 23.
You can use this to build a script using that code above,
import libmicon, time, os
press_time=0
poll_speed=0.5 ##currently this is fast as we can reliably poll
tickcnt=0
while True:
test = libmicon.micon_api("/dev/ttyS1")
state=int.from_bytes(test.send_read_cmd(0x36),byteorder="big")
##if button held down start counting
if state == 29:
tickcnt=tickcnt +1
if tickcnt > (press_time/poll_speed):
print("Function Button Pressed")
tickcnt=0
##reset counter if released
else:
tickcnt=0
test.port.close()
##currently this is fast as we can reliably poll
time.sleep(poll_speed)
quit()"""