-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbutton_daemon.py
More file actions
executable file
·39 lines (33 loc) · 1.16 KB
/
button_daemon.py
File metadata and controls
executable file
·39 lines (33 loc) · 1.16 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
#!/usr/bin/python3
##simple example of polling one button and taking an action if it is held down.
import libmicon
import os
import time
press_time=2
poll_speed=0.5 ##currently this is fast as we can reliably poll
button_num=1 ##buttons are each a power of 2, "1" is power button on most ARM devices
tickcnt=0
while True:
test = libmicon.micon_api("/dev/ttyS1")
state=int.from_bytes(test.send_read_cmd(0x36),byteorder="big") & button_num
##power button on ts3400 0=pressed, 1=not pressed
##if button held down start counting
if state == 0:
tickcnt=tickcnt +1
if tickcnt > (press_time/poll_speed):
test.set_lcd_buffer(0x90,"Shutting Down!!"," ")
test.cmd_force_lcd_disp(libmicon.lcd_disp_buffer0)
test.send_write_cmd(1,libmicon.lcd_set_dispitem,0x20)
test.set_lcd_color(libmicon.LCD_COLOR_RED)
test.set_lcd_brightness(libmicon.LCD_BRIGHT_FULL)
test.cmd_sound(libmicon.BZ_MUSIC1)
test.port.close() ##if we do something other than shutdown we'd probably skip this
os.system('shutdown -h 0')
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()