Added missing flags from ISR, fixed include issues
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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 = ⊤
|
||||
bottomEnc = ⊥
|
||||
|
||||
// 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();
|
||||
|
||||
@@ -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
|
||||
@@ -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);
|
||||
|
||||
16
src/main.cpp
16
src/main.cpp
@@ -10,8 +10,10 @@
|
||||
#include "calibration.hpp"
|
||||
|
||||
// Global encoder instances
|
||||
Encoder topEnc(ENCODER_PIN_A, ENCODER_PIN_B);
|
||||
Encoder bottomEnc(InputEnc_PIN_A, InputEnc_PIN_B);
|
||||
Encoder* topEnc = new Encoder(ENCODER_PIN_A, ENCODER_PIN_B);
|
||||
Encoder* bottomEnc = new Encoder(InputEnc_PIN_A, InputEnc_PIN_B);
|
||||
|
||||
// Global encoder pointers (used by servo.cpp)
|
||||
|
||||
// Global calibration instance
|
||||
Calibration calib;
|
||||
@@ -30,15 +32,15 @@ void mainApp() {
|
||||
calib.init();
|
||||
|
||||
// Initialize encoders
|
||||
topEnc.init();
|
||||
bottomEnc.init();
|
||||
servoInit(bottomEnc, topEnc);
|
||||
topEnc->init();
|
||||
bottomEnc->init();
|
||||
servoInit();
|
||||
|
||||
setupLoop();
|
||||
|
||||
statusResolved = false;
|
||||
|
||||
int32_t prevCount = topEnc.getCount();
|
||||
int32_t prevCount = topEnc->getCount();
|
||||
|
||||
// Main loop
|
||||
while (1) {
|
||||
@@ -63,7 +65,7 @@ void mainApp() {
|
||||
savePosFlag = false;
|
||||
|
||||
// Send position update to server
|
||||
uint8_t currentAppPos = calib.convertToAppPos(topEnc.getCount());
|
||||
uint8_t currentAppPos = calib.convertToAppPos(topEnc->getCount());
|
||||
emitPosHit(currentAppPos);
|
||||
|
||||
printf("Sent pos_hit: position %d\n", currentAppPos);
|
||||
|
||||
Reference in New Issue
Block a user