Storyboard mechanism tested, works.

Improved light command structure.
This commit is contained in:
jpunkt 2022-01-16 15:30:30 +01:00
parent 06cbde4179
commit 75c1d69850
4 changed files with 42 additions and 20 deletions

View file

@ -4,7 +4,7 @@ import threading
from time import sleep
from enum import Enum
from typing import Any, List
from typing import Any, List, Iterable
from scipy.io.wavfile import write as writewav
import sounddevice as sd
@ -181,8 +181,7 @@ def turn_off(hal: PizzaHAL, **kwargs):
"""
Turn off the lights.
"""
hal.send_cmd(SerialCommands.BACKLIGHT, 0)
hal.send_cmd(SerialCommands.FRONTLIGHT, 0)
light(hal, [SerialCommands.BACKLIGHT, SerialCommands.FRONTLIGHT], 0, 0, 0, 0, 0)
def wait_for_input(hal: PizzaHAL,
@ -243,12 +242,12 @@ def wait_for_input(hal: PizzaHAL,
def light(hal: PizzaHAL,
light: Iterable,
r: float,
g: float,
b: float,
w: float,
fade: float = 0.0,
backlight: bool = False,
**kwargs):
"""
Turn on the light to illuminate the upper scroll
@ -261,7 +260,9 @@ def light(hal: PizzaHAL,
:param steps: int
How many steps for the fade (default: 100)
"""
hal.send_cmd(SerialCommands.BACKLIGHT if backlight else SerialCommands.FRONTLIGHT,
# TODO send light as bitmask
for l in iter(light):
hal.send_cmd(l,
int(b * 255).to_bytes(1, 'little'),
int(g * 255).to_bytes(1, 'little'),
int(r * 255).to_bytes(1, 'little'),

View file

@ -74,8 +74,9 @@ class Statemachine:
self.state = State.POWER_ON
self.hal = PizzaHAL()
self.chapter = 0
self.next_chapter = 0
self.chapter = 0 # The storyboard index of the current chapter to play
self.next_chapter = 0 # The storyboard index of the next chapter to play
self.chapter_set = False # `True` if the next chapter has been set
self.story = None
self.story_de = story_de
@ -214,6 +215,7 @@ class Statemachine:
Continue in the Storyboard. Prepare advancing to the next chapter.
"""
self.move = self.MOVE
self.chapter_set = True
if len(self.story) > (self.chapter + 1):
self.next_chapter = self.chapter + 1
else:
@ -223,6 +225,7 @@ class Statemachine:
"""
Repeat the current chapter. Do not rewind if the selection says so.
"""
self.chapter_set = True
self.move = rewind
self.next_chapter = self.chapter
@ -230,10 +233,12 @@ class Statemachine:
"""
Jump to a specified chapter.
"""
self.chapter_set = True
self.move = self.MOVE
self.next_chapter = next_chapter
def _quit(**kwargs):
self.chapter_set = True
self.move = self.MOVE
self.loop = not shutdown
self.next_chapter = None
@ -273,7 +278,10 @@ class Statemachine:
logger.exception('Caught KeyError, ignoring...')
pass
if not self.chapter_set:
self.chapter_set = True
self.next_chapter = self.chapter + 1
else:
self.next_chapter = None
@ -282,7 +290,7 @@ class Statemachine:
Update chapters and move the scrolls.
Update self.chapter to self.next_chapter
"""
if self.next_chapter is not None:
if self.chapter_set and (self.next_chapter is not None):
diff = self.next_chapter - self.chapter
h_steps = 0
v_steps = 0
@ -315,16 +323,18 @@ class Statemachine:
move(self.hal, h_steps, True)
move(self.hal, v_steps, False)
logger.debug(f'Setting chapter (cur: {self.chapter}) to {self.next_chapter}.')
self.chapter = self.next_chapter
self.chapter_set = False
def _rewind(self):
"""
Rewind all scrolls, post-process videos
"""
# TODO postprocessing - add sound
logger.debug('Converting video...')
cmdstring = f'MP4Box -add {fs_names.REC_DRAW_CITY} {fs_names.REC_MERGED_VIDEO}'
call([cmdstring], shell=True)
# logger.debug('Converting video...')
# cmdstring = f'MP4Box -add {fs_names.REC_DRAW_CITY} {fs_names.REC_MERGED_VIDEO}'
# call([cmdstring], shell=True)
logger.debug('Rewinding...')
if self.move:

View file

@ -0,0 +1,9 @@
import sys
import logging
logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)
from pizzactrl.statemachine import Statemachine
sm = Statemachine(move=True, loop=False, test=True)

View file

@ -1,5 +1,7 @@
from enum import Enum, auto
from pizzactrl.hal_serial import SerialCommands
class Option(Enum):
"""
@ -52,13 +54,13 @@ class Activity(Enum):
'b': 0,
'w': 1.0,
'fade': 1.0,
'backlight': False}
'light': [ SerialCommands.FRONTLIGHT ]}
LIGHT_BACK = {'r': 0,
'g': 0,
'b': 0,
'w': 1.0,
'fade': 1.0,
'backlight': True}
'light': [ SerialCommands.BACKLIGHT ]}
class Do: