# cubespace-inha/cubespace-firmware architecture

> Architecture diagram of the GitHub repository cubespace-inha/cubespace-firmware, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cubespace-inha/cubespace-firmware
- Repository: https://github.com/cubespace-inha/cubespace-firmware

## Overview

This repository contains Arduino firmware for interactive cubes and a sensor/LED pad, plus shared protocol and decision headers. The main workflow runs from pad sensing and cube BLE events through serial messages to a PC app, with PC commands returning through the pad to update cubes and the pad display. The graph preserves documented display, touch/dial, battery, sleep/wake, and infrared-positioning capabilities. Several sketches and helpers were not excerpted; their connections are included only where the README documents them.

Main entry points: [`cube_fw/cube_fw.ino`](https://github.com/cubespace-inha/cubespace-firmware/blob/main/cube_fw/cube_fw.ino) (Cube loop), [`pad_fw/pad_fw.ino`](https://github.com/cubespace-inha/cubespace-firmware/blob/main/pad_fw/pad_fw.ino) (Pad loop), [`pad_fw/scan.cpp`](https://github.com/cubespace-inha/cubespace-firmware/blob/main/pad_fw/scan.cpp) (Sensor scan), [`pad_fw/leds.cpp`](https://github.com/cubespace-inha/cubespace-firmware/blob/main/pad_fw/leds.cpp) (Pad LEDs)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cube["Cube firmware"]
  node_cube_sketch["Cube loop<br/>[cube_fw.ino]"]
  node_cube_face["Face selection<br/>[face.h]"]
  node_cube_eyes["Eye rendering<br/>[eyes.h]"]
  node_cube_display["Cube display<br/>[display.cpp]"]
  node_cube_sleep["Sleep and wake<br/>[sleep.cpp]"]
  node_cube_pins["Cube pins<br/>[pins.h]"]
  node_cube_dial["Dial input<br/>[dial.h]"]
  node_cube_taps["Tap input<br/>[taps.h]"]
  node_cube_wake["Wake handling<br/>[wake.h]"]
end

subgraph group_pad["Pad firmware"]
  node_pad_sketch["Pad loop<br/>[pad_fw.ino]"]
  node_pad_scan["Sensor scan<br/>[scan.cpp]"]
  node_pad_ble["Cube BLE central<br/>[cubes.cpp]"]
  node_pad_led["Pad LEDs<br/>[leds.cpp]"]
end

subgraph group_shared["Shared protocol"]
  node_cube_logic["Cube decisions<br/>[cube_logic.h]"]
  node_protocol["BLE protocol"]
  node_pad_in["PC command parser<br/>[pad_lines.h]"]
  node_pad_out["PC line output<br/>[pad_out.h]"]
end

subgraph group_host["PC interface"]
end

node_person(("User"))
node_pc_app(("PC app"))
node_pc_lines["Serial link"]

node_person -->|"touches and moves"| node_cube_sketch
node_person -->|"places cubes"| node_pad_scan
node_pad_sketch -->|"samples sensors"| node_pad_scan
node_pad_sketch -->|"polls and commands"| node_pad_ble
node_pad_sketch -->|"updates display"| node_pad_led
node_pad_sketch -->|"parses commands"| node_pad_in
node_pad_sketch -->|"formats output"| node_pad_out
node_pad_scan -->|"formats sensor frame"| node_pad_out
node_pad_out -->|"emits lines"| node_pc_lines
node_pc_lines -->|"delivers serial data"| node_pc_app
node_pc_app -->|"sends commands"| node_pc_lines
node_pc_lines -->|"supplies commands"| node_pad_in
node_pad_in -->|"provides frame colors"| node_pad_led
node_pad_scan -->|"positions IR marks"| node_pad_led
node_pad_ble -->|"sends commands and receives events"| node_protocol
node_cube_sketch -->|"exchanges BLE packets"| node_protocol
node_cube_sketch -->|"steps inputs"| node_cube_logic
node_cube_logic -->|"encodes events"| node_protocol
node_cube_sketch -->|"selects presentation"| node_cube_face
node_cube_face -->|"selects eye state"| node_cube_eyes
node_cube_sketch -->|"draws output"| node_cube_display
node_cube_display -->|"renders selected face"| node_cube_face
node_cube_sketch -->|"sleeps and powers off"| node_cube_sleep
node_cube_sleep -->|"controls power pins"| node_cube_pins
node_cube_sketch -->|"reads dial input"| node_cube_dial
node_cube_sketch -->|"classifies taps"| node_cube_taps
node_cube_sketch -->|"handles wake events"| node_cube_wake
node_cube_sketch -->|"reads hardware inputs"| node_cube_pins
node_cube_sketch -->|"exchanges cube events"| node_pad_ble
node_pad_led -->|"shows pad feedback"| node_person

click node_cube_sketch "https://github.com/cubespace-inha/cubespace-firmware/blob/main/cube_fw/cube_fw.ino"
click node_cube_logic "https://github.com/cubespace-inha/cubespace-firmware/blob/main/libraries/CubeSpaceProto/cube_logic.h"
click node_cube_face "https://github.com/cubespace-inha/cubespace-firmware/blob/main/cube_fw/face.h"
click node_cube_eyes "https://github.com/cubespace-inha/cubespace-firmware/blob/main/cube_fw/eyes.h"
click node_cube_display "https://github.com/cubespace-inha/cubespace-firmware/blob/main/cube_fw/display.cpp"
click node_cube_sleep "https://github.com/cubespace-inha/cubespace-firmware/blob/main/cube_fw/sleep.cpp"
click node_cube_pins "https://github.com/cubespace-inha/cubespace-firmware/blob/main/cube_fw/pins.h"
click node_cube_dial "https://github.com/cubespace-inha/cubespace-firmware/blob/main/cube_fw/dial.h"
click node_cube_taps "https://github.com/cubespace-inha/cubespace-firmware/blob/main/cube_fw/taps.h"
click node_cube_wake "https://github.com/cubespace-inha/cubespace-firmware/blob/main/cube_fw/wake.h"
click node_protocol "https://github.com/cubespace-inha/cubespace-firmware/blob/main/libraries/CubeSpaceProto/cube_pad_protocol.h"
click node_pad_sketch "https://github.com/cubespace-inha/cubespace-firmware/blob/main/pad_fw/pad_fw.ino"
click node_pad_scan "https://github.com/cubespace-inha/cubespace-firmware/blob/main/pad_fw/scan.cpp"
click node_pad_ble "https://github.com/cubespace-inha/cubespace-firmware/blob/main/pad_fw/cubes.cpp"
click node_pad_led "https://github.com/cubespace-inha/cubespace-firmware/blob/main/pad_fw/leds.cpp"
click node_pad_in "https://github.com/cubespace-inha/cubespace-firmware/blob/main/libraries/CubeSpaceProto/pad_lines.h"
click node_pad_out "https://github.com/cubespace-inha/cubespace-firmware/blob/main/libraries/CubeSpaceProto/pad_out.h"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cube_sketch,node_cube_face,node_cube_eyes,node_cube_display,node_cube_sleep,node_cube_pins,node_cube_dial,node_cube_taps,node_cube_wake,node_person toneBlue
class node_pad_sketch,node_pad_scan,node_pad_ble,node_pad_led toneAmber
class node_cube_logic,node_protocol,node_pad_in,node_pad_out toneMint
class node_pc_app,node_pc_lines toneIndigo
```

## Components

### Cube firmware

- [Cube loop](https://github.com/cubespace-inha/cubespace-firmware/blob/main/cube_fw/cube_fw.ino): `cube_fw/cube_fw.ino`
- [Face selection](https://github.com/cubespace-inha/cubespace-firmware/blob/main/cube_fw/face.h): `cube_fw/face.h`
- [Eye rendering](https://github.com/cubespace-inha/cubespace-firmware/blob/main/cube_fw/eyes.h): `cube_fw/eyes.h`
- [Cube display](https://github.com/cubespace-inha/cubespace-firmware/blob/main/cube_fw/display.cpp): `cube_fw/display.cpp`
- [Sleep and wake](https://github.com/cubespace-inha/cubespace-firmware/blob/main/cube_fw/sleep.cpp): `cube_fw/sleep.cpp`
- [Cube pins](https://github.com/cubespace-inha/cubespace-firmware/blob/main/cube_fw/pins.h): `cube_fw/pins.h`
- [Dial input](https://github.com/cubespace-inha/cubespace-firmware/blob/main/cube_fw/dial.h): `cube_fw/dial.h`
- [Tap input](https://github.com/cubespace-inha/cubespace-firmware/blob/main/cube_fw/taps.h): `cube_fw/taps.h`
- [Wake handling](https://github.com/cubespace-inha/cubespace-firmware/blob/main/cube_fw/wake.h): `cube_fw/wake.h`

### Pad firmware

- [Pad loop](https://github.com/cubespace-inha/cubespace-firmware/blob/main/pad_fw/pad_fw.ino): `pad_fw/pad_fw.ino`
- [Sensor scan](https://github.com/cubespace-inha/cubespace-firmware/blob/main/pad_fw/scan.cpp): `pad_fw/scan.cpp`
- [Cube BLE central](https://github.com/cubespace-inha/cubespace-firmware/blob/main/pad_fw/cubes.cpp): `pad_fw/cubes.cpp`
- [Pad LEDs](https://github.com/cubespace-inha/cubespace-firmware/blob/main/pad_fw/leds.cpp): `pad_fw/leds.cpp`

### Shared protocol

- [Cube decisions](https://github.com/cubespace-inha/cubespace-firmware/blob/main/libraries/CubeSpaceProto/cube_logic.h): `libraries/CubeSpaceProto/cube_logic.h`
- [BLE protocol](https://github.com/cubespace-inha/cubespace-firmware/blob/main/libraries/CubeSpaceProto/cube_pad_protocol.h): `libraries/CubeSpaceProto/cube_pad_protocol.h`
- [PC command parser](https://github.com/cubespace-inha/cubespace-firmware/blob/main/libraries/CubeSpaceProto/pad_lines.h): `libraries/CubeSpaceProto/pad_lines.h`
- [PC line output](https://github.com/cubespace-inha/cubespace-firmware/blob/main/libraries/CubeSpaceProto/pad_out.h): `libraries/CubeSpaceProto/pad_out.h`

### Other components

- **User**
- **PC app**
- **Serial link**

## Connections

- User → Cube loop: touches and moves (evidence: `README.md`)
- User → Sensor scan: places cubes (evidence: `README.md`)
- Pad loop → Sensor scan: samples sensors (evidence: `README.md`)
- Pad loop → Cube BLE central: polls and commands (evidence: `README.md`)
- Pad loop → Pad LEDs: updates display (evidence: `README.md`)
- Pad loop → PC command parser: parses commands (evidence: `README.md`)
- Pad loop → PC line output: formats output (evidence: `README.md`)
- Sensor scan → PC line output: formats sensor frame (evidence: `README.md`)
- PC line output → Serial link: emits lines (evidence: `libraries/CubeSpaceProto/pad_out.h`)
- Serial link → PC app: delivers serial data (evidence: `README.md`)
- PC app → Serial link: sends commands (evidence: `README.md`)
- Serial link → PC command parser: supplies commands (evidence: `libraries/CubeSpaceProto/pad_lines.h`)
- PC command parser → Pad LEDs: provides frame colors (evidence: `libraries/CubeSpaceProto/pad_lines.h`)
- Sensor scan → Pad LEDs: positions IR marks (evidence: `README.md`)
- Cube BLE central → BLE protocol: sends commands and receives events (evidence: `libraries/CubeSpaceProto/cube_pad_protocol.h`)
- Cube loop → BLE protocol: exchanges BLE packets (evidence: `libraries/CubeSpaceProto/cube_pad_protocol.h`)
- Cube loop → Cube decisions: steps inputs (evidence: `libraries/CubeSpaceProto/cube_logic.h`)
- Cube decisions → BLE protocol: encodes events (evidence: `libraries/CubeSpaceProto/cube_logic.h`)
- Cube loop → Face selection: selects presentation (evidence: `cube_fw/face.h`)
- Face selection → Eye rendering: selects eye state (evidence: `cube_fw/face.h`)
- Cube loop → Cube display: draws output (evidence: `README.md`)
- Cube display → Face selection: renders selected face
- Cube loop → Sleep and wake: sleeps and powers off (evidence: `README.md`)
- Sleep and wake → Cube pins: controls power pins (evidence: `cube_fw/sleep.cpp`)
- Cube loop → Dial input: reads dial input (evidence: `README.md`)
- Cube loop → Tap input: classifies taps (evidence: `README.md`)
- Cube loop → Wake handling: handles wake events (evidence: `README.md`)
- Cube loop → Cube pins: reads hardware inputs (evidence: `README.md`)
- Cube loop → Cube BLE central: exchanges cube events
- Pad LEDs → User: shows pad feedback (evidence: `README.md`)
