diff --git a/platformio.ini b/platformio.ini index 98f405c..1d52f84 100644 --- a/platformio.ini +++ b/platformio.ini @@ -8,40 +8,42 @@ ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html +[common] +; All ESP32 targets use the pioarduino fork, which ships Arduino-ESP32 3.x +; (the registry espressif32 platform is still on 2.0.17 and lacks C6 support). +platform_esp32 = https://github.com/pioarduino/platform-espressif32/releases/download/55.03.39/platform-espressif32.zip + [env] +framework = arduino +monitor_speed = 115200 +lib_deps = + tzapu/WiFiManager@^2.0.17 + bblanchon/ArduinoJson@^7.4.3 + knolleary/PubSubClient@^2.8 [env:esp32-s3-devkitc-1] -platform = espressif32@^6.10.0 board = esp32-s3-devkitc-1 -framework = arduino -monitor_speed = 115200 board_build.filesystem = littlefs -lib_deps = - tzapu/WiFiManager@^2.0.17 - bblanchon/ArduinoJson@^7.0.0 - knolleary/PubSubClient@^2.8 [env:esp32dev] +platform = ${common.platform_esp32} board = esp32dev -framework = arduino -platform = espressif32@^6.10.0 -monitor_speed = 115200 board_build.filesystem = littlefs -lib_deps = - tzapu/WiFiManager@^2.0.17 - bblanchon/ArduinoJson@^7.4.3 - knolleary/PubSubClient@^2.8 [env:esp32-C3-devkitm-1] +platform = ${common.platform_esp32} board = esp32-c3-devkitm-1 -framework = arduino -platform = espressif32@^6.10.0 -monitor_speed = 115200 board_build.filesystem = littlefs -build_flags = - -DARDUINO_USB_MODE=1 - -DARDUINO_USB_CDC_ON_BOOT=1 -lib_deps = - tzapu/WiFiManager@^2.0.17 - bblanchon/ArduinoJson@^7.4.3 - knolleary/PubSubClient@^2.8 \ No newline at end of file + +[env:esp32-c6-devkitc-1] +platform = ${common.platform_esp32} +board = esp32-c6-devkitc-1 +board_build.filesystem = littlefs + +[env:rpipico2w] +; RP2350 support requires the maxgerhardt fork of the raspberrypi platform +; and the earlephilhower arduino-pico core. +platform = https://github.com/maxgerhardt/platform-raspberrypi.git +board = rpipico2w +board_build.core = earlephilhower +board_build.filesystem_size = 0.5m diff --git a/src/main.cpp b/src/main.cpp index aca2f13..b15e48f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -152,7 +152,7 @@ static void attachMeters() { // Release the channel if it's no longer used or its pin changed. if (attachedPin[i] != -1 && attachedPin[i] != pin) { - ledcDetachPin(attachedPin[i]); + ledcDetach(attachedPin[i]); pinMode(attachedPin[i], OUTPUT); digitalWrite(attachedPin[i], LOW); // drive freed pin low so the meter reads zero Serial.printf("[PWM] detach ch%d pin%d\n", i, attachedPin[i]); @@ -160,8 +160,7 @@ static void attachMeters() { } if (pin > 0 && attachedPin[i] != pin) { - ledcSetup(i, PWM_FREQ, PWM_RES); - ledcAttachPin(pin, i); + ledcAttach(pin, PWM_FREQ, PWM_RES); attachedPin[i] = pin; Serial.printf("[PWM] attach ch%d pin%d\n", i, pin); } @@ -173,7 +172,7 @@ static void applyMeters() { if (meters[i].pin <= 0 || meters[i].maxDuty <= 0) continue; float pct = meters[i].currentValue / 100.0f * meters[i].maxDuty / 100.0f; int duty = constrain((int)(pct * 1023), 0, 1023); - ledcWrite(i, duty); + ledcWrite(meters[i].pin, duty); Serial.printf("[PWM] ch%d duty=%d (cur=%.1f maxD=%.1f)\n", i, duty, meters[i].currentValue, meters[i].maxDuty); } } @@ -222,7 +221,7 @@ static void mqttCallback(char* topic, byte* payload, unsigned int len) { meters[idx].currentValue = physicalToPct(val, idx); if (meters[idx].pin > 0 && meters[idx].maxDuty > 0) { float pct = meters[idx].currentValue / 100.0f * meters[idx].maxDuty / 100.0f; - ledcWrite(idx, constrain((int)(pct * 1023), 0, 1023)); + ledcWrite(meters[idx].pin, constrain((int)(pct * 1023), 0, 1023)); } mqttPublishCurrent(idx); } @@ -441,6 +440,15 @@ static void handleRoot() { if (!requireAuth()) { Serial.println("[HTTP] GET / -> 401"); return; } Serial.println("[HTTP] GET /"); String meterRows; + bool useTabs = meterCount > 1; + if (useTabs) { + meterRows += "
