ensure we don't keep queueing http requests when we're not in the looping state.
This commit is contained in:
@@ -6,12 +6,16 @@
|
|||||||
#include "cJSON.h"
|
#include "cJSON.h"
|
||||||
#include "encoder.hpp"
|
#include "encoder.hpp"
|
||||||
#include "WiFi.hpp"
|
#include "WiFi.hpp"
|
||||||
|
#include "socketIO.hpp"
|
||||||
|
|
||||||
TaskHandle_t wakeTaskHandle = NULL;
|
TaskHandle_t wakeTaskHandle = NULL;
|
||||||
|
|
||||||
void wakeTimer(void* pvParameters) {
|
void wakeTimer(void* pvParameters) {
|
||||||
while (1) {
|
while (1) {
|
||||||
vTaskDelay(pdMS_TO_TICKS(60000));
|
vTaskDelay(pdMS_TO_TICKS(60000));
|
||||||
|
// avoid accumulating events during re-setup or calibration
|
||||||
|
if (setupTaskHandle != NULL || socketIOactive
|
||||||
|
|| uxQueueMessagesWaiting(main_event_queue) > 2) continue;
|
||||||
main_event_type_t evt = EVENT_REQUEST_POS;
|
main_event_type_t evt = EVENT_REQUEST_POS;
|
||||||
xQueueSend(main_event_queue, &evt, portMAX_DELAY);
|
xQueueSend(main_event_queue, &evt, portMAX_DELAY);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,10 +142,6 @@ void initMainLoop() {
|
|||||||
|
|
||||||
void IRAM_ATTR watchdogCallback(void* arg) {
|
void IRAM_ATTR watchdogCallback(void* arg) {
|
||||||
if (runningManual || runningServer) {
|
if (runningManual || runningServer) {
|
||||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
|
||||||
main_event_type_t evt = EVENT_CLEAR_CALIB;
|
|
||||||
BaseType_t result = xQueueSendFromISR(main_event_queue, &evt, &xHigherPriorityTaskWoken);
|
|
||||||
if (result == pdPASS) portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
|
||||||
topEnc->pauseWatchdog();
|
topEnc->pauseWatchdog();
|
||||||
|
|
||||||
// get ready for recalibration by clearing all these listeners
|
// get ready for recalibration by clearing all these listeners
|
||||||
@@ -153,6 +149,10 @@ void IRAM_ATTR watchdogCallback(void* arg) {
|
|||||||
topEnc->wandListen.store(false, std::memory_order_release);
|
topEnc->wandListen.store(false, std::memory_order_release);
|
||||||
topEnc->serverListen.store(false, std::memory_order_release);
|
topEnc->serverListen.store(false, std::memory_order_release);
|
||||||
servoOff();
|
servoOff();
|
||||||
|
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||||
|
main_event_type_t evt = EVENT_CLEAR_CALIB;
|
||||||
|
BaseType_t result = xQueueSendFromISR(main_event_queue, &evt, &xHigherPriorityTaskWoken);
|
||||||
|
if (result == pdPASS) portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// if no movement is running, we're fine
|
// if no movement is running, we're fine
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
static esp_socketio_client_handle_t io_client;
|
static esp_socketio_client_handle_t io_client;
|
||||||
static esp_socketio_packet_handle_t tx_packet = NULL;
|
static esp_socketio_packet_handle_t tx_packet = NULL;
|
||||||
static bool stopSocketFlag = false;
|
static bool stopSocketFlag = false;
|
||||||
|
std::atomic<bool> socketIOactive{false};
|
||||||
|
|
||||||
// Event handler for Socket.IO events
|
// Event handler for Socket.IO events
|
||||||
static void socketio_event_handler(void *handler_args, esp_event_base_t base,
|
static void socketio_event_handler(void *handler_args, esp_event_base_t base,
|
||||||
@@ -300,6 +301,8 @@ void initSocketIO() {
|
|||||||
|
|
||||||
esp_socketio_register_events(io_client, SOCKETIO_EVENT_ANY, socketio_event_handler, NULL);
|
esp_socketio_register_events(io_client, SOCKETIO_EVENT_ANY, socketio_event_handler, NULL);
|
||||||
esp_socketio_client_start(io_client);
|
esp_socketio_client_start(io_client);
|
||||||
|
|
||||||
|
socketIOactive = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void stopSocketIO() {
|
void stopSocketIO() {
|
||||||
@@ -310,6 +313,7 @@ void stopSocketIO() {
|
|||||||
io_client = NULL;
|
io_client = NULL;
|
||||||
tx_packet = NULL;
|
tx_packet = NULL;
|
||||||
}
|
}
|
||||||
|
socketIOactive = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper function to emit Socket.IO event with data
|
// Helper function to emit Socket.IO event with data
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
#define SOCKETIO_HPP
|
#define SOCKETIO_HPP
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
|
||||||
|
extern std::atomic<bool> socketIOactive;
|
||||||
|
|
||||||
// Initialize Socket.IO client and connect to server
|
// Initialize Socket.IO client and connect to server
|
||||||
void initSocketIO();
|
void initSocketIO();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user