Skip to content

Commit d1ff89a

Browse files
committed
Remove WIFI_DEBUG code and update documentation
Eliminated conditional WIFI_DEBUG code and related includes from sp140.ino, and removed commented build flag from platformio.ini. Also fixed a minor typo in the README.md.
1 parent 27cae8c commit d1ff89a

File tree

5 files changed

+36
-114
lines changed

5 files changed

+36
-114
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Arduino based logic for OpenPPG SP140 Throttle Controller
66

7-
#### This master branch is only for testing the latest firmware for the and SP140 controllers running the ESP32-S3 processor.
7+
#### This master branch is only for testing the latest firmware for the SP140 controllers running the ESP32-S3 processor.
88

99
X4 code has been migrated to a separate repo - https://github.com/openppg/x4-controller
1010

SIMPLE_MONITOR_README.md

Lines changed: 35 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,50 @@
1-
# Simple Sensor Monitoring System
1+
# Sensor Monitoring System
22

33
## Overview
4-
A lightweight, elegant monitoring system for ESP32 electric ultralight sensors. Based on modern C++ patterns with easy extensibility.
4+
Real-time health monitoring for ESP32 electric ultralight sensors. Monitors ESC, BMS, altimeter, and system health with threshold-based alerting.
55

6-
## Design Philosophy
7-
- **Simple**: ~50 lines of core code vs complex alerting systems
8-
- **Flexible**: Easy to add new sensors and output methods
9-
- **Modern**: Uses `std::function` and lambdas for clean sensor definitions
10-
- **Extensible**: Interface-based design for multiple output channels
6+
## Features
7+
- **Comprehensive**: 50+ sensors monitored across all flight systems
8+
- **Smart Alerting**: Hysteresis protection prevents false alerts
9+
- **Multiple Outputs**: Serial, display, and extensible logging
10+
- **Efficient**: Minimal overhead, change-only notifications
1111

12-
## Usage
12+
## What's Monitored
1313

14-
### Current ESC Temperature Monitoring
15-
```cpp
16-
// Automatically monitors:
17-
// - ESC MOS: Warning 90°C, Critical 110°C
18-
// - ESC MCU: Warning 80°C, Critical 95°C
19-
// - ESC CAP: Warning 85°C, Critical 100°C
20-
// - Motor: Warning 90°C, Critical 110°C
21-
```
14+
### ESC
15+
- Temperatures (MOS, MCU, CAP, Motor)
16+
- Error states (over-current, over-temp, voltage issues)
17+
- Hardware faults and diagnostics
2218

23-
### Adding New Sensors
24-
```cpp
25-
// Example: Battery voltage monitoring
26-
static SensorMonitor batteryVoltage = {
27-
"BatteryVolt",
28-
{.warnLow = 70, .warnHigh = 105, .critLow = 65, .critHigh = 110},
29-
[]() { return bmsTelemetryData.battery_voltage; },
30-
AlertLevel::OK,
31-
&serialLogger
32-
};
33-
sensors.push_back(&batteryVoltage);
34-
```
19+
### BMS
20+
- Cell voltages and temperature sensors
21+
- State of charge and charge/discharge status
22+
- Voltage differential monitoring
3523

36-
### Example Output
37-
```
38-
[15234] [WARN_HIGH] ESC_MOS_Temp = 92.50
39-
[15467] [CRIT_HIGH] Motor_Temp = 112.30
40-
[15890] [OK] ESC_MOS_Temp = 88.20
41-
```
24+
### System
25+
- CPU temperature and altimeter readings
26+
- System health and diagnostics
4227

43-
## Easy Extensions
28+
## How It Works
4429

45-
### SD Card Logging
46-
```cpp
47-
struct SDLogger : ILogger {
48-
void log(const char* name, AlertLevel lvl, float v) override {
49-
// Write timestamp, name, level, value to SD card
50-
File logFile = SD.open("/alerts.log", FILE_APPEND);
51-
logFile.printf("%lu,%s,%d,%.2f\n", millis(), name, (int)lvl, v);
52-
logFile.close();
53-
}
54-
};
55-
```
30+
System automatically monitors all sensors and alerts on threshold violations. Hysteresis prevents false alerts from sensor noise.
5631

57-
### Display Alerts
58-
```cpp
59-
struct DisplayLogger : ILogger {
60-
void log(const char* name, AlertLevel lvl, float v) override {
61-
// Show alert on LVGL display
62-
if (lvl >= AlertLevel::WARN_HIGH) {
63-
showAlertPopup(name, lvl, v);
64-
}
65-
}
66-
};
67-
```
32+
### Alert Levels
33+
- **OK**: Normal operation
34+
- **WARN**: Advisory thresholds exceeded
35+
- **CRIT**: Critical thresholds requiring attention
6836

69-
### Multiple Outputs
70-
```cpp
71-
// Log to both serial and SD card
72-
static SerialLogger serialLog;
73-
static SDLogger sdLog;
74-
75-
sensorMonitor.logger = &serialLog; // Or use both with composite pattern
37+
### Example Output
7638
```
77-
78-
## Architecture
79-
80-
```cpp
81-
ILogger (interface)
82-
├── SerialLogger (serial console)
83-
├── SDLogger (SD card - future)
84-
└── DisplayLogger (LVGL display - future)
85-
86-
SensorMonitor
87-
├── name (string identifier)
88-
├── thresholds (warn/crit levels)
89-
├── read (lambda function)
90-
└── logger (output interface)
39+
[15234] [WARN_HIGH] ESC_MOS_Temp = 92.50
40+
[15467] [CRIT_HIGH] Motor_Temp = 112.30
41+
[15890] [OK] ESC_MOS_Temp = 88.20
9142
```
9243

93-
## Integration
94-
- Monitors check every 40ms in main SPI communication task
95-
- Only logs when alert level changes (no spam)
96-
- Uses existing telemetry data (no additional sensor reads)
97-
- Zero overhead when sensors are in OK state
98-
99-
## Memory Usage
100-
- ~1KB total code size
101-
- ~200 bytes per monitored sensor
102-
- Minimal RAM footprint
103-
- No dynamic allocation during runtime
44+
### Integration
45+
- Runs every 40ms in FreeRTOS task
46+
- Displays alerts on screen with haptic feedback
47+
- Serial logging for diagnostics
48+
- Thread-safe with minimal CPU overhead
10449

105-
This approach perfectly balances simplicity with extensibility - start with basic serial logging, easily expand to SD cards, displays, or remote monitoring as needed.
50+
The system provides comprehensive flight safety monitoring while maintaining performance for electric ultralight operation.

inc/sp140/throttle.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,6 @@
2323
#define CHILL_MODE_RAMP_RATE 10 // us/tick in chill mode (~1.6s 1035->1850)
2424
#define SPORT_MODE_RAMP_RATE 27 // us/tick in sport mode (~0.68s 1035->1950)
2525

26-
/**
27-
* Throttle easing function based on threshold/performance mode
28-
* Limits how quickly throttle can increase or decrease
29-
*
30-
* @param current Current throttle value
31-
* @param last Previous throttle value
32-
* @param threshold Maximum allowed change per cycle
33-
* @return Limited throttle value
34-
*/
3526
/**
3627
* Limits how quickly a value may change between ticks.
3728
* - Caps acceleration to `threshold` per tick.

platformio.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ extra_scripts =
2929
pre:extra_script.py
3030
merge-esp.py
3131
build_flags =
32-
; -D WIFI_DEBUG=false
3332
; -D SCREEN_DEBUG=false
3433
; -D SCREEN_DEBUG_STATIC=false
3534
-D LV_CONF_INCLUDE_SIMPLE

src/sp140/sp140.ino

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@
1616
// ESP32S3 (CAN) specific libraries here
1717
#include "esp_task_wdt.h"
1818

19-
#ifdef WIFI_DEBUG
20-
#include "Insights.h"
21-
#include "WiFi.h"
22-
#include "inttypes.h"
23-
#include "esp_err.h"
24-
#endif
25-
2619
#include "../../inc/sp140/globals.h" // device config
2720
#include "../../inc/sp140/esc.h"
2821
#include "../../inc/sp140/lvgl/lvgl_core.h"
@@ -61,8 +54,6 @@ int8_t bmsCS = MCP_CS;
6154
#define PERFORMANCE_MODE_HOLD_MS 3000 // Longer hold time for performance mode
6255

6356
// Throttle control constants moved to inc/sp140/throttle.h
64-
65-
#define DECEL_MULTIPLIER 2.0 // How much faster deceleration is vs acceleration
6657
#define CRUISE_MAX_PERCENTAGE 0.60 // Maximum cruise throttle as a percentage of the total ESC range (e.g., 0.60 = 60%)
6758
#define CRUISE_DISENGAGE_POT_THRESHOLD_PERCENTAGE 0.80 // Current pot must be >= this % of activation value to disengage
6859
#define CRUISE_DISENGAGE_GRACE_PERIOD_MS 2000 // Delay before checking pot disengagement after cruise activation
@@ -620,16 +611,12 @@ void setup() {
620611
setupWatchdog();
621612
setup140();
622613

623-
#ifdef WIFI_DEBUG
624-
setupWiFi();
625-
#endif
626614
setLEDColor(LED_YELLOW); // Booting up
627615

628616
// First initialize the shared SPI bus
629617
setupSPI(board_config);
630618

631619
// Then setup the display - use LVGL display instead of the old one
632-
// setupDisplay(deviceData, board_config, hardwareSPI);
633620
// Pass hardcoded pin values for DC and RST
634621
setupLvglDisplay(deviceData, board_config.tft_dc, board_config.tft_rst, hardwareSPI);
635622

0 commit comments

Comments
 (0)