-
Notifications
You must be signed in to change notification settings - Fork 0
/
reset_pomodoro.py
50 lines (41 loc) · 1.31 KB
/
reset_pomodoro.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
import signal
import RPi.GPIO as GPIO
import os
from tinkycare import run_tinky_care
from clear import clear_inky
from pathlib import Path
import contextlib
import json
from datetime import datetime as dt
PATH = os.path.dirname(os.path.abspath(__file__))
BUTTONS = [5, 6, 16, 24]
LABELS = ['A', 'B', 'C', 'D']
GPIO.setmode(GPIO.BCM)
GPIO.setup(BUTTONS, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def handle_button(pin):
label = LABELS[BUTTONS.index(pin)]
status_file = Path(PATH + '/assets/status.json')
if label == 'A':
with open(status_file, 'r') as file:
data = json.load(file)
data['reset'] = True
data['pomodoro_mode'] = True
data['start_time'] = int(dt.utcnow().timestamp()) % 86400
with open(status_file, 'w') as file:
json.dump(data, file)
run_tinky_care()
if label == 'D':
clear_inky()
if label == 'C':
# cancel pomodoro mode
with open(status_file, 'r') as file:
data = json.load(file)
data['reset'] = True
data['pomodoro_mode'] = False
with open(status_file, 'w') as file:
json.dump(data, file)
run_tinky_care()
return
for pin in BUTTONS:
GPIO.add_event_detect(pin, GPIO.FALLING, handle_button, bouncetime=250)
signal.pause()