commit 71fd1d0f02e20b5aad6fc72a1681d337b02f8583
parent 4c0c4414778fd90e5c053ab6fc9cc969d14adb3c
Author: rbckman <robinbackman@gmail.com>
Date: Thu, 19 Jan 2017 08:55:10 +0000
mcp23017 buttons2
Diffstat:
11 files changed, 178 insertions(+), 22 deletions(-)
diff --git a/random/alsaout.wav b/random/alsaout.wav
Binary files differ.
diff --git a/random/audiosync.py b/random/audiosync.py
@@ -0,0 +1,39 @@
+#!/bin/env python
+
+import os
+import time
+import sys
+import subprocess
+
+pipe = subprocess.Popen('mediainfo --Inform="Video;%Duration%" test.mp4', shell=True, stdout=subprocess.PIPE).stdout
+videolenght = pipe.read()
+pipe = subprocess.Popen('mediainfo --Inform="Audio;%Duration%" test.wav', shell=True, stdout=subprocess.PIPE).stdout
+audiolenght = pipe.read()
+print "Videolenght: " + videolenght
+print "Audiolenght: " + audiolenght
+
+videoms = int(videolenght) % 1000
+audioms = int(audiolenght) % 1000
+
+print videoms
+print audioms
+
+videos = int(videolenght) / 1000
+audios = int(audiolenght) / 1000
+
+print 'Video is ' + str(videos) + ' sec and ' + str(videoms) + ' ms long'
+print 'Audio is ' + str(audios) + ' sec and ' + str(audioms) + ' ms long'
+
+audiosyncs = videos - audios
+audiosyncms = videoms - audioms
+
+if audiosyncms < 0:
+ audiosyncs = audiosyncs - 1
+ audiosyncms = 1000 + audiosyncms
+
+print "Difference: " + str(audiosyncs) + " s " + str(audiosyncms) + " ms"
+
+os.system('sox -n -r 44100 -c 1 silence.wav trim 0.0 ' + str(audiosyncs) + '.' + str(audiosyncms))
+
+#os.system('mediainfo --Inform="Video;%Duration%" scene10.mp4')
+#os.system('mediainfo --Inform="Audio;%Duration%" scene10.wav')
diff --git a/random/i2cbuttons.py b/random/i2cbuttons.py
@@ -0,0 +1,31 @@
+import wiringpi
+from time import sleep
+
+pin_base = 65 # lowest available starting number is 65
+i2c_addr = 0x20 # A0, A1, A2 pins all wired to GND
+
+wiringpi.wiringPiSetup() # initialise wiringpi
+wiringpi.mcp23017Setup(pin_base,i2c_addr) # set up the pins and i2c address
+
+wiringpi.pinMode(80, 0) # sets GPB7 to input
+wiringpi.pinMode(79, 0) # sets GPB7 to input
+wiringpi.pinMode(78, 0) # sets GPB7 to input
+wiringpi.pinMode(77, 0) # sets GPB7 to input
+wiringpi.pullUpDnControl(80, 2) # set internal pull-up
+wiringpi.pullUpDnControl(79, 2) # set internal pull-up
+wiringpi.pullUpDnControl(78, 2) # set internal pull-up
+wiringpi.pullUpDnControl(77, 2) # set internal pull-up
+
+# Note: MCP23017 has no internal pull-down, so I used pull-up and inverted
+# the button reading logic with a "not"
+
+try:
+ while True:
+ if not wiringpi.digitalRead(79): # inverted the logic as using pull-up
+ print "button is pressed!!" # sets port GPA1 to 1 (3V3, on)
+ else:
+ print "no buttons pressed" # sets port GPA1 to 0 (0V, off)
+ sleep(0.01)
+finally:
+ print "fuck" # sets port GPA1 to 0 (0V, off)
+ # GPB7 is already an input, so no need to change anything
diff --git a/random/i2cpython.py b/random/i2cpython.py
@@ -0,0 +1,21 @@
+import smbus
+import time
+
+bus = smbus.SMBus(1) # Rev 2 Pi uses 1
+
+DEVICE = 0x20 # Device address (A0-A2)
+IODIRA = 0x00 # Pin direction register
+GPIOA = 0x12 # Register for inputs
+
+# Set first 7 GPA pins as outputs and
+# last one as input.
+bus.write_byte_data(DEVICE,IODIRA,0x80)
+
+# Loop until user presses CTRL-C
+while True:
+ # Read state of GPIOA register
+ MySwitch = bus.read_byte_data(DEVICE,GPIOA)
+
+ if MySwitch & 0b10000000 == 0b10000000:
+ print "Switch was pressed!"
+ time.sleep(1)
diff --git a/random/mcp23017_inputs.py b/random/mcp23017_inputs.py
@@ -0,0 +1,18 @@
+import smbus
+import time
+
+#bus = smbus.SMBus(0) # Rev 1 Pi uses 0
+bus = smbus.SMBus(3) # Rev 2 Pi uses 1
+
+DEVICE = 0x20 # Device address (A0-A2)
+IODIRB = 0x0d # Pin direction register
+GPIOB = 0x13 # Register for inputs
+
+bus.write_byte_data(DEVICE,IODIRB,0xFF) # set all gpiob to input
+
+# Loop until user presses CTRL-C
+while True:
+ # Read state of GPIOA register
+ readbus = bus.read_byte_data(DEVICE,GPIOB)
+ print readbus
+ time.sleep(0.1)
diff --git a/random/robsi2cbuttons.py b/random/robsi2cbuttons.py
@@ -0,0 +1,34 @@
+import smbus
+import time
+
+#bus = smbus.SMBus(0) # Rev 1 Pi uses 0
+bus = smbus.SMBus(3) # Rev 2 Pi uses 1
+
+DEVICE = 0x20 # Device address (A0-A2)
+IODIRB = 0x0d # Pin pullups B-side
+GPIOB = 0x13 # Register B-side for inputs
+
+bus.write_byte_data(DEVICE,IODIRB,0xFF) # set all gpiob to input
+
+# Loop until user presses CTRL-C
+while True:
+ # Read state of GPIOA register
+ readbus = bus.read_byte_data(DEVICE,GPIOB)
+ if readbus == 239:
+ print "right"
+ elif readbus == 247:
+ print "left"
+ elif readbus == 191:
+ print "down"
+ elif readbus == 254:
+ print "up"
+ elif readbus == 251:
+ print "rightup"
+ elif readbus == 253:
+ print "leftup"
+ elif readbus == 223:
+ print "leftdown"
+ elif readbus == 127:
+ print "rightdown"
+ print readbus
+ time.sleep(0.1)
diff --git a/random/stream.sh b/random/stream.sh
@@ -0,0 +1,3 @@
+[ -d /tmp/capture ] || mkdir /tmp/capture; rm -f /tmp/capture/* && cd /tmp/capture/ && \
+raspivid -ih -t 0 -w 1280 -h 720 -b 1000000 -pf baseline -o - | /usr/bin/avconv -f alsa -ac 1 -i hw:0 -acodec aac -strict -2 \
+-i - -vcodec copy -f segment -segment_list out.list out%10d
diff --git a/splash.png b/splash.png
Binary files differ.
diff --git a/tarina.py b/tarina.py
@@ -12,6 +12,13 @@ import cPickle as pickle
import curses
import RPi.GPIO as GPIO
from PIL import Image
+import smbus
+
+bus = smbus.SMBus(3) # Rev 2 Pi uses 1
+DEVICE = 0x20 # Device address (A0-A2)
+IODIRB = 0x0d # Pin direction register
+GPIOB = 0x13 # Register for inputs
+bus.write_byte_data(DEVICE,IODIRB,0xFF) # set all gpiob to input
#GPIO.setmode(GPIO.BCM)
#GPIO.setup(1, GPIO.OUT)
@@ -924,28 +931,31 @@ def empty(filename):
def getbutton(lastbutton, buttonpressed, buttontime, holdbutton):
event = screen.getch()
+ readbus = bus.read_byte_data(DEVICE,GPIOB)
pressed = ''
#middlebutton = GPIO.input(22)
#upbutton = GPIO.input(12)
#downbutton = GPIO.input(13)
#leftbutton = GPIO.input(16)
#rightbutton = GPIO.input(26)
- if event == 27:
- pressed = 'quit'
- elif event == curses.KEY_ENTER or event == 10 or event == 13:
- pressed = 'middle'
- elif event == ord('w') or event == curses.KEY_UP:
- pressed = 'up'
- elif event == ord('s') or event == curses.KEY_DOWN:
- pressed = 'down'
- elif event == ord('a') or event == curses.KEY_LEFT:
- pressed = 'left'
- elif event == ord('d') or event == curses.KEY_RIGHT:
- pressed = 'right'
- #elif middlebutton == False:
- # pressed = 'middle'
- buttontime = time.time()
- holdbutton = pressed
+ if buttonpressed == False:
+ if event == 27:
+ pressed = 'quit'
+ elif event == curses.KEY_ENTER or event == 10 or event == 13 or readbus == 247:
+ pressed = 'middle'
+ elif event == ord('w') or event == curses.KEY_UP or readbus == 191:
+ pressed = 'up'
+ elif event == ord('s') or event == curses.KEY_DOWN or readbus == 254:
+ pressed = 'down'
+ elif event == ord('a') or event == curses.KEY_LEFT or readbus == 239:
+ pressed = 'left'
+ elif event == ord('d') or event == curses.KEY_RIGHT or readbus == 251:
+ pressed = 'right'
+ buttonpressed = True
+ buttontime = time.time()
+ holdbutton = pressed
+ if readbus == 255:
+ buttonpressed = False
if float(time.time() - buttontime) > 1.0 and buttonpressed == True:
pressed = holdbutton
return pressed, buttonpressed, buttontime, holdbutton
@@ -1111,8 +1121,8 @@ def main():
time.sleep(0.1)
recording = True
#camera.led = True
- #camera.start_recording(foldername + filename + '.h264', format='h264', quality=20)
- camera.start_recording('/dev/shm/' + filename + '.h264', format='h264', quality=16)
+ camera.start_recording(foldername + filename + '.h264', format='h264', quality=20)
+ #camera.start_recording('/dev/shm/' + filename + '.h264', format='h264', quality=16)
os.system(tarinafolder + '/alsa-utils-1.0.25/aplay/arecord -f S16_LE -c 1 -r 44100 -vv /dev/shm/' + filename + '.wav &')
starttime = time.time()
#camera.wait_recording(10)
@@ -1128,8 +1138,8 @@ def main():
showrec = ''
vumetermessage('Tarina ' + tarinaversion[:-1] + ' ' + tarinavername[:-1])
thefile = foldername + filename
- writemessage('Copying video file...')
- os.system('mv /dev/shm/' + filename + '.h264 ' + foldername)
+ #writemessage('Copying video file...')
+ #os.system('mv /dev/shm/' + filename + '.h264 ' + foldername)
compileshot(foldername + filename)
audiodelay(foldername,filename)
try:
@@ -1467,7 +1477,7 @@ def main():
writemenu(menu,settings,selected,header)
#writemessage(pressed)
rendermenu = False
- time.sleep(0.02)
+ time.sleep(0.05)
if __name__ == '__main__':
import sys
try:
diff --git a/vc/src/hello_pi/hello_interface/camerainterface.bin b/vc/src/hello_pi/hello_interface/camerainterface.bin
Binary files differ.
diff --git a/vc/src/hello_pi/hello_interface/main.c b/vc/src/hello_pi/hello_interface/main.c
@@ -109,7 +109,7 @@ int main(void)
graphics_display_resource(img, 0, LAYER, 0, 0, GRAPHICS_RESOURCE_WIDTH, GRAPHICS_RESOURCE_HEIGHT, VC_DISPMAN_ROT0, 1);
- uint32_t text_size = 22;
+ uint32_t text_size = 20;
char text[63];
char text2[63];
char text3[63];