basic commit
This commit is contained in:
parent
1d661e41ad
commit
9e9c045a3f
@ -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");
|
||||
}
|
||||
*/
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -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<LEDC_CHANNEL_COUNT; ++ch){
|
||||
if(((s_ledcAllocMask >> 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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):
|
||||
Loading…
x
Reference in New Issue
Block a user