diff --git a/firmware_update/GenUpdateV2.py b/firmware_update/Tools/GenUpdateV2.py similarity index 100% rename from firmware_update/GenUpdateV2.py rename to firmware_update/Tools/GenUpdateV2.py diff --git a/firmware_update/UploadToGoogle.py b/firmware_update/Tools/UploadToGoogle.py similarity index 100% rename from firmware_update/UploadToGoogle.py rename to firmware_update/Tools/UploadToGoogle.py diff --git a/firmware_update/UploadToMinioV2.py b/firmware_update/Tools/UploadToMinioV2.py similarity index 100% rename from firmware_update/UploadToMinioV2.py rename to firmware_update/Tools/UploadToMinioV2.py diff --git a/firmware_update/loyal-column-439819-e3-8cddff2ee2c2.json b/firmware_update/Tools/loyal-column-439819-e3-8cddff2ee2c2.json similarity index 100% rename from firmware_update/loyal-column-439819-e3-8cddff2ee2c2.json rename to firmware_update/Tools/loyal-column-439819-e3-8cddff2ee2c2.json diff --git a/firmware_update/minio-boothifier-key.json b/firmware_update/Tools/minio-boothifier-key.json similarity index 100% rename from firmware_update/minio-boothifier-key.json rename to firmware_update/Tools/minio-boothifier-key.json diff --git a/src/BLE_SP110E.cpp b/src/BLE_SP110E.cpp index 8a5868d..861af0b 100644 --- a/src/BLE_SP110E.cpp +++ b/src/BLE_SP110E.cpp @@ -73,87 +73,6 @@ class SP110ECallbacks : public NimBLECharacteristicCallbacks { sendToAllClients(value, length); process_BLE_SP110E_Command(value, length, pCharacteristic); - /* - if (length >= 4) { - uint8_t command = value[3]; - ESP_LOGI(tag, "Command received: 0x%02X", command); - - uint8_t response[sizeof(INFO_PACK)]; // Use a single response buffer - - // Handle different commands - switch (command) { - case TURN_ON: - Lights_Set_ON(); - led_status.enable = 1; - //ESP_LOGI(tag, "Lights ON"); - break; - case TURN_OFF: - Lights_Set_OFF(); - led_status.enable = 0; - //ESP_LOGI(tag, "Lights OFF"); - break; - case SET_STATIC_COLOR: - led_status.red = value[1]; - led_status.green = value[2]; - led_status.blue = value[0]; - Lights_Set_Animation(SOLID_COLOR_INDEX, value[0], value[1], value[2]); - //ESP_LOGI(tag, "Color set to R:%d G:%d B:%d", led_status.red, led_status.green, led_status.blue); - break; - case SET_BRIGHT: - led_status.bright = value[0]; - Lights_Set_Brightness(value[0]); - //ESP_LOGI(tag, "Bright set to %d", led_status.bright); - break; - case SET_WHITE: - led_status.white = value[0]; - Lights_Set_White(value[0]); - //ESP_LOGI(tag, "White set to %d", led_status.white); - break; - case SET_PRESET: - led_status.preset = value[0]; - Lights_Set_Animation(value[0], value[1], value[2], 0); - //ESP_LOGI(tag, "Animation set to %d", led_status.preset); - break; - case SET_SPEED: - led_status.speed = value[0]; - ESP_LOGI(tag, "Mode set to %d", led_status.speed); - break; - case GET_CHECK_DEVICE: // This prepends a checksum - led_status.checksum = calculateChecksum((uint8_t *)value); - pCharacteristic->setValue((uint8_t *)&led_status, sizeof(INFO_PACK)); - pCharacteristic->notify(); // Send the data immediately - ESP_LOGI(tag, "Check Device"); - break; - case GET_DEVICE_INFO: // No checksum - led_status.checksum = 0; - pCharacteristic->setValue(((uint8_t *)&led_status) + 1, sizeof(INFO_PACK) - 1); - pCharacteristic->notify(); // Send the data immediately - ESP_LOGI(tag, "Get Device Info"); - break; - case SET_IC_MODEL: - led_status.ic_model = value[0]; - ESP_LOGI(tag, "IC Model set to %d", led_status.ic_model); - break; - case SET_RGB_SEQUENCE: - led_status.channel = 0; - ESP_LOGI(tag, "Set RGB Sequence"); - break; - case SET_LED_NUM: - led_status.count_msb = 0; - led_status.count_lsb = 100; - ESP_LOGI(tag, "Set LED Num"); - break; - case SET_DEVICE_NAME: - ESP_LOGI(tag, "Set Device Name"); - break; - default: - ESP_LOGW(tag, "Unknown command: 0x%02X", command); - break; - } - } else { - ESP_LOGW(tag, "Data too short to process"); - } - */ } }; diff --git a/src/global.cpp b/src/global.cpp index 388f280..acdf5b8 100644 --- a/src/global.cpp +++ b/src/global.cpp @@ -207,16 +207,53 @@ bool updateJsonDocument(JsonDocument &doc, const char* filePath) { #include "soc/ledc_struct.h" -#define LEDC_CHANNEL_COUNT 8 // ESP32 supports up to 8 channels (0 to 7) -int findUnusedLedcChannel() { - // Iterate over all LEDC channels - for (int channel = 0; channel < LEDC_CHANNEL_COUNT; ++channel) { - // Check group 0 registers for channel usage - if (LEDC.channel_group[0].channel[channel].conf0.val == 0) { - return channel; // Found an unused channel +#define LEDC_CHANNEL_COUNT 8 // ESP32 (one speed mode) exposes 8 channels (0..7) per mode + +// NOTE: +// The previous implementation attempted to detect a free channel by checking a raw +// register (conf0.val == 0). This is unreliable because once a channel is configured +// the register won't return to zero automatically, and depending on initialization +// order / speed mode the heuristic can yield false positives or negatives. +// Maintaining our own allocation bitmap is deterministic and thread-safe when +// guarded by a critical section. + +static uint32_t s_ledcAllocMask = 0; // bit set => channel allocated +static portMUX_TYPE s_ledcMux = portMUX_INITIALIZER_UNLOCKED; + +static inline bool ledcIsAllocated(int ch){ + return (ch >= 0 && ch < LEDC_CHANNEL_COUNT) && ((s_ledcAllocMask >> ch) & 0x1); +} + +int findUnusedLedcChannel() { // allocates & returns a free channel, or -1 + portENTER_CRITICAL(&s_ledcMux); + for(int ch=0; ch> ch) & 0x1) == 0){ + s_ledcAllocMask |= (1u << ch); + portEXIT_CRITICAL(&s_ledcMux); + return ch; } } - return -1; // Return -1 if no unused channel is found + portEXIT_CRITICAL(&s_ledcMux); + return -1; +} + +void releaseLedcChannel(int ch){ + if(ch < 0 || ch >= LEDC_CHANNEL_COUNT) return; + portENTER_CRITICAL(&s_ledcMux); + s_ledcAllocMask &= ~(1u << ch); + portEXIT_CRITICAL(&s_ledcMux); +} + +bool markLedcChannelUsed(int ch){ // use if channel configured elsewhere before allocator + if(ch < 0 || ch >= LEDC_CHANNEL_COUNT) return false; + portENTER_CRITICAL(&s_ledcMux); + if( (s_ledcAllocMask >> ch) & 0x1 ){ // already allocated + portEXIT_CRITICAL(&s_ledcMux); + return false; + } + s_ledcAllocMask |= (1u << ch); + portEXIT_CRITICAL(&s_ledcMux); + return true; } diff --git a/src/main.cpp b/src/main.cpp index 7343c7b..0dd8aa4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -161,7 +161,7 @@ void setup() // Initialize Temperature Sensor Init_TSensor(72); - + float val = readBoardInputVoltage(); ESP_LOGI(tag, "Input Volage = %f", val); @@ -373,7 +373,7 @@ void Init_PWM_Outputs(int8_t (&pin)[4], PWM_OUT_SETTINGS (&pwmSettings)[4]) pwmOutputs[i] = new PWM_Output(pin[i], chIndex, RELAY_RES, pwmSettings[i].freq, pwmSettings[i].max, false); pwmOutputs[i]->setOutput(pwmSettings[i].def); // pwmOutputs[i]->setOutput(5.0); - ESP_LOGD(tag, "PWM Output%d: Pin=%d, Freq=%d, ch=%d", i, pin[i], pwmSettings[i].freq, chIndex); + ESP_LOGI(tag, "PWM Output%d: Pin=%d, Freq=%d, ch=%d", i, pin[i], pwmSettings[i].freq, chIndex); } } diff --git a/temporary/BLE-FlashStick-Service.h b/temporary/Temp/BLE-FlashStick-Service.h similarity index 100% rename from temporary/BLE-FlashStick-Service.h rename to temporary/Temp/BLE-FlashStick-Service.h diff --git a/temporary/BLE-FlaskStick-Service.cpp b/temporary/Temp/BLE-FlaskStick-Service.cpp similarity index 100% rename from temporary/BLE-FlaskStick-Service.cpp rename to temporary/Temp/BLE-FlaskStick-Service.cpp diff --git a/temporary/EventBoxTest.html b/temporary/Temp/EventBoxTest.html similarity index 100% rename from temporary/EventBoxTest.html rename to temporary/Temp/EventBoxTest.html diff --git a/firmware_update/GenUpdate.py b/temporary/Temp/GenUpdate.py similarity index 99% rename from firmware_update/GenUpdate.py rename to temporary/Temp/GenUpdate.py index 1356185..51c40b3 100644 --- a/firmware_update/GenUpdate.py +++ b/temporary/Temp/GenUpdate.py @@ -70,7 +70,6 @@ def update_json_file(json_array, folder_path): json_array.clear() json_array.extend(file_array) - def update_files(src_path, dest_path, skip_dirs=None, skip_files=None): # Check if the source folder exists if not os.path.isdir(src_path) or not os.path.isdir(dest_path): diff --git a/firmware_update/UploadToMinio.py b/temporary/Temp/UploadToMinio.py similarity index 100% rename from firmware_update/UploadToMinio.py rename to temporary/Temp/UploadToMinio.py diff --git a/temporary/appcontrol old.html b/temporary/Temp/appcontrol old.html similarity index 100% rename from temporary/appcontrol old.html rename to temporary/Temp/appcontrol old.html diff --git a/temporary/ata-boothifier-upgrade(copy).html b/temporary/Temp/ata-boothifier-upgrade(copy).html similarity index 100% rename from temporary/ata-boothifier-upgrade(copy).html rename to temporary/Temp/ata-boothifier-upgrade(copy).html diff --git a/data/ata-boothifier-upgrade.html b/temporary/Temp/ata-boothifier-upgrade.html similarity index 100% rename from data/ata-boothifier-upgrade.html rename to temporary/Temp/ata-boothifier-upgrade.html diff --git a/data/ata-boothifier-upgradeV2.html b/temporary/Temp/ata-boothifier-upgradeV2.html similarity index 100% rename from data/ata-boothifier-upgradeV2.html rename to temporary/Temp/ata-boothifier-upgradeV2.html diff --git a/temporary/bleconfig.html b/temporary/Temp/bleconfig.html similarity index 100% rename from temporary/bleconfig.html rename to temporary/Temp/bleconfig.html diff --git a/temporary/colorPicket.html b/temporary/Temp/colorPicket.html similarity index 100% rename from temporary/colorPicket.html rename to temporary/Temp/colorPicket.html diff --git a/temporary/eventTest.htm b/temporary/Temp/eventTest.htm similarity index 100% rename from temporary/eventTest.htm rename to temporary/Temp/eventTest.htm diff --git a/temporary/gridstyles.css b/temporary/Temp/gridstyles.css similarity index 100% rename from temporary/gridstyles.css rename to temporary/Temp/gridstyles.css diff --git a/temporary/gridtest.html b/temporary/Temp/gridtest.html similarity index 100% rename from temporary/gridtest.html rename to temporary/Temp/gridtest.html diff --git a/temporary/hue-select-min.js b/temporary/Temp/hue-select-min.js similarity index 100% rename from temporary/hue-select-min.js rename to temporary/Temp/hue-select-min.js diff --git a/temporary/lights-old.html b/temporary/Temp/lights-old.html similarity index 100% rename from temporary/lights-old.html rename to temporary/Temp/lights-old.html diff --git a/temporary/log.html b/temporary/Temp/log.html similarity index 100% rename from temporary/log.html rename to temporary/Temp/log.html diff --git a/temporary/neo_colors.h b/temporary/Temp/neo_colors.h similarity index 100% rename from temporary/neo_colors.h rename to temporary/Temp/neo_colors.h diff --git a/temporary/styles.css b/temporary/Temp/styles.css similarity index 100% rename from temporary/styles.css rename to temporary/Temp/styles.css diff --git a/update.json b/temporary/Temp/update.json similarity index 100% rename from update.json rename to temporary/Temp/update.json diff --git a/temporary/upgrade.html b/temporary/Temp/upgrade.html similarity index 100% rename from temporary/upgrade.html rename to temporary/Temp/upgrade.html diff --git a/web_ble.html b/temporary/Temp/web_ble.html similarity index 100% rename from web_ble.html rename to temporary/Temp/web_ble.html