-
Notifications
You must be signed in to change notification settings - Fork 0
/
phone.py
57 lines (47 loc) · 1.05 KB
/
phone.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
import os
import requests
import sys
import subprocess
import time
import RPi.GPIO as GPIO
INPUT_PIN = 27
OUTPUT_PIN = 21
RING = False
TIMER = 0
RINGTIMER = 0
def mute():
subprocess.Popen(['amixer -c 1 sset Mic nocap'], shell=True, stdout=subprocess.PIPE)
def unmute():
subprocess.Popen(['amixer -c 1 sset Mic cap'], shell=True, stdout=subprocess.PIPE )
if __name__ == '__main__':
GPIO.setmode(GPIO.BCM)
GPIO.setup(INPUT_PIN, GPIO.IN)
GPIO.setup(OUTPUT_PIN, GPIO.OUT)
GPIO.output(OUTPUT_PIN, 0)
while True:
HORN_LIFTED = not GPIO.input(INPUT_PIN)
if HORN_LIFTED:
unmute()
else:
mute()
if HORN_LIFTED:
if RINGTIMER == 0:
try:
r = requests.get("http://192.168.0.1:4567/?ring")
except requests.exceptions.RequestException as e:
m = 0 # do nothing
RINGTIMER += 1
if RINGTIMER > 6:
RINGTIMER = 0
if TIMER > 6:
TIMER = 0
RING = False
GPIO.output(OUTPUT_PIN, 0)
if os.path.exists('ring'):
RING = True
TIMER = 0
os.remove('ring')
if RING:
GPIO.output(OUTPUT_PIN, 1)
TIMER += 1
time.sleep(0.5)