# ybin2024/nas-fan-control architecture

> Architecture diagram of the GitHub repository ybin2024/nas-fan-control, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ybin2024/nas-fan-control
- Repository: https://github.com/ybin2024/nas-fan-control

## Overview

This ESP32-H2 firmware controls NAS hard-disk cooling by combining disk-current and temperature measurements into a fan PWM demand, with startup fan diagnostics and optional sleep management. The main application is a single substantial C module, so its distinct runtime responsibilities share that source path rather than implying separate modules. The excerpts show ADC setup and sampling, conversion helpers, and the fusion calculation; README statements support the broader PWM-control and sleep capabilities. Some wiring is omitted from the excerpts, so only documented or visible relationships are drawn.

Main entry points: [`main/oneshot_read_main.c`](https://github.com/ybin2024/nas-fan-control/blob/main/main/oneshot_read_main.c) (ADC sampling)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_sensing["Sensing and conversion"]
  node_sampling["ADC sampling"]
  node_temperature["Temperature conversion"]
  node_current["Current mapping"]
end

subgraph group_control["Fan control"]
  node_fusion["Demand fusion"]
  node_diagnostics["Fan diagnostics"]
  node_pwm["PWM control"]
end

subgraph group_runtime["Board runtime"]
  node_sleep["Sleep management"]
end

node_hardware(("Disk sensors"))
node_fan(("Cooling fan"))

node_hardware -->|"provides signals"| node_sampling
node_sampling -->|"converts NTC"| node_temperature
node_sampling -->|"reads current"| node_current
node_temperature -->|"supplies temperatures"| node_fusion
node_current -->|"supplies current"| node_fusion
node_fusion -->|"sets duty"| node_pwm
node_diagnostics -->|"checks rotation"| node_fan
node_pwm -->|"drives speed"| node_fan

click node_sampling "https://github.com/ybin2024/nas-fan-control/blob/main/main/oneshot_read_main.c"
click node_temperature "https://github.com/ybin2024/nas-fan-control/blob/main/main/oneshot_read_main.c"
click node_current "https://github.com/ybin2024/nas-fan-control/blob/main/main/oneshot_read_main.c"
click node_fusion "https://github.com/ybin2024/nas-fan-control/blob/main/main/oneshot_read_main.c"
click node_diagnostics "https://github.com/ybin2024/nas-fan-control/blob/main/main/oneshot_read_main.c"
click node_pwm "https://github.com/ybin2024/nas-fan-control/blob/main/main/oneshot_read_main.c"
click node_sleep "https://github.com/ybin2024/nas-fan-control/blob/main/main/oneshot_read_main.c"

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_sampling,node_temperature,node_current toneBlue
class node_fusion,node_diagnostics,node_pwm toneAmber
class node_sleep toneMint
class node_hardware,node_fan toneIndigo
```

## Components

### Sensing and conversion

- [ADC sampling](https://github.com/ybin2024/nas-fan-control/blob/main/main/oneshot_read_main.c): `main/oneshot_read_main.c`
- [Temperature conversion](https://github.com/ybin2024/nas-fan-control/blob/main/main/oneshot_read_main.c): `main/oneshot_read_main.c`
- [Current mapping](https://github.com/ybin2024/nas-fan-control/blob/main/main/oneshot_read_main.c): `main/oneshot_read_main.c`

### Fan control

- [Demand fusion](https://github.com/ybin2024/nas-fan-control/blob/main/main/oneshot_read_main.c): `main/oneshot_read_main.c`
- [Fan diagnostics](https://github.com/ybin2024/nas-fan-control/blob/main/main/oneshot_read_main.c): `main/oneshot_read_main.c`
- [PWM control](https://github.com/ybin2024/nas-fan-control/blob/main/main/oneshot_read_main.c): `main/oneshot_read_main.c`

### Board runtime

- [Sleep management](https://github.com/ybin2024/nas-fan-control/blob/main/main/oneshot_read_main.c): `main/oneshot_read_main.c`

### Other components

- **Disk sensors**
- **Cooling fan**

## Connections

- Disk sensors → ADC sampling: provides signals (evidence: `README.md`)
- ADC sampling → Temperature conversion: converts NTC (evidence: `main/oneshot_read_main.c`)
- ADC sampling → Current mapping: reads current (evidence: `main/oneshot_read_main.c`)
- Temperature conversion → Demand fusion: supplies temperatures (evidence: `README.md`)
- Current mapping → Demand fusion: supplies current (evidence: `main/oneshot_read_main.c`)
- Demand fusion → PWM control: sets duty (evidence: `README.md`)
- Fan diagnostics → Cooling fan: checks rotation (evidence: `main/oneshot_read_main.c`)
- PWM control → Cooling fan: drives speed (evidence: `README.md`)
