Hardware Module¶
SquishBox Raspberry Pi hardware interface.
Provides low-level access to GPIO-backed hardware components used by SquishBox, including buttons, rotary encoders, LCD display, and outputs.
Also implements event-driven input handling and a buffered LCD rendering system with support for scrolling, blinking, and custom glyphs.
- Requires:
gpiod
- class squishbox.hardware.Control[source]¶
Bases:
objectBase class for input controls with event binding.
Provides a simple event → callback mapping. Subclasses trigger events (e.g. “tap”, “left”) which invoke the bound functions.
- class squishbox.hardware.Button(pin, pull_up=True)[source]¶
Bases:
ControlGPIO button with tap/hold detection.
Monitors a GPIO input line and emits events based on press duration.
- Events:
“down”: button pressed
“up”: button released
“in”/”out”: toggles on button press
“tap”: short press
“hold”: long press (duration >= CONFIG[“hold_time”])
- UP = 0¶
- DOWN = 1¶
- HELD = 2¶
- class squishbox.hardware.Encoder(pin1, pin2, pull_up=True)[source]¶
Bases:
ControlQuadrature rotary encoder.
Detects rotation direction using two GPIO inputs.
- Events:
“left”: counterclockwise rotation
“right”: clockwise rotation
- class squishbox.hardware.PWMOutput(pin, freq=2000, level=0)[source]¶
Bases:
objectSoftware PWM output using a background thread.
Generates a PWM signal by toggling a GPIO line at a fixed frequency. Duty cycle is controlled via the level attribute (0–100).
- level¶
Duty cycle percentage (0-100)
- Type:
float
- class squishbox.hardware.LCD_HD44780(regsel, enable, data)[source]¶
Bases:
objectHD44780-compatible character LCD driver.
- Provides buffered text rendering with support for:
Static text
Scrolling text (for long lines)
Timed/blinking overlays
Custom glyphs (up to 8 hardware slots)
Rendering is layered and only updates changed characters to minimize GPIO traffic.
- glyph2char = (('backslash', '\\'), ('tilde', '~'))¶
- clear()[source]¶
Clear the display and reset all rendering layers.
Also resets scrolling state, blinking timers, and cursor position.
- write(text, row, col=0, align='', timeout=0, force=True)[source]¶
Write text to the LCD using layered rendering.
- Behavior depends on text length and parameters:
Long text is placed in scroll buffer
timeout > 0 creates temporary (blinking) overlay
Otherwise writes to static layer
- Parameters:
text (str) – String to display.
row (int) – Target row.
col (int) – Starting column.
align (str) – “left”, “right”, or default (no alignment).
timeout (float) – Duration for temporary text (seconds).
force (bool) – Overwrite existing timed text if True.
- update()[source]¶
Render buffered content to the LCD.
- Handles:
Scrolling updates
Expiring timed/blinking text
Layer compositing
Does nothing if activity spinner is active.
- property cursor_pos¶
Cursor position as (row, col)
- property cursor_mode¶
Cursor display mode.
- Modes:
“hide” – no cursor
“blink” – blinking block cursor
“line” - underline cursor