Fixed remaining states, GuiPostprocessing and Worker not yet done

This commit is contained in:
Balthasar Reuter
2018-07-16 01:20:48 +02:00
parent 436c2fe6c9
commit f84fc20a62
3 changed files with 36 additions and 16 deletions

View File

@@ -316,45 +316,59 @@ class GreeterState(State):
if ((isinstance(event, GuiEvent) or isinstance(event, GpioEvent)) and if ((isinstance(event, GuiEvent) or isinstance(event, GpioEvent)) and
event.name == 'countdown'): event.name == 'countdown'):
context.state = CountdownState() context.state = CountdownState(1)
else: else:
raise TypeError('Unknown Event type "{}"'.format(event)) raise TypeError('Unknown Event type "{}"'.format(event))
class CountdownState(State): class CountdownState(State):
def __init__(self): def __init__(self, num_picture):
super().__init__() super().__init__()
self._num_picture = num_picture
def __str__(self): def __str__(self):
return 'CountdownState' return 'CountdownState'
@property
def num_picture(self):
return self._num_picture
def handleEvent(self, event, context): def handleEvent(self, event, context):
if isinstance(event, GuiEvent) and event.name == 'countdown': if isinstance(event, GuiEvent) and event.name == 'countdown':
pass pass
elif isinstance(event, GuiEvent) and event.name == 'capture': elif isinstance(event, GuiEvent) and event.name == 'capture':
context.state == CaptureState() context.state = CaptureState(self.num_picture)
else: else:
raise TypeError('Unknown Event type "{}"'.format(event)) raise TypeError('Unknown Event type "{}"'.format(event))
class CaptureState(State): class CaptureState(State):
def __init__(self): def __init__(self, num_picture):
super().__init__() super().__init__()
self._num_picture = num_picture
def __str__(self): def __str__(self):
return 'CaptureState' return 'CaptureState'
@property
def num_picture(self):
return self._num_picture
def handleEvent(self, event, context): def handleEvent(self, event, context):
if isinstance(event, CameraEvent) and event.name == 'countdown': if isinstance(event, CameraEvent) and event.name == 'countdown':
context.state = CountdownState() context.state = CountdownState(self.num_picture + 1)
elif isinstance(event, CameraEvent) and event.name == 'assemble': elif isinstance(event, CameraEvent) and event.name == 'assemble':
context.state = AssembleState() context.state = AssembleState()
else: else:
@@ -374,25 +388,31 @@ class AssembleState(State):
def handleEvent(self, event, context): def handleEvent(self, event, context):
if isinstance(event, CameraEvent) and event.name == 'review': if isinstance(event, CameraEvent) and event.name == 'review':
context.state = ReviewState() context.state = ReviewState(event.picture)
else: else:
raise TypeError('Unknown Event type "{}"'.format(event)) raise TypeError('Unknown Event type "{}"'.format(event))
class ReviewState(State): class ReviewState(State):
def __init__(self): def __init__(self, picture):
super().__init__() super().__init__()
self._picture = picture
def __str__(self): def __str__(self):
return 'ReviewState' return 'ReviewState'
@property
def picture(self):
return self._picture
def handleEvent(self, event, context): def handleEvent(self, event, context):
if isinstance(event, GuiEvent) and event.name == 'postprocess': if isinstance(event, GuiEvent) and event.name == 'postprocess':
context.state == PostprocessState() context.state = PostprocessState()
else: else:
raise TypeError('Unknown Event type "{}"'.format(event)) raise TypeError('Unknown Event type "{}"'.format(event))
@@ -411,6 +431,6 @@ class PostprocessState(State):
if ((isinstance(event, GuiEvent) or isinstance(event, GpioEvent)) and if ((isinstance(event, GuiEvent) or isinstance(event, GpioEvent)) and
event.name == 'idle'): event.name == 'idle'):
context.state == IdleState() context.state = IdleState()
else: else:
raise TypeError('Unknown Event type "{}"'.format(event)) raise TypeError('Unknown Event type "{}"'.format(event))

View File

@@ -70,7 +70,7 @@ class Camera:
def teardown(self, state): def teardown(self, state):
if not self._cap is None: if self._cap is not None:
self._cap.cleanup() self._cap.cleanup()
if state.target == StateMachine.TeardownEvent.EXIT: if state.target == StateMachine.TeardownEvent.EXIT:
sys.exit(0) sys.exit(0)
@@ -91,7 +91,7 @@ class Camera:
elif isinstance(state, StateMachine.CountdownState): elif isinstance(state, StateMachine.CountdownState):
self.capturePreview() self.capturePreview()
elif isinstance(state, StateMachine.CaptureState): elif isinstance(state, StateMachine.CaptureState):
self.capturePicture() self.capturePicture(state)
elif isinstance(state, StateMachine.AssembleState): elif isinstance(state, StateMachine.AssembleState):
self.assemblePicture() self.assemblePicture()
elif isinstance(state, StateMachine.TeardownState): elif isinstance(state, StateMachine.TeardownState):
@@ -119,7 +119,7 @@ class Camera:
self._comm.send(Workers.GUI, self._comm.send(Workers.GUI,
StateMachine.CameraEvent('preview', picture)) StateMachine.CameraEvent('preview', picture))
def capturePicture(self): def capturePicture(self, state):
self.setIdle() self.setIdle()
picture = self._cap.getPicture() picture = self._cap.getPicture()
@@ -130,12 +130,12 @@ class Camera:
self._comm.send(Workers.WORKER, self._comm.send(Workers.WORKER,
StateMachine.CameraEvent('capture', picture)) StateMachine.CameraEvent('capture', picture))
if len(self._pictures) < self._pic_dims.totalNumPictures: if state.num_picture < self._pic_dims.totalNumPictures:
self._comm.send(Workers.MASTER, self._comm.send(Workers.MASTER,
StateMachine.CameraEvent('countdown', picture)) StateMachine.CameraEvent('countdown'))
else: else:
self._comm.send(Workers.MASTER, self._comm.send(Workers.MASTER,
StateMachine.CameraEvent('assemble', picture)) StateMachine.CameraEvent('assemble'))
def assemblePicture(self): def assemblePicture(self):

View File

@@ -31,7 +31,7 @@ import sys
from . import camera, gui from . import camera, gui
from .Config import Config from .Config import Config
from .util import lookup_and_import from .util import lookup_and_import
from .StateMachine import Context, ErrorEvent, StartupState from .StateMachine import Context, ErrorEvent
from .Threading import Communicator, Workers from .Threading import Communicator, Workers
from .Worker import Worker from .Worker import Worker