|
| 1 | +# MAZDUINO Display Modularization Status |
| 2 | + |
| 3 | +## Overview |
| 4 | +The ESP32 dashboard project has been successfully modularized from a single `.ino` file into multiple `.h` and `.cpp` files. The main file has been converted from `.ino` to `.cpp` format. |
| 5 | + |
| 6 | +## File Structure |
| 7 | + |
| 8 | +### Main Application |
| 9 | +- **main.cpp** - Main application file (replaces ESP32_DevkitC_3.5_SPI.ino) |
| 10 | +- **ESP32_DevkitC_3.5_SPI.ino.backup** - Backup of original file |
| 11 | + |
| 12 | +### Modular Components |
| 13 | + |
| 14 | +#### Configuration & Data |
| 15 | +- **Config.h** - System constants, pin definitions, and configuration |
| 16 | +- **DataTypes.h** - Global variable declarations |
| 17 | +- **GlobalVariables.cpp** - Global variable definitions |
| 18 | + |
| 19 | +#### Hardware Modules |
| 20 | +- **BacklightControl.h/cpp** - PWM backlight control on pin 32 |
| 21 | +- **CANHandler.h/cpp** - CAN communication and message parsing |
| 22 | +- **DisplayManager.h/cpp** - Display/UI management and rendering |
| 23 | + |
| 24 | +#### Network & Communication |
| 25 | +- **WebServerHandler.h/cpp** - OTA updates and web server functionality |
| 26 | +- **Comms.h/cpp** - Serial communication with ECU (formerly Comms.ino) |
| 27 | + |
| 28 | +#### Legacy/Utility Files |
| 29 | +- **drawing_utils.h** - Drawing utility functions |
| 30 | +- **text_utils.h** - Text utility functions |
| 31 | +- **NotoSansBold15.h** - Font definition |
| 32 | +- **NotoSansBold36.h** - Font definition |
| 33 | +- **splash.bmp** - Splash screen image |
| 34 | + |
| 35 | +## Key Features Implemented |
| 36 | + |
| 37 | +### 1. CAN ID 0x369 (Trigger System Error Count) |
| 38 | +- ✅ Added CAN0.watchFor(0x369) in setupCAN() |
| 39 | +- ✅ Implemented parsing in handleCANCommunication() |
| 40 | +- ✅ Added triggerError variable to DataTypes.h |
| 41 | +- ✅ Updated display to show "Trigger" instead of "FPS" when EEPROM.read(0) == 1 |
| 42 | +- ✅ Updated Serial output to include "Trigger Error: " + triggerError |
| 43 | + |
| 44 | +### 2. PWM Backlight Control |
| 45 | +- ✅ Added PWM setup for pin 32 in BacklightControl.cpp |
| 46 | +- ✅ Implemented automatic brightness adjustment based on RPM |
| 47 | +- ✅ Added initializeBacklight() and adjustBacklightAutomatically() functions |
| 48 | +- ✅ Removed old backlight defines from platformio.ini |
| 49 | + |
| 50 | +### 3. Floating Point Display |
| 51 | +- ✅ Fixed AFR display to show floating point values (afrConv with 1 decimal) |
| 52 | +- ✅ Fixed Voltage display to show floating point values (bat with 1 decimal) |
| 53 | +- ✅ Used drawFloat() function in drawDataBox() for proper decimal display |
| 54 | + |
| 55 | +### 4. Modularization |
| 56 | +- ✅ Separated concerns into logical modules |
| 57 | +- ✅ Clean include structure with proper header guards |
| 58 | +- ✅ Maintained backward compatibility with legacy utility files |
| 59 | +- ✅ Converted main file from .ino to .cpp format |
| 60 | + |
| 61 | +## Function Distribution |
| 62 | + |
| 63 | +### main.cpp |
| 64 | +- setup() - Main initialization |
| 65 | +- loop() - Main application loop |
| 66 | +- handleSerialCommunication() - Serial ECU communication |
| 67 | + |
| 68 | +### CANHandler.cpp |
| 69 | +- setupCAN() - CAN initialization |
| 70 | +- handleCANCommunication() - CAN message processing |
| 71 | +- canTask() - FreeRTOS task for CAN |
| 72 | + |
| 73 | +### DisplayManager.cpp |
| 74 | +- setupDisplay() - Display initialization |
| 75 | +- drawSplashScreenWithImage() - Startup splash screen |
| 76 | +- itemDraw() - UI element rendering |
| 77 | +- startUpDisplay() - Initial display setup |
| 78 | +- drawDataBox() - Individual data box rendering |
| 79 | +- drawData() - Main display update |
| 80 | + |
| 81 | +### BacklightControl.cpp |
| 82 | +- initializeBacklight() - PWM setup |
| 83 | +- setBacklightBrightness() - Brightness control |
| 84 | +- adjustBacklightAutomatically() - Automatic brightness based on RPM |
| 85 | + |
| 86 | +### WebServerHandler.cpp |
| 87 | +- setupWebServer() - Web server initialization |
| 88 | +- handleRoot() - Root page handler |
| 89 | +- handleUpdate() - OTA update handler |
| 90 | +- handleToggle() - Display toggle handler |
| 91 | +- handleWebServerClients() - Client management |
| 92 | + |
| 93 | +## Build Configuration |
| 94 | +- **platformio.ini** - Updated with proper build flags |
| 95 | +- **src/main.cpp** - New main application file |
| 96 | +- All modules properly linked and included |
| 97 | + |
| 98 | +## Usage |
| 99 | +1. The project should now build with PlatformIO |
| 100 | +2. CAN ID 0x369 (Trigger System Error Count) is automatically parsed and displayed |
| 101 | +3. PWM backlight control automatically adjusts based on RPM |
| 102 | +4. AFR and Voltage display as floating point values |
| 103 | +5. Modular structure allows easy maintenance and updates |
| 104 | + |
| 105 | +## Notes |
| 106 | +- Original .ino file backed up as .ino.backup |
| 107 | +- All legacy functionality preserved |
| 108 | +- Web server features available but commented out in main.cpp |
| 109 | +- Serial communication mode still supported |
| 110 | +- All previous CAN IDs still supported with new 0x369 addition |
0 commit comments