Commit 62d68f63 authored by Antoine Lima's avatar Antoine Lima

Fixed crashing bug when not on rasp

parent b731184c
......@@ -103,4 +103,4 @@ For the time being, those are provided by the PI camera module.
## Todo
* [ ] Filter serial ports to get arduinos or specific serial id
* [ ] Add the possibility to stop the replay mid-video by pushing any button
......@@ -9,7 +9,11 @@ Created on Wed Apr 18 18:34:40 2018
import logging
import pyautogui # PyPi library
from threading import Thread
import RPi.GPIO as GPIO
from main import OnRasp
if OnRasp:
import RPi.GPIO as GPIO
from player import Side
......@@ -27,21 +31,23 @@ class GPIOThread(Thread):
Thread.__init__(self)
self.dispatcher = dispatcher
self.continueRunning = True
if OnRasp:
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
for pin in GPIOThread._keyButtonBindings.keys():
print(pin)
GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(pin, GPIO.RISING, callback=self.handleButtonPress)
for pin in GPIOThread._keyButtonBindings.keys():
print(pin)
GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(pin, GPIO.RISING, callback=self.handleButtonPress)
def run(self):
try:
while self.continueRunning:
pass
finally:
GPIOThread.clean()
if OnRasp:
try:
while self.continueRunning:
pass
finally:
GPIOThread.clean()
def handleButtonPress(self, button_pin):
if button_pin not in GPIOThread._keyButtonBindings.keys():
......@@ -56,4 +62,5 @@ class GPIOThread(Thread):
@staticmethod
def clean():
GPIO.cleanup()
if OnRasp:
GPIO.cleanup()
......@@ -6,6 +6,9 @@ Created on Wed Apr 18 18:34:40 2018
@author: Antoine Lima, Leo Reynaert, Domitille Jehenne
"""
import os
OnRasp = os.uname()[1] == 'raspberrypi'
import sys
import logging
import threading
......
......@@ -6,15 +6,12 @@ Created on Wed Apr 18 18:34:40 2018
@author: Antoine Lima, Leo Reynaert, Domitille Jehenne
"""
import os
from threading import Thread, Event
from main import MainWin
from main import MainWin, OnRasp
from settings import Settings
onRasp = os.uname()[1] == 'raspberrypi'
if onRasp:
if OnRasp:
import picamera
class Replay(Thread):
......@@ -27,7 +24,7 @@ class Replay(Thread):
self.stop_flag = Event()
self.stopped_flag = Event()
if onRasp:
if OnRasp:
self.cam = picamera.PiCamera()
self.cam.resolution = Settings['picam.resolution']
self.cam.framerate = Settings['picam.fps']
......@@ -36,14 +33,15 @@ class Replay(Thread):
self.stream = picamera.PiCameraCircularIO(self.cam, seconds=Settings['replay.duration'])
def start_recording(self):
if onRasp:
if OnRasp:
self.start_flag.set()
def stop_recording(self):
if onRasp:
if OnRasp:
self.stop_flag.set()
self.stopped_flag.wait()
# Clear all control flags
self.stop_flag.clear()
self.start_flag.clear()
self.stopped_flag.clear()
......@@ -69,6 +67,8 @@ class Replay(Thread):
self.stream.copy_to(self.replayPath)
self.stream.clear()
# Set this flag to tell the calling thread that replay is saved
self.stopped_flag.set()
self.cam.close()
......@@ -76,4 +76,4 @@ class Replay(Thread):
@staticmethod
def isCamAvailable():
return onRasp # and other checks (ToDo)
return OnRasp # and other checks (ToDo)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment