commit ae19b1bf9f09c495296c3fea27d8c679e4d1a28c
parent 6f29bfeea9aa2254f41d66eb6df40a4e2f23dbe7
Author: rbckman <robinbackman@gmail.com>
Date: Mon, 6 Mar 2017 13:58:38 +0000
shutdown feature
Diffstat:
2 files changed, 35 insertions(+), 20 deletions(-)
diff --git a/random/robsi2cbuttons.py b/random/robsi2cbuttons.py
@@ -10,14 +10,16 @@ bus = smbus.SMBus(3) # Rev 2 Pi uses 1
DEVICE = 0x20 # Device address (A0-A2)
IODIRB = 0x0d # Pin pullups B-side
-IODIRA = 0x0c # Pin pullups B-side
+IODIRA = 0x00 # Pin pullups A-side 0x0c
+IODIRApullup = 0x0c # Pin pullups A-side 0x0c
GPIOB = 0x13 # Register B-side for inputs
GPIOA = 0x12 # Register A-side for inputs
OLATA = 0x14 # Register for outputs
bus.write_byte_data(DEVICE,IODIRB,0xFF) # set all gpiob to input
-bus.write_byte_data(DEVICE,IODIRA,0xCF) # set two inputs and two outputs
-bus.write_byte_data(DEVICE,OLATA,0x20)
+bus.write_byte_data(DEVICE,IODIRApullup,0xF3) # set two pullup inputs and two outputs
+bus.write_byte_data(DEVICE,IODIRA,0xF3) # set two inputs and two outputs
+bus.write_byte_data(DEVICE,OLATA,0x4)
# Loop until user presses CTRL-C
while True:
@@ -40,16 +42,17 @@ while True:
print "leftdown"
elif readbus == 127:
print "rightdown"
- elif readbus2 == 236:
+ elif readbus2 == 244:
print "remove"
- elif readbus2 == 231:
+ elif readbus2 == 247:
print "shutdown"
- bus.write_byte_data(DEVICE,OLATA,0x0)
+ bus.write_byte_data(DEVICE,OLATA,0)
os.system('sudo shutdown -h now')
time.sleep(15)
print readbus
print readbus2
- bus.write_byte_data(DEVICE,OLATA,0x30)
- time.sleep(0.001)
+ bus.write_byte_data(DEVICE,OLATA,0xC)
+ time.sleep(1)
os.system('clear')
- bus.write_byte_data(DEVICE,OLATA,0x20)
+ bus.write_byte_data(DEVICE,OLATA,0x4)
+ time.sleep(1)
diff --git a/tarina.py b/tarina.py
@@ -16,14 +16,17 @@ import smbus
bus = smbus.SMBus(3) # Rev 2 Pi uses 1
DEVICE = 0x20 # Device address (A0-A2)
-IODIRB = 0x0d # Pin direction register, pull-up enabled
-IODIRA = 0x0c # Pin direction register, pull-up enabled
-GPIOB = 0x13 # Register for inputs
-GPIOA = 0x12 # Register for inputs
+IODIRB = 0x0d # Pin pullups B-side
+IODIRA = 0x00 # Pin pullups A-side 0x0c
+IODIRApullup = 0x0c # Pin pullups A-side 0x0c
+GPIOB = 0x13 # Register B-side for inputs
+GPIOA = 0x12 # Register A-side for inputs
OLATA = 0x14 # Register for outputs
-bus.write_byte_data(DEVICE,IODIRB,0xFF) # set all gpiob to input with intern pull-up enabled
-bus.write_byte_data(DEVICE,IODIRA,0xCF) # set gpioa to input with intern pull-up enabled
-bus.write_byte_data(DEVICE,OLATA,0x20)
+bus.write_byte_data(DEVICE,IODIRB,0xFF) # set all gpiob to input
+bus.write_byte_data(DEVICE,IODIRApullup,0xF3) # set two pullup inputs and two outputs
+bus.write_byte_data(DEVICE,IODIRA,0xF3) # set two inputs and two outputs
+bus.write_byte_data(DEVICE,OLATA,0x4)
+
#GPIO.setmode(GPIO.BCM)
#GPIO.setup(1, GPIO.OUT)
#GPIO.setup(18, GPIO.OUT)
@@ -932,7 +935,7 @@ def buzzer(beeps):
while beeps > 1:
buzzerdelay = 0.0001
for _ in xrange(buzzerrepetitions):
- for value in [0x20, 0x30]:
+ for value in [0xC, 0x4]:
#GPIO.output(1, value)
bus.write_byte_data(DEVICE,OLATA,value)
time.sleep(buzzerdelay)
@@ -940,12 +943,12 @@ def buzzer(beeps):
beeps = beeps - 1
buzzerdelay = 0.0001
for _ in xrange(buzzerrepetitions * 10):
- for value in [0x20, 0x30]:
+ for value in [0xC, 0x4]:
#GPIO.output(1, value)
bus.write_byte_data(DEVICE,OLATA,value)
buzzerdelay = buzzerdelay - 0.00000004
time.sleep(buzzerdelay)
- bus.write_byte_data(DEVICE,OLATA,0x20)
+ bus.write_byte_data(DEVICE,OLATA,0x4)
#-------------Check if file empty----------
@@ -988,8 +991,10 @@ def getbutton(lastbutton, buttonpressed, buttontime, holdbutton):
pressed = 'retake'
elif event == ord('q') or readbus == 223:
pressed = 'view'
- elif event == ord('z') or readbus2 == 206:
+ elif event == ord('z') or readbus2 == 244:
pressed = 'delete'
+ elif readbus2 == 247:
+ pressed = 'shutdown'
buttonpressed = True
buttontime = time.time()
holdbutton = pressed
@@ -1148,6 +1153,13 @@ def main():
else:
backlight = True
+ #SHUTDOWN
+ elif pressed == 'shutdown':
+ time.sleep(0.1)
+ if recording == False:
+ bus.write_byte_data(DEVICE,OLATA,0)
+ os.system('shutdown -h now')
+
#RECORD AND PAUSE
elif pressed == 'record' or pressed == 'retake' or reclenght != 0 and t > reclenght or t > 800:
overlay = removeimage(camera, overlay)