-
Notifications
You must be signed in to change notification settings - Fork 0
/
zeiterfassung_raw.py
executable file
·73 lines (69 loc) · 2.17 KB
/
zeiterfassung_raw.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
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python
from datetime import datetime
import os
import pifacecad
cum_dt=datetime.utcnow()
go_dt=datetime.utcnow()
kommen_counter=0
kommen_flag=False
def calc_work_time(start,ende):
calc_time=ende-start
#if calc_time
return calc_time
def kommen(event):
global cum_dt
cum_dt=datetime.utcnow()
global kommen_flag
kommen_flag=True
global kommen_counter
kommen_counter+=1
event.chip.lcd.clear()
event.chip.lcd.set_cursor(0,0)
event.chip.lcd.write('Kommen saved!')
def gehen(event):
global go_dt
global cum_dt
global kommen_flag
event.chip.lcd.clear()
event.chip.lcd.set_cursor(0,0)
if kommen_flag:
go_dt=datetime.utcnow()
event.chip.lcd.write('Gehen saved!')
event.chip.lcd.set_cursor(0,1)
event.chip.lcd.write(str(calc_work_time(cum_dt,go_dt)))
kommen_flag=False
else:
event.chip.lcd.write('Noch nicht')
event.chip.lcd.set_cursor(0,1)
event.chip.lcd.write('eingestempelt!')
def calc(event):
event.chip.lcd.clear()
global cum_dt
global go_dt
event.chip.lcd.set_cursor(0,0)
if kommen_flag and kommen_counter>0:
event.chip.lcd.write('Aktuelle Zeit:')
event.chip.lcd.set_cursor(0,1)
event.chip.lcd.write(str(calc_work_time(cum_dt,datetime.utcnow())))
elif kommen_counter==0:
event.chip.lcd.write('Noch nicht')
event.chip.lcd.set_cursor(0,1)
event.chip.lcd.write('eingestempelt!')
else:
event.chip.lcd.write('Letzte Zeit war:')
event.chip.lcd.set_cursor(0,1)
event.chip.lcd.write(str(calc_work_time(cum_dt,go_dt)))
def clearit(event):
event.chip.lcd.clear()
cad = pifacecad.PiFaceCAD()
cad.lcd.clear()
cad.lcd.write('Willkommen zur')
cad.lcd.set_cursor(0,1)
cad.lcd.write('Zeiterfassung!')
listener = pifacecad.SwitchEventListener(chip=cad)
listener.register(0, pifacecad.IODIR_FALLING_EDGE, kommen)
listener.register(1, pifacecad.IODIR_FALLING_EDGE, calc)
listener.register(2, pifacecad.IODIR_FALLING_EDGE, gehen)
listener.register(3, pifacecad.IODIR_FALLING_EDGE, clearit)
#listener.register(4, pifacecad.IODIR_RISING_EDGE, os.system('sudo poweroff'))
listener.activate()