Commit d2dfdd6f authored by Antoine Lima's avatar Antoine Lima

Fixed a PiCam bug when it wasn't on the pi

parent 1776ccaa
......@@ -121,3 +121,10 @@ if __name__=='__main__':
#threadArduinoRight.stop()
threadArduinoLeft.join()
#threadArduinoRight.join()
if ReplayThread.isCamAvailable():
threadReplay = ReplayThread(Side.Left)
threadReplay.start()
myapp.dispatchMessage({'replayThread': threadReplay}, toType=GameModule)
if ReplayThread.isCamAvailable():
threadReplay.stop()
threadReplay.join()
......@@ -56,6 +56,8 @@ class GameModule(Module):
# Button connections
self.ui.btnScore1.clicked.connect(lambda: self.goal(Side.Left))
self.ui.btnScore2.clicked.connect(lambda: self.goal(Side.Right))
self.replayer = None
def load(self):
logging.debug('Loading GameModule')
......@@ -65,7 +67,8 @@ class GameModule(Module):
self.ui.lcdChrono.display(QTime(0,0).toString("hh:mm:ss"))
self.showingReplay = False
self.replayer.start_recording()
if self.replayer:
self.replayer.start_recording()
self.gameoverChecker = GameOverChecker('score', 10)
if all([len(val)==0 for val in self.players.values()]):
......@@ -79,7 +82,8 @@ class GameModule(Module):
logging.debug('Unloading GameModule')
del self.gameStartTime
self.timerUpdateChrono.stop()
self.replayer.stop_recording()
if self.replayer:
self.replayer.stop_recording()
def other(self, **kwargs):
logging.debug('Other GameModule')
......@@ -139,9 +143,11 @@ class GameModule(Module):
# Show replay
# May require `sudo apt-get install qtmultimedia5-examples` in order to install the right libraries
replayFile = self.replayer.stop_recording()
if self.replayer:
replayFile = self.replayer.stop_recording()
if not (Settings['replay.show'] and os.path.exists(replayFile)):
if not (self.replayer and Settings['replay.show'] and os.path.exists(replayFile)):
self.updateScores()
else:
self.showingReplay = True
......@@ -158,7 +164,8 @@ class GameModule(Module):
self.ui.videoWidget.setFullScreen(False);
self.showingReplay = False
self.updateScores()
self.replayer.start_recording()
if self.replayer:
self.replayer.start_recording()
def handleCancel(self):
self.switchModule(modules.MenuModule)
......
......@@ -23,16 +23,18 @@ class Replay(Thread):
self.replayPath = MainWin.getContent('Replay {}.mp4'.format(side.name))
self.shutdown = False
self.cam = picamera.PiCamera()
self.cam.resolution = Settings['picam.resolution']
self.cam.framerate = Settings['picam.fps']
self.cam.hflip = Settings['picam.hflip']
self.cam.vflip = Settings['picam.vflip']
self.stream = picamera.PiCameraCircularIO(self.cam, seconds=Settings['replay.duration'])
self.start_flag = Event()
self.stop_flag = Event()
self.stopped_flag = Event()
if onRasp:
self.cam = picamera.PiCamera()
self.cam.resolution = Settings['picam.resolution']
self.cam.framerate = Settings['picam.fps']
self.cam.hflip = Settings['picam.hflip']
self.cam.vflip = Settings['picam.vflip']
self.stream = picamera.PiCameraCircularIO(self.cam, seconds=Settings['replay.duration'])
def start_recording(self):
if onRasp:
self.start_flag.set()
......@@ -54,17 +56,13 @@ class Replay(Thread):
def run(self):
while not self.shutdown:
print('1')
self.start_flag.wait()
print('2')
if not self.shutdown:
print('3')
self.cam.start_recording(self.stream, Settings['picam.format'])
try:
while not self.stop_flag.is_set():
self.cam.wait_recording(1)
print('4')
finally :
self.cam.stop_recording()
......@@ -72,8 +70,10 @@ class Replay(Thread):
self.stream.copy_to(self.replayPath)
self.stream.clear()
self.stopped_flag.set()
print('5')
self.cam.close()
self.stream.close()
print('6')
\ No newline at end of file
@staticmethod
def isCamAvailable():
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