Skip to content

Conversation

@m-RNA
Copy link
Contributor

@m-RNA m-RNA commented Dec 23, 2025

Summary

Add AdcSampler for Monitoring component and added battery monitoring with SOC calculation.

Architecture:

+-----------------------+
|   MonitoringManager   | ← High-level coordinator
+-----------------------+
|  BatteryMonitor       | ← Battery logic (platform-independent)
|  CurrentMonitor       | ← Current logic (platform-independent)
+-----------------------+
|      AdcSampler       | ← BSP: Unified ADC sampling interface
+-----------------------+
|   ESP-IDF ADC HAL     | ← Espressif official driver
+-----------------------+

Details

BSP Layer (AdcSampler)

  • Unified ADC1 oneshot sampling interface
  • Platform-specific GPIO-to-channel mapping:
    • AdcSampler_esp32.cpp: GPIO32-39 → ADC1_CH0-7
    • AdcSampler_esp32s3.cpp: GPIO1-10 → ADC1_CH0-9
  • Shared ADC unit initialization with curve-fitting calibration

Business Logic Layer

  • BatteryMonitor: Voltage divider compensation, Li-ion SOC lookup table with linear interpolation
  • CurrentMonitor: Shunt-based current calculation with gain compensation
  • Both are delegate hardware access to AdcSampler

Coordinator Layer (MonitoringManager)

  • Caches BatteryStatus (voltage + percentage + validity) directly
  • Schedules LED current and battery sampling with configurable periods
  • Thread-safe access via mutex for BatteryStatus

Command Layer

  • Add getBatteryStatusCommand()

MenuConfig

image

Testing

Platform Board ADC Pins Result
ESP32-S3 wrooms3QIO Pin 1 & Pin 3 PASS
ESP32 esp32AIThinker Pin 32 & Pin 33 PASS
  • CONFIG_MONITORING_LED_CURRENT=y
  • CONFIG_MONITORING_BATTERY_ENABLE=y
🔧 OpenIris Setup Tool
==================================================
📡 Connecting directly to COMX...
✅ Connected to the device on COMX
 1  📶 WiFi settings
 2  🌐 Configure MDNS
 3  💻 Configure UVC Name
 4  🚀 Start streaming mode
 5  🔄 Switch device mode (WiFi/UVC/Auto)
 6  💡 Update PWM Duty Cycle
 7  🧩 Get settings summary
 8  🔪 Restart device
[Back] To go back
>> 7
--------------------------------------------------
🧩 Collecting device settings...

🔑 Serial: xxx
💡 LED PWM Duty: 100%
🎚️  Mode: wifi
🔌 LED Current: 0.091 mA
🔋 Battery: 4388.00 mV | 100.0 %
📛 Name: openiristracker
🏷️  Device: OpenIris
🧭 Version: 0.2.1rc0
📶 WiFi: connecting  |  IP: -  |  Networks configured: 0

@m-RNA m-RNA force-pushed the feature/add-battery-monitor branch from 6d84336 to 97b910a Compare January 1, 2026 09:20
@m-RNA m-RNA marked this pull request as ready for review January 1, 2026 09:48
@m-RNA m-RNA changed the title Add battery monitor Add AdcSampler & BatteryMonitor Jan 1, 2026
@m-RNA m-RNA marked this pull request as draft January 1, 2026 09:52
@m-RNA m-RNA marked this pull request as ready for review January 1, 2026 14:00
@m-RNA
Copy link
Contributor Author

m-RNA commented Jan 1, 2026

@lorow This Pr is ready for review.

Copy link
Member

@lorow lorow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly I like the changes!

Thanks for bringing in the battery monitoring and expanding what we already had with the current monitor! Though, I'm on the verge with checking for esp32s3 || esp32 since those are the only two platforms we support (and stuff from s2 should work under s3 iirc, if we even have a board like that) but it doesn't hurt or obscure the logic anyway so I didn't point it out in the review. Heck, I may be wrong here for all I know!

Thanks for giving it a go on both - the wrooms and esp32cams btw!

I'll go ahead and merge the changes

@lorow lorow merged commit 567d3eb into EyeTrackVR:main Jan 6, 2026
26 checks passed
@m-RNA
Copy link
Contributor Author

m-RNA commented Jan 9, 2026

You're right — platform-specific logic like ADC calibration and pin mappings really should live in separate files rather than being tangled together with macros. It’s cleaner and makes future porting much simpler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants