# benjaalonso357-dot/campera-calefactor architecture

> Architecture diagram of the GitHub repository benjaalonso357-dot/campera-calefactor, 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/benjaalonso357-dot/campera-calefactor
- Repository: https://github.com/benjaalonso357-dot/campera-calefactor

## Overview

This is ESP32 firmware for a four-zone heated jacket. The intended workflow is to read four LM35 sensors, compare measurements with target temperatures, and switch the corresponding MOSFET heaters; users set targets with buttons, BLE, or serial, and can inspect zone status. Targets are persisted in EEPROM, and a long press enters deep sleep. The main sketch and sensor/state implementations were not excerpted, so orchestration and some data-flow links are left unverified rather than inferred as confirmed calls.

Main entry points: [`campera-calefactor.ino`](https://github.com/benjaalonso357-dot/campera-calefactor/blob/main/campera-calefactor.ino) (Setup and loop), [`comandos.cpp`](https://github.com/benjaalonso357-dot/campera-calefactor/blob/main/comandos.cpp) (Command processing), [`botones.cpp`](https://github.com/benjaalonso357-dot/campera-calefactor/blob/main/botones.cpp) (Button handling), [`estado.cpp`](https://github.com/benjaalonso357-dot/campera-calefactor/blob/main/estado.cpp) (Shared zone state)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_control["User controls"]
  node_buttons["Button handling<br/>[botones.cpp]"]
  node_commands["Command processing<br/>[comandos.cpp]"]
  node_ble["BLE service<br/>[bluetooth.cpp]"]
end

subgraph group_thermal["Thermal control"]
  node_sensors["Temperature sensing<br/>[sensores.cpp]"]
  node_heaters["Heater control<br/>[calefactores.cpp]"]
end

subgraph group_state["State and persistence"]
  node_state["Shared zone state<br/>[estado.cpp]"]
  node_memory["Target persistence<br/>[memoria.cpp]"]
end

subgraph group_platform["Firmware platform"]
  node_sketch["Setup and loop"]
  node_config["Pin and limits config<br/>[configuracion.h]"]
  node_power["Sleep and wake<br/>[energia.cpp]"]
end

node_user(("Jacket user"))
node_phone(("BLE phone"))
node_serial(("Serial monitor"))
node_buttons_hw(("Physical buttons"))
node_lm35(("Four LM35 sensors"))
node_mosfets(("Heater MOSFETs"))
node_eeprom[("EEPROM")]

node_user -->|"presses"| node_buttons_hw
node_buttons_hw -.->|"reads presses"| node_buttons
node_buttons -->|"sleeps on hold"| node_power
node_buttons -.->|"sets targets"| node_state
node_phone -->|"sends commands"| node_ble
node_ble -->|"dispatches"| node_commands
node_ble -->|"notifies zones"| node_phone
node_serial -->|"sends commands"| node_commands
node_commands -->|"sets targets"| node_state
node_commands -->|"checks heating"| node_heaters
node_commands -->|"prints status"| node_serial
node_lm35 -->|"provides readings"| node_sensors
node_sensors -.->|"updates measurements"| node_state
node_state -->|"supplies temperatures"| node_heaters
node_heaters -->|"switches zones"| node_mosfets
node_state -->|"provides targets"| node_memory
node_memory -->|"reads and writes"| node_eeprom
node_sketch -.->|"orchestrates"| node_sensors
node_sketch -.->|"orchestrates"| node_heaters
node_sketch -.->|"orchestrates"| node_buttons
node_sketch -.->|"orchestrates"| node_ble
node_sketch -.->|"orchestrates"| node_memory
node_config -.->|"configures pins"| node_buttons

click node_sketch "https://github.com/benjaalonso357-dot/campera-calefactor/blob/main/campera-calefactor.ino"
click node_config "https://github.com/benjaalonso357-dot/campera-calefactor/blob/main/configuracion.h"
click node_buttons "https://github.com/benjaalonso357-dot/campera-calefactor/blob/main/botones.cpp"
click node_commands "https://github.com/benjaalonso357-dot/campera-calefactor/blob/main/comandos.cpp"
click node_ble "https://github.com/benjaalonso357-dot/campera-calefactor/blob/main/bluetooth.cpp"
click node_sensors "https://github.com/benjaalonso357-dot/campera-calefactor/blob/main/sensores.cpp"
click node_heaters "https://github.com/benjaalonso357-dot/campera-calefactor/blob/main/calefactores.cpp"
click node_state "https://github.com/benjaalonso357-dot/campera-calefactor/blob/main/estado.cpp"
click node_memory "https://github.com/benjaalonso357-dot/campera-calefactor/blob/main/memoria.cpp"
click node_power "https://github.com/benjaalonso357-dot/campera-calefactor/blob/main/energia.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_buttons,node_commands,node_ble,node_user toneBlue
class node_sensors,node_heaters,node_eeprom toneAmber
class node_state,node_memory toneMint
class node_sketch,node_config,node_power toneRose
class node_phone,node_serial,node_buttons_hw,node_lm35,node_mosfets toneIndigo
```

## Components

### User controls

- [Button handling](https://github.com/benjaalonso357-dot/campera-calefactor/blob/main/botones.cpp): `botones.cpp`
- [Command processing](https://github.com/benjaalonso357-dot/campera-calefactor/blob/main/comandos.cpp): `comandos.cpp`
- [BLE service](https://github.com/benjaalonso357-dot/campera-calefactor/blob/main/bluetooth.cpp): `bluetooth.cpp`

### Thermal control

- [Temperature sensing](https://github.com/benjaalonso357-dot/campera-calefactor/blob/main/sensores.cpp): `sensores.cpp`
- [Heater control](https://github.com/benjaalonso357-dot/campera-calefactor/blob/main/calefactores.cpp): `calefactores.cpp`

### State and persistence

- [Shared zone state](https://github.com/benjaalonso357-dot/campera-calefactor/blob/main/estado.cpp): `estado.cpp`
- [Target persistence](https://github.com/benjaalonso357-dot/campera-calefactor/blob/main/memoria.cpp): `memoria.cpp`

### Firmware platform

- [Setup and loop](https://github.com/benjaalonso357-dot/campera-calefactor/blob/main/campera-calefactor.ino): `campera-calefactor.ino`
- [Pin and limits config](https://github.com/benjaalonso357-dot/campera-calefactor/blob/main/configuracion.h): `configuracion.h`
- [Sleep and wake](https://github.com/benjaalonso357-dot/campera-calefactor/blob/main/energia.cpp): `energia.cpp`

### Other components

- **Jacket user**
- **BLE phone**
- **Serial monitor**
- **Physical buttons**
- **Four LM35 sensors**
- **Heater MOSFETs**
- **EEPROM**

## Connections

- Jacket user → Physical buttons: presses (evidence: `README.md`)
- Physical buttons → Button handling: reads presses
- Button handling → Sleep and wake: sleeps on hold (evidence: `botones.cpp`)
- Button handling → Shared zone state: sets targets
- BLE phone → BLE service: sends commands (evidence: `README.md`)
- BLE service → Command processing: dispatches (evidence: `bluetooth.cpp`)
- BLE service → BLE phone: notifies zones (evidence: `bluetooth.cpp`)
- Serial monitor → Command processing: sends commands (evidence: `README.md`)
- Command processing → Shared zone state: sets targets (evidence: `comandos.cpp`)
- Command processing → Heater control: checks heating (evidence: `comandos.cpp`)
- Command processing → Serial monitor: prints status (evidence: `comandos.cpp`)
- Four LM35 sensors → Temperature sensing: provides readings (evidence: `README.md`)
- Temperature sensing → Shared zone state: updates measurements
- Shared zone state → Heater control: supplies temperatures (evidence: `calefactores.cpp`)
- Heater control → Heater MOSFETs: switches zones (evidence: `README.md`)
- Shared zone state → Target persistence: provides targets (evidence: `memoria.cpp`)
- Target persistence → EEPROM: reads and writes (evidence: `memoria.cpp`)
- Setup and loop → Temperature sensing: orchestrates
- Setup and loop → Heater control: orchestrates
- Setup and loop → Button handling: orchestrates
- Setup and loop → BLE service: orchestrates
- Setup and loop → Target persistence: orchestrates
- Pin and limits config → Button handling: configures pins
