This repository has been archived by the owner on Jun 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
switch.py
66 lines (60 loc) · 2.09 KB
/
switch.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
# -*- coding: utf-8 -*-
import time
import pigpio
from door import Door
import slack
import database
import subprocess
import led
class Switch:
switch_pin = 22
def __init__(self, pi, servo):
self.pi = pi
self.door = Door(pi)
self.time_old = time.time()
self.servo = servo
pi.set_mode(Switch.switch_pin, pigpio.INPUT)
pi.set_pull_up_down(Switch.switch_pin, pigpio.PUD_DOWN)
self._cb = pi.callback(Switch.switch_pin, pigpio.RISING_EDGE, self._cbf1)
def _cbf(self, gpio, level, tick):
if time.time() - self.time_old < 1:
return
else:
self.servo.open_lock()
database.button_info_insert()
slack.button()
time.sleep(5)
while self.door.door_status() == self.door.OPEN:
time.sleep(0.5)
self.servo.close_lock()
self.time_old = time.time()
def _cbf1(self, gpio, level, tick):
# 長押しでリスタートの機能追加版
if time.time() - self.time_old < 1:
return
else:
counter = 0
while True:
status = self.pi.read(Switch.switch_pin)
if status == 1:
counter += 1
if counter >= 60:
led.red_led_on()
led.green_led_on()
time.sleep(2)
led.green_led_off()
led.red_led_off()
self.time_old = time.time()
subprocess.Popen("sudo systemctl restart badegg.service", shell=True)
break
else:
self.servo.open_lock()
database.button_info_insert()
slack.button()
time.sleep(5)
while self.door.door_status() == self.door.OPEN:
time.sleep(0.5)
self.servo.close_lock()
self.time_old = time.time()
break
time.sleep(0.05)