Added missing flags from ISR, fixed include issues

This commit is contained in:
2025-12-31 17:23:44 -06:00
parent d3e4b9a59e
commit f7bad6f505
5 changed files with 24 additions and 31 deletions

View File

@@ -50,6 +50,7 @@ void IRAM_ATTR Encoder::isr_handler(void* arg)
if (calibListen) servoCalibListen();
if (encoder->feedWDog) esp_timer_restart(encoder->watchdog_handle, 500000);
if (encoder->wandListen) servoWandListen();
if (encoder->serverListen) servoServerListen();
}
else if (encoder->last_count_base < 0) {
encoder->count -= 1;
@@ -57,6 +58,7 @@ void IRAM_ATTR Encoder::isr_handler(void* arg)
if (calibListen) servoCalibListen();
if (encoder->feedWDog) esp_timer_restart(encoder->watchdog_handle, 500000);
if (encoder->wandListen) servoWandListen();
if (encoder->serverListen) servoServerListen();
}
encoder->last_state_a = current_a;

View File

@@ -10,16 +10,13 @@ std::atomic<bool> calibListen{false};
std::atomic<int32_t> baseDiff{0};
std::atomic<int32_t> target{0};
Encoder* topEnc = nullptr;
Encoder* bottomEnc = nullptr;
std::atomic<bool> runningManual{false};
std::atomic<bool> runningServer{false};
std::atomic<bool> clearCalibFlag{false};
std::atomic<bool> savePosFlag{false};
std::atomic<bool> startLess{false};
void servoInit(Encoder& bottom, Encoder& top) {
void servoInit() {
// LEDC timer configuration (C++ aggregate initialization)
ledc_timer_config_t ledc_timer = {};
ledc_timer.speed_mode = LEDC_LOW_SPEED_MODE;
@@ -40,9 +37,6 @@ void servoInit(Encoder& bottom, Encoder& top) {
ledc_channel.hpoint = 0;
ESP_ERROR_CHECK(ledc_channel_config(&ledc_channel));
topEnc = &top;
bottomEnc = &bottom;
// Configure servo power switch pin as output
gpio_set_direction(servoSwitch, GPIO_MODE_OUTPUT);
gpio_set_level(servoSwitch, 0); // Start with servo power off
@@ -203,12 +197,12 @@ void servoWandListen() {
topEnc->wandListen = false;
}
else if (effDiff > 1) {
servoOn(CCW, manual);
topEnc->wandListen = true;
servoOn(CCW, manual);
}
else if (effDiff < -1) {
servoOn(CW, manual);
topEnc->wandListen = true;
servoOn(CW, manual);
}
else {
servoOff();

View File

@@ -9,19 +9,14 @@
#define server 1
#define manual 0
extern Encoder* topEnc;
extern Encoder* bottomEnc;
extern std::atomic<bool> calibListen;
extern std::atomic<bool> runningManual;
extern std::atomic<bool> runningServer;
extern std::atomic<bool> clearCalibFlag;
extern std::atomic<bool> savePosFlag;
extern std::atomic<bool> startLess;
extern std::atomic<int32_t> baseDiff;
extern std::atomic<int32_t> target;
extern Encoder* topEnc;
extern Encoder* bottomEnc;
void servoInit(Encoder& bottom, Encoder& top);
void servoInit();
void servoOn(uint8_t dir, uint8_t manOrServer);
void servoOff();
void servoMainSwitch(uint8_t onOff);
@@ -37,7 +32,7 @@ void servoSavePos();
int32_t servoReadPos();
void stopServerRun();
void servoWandListen();
void servoServerListen();
void runToAppPos(uint8_t appPos);
#endif

View File

@@ -296,28 +296,28 @@ static void emitSocketEvent(const char* eventName, cJSON* data) {
}
// Function to emit 'calib_done' as expected by your server
void emitCalibDone(int port = 1) {
void emitCalibDone(int port) {
cJSON *data = cJSON_CreateObject();
cJSON_AddNumberToObject(data, "port", port);
emitSocketEvent("calib_done", data);
}
// Function to emit 'calib_stage1_ready' to notify server device is ready for tilt up
void emitCalibStage1Ready(int port = 1) {
void emitCalibStage1Ready(int port) {
cJSON *data = cJSON_CreateObject();
cJSON_AddNumberToObject(data, "port", port);
emitSocketEvent("calib_stage1_ready", data);
}
// Function to emit 'calib_stage2_ready' to notify server device is ready for tilt down
void emitCalibStage2Ready(int port = 1) {
void emitCalibStage2Ready(int port) {
cJSON *data = cJSON_CreateObject();
cJSON_AddNumberToObject(data, "port", port);
emitSocketEvent("calib_stage2_ready", data);
}
// Function to emit 'report_calib_status' to tell server device's actual calibration state
void emitCalibStatus(bool calibrated, int port = 1) {
void emitCalibStatus(bool calibrated, int port) {
cJSON *data = cJSON_CreateObject();
cJSON_AddNumberToObject(data, "port", port);
cJSON_AddBoolToObject(data, "calibrated", calibrated);
@@ -325,7 +325,7 @@ void emitCalibStatus(bool calibrated, int port = 1) {
}
// Function to emit 'device_calib_error' to notify server of calibration failure
void emitCalibError(const char* errorMessage, int port = 1) {
void emitCalibError(const char* errorMessage, int port) {
cJSON *data = cJSON_CreateObject();
cJSON_AddNumberToObject(data, "port", port);
cJSON_AddStringToObject(data, "message", errorMessage);
@@ -333,7 +333,7 @@ void emitCalibError(const char* errorMessage, int port = 1) {
}
// Function to emit 'pos_hit' to notify server of position change
void emitPosHit(int pos, int port = 1) {
void emitPosHit(int pos, int port) {
cJSON *data = cJSON_CreateObject();
cJSON_AddNumberToObject(data, "port", port);
cJSON_AddNumberToObject(data, "pos", pos);