Storyboard mechanism tested, works.
Improved light command structure.
This commit is contained in:
parent
06cbde4179
commit
75c1d69850
4 changed files with 42 additions and 20 deletions
|
@ -4,7 +4,7 @@ import threading
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
from typing import Any, List
|
from typing import Any, List, Iterable
|
||||||
from scipy.io.wavfile import write as writewav
|
from scipy.io.wavfile import write as writewav
|
||||||
|
|
||||||
import sounddevice as sd
|
import sounddevice as sd
|
||||||
|
@ -181,8 +181,7 @@ def turn_off(hal: PizzaHAL, **kwargs):
|
||||||
"""
|
"""
|
||||||
Turn off the lights.
|
Turn off the lights.
|
||||||
"""
|
"""
|
||||||
hal.send_cmd(SerialCommands.BACKLIGHT, 0)
|
light(hal, [SerialCommands.BACKLIGHT, SerialCommands.FRONTLIGHT], 0, 0, 0, 0, 0)
|
||||||
hal.send_cmd(SerialCommands.FRONTLIGHT, 0)
|
|
||||||
|
|
||||||
|
|
||||||
def wait_for_input(hal: PizzaHAL,
|
def wait_for_input(hal: PizzaHAL,
|
||||||
|
@ -243,12 +242,12 @@ def wait_for_input(hal: PizzaHAL,
|
||||||
|
|
||||||
|
|
||||||
def light(hal: PizzaHAL,
|
def light(hal: PizzaHAL,
|
||||||
|
light: Iterable,
|
||||||
r: float,
|
r: float,
|
||||||
g: float,
|
g: float,
|
||||||
b: float,
|
b: float,
|
||||||
w: float,
|
w: float,
|
||||||
fade: float = 0.0,
|
fade: float = 0.0,
|
||||||
backlight: bool = False,
|
|
||||||
**kwargs):
|
**kwargs):
|
||||||
"""
|
"""
|
||||||
Turn on the light to illuminate the upper scroll
|
Turn on the light to illuminate the upper scroll
|
||||||
|
@ -261,12 +260,14 @@ def light(hal: PizzaHAL,
|
||||||
:param steps: int
|
:param steps: int
|
||||||
How many steps for the fade (default: 100)
|
How many steps for the fade (default: 100)
|
||||||
"""
|
"""
|
||||||
hal.send_cmd(SerialCommands.BACKLIGHT if backlight else SerialCommands.FRONTLIGHT,
|
# TODO send light as bitmask
|
||||||
int(b * 255).to_bytes(1, 'little'),
|
for l in iter(light):
|
||||||
int(g * 255).to_bytes(1, 'little'),
|
hal.send_cmd(l,
|
||||||
int(r * 255).to_bytes(1, 'little'),
|
int(b * 255).to_bytes(1, 'little'),
|
||||||
int(w * 255).to_bytes(1, 'little'),
|
int(g * 255).to_bytes(1, 'little'),
|
||||||
int(fade * 1000).to_bytes(4, 'little'))
|
int(r * 255).to_bytes(1, 'little'),
|
||||||
|
int(w * 255).to_bytes(1, 'little'),
|
||||||
|
int(fade * 1000).to_bytes(4, 'little'))
|
||||||
|
|
||||||
|
|
||||||
def play_sound(hal: PizzaHAL, sound: Any, **kwargs):
|
def play_sound(hal: PizzaHAL, sound: Any, **kwargs):
|
||||||
|
|
|
@ -74,8 +74,9 @@ class Statemachine:
|
||||||
self.state = State.POWER_ON
|
self.state = State.POWER_ON
|
||||||
self.hal = PizzaHAL()
|
self.hal = PizzaHAL()
|
||||||
|
|
||||||
self.chapter = 0
|
self.chapter = 0 # The storyboard index of the current chapter to play
|
||||||
self.next_chapter = 0
|
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 = None
|
||||||
self.story_de = story_de
|
self.story_de = story_de
|
||||||
|
@ -214,6 +215,7 @@ class Statemachine:
|
||||||
Continue in the Storyboard. Prepare advancing to the next chapter.
|
Continue in the Storyboard. Prepare advancing to the next chapter.
|
||||||
"""
|
"""
|
||||||
self.move = self.MOVE
|
self.move = self.MOVE
|
||||||
|
self.chapter_set = True
|
||||||
if len(self.story) > (self.chapter + 1):
|
if len(self.story) > (self.chapter + 1):
|
||||||
self.next_chapter = self.chapter + 1
|
self.next_chapter = self.chapter + 1
|
||||||
else:
|
else:
|
||||||
|
@ -223,6 +225,7 @@ class Statemachine:
|
||||||
"""
|
"""
|
||||||
Repeat the current chapter. Do not rewind if the selection says so.
|
Repeat the current chapter. Do not rewind if the selection says so.
|
||||||
"""
|
"""
|
||||||
|
self.chapter_set = True
|
||||||
self.move = rewind
|
self.move = rewind
|
||||||
self.next_chapter = self.chapter
|
self.next_chapter = self.chapter
|
||||||
|
|
||||||
|
@ -230,10 +233,12 @@ class Statemachine:
|
||||||
"""
|
"""
|
||||||
Jump to a specified chapter.
|
Jump to a specified chapter.
|
||||||
"""
|
"""
|
||||||
|
self.chapter_set = True
|
||||||
self.move = self.MOVE
|
self.move = self.MOVE
|
||||||
self.next_chapter = next_chapter
|
self.next_chapter = next_chapter
|
||||||
|
|
||||||
def _quit(**kwargs):
|
def _quit(**kwargs):
|
||||||
|
self.chapter_set = True
|
||||||
self.move = self.MOVE
|
self.move = self.MOVE
|
||||||
self.loop = not shutdown
|
self.loop = not shutdown
|
||||||
self.next_chapter = None
|
self.next_chapter = None
|
||||||
|
@ -273,7 +278,10 @@ class Statemachine:
|
||||||
logger.exception('Caught KeyError, ignoring...')
|
logger.exception('Caught KeyError, ignoring...')
|
||||||
pass
|
pass
|
||||||
|
|
||||||
self.next_chapter = self.chapter + 1
|
if not self.chapter_set:
|
||||||
|
self.chapter_set = True
|
||||||
|
self.next_chapter = self.chapter + 1
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.next_chapter = None
|
self.next_chapter = None
|
||||||
|
|
||||||
|
@ -282,7 +290,7 @@ class Statemachine:
|
||||||
Update chapters and move the scrolls.
|
Update chapters and move the scrolls.
|
||||||
Update self.chapter to self.next_chapter
|
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
|
diff = self.next_chapter - self.chapter
|
||||||
h_steps = 0
|
h_steps = 0
|
||||||
v_steps = 0
|
v_steps = 0
|
||||||
|
@ -315,16 +323,18 @@ class Statemachine:
|
||||||
move(self.hal, h_steps, True)
|
move(self.hal, h_steps, True)
|
||||||
move(self.hal, v_steps, False)
|
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 = self.next_chapter
|
||||||
|
self.chapter_set = False
|
||||||
|
|
||||||
def _rewind(self):
|
def _rewind(self):
|
||||||
"""
|
"""
|
||||||
Rewind all scrolls, post-process videos
|
Rewind all scrolls, post-process videos
|
||||||
"""
|
"""
|
||||||
# TODO postprocessing - add sound
|
# TODO postprocessing - add sound
|
||||||
logger.debug('Converting video...')
|
# logger.debug('Converting video...')
|
||||||
cmdstring = f'MP4Box -add {fs_names.REC_DRAW_CITY} {fs_names.REC_MERGED_VIDEO}'
|
# cmdstring = f'MP4Box -add {fs_names.REC_DRAW_CITY} {fs_names.REC_MERGED_VIDEO}'
|
||||||
call([cmdstring], shell=True)
|
# call([cmdstring], shell=True)
|
||||||
|
|
||||||
logger.debug('Rewinding...')
|
logger.debug('Rewinding...')
|
||||||
if self.move:
|
if self.move:
|
||||||
|
|
9
pizzactrl/statemachine_test.py
Normal file
9
pizzactrl/statemachine_test.py
Normal 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)
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
from enum import Enum, auto
|
from enum import Enum, auto
|
||||||
|
|
||||||
|
from pizzactrl.hal_serial import SerialCommands
|
||||||
|
|
||||||
|
|
||||||
class Option(Enum):
|
class Option(Enum):
|
||||||
"""
|
"""
|
||||||
|
@ -52,13 +54,13 @@ class Activity(Enum):
|
||||||
'b': 0,
|
'b': 0,
|
||||||
'w': 1.0,
|
'w': 1.0,
|
||||||
'fade': 1.0,
|
'fade': 1.0,
|
||||||
'backlight': False}
|
'light': [ SerialCommands.FRONTLIGHT ]}
|
||||||
LIGHT_BACK = {'r': 0,
|
LIGHT_BACK = {'r': 0,
|
||||||
'g': 0,
|
'g': 0,
|
||||||
'b': 0,
|
'b': 0,
|
||||||
'w': 1.0,
|
'w': 1.0,
|
||||||
'fade': 1.0,
|
'fade': 1.0,
|
||||||
'backlight': True}
|
'light': [ SerialCommands.BACKLIGHT ]}
|
||||||
|
|
||||||
|
|
||||||
class Do:
|
class Do:
|
||||||
|
|
Loading…
Reference in a new issue