Skip to content

Commit

Permalink
Commands done
Browse files Browse the repository at this point in the history
  • Loading branch information
peteGSX committed Feb 18, 2024
1 parent db5b841 commit 2694ce4
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 152 deletions.
23 changes: 12 additions & 11 deletions EEPROMFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "EEPROMFunctions.h"
#include <EEPROM.h>
#include "IOFunctions.h"

char eepromFlag[4] = {'T', 'T', 'E', 'X'}; // EEPROM location 0 to 3 should contain TTEX if we have stored steps.
const uint8_t eepromVersion = EEPROM_VERSION; // Version of stored EEPROM data to invalidate stored steps if config changes.
Expand Down Expand Up @@ -46,23 +47,23 @@ long getSteps() {
if (stepsSet) {
eepromSteps = ((long)EEPROM.read(5) << 24) + ((long)EEPROM.read(6) << 16) + ((long)EEPROM.read(7) << 8) + (long)EEPROM.read(8);
if (eepromSteps <= sanitySteps) {
#ifdef DEBUG
Serial.print(F("DEBUG: TTEX steps defined in EEPROM: "));
Serial.println(eepromSteps);
#endif
if (debug) {
Serial.print(F("DEBUG: TTEX steps defined in EEPROM: "));
Serial.println(eepromSteps);
}
return eepromSteps;
} else {
#ifdef DEBUG
Serial.print(F("DEBUG: TTEX steps defined in EEPROM are invalid: "));
Serial.println(eepromSteps);
#endif
if (debug) {
Serial.print(F("DEBUG: TTEX steps defined in EEPROM are invalid: "));
Serial.println(eepromSteps);
}
calibrating = true;
return 0;
}
} else {
#ifdef DEBUG
Serial.println(F("DEBUG: TTEX steps not defined in EEPROM"));
#endif
if (debug) {
Serial.println(F("DEBUG: TTEX steps not defined in EEPROM"));
}
calibrating = true;
return 0;
}
Expand Down
100 changes: 47 additions & 53 deletions EX-Turntable.ino
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ void setup() {
startupConfiguration();

// If we're not sensor testing, start Wire()
#ifndef SENSOR_TESTING
setupWire();
#endif
if (!sensorTesting) setupWire();

// Display EX-Turntable configuration
displayTTEXConfig();
Expand All @@ -45,80 +43,76 @@ void setup() {
}

void loop() {
#ifdef SENSOR_TESTING
// If we're only testing sensors, don't do anything else.
bool testHomeSensorState = getHomeState();
if (testHomeSensorState != homeSensorState) {
if (testHomeSensorState == HOME_SENSOR_ACTIVE_STATE) {
Serial.println(F("Home sensor ACTIVATED"));
} else {
Serial.println(F("Home sensor DEACTIVATED"));
if (sensorTesting) {
bool testHomeSensorState = getHomeState();
if (testHomeSensorState != homeSensorState) {
if (testHomeSensorState == HOME_SENSOR_ACTIVE_STATE) {
Serial.println(F("Home sensor ACTIVATED"));
} else {
Serial.println(F("Home sensor DEACTIVATED"));
}
homeSensorState = testHomeSensorState;
}
homeSensorState = testHomeSensorState;
}
getHomeState();
getHomeState();

#if TURNTABLE_EX_MODE == TRAVERSER
bool testLimitSensorState = getLimitState();
if (testLimitSensorState != limitSensorState) {
if (testLimitSensorState == LIMIT_SENSOR_ACTIVE_STATE) {
Serial.println(F("Limit sensor ACTIVATED"));
} else {
Serial.println(F("Limit sensor DEACTIVATED"));
bool testLimitSensorState = getLimitState();
if (testLimitSensorState != limitSensorState) {
if (testLimitSensorState == LIMIT_SENSOR_ACTIVE_STATE) {
Serial.println(F("Limit sensor ACTIVATED"));
} else {
Serial.println(F("Limit sensor DEACTIVATED"));
}
limitSensorState = testLimitSensorState;
}
limitSensorState = testLimitSensorState;
}
#endif

#else

} else {
#if TURNTABLE_EX_MODE == TRAVERSER
// If we hit our limit switch when not calibrating, stop!
if (getLimitState() == LIMIT_SENSOR_ACTIVE_STATE && !calibrating && stepper.isRunning() && stepper.targetPosition() < 0) {
Serial.println(F("ALERT! Limit sensor activitated, halting stepper"));
if (!homed) {
homed = 1;
if (getLimitState() == LIMIT_SENSOR_ACTIVE_STATE && !calibrating && stepper.isRunning() && stepper.targetPosition() < 0) {
Serial.println(F("ALERT! Limit sensor activitated, halting stepper"));
if (!homed) {
homed = 1;
}
stepper.stop();
stepper.setCurrentPosition(stepper.currentPosition());
}
stepper.stop();
stepper.setCurrentPosition(stepper.currentPosition());
}

// If we hit our home switch when not homing, stop!
if (getHomeState() == HOME_SENSOR_ACTIVE_STATE && homed && !calibrating && stepper.isRunning() && stepper.distanceToGo() > 0) {
Serial.println(F("ALERT! Home sensor activitated, halting stepper"));
stepper.stop();
stepper.setCurrentPosition(0);
}
if (getHomeState() == HOME_SENSOR_ACTIVE_STATE && homed && !calibrating && stepper.isRunning() && stepper.distanceToGo() > 0) {
Serial.println(F("ALERT! Home sensor activitated, halting stepper"));
stepper.stop();
stepper.setCurrentPosition(0);
}
#endif

// If we haven't successfully homed yet, do it.
if (homed == 0) {
moveHome();
}
if (homed == 0) {
moveHome();
}

// If flag is set for calibrating, do it.
if (calibrating) {
calibration();
}
if (calibrating) {
calibration();
}

// Process the stepper object continuously.
stepper.run();
stepper.run();

// Process our LED.
processLED();
processLED();

// If disabling on idle is enabled, disable the stepper.
#if defined(DISABLE_OUTPUTS_IDLE)
if (stepper.isRunning() != lastRunningState) {
lastRunningState = stepper.isRunning();
if (!lastRunningState) {
stepper.disableOutputs();
if (stepper.isRunning() != lastRunningState) {
lastRunningState = stepper.isRunning();
if (!lastRunningState) {
stepper.disableOutputs();
}
}
}
#endif

// Receive and process and serial input for test commands.
}
// Receive and process and serial input for test commands.
processSerialInput();

#endif
}
Loading

0 comments on commit 2694ce4

Please sign in to comment.