This commit is contained in:
tilman
2016-12-28 08:41:34 +01:00
parent fec709d2ab
commit c70f3257f9
3 changed files with 57 additions and 1 deletions
+1 -1
View File
@@ -75,7 +75,7 @@ try:
logging.debug('Photo sensor active, activating light and camera')
subprocess.call(["mocp", "-l", SOUND_SCANNING])
# turn LED onGPIO.wait_for_edge(23, GPIO.FALLING)
# turn LED on
GPIO.output(27, GPIO.HIGH)
# scan QR code
+51
View File
@@ -0,0 +1,51 @@
import RPi.GPIO as GPIO
import time
import subprocess
import select # see http://stackoverflow.com/a/10759061/3761783
QR_SCANNER_TIMEOUT = 3
# photo sensor on PIN 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN)
# LED on PIN 27
GPIO.setup(27, GPIO.OUT)
GPIO.output(27, GPIO.LOW)
try:
print('Start QR scan test')
while True:
time.sleep(0.25)
if (GPIO.input(17) == GPIO.LOW):
#print('LOW')
GPIO.output(27, GPIO.LOW)
else:
print('Sensor active')
GPIO.output(27, GPIO.HIGH)
zbarcam = subprocess.Popen(['zbarcam', '--quiet', '--nodisplay', '--raw', '-Sdisable', '-Sqrcode.enable', '--prescale=320x240', '/dev/video0'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
poll_obj = select.poll()
poll_obj.register(zbarcam.stdout, select.POLLIN)
# wait for scan result (or timeout)
start_time = time.time()
poll_result = False
while ((time.time() - start_time) < QR_SCANNER_TIMEOUT and (not poll_result)):
poll_result = poll_obj.poll(100)
if (poll_result):
qr_code = zbarcam.stdout.readline().rstrip()
qr_code = qr_code.decode("utf-8") # python3
print("QR Code: {}".format(qr_code))
else:
print('Timeout on zbarcam')
zbarcam.terminate()
GPIO.output(27, GPIO.LOW)
except KeyboardInterrupt:
print('bye')
GPIO.cleanup()
+5
View File
@@ -61,6 +61,11 @@ python3 lighton.py
sudo fswebcam -r 320x240 -d /dev/video0 -v ~/test.jpg
python3 lightoff.py
# QR-Test
python3 lighton.py
zbarcam --quiet --nodisplay --raw -Sdisable -Sqrcode.enable --prescale=320x240 /dev/video0
python3 lightoff.py
# enable lirc in /boot/config.txt and add parameters
sudo nano /boot/config.txt