# universalgeek56/ug56-lab-psu architecture

> Architecture diagram of the GitHub repository universalgeek56/ug56-lab-psu, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/universalgeek56/ug56-lab-psu
- Repository: https://github.com/universalgeek56/ug56-lab-psu

## Overview

This is ESP32 firmware that turns a DC-DC converter into a remotely configurable lab supply. Its main user workflow is to set voltage/current limits through the local controls or web UI, regulate and monitor the output, and display readings and protection status. Distinct subsystems cover feedback control, sensing and cutoff protection, local UI, web access, Wi-Fi/OTA, and persistent settings. The README documents these capabilities, but the main loop and several subsystem implementations were not sampled, so orchestration links are marked unverified rather than asserted as source-visible calls.

Main entry points: [`src/main.ino`](https://github.com/universalgeek56/ug56-lab-psu/blob/main/src/main.ino) (Firmware entry), [`src/DcControl.cpp`](https://github.com/universalgeek56/ug56-lab-psu/blob/main/src/DcControl.cpp) (CV/CC PID control), [`src/WebInterface.cpp`](https://github.com/universalgeek56/ug56-lab-psu/blob/main/src/WebInterface.cpp) (Dashboard and charts), [`src/DisplayManager.cpp`](https://github.com/universalgeek56/ug56-lab-psu/blob/main/src/DisplayManager.cpp) (OLED display)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_control["Regulation and safety"]
  node_dc["CV/CC PID control<br/>[DcControl.cpp]"]
  node_output["Output cutoff<br/>[OutputControl.cpp]"]
  node_errors["Protection flags<br/>[ErrMgr.cpp]"]
  node_measurement["Electrical sensing<br/>[Ina226Manager.cpp]"]
end

subgraph group_local["Local controls"]
  node_encoder["Encoder menus<br/>[EncoderManager.cpp]"]
  node_touch["Touch and LEDs<br/>[TouchUI.cpp]"]
  node_display["OLED display<br/>[DisplayManager.cpp]"]
  node_font["Segment rendering<br/>[SegmentFont.cpp]"]
end

subgraph group_remote["Network interface"]
  node_web["Dashboard and charts<br/>[WebInterface.cpp]"]
  node_wifi["Wi-Fi and OTA<br/>[WifiOtaManager.cpp]"]
end

subgraph group_state["Settings and state"]
  node_preferences["Settings persistence"]
end

subgraph group_runtime["Firmware runtime"]
  node_main["Firmware entry<br/>[main.ino]"]
  node_globals["Shared runtime state<br/>[Globals.cpp]"]
end

node_operator(("Supply operator"))
node_browser(("Web browser"))
node_converter["DC-DC converter"]
node_ina226["INA226 sensor"]
node_nvs[("ESP32 NVS")]

node_operator -.->|"adjusts locally"| node_encoder
node_operator -.->|"uses touch UI"| node_touch
node_operator -.->|"opens dashboard"| node_browser
node_browser -.->|"requests controls"| node_web
node_web -.->|"serves dashboard"| node_browser
node_main -.->|"updates periodically"| node_measurement
node_measurement -.->|"reads measurements"| node_ina226
node_measurement -.->|"provides feedback"| node_dc
node_dc -.->|"modulates feedback"| node_converter
node_dc -.->|"coordinates cutoff"| node_output
node_errors -.->|"reports faults"| node_display
node_encoder -->|"selects menu views"| node_display
node_display -->|"draws segments"| node_font
node_main -.->|"updates periodically"| node_dc
node_main -.->|"updates periodically"| node_display
node_main -.->|"updates periodically"| node_web
node_main -.->|"services network"| node_wifi
node_main -.->|"loads and saves"| node_preferences
node_preferences -->|"reads and writes"| node_nvs
node_preferences -->|"applies settings"| node_globals
node_wifi -->|"updates status"| node_globals
node_web -->|"uses shared state"| node_globals

click node_main "https://github.com/universalgeek56/ug56-lab-psu/blob/main/src/main.ino"
click node_globals "https://github.com/universalgeek56/ug56-lab-psu/blob/main/src/Globals.cpp"
click node_dc "https://github.com/universalgeek56/ug56-lab-psu/blob/main/src/DcControl.cpp"
click node_output "https://github.com/universalgeek56/ug56-lab-psu/blob/main/src/OutputControl.cpp"
click node_errors "https://github.com/universalgeek56/ug56-lab-psu/blob/main/src/ErrMgr.cpp"
click node_measurement "https://github.com/universalgeek56/ug56-lab-psu/blob/main/src/Ina226Manager.cpp"
click node_encoder "https://github.com/universalgeek56/ug56-lab-psu/blob/main/src/EncoderManager.cpp"
click node_touch "https://github.com/universalgeek56/ug56-lab-psu/blob/main/src/TouchUI.cpp"
click node_display "https://github.com/universalgeek56/ug56-lab-psu/blob/main/src/DisplayManager.cpp"
click node_font "https://github.com/universalgeek56/ug56-lab-psu/blob/main/src/SegmentFont.cpp"
click node_web "https://github.com/universalgeek56/ug56-lab-psu/blob/main/src/WebInterface.cpp"
click node_wifi "https://github.com/universalgeek56/ug56-lab-psu/blob/main/src/WifiOtaManager.cpp"
click node_preferences "https://github.com/universalgeek56/ug56-lab-psu/blob/main/src/PreferencesManager.cpp"

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_dc,node_output,node_errors,node_measurement,node_browser toneBlue
class node_encoder,node_touch,node_display,node_font,node_nvs toneAmber
class node_web,node_wifi toneMint
class node_preferences toneRose
class node_main,node_globals,node_operator,node_converter,node_ina226 toneIndigo
```

## Components

### Regulation and safety

- [CV/CC PID control](https://github.com/universalgeek56/ug56-lab-psu/blob/main/src/DcControl.cpp): `src/DcControl.cpp`
- [Output cutoff](https://github.com/universalgeek56/ug56-lab-psu/blob/main/src/OutputControl.cpp): `src/OutputControl.cpp`
- [Protection flags](https://github.com/universalgeek56/ug56-lab-psu/blob/main/src/ErrMgr.cpp): `src/ErrMgr.cpp`
- [Electrical sensing](https://github.com/universalgeek56/ug56-lab-psu/blob/main/src/Ina226Manager.cpp): `src/Ina226Manager.cpp`

### Local controls

- [Encoder menus](https://github.com/universalgeek56/ug56-lab-psu/blob/main/src/EncoderManager.cpp): `src/EncoderManager.cpp`
- [Touch and LEDs](https://github.com/universalgeek56/ug56-lab-psu/blob/main/src/TouchUI.cpp): `src/TouchUI.cpp`
- [OLED display](https://github.com/universalgeek56/ug56-lab-psu/blob/main/src/DisplayManager.cpp): `src/DisplayManager.cpp`
- [Segment rendering](https://github.com/universalgeek56/ug56-lab-psu/blob/main/src/SegmentFont.cpp): `src/SegmentFont.cpp`

### Network interface

- [Dashboard and charts](https://github.com/universalgeek56/ug56-lab-psu/blob/main/src/WebInterface.cpp): `src/WebInterface.cpp`
- [Wi-Fi and OTA](https://github.com/universalgeek56/ug56-lab-psu/blob/main/src/WifiOtaManager.cpp): `src/WifiOtaManager.cpp`

### Settings and state

- [Settings persistence](https://github.com/universalgeek56/ug56-lab-psu/blob/main/src/PreferencesManager.cpp): `src/PreferencesManager.cpp`

### Firmware runtime

- [Firmware entry](https://github.com/universalgeek56/ug56-lab-psu/blob/main/src/main.ino): `src/main.ino`
- [Shared runtime state](https://github.com/universalgeek56/ug56-lab-psu/blob/main/src/Globals.cpp): `src/Globals.cpp`

### Other components

- **Supply operator**
- **Web browser**
- **DC-DC converter**
- **INA226 sensor**
- **ESP32 NVS**

## Connections

- Supply operator → Encoder menus: adjusts locally (evidence: `README.md`)
- Supply operator → Touch and LEDs: uses touch UI (evidence: `README.md`)
- Supply operator → Web browser: opens dashboard (evidence: `README.md`)
- Web browser → Dashboard and charts: requests controls (evidence: `README.md`)
- Dashboard and charts → Web browser: serves dashboard (evidence: `README.md`)
- Firmware entry → Electrical sensing: updates periodically
- Electrical sensing → INA226 sensor: reads measurements (evidence: `README.md`)
- Electrical sensing → CV/CC PID control: provides feedback (evidence: `README.md`)
- CV/CC PID control → DC-DC converter: modulates feedback (evidence: `README.md`)
- CV/CC PID control → Output cutoff: coordinates cutoff
- Protection flags → OLED display: reports faults (evidence: `README.md`)
- Encoder menus → OLED display: selects menu views (evidence: `src/EncoderManager.cpp`)
- OLED display → Segment rendering: draws segments (evidence: `src/DisplayManager.cpp`)
- Firmware entry → CV/CC PID control: updates periodically
- Firmware entry → OLED display: updates periodically
- Firmware entry → Dashboard and charts: updates periodically
- Firmware entry → Wi-Fi and OTA: services network
- Firmware entry → Settings persistence: loads and saves
- Settings persistence → ESP32 NVS: reads and writes (evidence: `src/PreferencesManager.cpp`)
- Settings persistence → Shared runtime state: applies settings (evidence: `src/PreferencesManager.cpp`)
- Wi-Fi and OTA → Shared runtime state: updates status (evidence: `src/WifiOtaManager.cpp`)
- Dashboard and charts → Shared runtime state: uses shared state (evidence: `src/WebInterface.cpp`)
