OTA works, log download works, integrated OTA build sys
This commit is contained in:
128
main/rf_433.c
128
main/rf_433.c
@@ -37,9 +37,6 @@ typedef struct {
|
||||
size_t num_symbols;
|
||||
} rf_code_t;
|
||||
|
||||
// Global queue for passing decoded codes between tasks
|
||||
static QueueHandle_t g_code_queue = NULL;
|
||||
|
||||
int learn_flag = -1;
|
||||
|
||||
// For rmt_rx_register_event_callbacks
|
||||
@@ -52,8 +49,8 @@ static bool rfrx_done(rmt_channel_handle_t channel, const rmt_rx_done_event_data
|
||||
|
||||
// Task that receives and decodes RF signals
|
||||
static void rf_433_receiver_task(void* param) {
|
||||
esp_task_wdt_add(NULL);
|
||||
esp_log_level_set("rmt", ESP_LOG_NONE); // disable rmt messages about hw buffer too small
|
||||
esp_task_wdt_add(NULL);
|
||||
esp_log_level_set("rmt", ESP_LOG_NONE); // disable rmt messages about hw buffer too small
|
||||
const uint16_t tlow = (P_HIGH - P_LOW - (2 * P_MARGIN));
|
||||
const uint16_t thigh = (P_HIGH - P_LOW + (2 * P_MARGIN));
|
||||
|
||||
@@ -130,45 +127,38 @@ static void rf_433_receiver_task(void* param) {
|
||||
}
|
||||
}
|
||||
|
||||
// If we got a valid code, send it to processing task
|
||||
// If we got a valid code, process it
|
||||
if (code) {
|
||||
int64_t encoded = ((int64_t)len << 56) | code;
|
||||
|
||||
ESP_LOGI(TAG, "GOT KEYCODE 0x%lx [%d]", (long) code, len);
|
||||
|
||||
if (learn_flag >= 0) {
|
||||
set_param_value_t(PARAM_KEYCODE_0 + learn_flag,
|
||||
(param_value_t){.i64 = encoded});
|
||||
ESP_LOGI(TAG, "LEARNED KEYCODE");
|
||||
learn_flag = -1;
|
||||
} else {
|
||||
rf_code_t rf_msg = {
|
||||
.code = code,
|
||||
.high_avg = high / 24,
|
||||
.low_avg = low / 24,
|
||||
.errors = err,
|
||||
.num_symbols = len
|
||||
};
|
||||
|
||||
// Don't do this anymore. No need to pass data between threads. Just act on it.
|
||||
// Non-blocking send - if queue is full, just drop it
|
||||
//xQueueSend(g_code_queue, &rf_msg, 0);
|
||||
|
||||
|
||||
for (uint8_t i = 0; i < NUM_RF_BUTTONS; i++) {
|
||||
int64_t match = get_param_value_t(PARAM_KEYCODE_0+i).i64;
|
||||
if (encoded == match) {
|
||||
switch (i) {
|
||||
case 0: pulseOverride(RELAY_A1); pulseOverride(RELAY_A3); break;
|
||||
case 1: pulseOverride(RELAY_B1); pulseOverride(RELAY_A3); break;
|
||||
case 2: pulseOverride(RELAY_A2); break;
|
||||
case 3: pulseOverride(RELAY_B2); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int64_t encoded = ((int64_t)len << 56) | code;
|
||||
|
||||
ESP_LOGI(TAG, "GOT KEYCODE 0x%lx [%d]", (long) code, len);
|
||||
|
||||
if (learn_flag >= 0) {
|
||||
set_param_value_t(PARAM_KEYCODE_0 + learn_flag,
|
||||
(param_value_t){.i64 = encoded});
|
||||
ESP_LOGI(TAG, "LEARNED KEYCODE");
|
||||
learn_flag = -1;
|
||||
} else {
|
||||
rf_code_t rf_msg = {
|
||||
.code = code,
|
||||
.high_avg = high / 24,
|
||||
.low_avg = low / 24,
|
||||
.errors = err,
|
||||
.num_symbols = len
|
||||
};
|
||||
|
||||
for (uint8_t i = 0; i < NUM_RF_BUTTONS; i++) {
|
||||
int64_t match = get_param_value_t(PARAM_KEYCODE_0+i).i64;
|
||||
if (encoded == match) {
|
||||
switch (i) {
|
||||
case 0: pulseOverride(RELAY_A1); pulseOverride(RELAY_A3); break;
|
||||
case 1: pulseOverride(RELAY_B1); pulseOverride(RELAY_A3); break;
|
||||
case 2: pulseOverride(RELAY_A2); break;
|
||||
case 3: pulseOverride(RELAY_B2); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,11 +193,10 @@ static void rf_433_receiver_task(void* param) {
|
||||
}
|
||||
|
||||
// Start next receive
|
||||
|
||||
rmt_receive(rx_channel, symbols, sizeof(symbols), &rx_config);
|
||||
|
||||
esp_task_wdt_reset();
|
||||
}
|
||||
|
||||
esp_task_wdt_reset();
|
||||
}
|
||||
|
||||
// Cleanup (never reached in this case)
|
||||
@@ -216,53 +205,22 @@ static void rf_433_receiver_task(void* param) {
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
esp_err_t rf_433_init() {
|
||||
g_code_queue = xQueueCreate(5, sizeof(rf_code_t));
|
||||
assert(g_code_queue);
|
||||
|
||||
esp_err_t rf_433_init() {
|
||||
xTaskCreate(rf_433_receiver_task, TAG, 4096, NULL, 10, NULL);
|
||||
|
||||
return ESP_OK;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t rf_433_stop() { return ESP_OK; }
|
||||
|
||||
void rf_433_set_keycode(uint8_t index, int64_t code) {
|
||||
set_param_value_t(PARAM_KEYCODE_0+index, (param_value_t){.i64=code});
|
||||
set_param_value_t(PARAM_KEYCODE_0+index, (param_value_t){.i64=code});
|
||||
}
|
||||
|
||||
void rf_433_learn_keycode(uint8_t index) {
|
||||
if (index >= 8) return;
|
||||
learn_flag = index;
|
||||
if (index >= 8) return;
|
||||
learn_flag = index;
|
||||
}
|
||||
|
||||
void rf_433_cancel_learn_keycode() {
|
||||
learn_flag = -1;
|
||||
}
|
||||
|
||||
/*int8_t rf_433_get_keycode() {
|
||||
rf_code_t received_code;
|
||||
|
||||
if (xQueueReceive(g_code_queue, &received_code, 0) == pdPASS) {
|
||||
int64_t newcode = ((int64_t)received_code.num_symbols << 56) | received_code.code;
|
||||
|
||||
for (uint8_t i = 0; i < NUM_RF_BUTTONS; i++) {
|
||||
if (newcode == get_param_value_t(PARAM_KEYCODE_0+i).i64)
|
||||
return i;
|
||||
}
|
||||
ESP_LOGI("RF", "Received unknown code 0x%08lx (%d) [0x%16llx]", (unsigned long)received_code.code, received_code.num_symbols, (unsigned long long) newcode);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int64_t rf_433_get_raw_keycode() {
|
||||
rf_code_t received_code;
|
||||
int64_t code = -1;
|
||||
if (xQueueReceive(g_code_queue, &received_code, 0) == pdPASS) {
|
||||
code = ((int64_t)received_code.num_symbols << 56) | received_code.code;
|
||||
//ESP_LOGI("RF", "Raw Code 0x%08lx (%d) [0x%16llx]", (unsigned long)received_code.code, received_code.num_symbols, (unsigned long long) code);
|
||||
}
|
||||
return code;
|
||||
}*/
|
||||
|
||||
void rf_433_clear_queue() {
|
||||
xQueueReset(g_code_queue);
|
||||
learn_flag = -1;
|
||||
}
|
||||
Reference in New Issue
Block a user