update angle storage logic
This commit is contained in:
parent
3c456f6875
commit
09886e2e04
10
src/main.cpp
10
src/main.cpp
|
@ -48,14 +48,12 @@ RotaryEncoder encoder(encoder_a, encoder_b);
|
|||
WiFiClient wifiClient;
|
||||
PubSubClient mqttClient(wifiClient);
|
||||
|
||||
volatile long long bottom_step_goal = 0, top_step_goal = 0;
|
||||
volatile long bottom_step_goal = 0, top_step_goal = 0;
|
||||
volatile bool bottom_step_done = true, top_step_done = true;
|
||||
volatile bool bottom_step_sent = false, top_step_sent = false;
|
||||
volatile bool stop = false;
|
||||
bool system_locked = false;
|
||||
|
||||
volatile int top_angle_difference_steps = EEPROM.read(EEPROM_TOP_BOTTOM_DIFF_ADDR);
|
||||
|
||||
void writePositionToEEPROM(int addr, long pos)
|
||||
{
|
||||
EEPROM.write(addr, (pos >> 24) & 0xFF);
|
||||
|
@ -73,6 +71,8 @@ long readPositionFromEEPROM(int addr)
|
|||
return pos;
|
||||
}
|
||||
|
||||
volatile long top_angle_difference_steps = readPositionFromEEPROM(EEPROM_TOP_BOTTOM_DIFF_ADDR);
|
||||
|
||||
void callback(char *topic, byte *payload, unsigned int length)
|
||||
{
|
||||
String topic_str = String(topic);
|
||||
|
@ -294,7 +294,7 @@ void loop()
|
|||
bottom_step_done = true;
|
||||
bottom_step_sent = false;
|
||||
writePositionToEEPROM(EEPROM_BOTTOM_POS_ADDR, bottom_stepper->getCurrentPosition());
|
||||
EEPROM.write(EEPROM_TOP_BOTTOM_DIFF_ADDR, top_angle_difference_steps);
|
||||
writePositionToEEPROM(EEPROM_TOP_BOTTOM_DIFF_ADDR, top_angle_difference_steps);
|
||||
EEPROM.write(EEPROM_BOTTOM_MOVING_FLAG_ADDR, MOVING_FLAG_CLEAR);
|
||||
EEPROM.commit();
|
||||
Serial.println("Bottom stepper done");
|
||||
|
@ -305,7 +305,7 @@ void loop()
|
|||
top_step_done = true;
|
||||
top_step_sent = false;
|
||||
writePositionToEEPROM(EEPROM_TOP_POS_ADDR, top_stepper->getCurrentPosition());
|
||||
EEPROM.write(EEPROM_TOP_BOTTOM_DIFF_ADDR, top_angle_difference_steps);
|
||||
writePositionToEEPROM(EEPROM_TOP_BOTTOM_DIFF_ADDR, top_angle_difference_steps);
|
||||
EEPROM.write(EEPROM_TOP_MOVING_FLAG_ADDR, MOVING_FLAG_CLEAR);
|
||||
EEPROM.commit();
|
||||
Serial.println("Top stepper done");
|
||||
|
|
Loading…
Reference in New Issue