workflows¶
State machine coordinating the full device lifecycle.
omgrab.workflows.state_machine
¶
State machine for omgrab workflow management.
WorkflowState
¶
Bases: Enum
High-level workflow states.
StateMachine(gpio_controller, recording_manager)
¶
Manages omgrab state transitions and GPIO updates.
Initialize state machine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gpio_controller
|
GPIOController
|
GPIO controller instance for LED/buzzer control. |
required |
recording_manager
|
RecordingController
|
Recording controller for start/stop recording. |
required |
on_network_change(snapshot)
¶
Callback for network state changes.
is_recording()
¶
Check if currently in RECORDING state.
Returns:
| Type | Description |
|---|---|
bool
|
True if in RECORDING workflow state. |
get_current_state()
¶
Get the current workflow state.
Returns:
| Type | Description |
|---|---|
str
|
Current state as a string |
str
|
(boot/idle/recording/camera_preview/wifi_setup/shutdown). |
set_show_alert_callback(callback)
¶
Set callback for displaying alert messages on screen.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
callback
|
Callable[[str], None]
|
Called with a warning message string when the state machine needs to alert the user (e.g. camera error). |
required |
set_preview_callbacks(is_available, start, stop)
¶
Set callbacks for camera preview lifecycle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
is_available
|
Callable[[], bool]
|
Returns True if the display hardware is connected and preview can be started. |
required |
start
|
Callable[[], None]
|
Called to start the preview pipeline and display. |
required |
stop
|
Callable[[], None]
|
Called to stop the preview pipeline and display. |
required |
handle_button_press()
¶
Handle single button press event.
handle_double_press()
¶
Handle double button press event (camera preview).
on_device_unhealthy()
¶
Handle device becoming unhealthy during recording.
Called by RecordingManager's health monitor. This method is responsible for stopping the recording (the health monitor only detects and signals).
on_recording_error()
¶
Handle a recording error (e.g. encoder crash).
Called by RecordingManager when an encoder thread crashes. Stops the recording, beeps an error pattern, and shows an alert.
enter_wifi_setup()
¶
Enter WiFi setup state (triggered by long press).
Returns:
| Type | Description |
|---|---|
bool
|
True if transitioned to WIFI_SETUP, False if not possible. |
exit_wifi_setup()
¶
Exit WiFi setup state (called when wifi-connect completes).
Returns:
| Type | Description |
|---|---|
bool
|
True if exited WIFI_SETUP, False if not in WIFI_SETUP state. |
shutdown()
¶
Public method to shutdown the state machine.
cleanup()
¶
Cleanup resources.