# drngominhtu/esp32_wirelessmouse architecture

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

- Interactive diagram: https://gitdiagram.com/drngominhtu/esp32_wirelessmouse
- Repository: https://github.com/drngominhtu/esp32_wirelessmouse

## Overview

This repository is an ESP32 firmware air mouse. Its workflow initializes the MPU6050 and calibrates it, then the main loop handles serial commands and—when BLE is connected—updates mouse input at a 50 Hz cadence. Motion processing applies calibration, deadzone and drift handling before sending cursor, scroll and click actions over BLE. Serial controls also expose configuration, status and I2C scanning. The single source file combines these responsibilities; finer internal boundaries reflect functions described in its excerpts. Other README capabilities are included where documented, though their implementation details were not sampled.

Main entry points: [`src/main.cpp`](https://github.com/drngominhtu/esp32_wirelessmouse/blob/main/src/main.cpp) (Mouse update)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Firmware runtime"]
  node_mainloop["Main loop<br/>[main.cpp]"]
end

subgraph group_motion["Motion processing"]
  node_calibration["Gyro calibration<br/>[main.cpp]"]
  node_motionupdate["Mouse update<br/>[main.cpp]"]
  node_drift["Drift correction<br/>[main.cpp]"]
end

subgraph group_interfaces["Device interfaces"]
  node_sensor["MPU6050"]
  node_ble["BLE mouse output<br/>[main.cpp]"]
  node_serial["Serial commands<br/>[main.cpp]"]
  node_scanner["I2C scanner<br/>[main.cpp]"]
end

node_user(("Device user"))
node_host(("BLE host"))

node_mainloop -->|"calibrates at setup"| node_calibration
node_mainloop -->|"handles commands"| node_serial
node_mainloop -->|"updates when connected"| node_motionupdate
node_calibration -->|"samples readings"| node_sensor
node_motionupdate -->|"reads events"| node_sensor
node_motionupdate -->|"sends mouse actions"| node_ble
node_serial -->|"recalibrates"| node_calibration
node_serial -->|"starts scan"| node_scanner
node_user -->|"sends commands"| node_serial
node_user -->|"moves device"| node_sensor
node_ble -->|"controls cursor"| node_host
node_motionupdate -.->|"uses correction"| node_drift

click node_mainloop "https://github.com/drngominhtu/esp32_wirelessmouse/blob/main/src/main.cpp"
click node_calibration "https://github.com/drngominhtu/esp32_wirelessmouse/blob/main/src/main.cpp"
click node_motionupdate "https://github.com/drngominhtu/esp32_wirelessmouse/blob/main/src/main.cpp"
click node_drift "https://github.com/drngominhtu/esp32_wirelessmouse/blob/main/src/main.cpp"
click node_ble "https://github.com/drngominhtu/esp32_wirelessmouse/blob/main/src/main.cpp"
click node_serial "https://github.com/drngominhtu/esp32_wirelessmouse/blob/main/src/main.cpp"
click node_scanner "https://github.com/drngominhtu/esp32_wirelessmouse/blob/main/src/main.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_mainloop,node_user toneBlue
class node_calibration,node_motionupdate,node_drift toneAmber
class node_sensor,node_ble,node_serial,node_scanner toneMint
class node_host toneIndigo
```

## Components

### Firmware runtime

- [Main loop](https://github.com/drngominhtu/esp32_wirelessmouse/blob/main/src/main.cpp): `src/main.cpp`

### Motion processing

- [Gyro calibration](https://github.com/drngominhtu/esp32_wirelessmouse/blob/main/src/main.cpp): `src/main.cpp`
- [Mouse update](https://github.com/drngominhtu/esp32_wirelessmouse/blob/main/src/main.cpp): `src/main.cpp`
- [Drift correction](https://github.com/drngominhtu/esp32_wirelessmouse/blob/main/src/main.cpp): `src/main.cpp`

### Device interfaces

- **MPU6050**
- [BLE mouse output](https://github.com/drngominhtu/esp32_wirelessmouse/blob/main/src/main.cpp): `src/main.cpp`
- [Serial commands](https://github.com/drngominhtu/esp32_wirelessmouse/blob/main/src/main.cpp): `src/main.cpp`
- [I2C scanner](https://github.com/drngominhtu/esp32_wirelessmouse/blob/main/src/main.cpp): `src/main.cpp`

### Other components

- **Device user**
- **BLE host**

## Connections

- Main loop → Gyro calibration: calibrates at setup (evidence: `src/main.cpp`)
- Main loop → Serial commands: handles commands (evidence: `src/main.cpp`)
- Main loop → Mouse update: updates when connected (evidence: `src/main.cpp`)
- Gyro calibration → MPU6050: samples readings (evidence: `src/main.cpp`)
- Mouse update → MPU6050: reads events (evidence: `src/main.cpp`)
- Mouse update → BLE mouse output: sends mouse actions (evidence: `src/main.cpp`)
- Serial commands → Gyro calibration: recalibrates (evidence: `src/main.cpp`)
- Serial commands → I2C scanner: starts scan (evidence: `src/main.cpp`)
- Device user → Serial commands: sends commands (evidence: `README.md`)
- Device user → MPU6050: moves device (evidence: `README.md`)
- BLE mouse output → BLE host: controls cursor (evidence: `README.md`)
- Mouse update → Drift correction: uses correction (evidence: `src/main.cpp`)
