Housekeeping
This commit is contained in:
parent
451cefdae0
commit
ba96c67893
|
@ -111,8 +111,8 @@ bool XGZP::read(float * reading) {
|
|||
if (count == 3) { // got data
|
||||
XGZPC_Value = Wire.read() * 65536.0 + Wire.read() * 256.0 + Wire.read();
|
||||
XGZPC_Value = XGZPC_Value / 8.0;
|
||||
Serial.print("Pa Value: ");
|
||||
Serial.println(XGZPC_Value);
|
||||
//Serial.print("Pa Value: ");
|
||||
//Serial.println(XGZPC_Value);
|
||||
|
||||
XGZPC_Value = XGZPC_Value / 6895.0;
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
#define SOLENOID_INFLATE 1
|
||||
#define SOLENOID_DEFLATE 2
|
||||
|
||||
#define RELAY1_PIN 7
|
||||
#define RELAY2_PIN 11
|
||||
#define RELAY1_PIN 11
|
||||
#define RELAY2_PIN 7
|
||||
|
||||
#define PRESSURE_SENSOR_PIN A0
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ enum buttonStates {
|
|||
NUM_BUTTONSTATES
|
||||
};
|
||||
|
||||
enum screenStates {
|
||||
enum machineStates {
|
||||
BOOT_UP,
|
||||
PRESSURE,
|
||||
SET_POINT,
|
||||
|
@ -71,7 +71,7 @@ enum buttonStates upButton = OPEN;
|
|||
enum buttonStates enterButton = OPEN;
|
||||
enum buttonStates downButton = OPEN;
|
||||
|
||||
enum screenStates screenState = BOOT_UP;
|
||||
enum machineStates machineState = BOOT_UP;
|
||||
double pressureValue = 0.0;
|
||||
int pressureSetPoint = 0;
|
||||
double initialPressure = 0.0;
|
||||
|
@ -108,9 +108,9 @@ void setup()
|
|||
|
||||
#ifdef SIMULATE
|
||||
initSimulation();
|
||||
#endif
|
||||
|
||||
#else
|
||||
initHardware();
|
||||
#endif
|
||||
|
||||
resamplePressure(pressureValue);
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ void setup()
|
|||
void loop() {
|
||||
measurePressure(pressureValue);
|
||||
pollButtons();
|
||||
runUI();
|
||||
runStateMachine();
|
||||
logData();
|
||||
|
||||
#ifdef SIMULATE
|
||||
|
@ -130,7 +130,9 @@ void logData() {
|
|||
static unsigned long lastLogTime = millis();
|
||||
|
||||
if (millis() > lastLogTime + 100) {
|
||||
Serial.print("pressure: ");
|
||||
Serial.print("millis: ");
|
||||
Serial.print(millis());
|
||||
Serial.print(", pressure: ");
|
||||
Serial.print(pressureValue);
|
||||
#ifdef SIMULATE
|
||||
Serial.print(", simulated: ");
|
||||
|
@ -143,15 +145,15 @@ void logData() {
|
|||
Serial.print(", setpoint: ");
|
||||
Serial.print(pressureSetPoint);
|
||||
Serial.print(", state: ");
|
||||
Serial.print(stateLabels[screenState]);
|
||||
Serial.print(stateLabels[machineState]);
|
||||
Serial.println("");
|
||||
|
||||
lastLogTime = millis();
|
||||
}
|
||||
}
|
||||
|
||||
void runUI() {
|
||||
static enum screenStates nextState = BOOT_UP;
|
||||
void runStateMachine() {
|
||||
static enum machineStates nextState = BOOT_UP;
|
||||
|
||||
static unsigned long timer = millis();
|
||||
|
||||
|
@ -165,10 +167,10 @@ void runUI() {
|
|||
|
||||
oled.clearDisplay();
|
||||
|
||||
switch (screenState) {
|
||||
switch (machineState) {
|
||||
case BOOT_UP:
|
||||
if (millis() >= timer + 2000) {
|
||||
screenState = PRESSURE;
|
||||
machineState = PRESSURE;
|
||||
}
|
||||
|
||||
oled.setCursor(0,0);
|
||||
|
@ -184,25 +186,25 @@ void runUI() {
|
|||
|
||||
case PRESSURE:
|
||||
if (enterButton == PRESSED) {
|
||||
screenState = SAY_HOLD;
|
||||
machineState = SAY_HOLD;
|
||||
nextState = PRESSURE;
|
||||
timer = millis();
|
||||
} else if (enterButton == HELD) {
|
||||
; // settings?
|
||||
} else if (upButton == PRESSED) {
|
||||
screenState = SET_POINT;
|
||||
machineState = SET_POINT;
|
||||
pressureSetPoint = debouncedPressureValue+1;
|
||||
timer = millis();
|
||||
} else if (downButton == PRESSED) {
|
||||
screenState = SET_POINT;
|
||||
machineState = SET_POINT;
|
||||
pressureSetPoint = debouncedPressureValue-1;
|
||||
timer = millis();
|
||||
} else if (upButton == HELD) {
|
||||
screenState = SET_POINT;
|
||||
machineState = SET_POINT;
|
||||
pressureSetPoint = debouncedPressureValue+1;
|
||||
timer = millis();
|
||||
} else if (downButton == HELD) {
|
||||
screenState = SET_POINT;
|
||||
machineState = SET_POINT;
|
||||
pressureSetPoint = debouncedPressureValue-1;
|
||||
timer = millis();
|
||||
}
|
||||
|
@ -217,12 +219,12 @@ void runUI() {
|
|||
|
||||
case SET_POINT:
|
||||
if (enterButton == PRESSED) {
|
||||
screenState = SAY_HOLD;
|
||||
machineState = SAY_HOLD;
|
||||
nextState = SET_POINT;
|
||||
timer = millis();
|
||||
} else if (enterButton == HELD) {
|
||||
timer = millis();
|
||||
screenState = INIT_RUN;
|
||||
machineState = INIT_RUN;
|
||||
} else if (upButton == PRESSED) {
|
||||
timer = millis();
|
||||
pressureSetPoint++;
|
||||
|
@ -238,7 +240,7 @@ void runUI() {
|
|||
pressureSetPoint--;
|
||||
delay(75);
|
||||
} else if (millis() >= timer + TIMEOUT_TIME) {
|
||||
screenState = SAY_TIMEOUT;
|
||||
machineState = SAY_TIMEOUT;
|
||||
nextState = PRESSURE;
|
||||
timer = millis();
|
||||
}
|
||||
|
@ -258,7 +260,7 @@ void runUI() {
|
|||
initialPressure = pressureValue;
|
||||
startTime = millis();
|
||||
timer = millis();
|
||||
screenState = BEGIN_RUN;
|
||||
machineState = BEGIN_RUN;
|
||||
|
||||
oled.setCursor(0,0);
|
||||
oled.setTextSize(1);
|
||||
|
@ -276,7 +278,7 @@ void runUI() {
|
|||
isInflating = false;
|
||||
} else {
|
||||
setSoleniod(SOLENOID_STOP);
|
||||
screenState = SAY_DONE;
|
||||
machineState = SAY_DONE;
|
||||
nextState = PRESSURE;
|
||||
}
|
||||
|
||||
|
@ -288,7 +290,7 @@ void runUI() {
|
|||
if (millis() >= timer + 5000) {
|
||||
//runningPressure = pressureValue;
|
||||
setSoleniod(SOLENOID_STOP);
|
||||
screenState = MEASURING;
|
||||
machineState = MEASURING;
|
||||
timer = millis();
|
||||
stopTime = millis();
|
||||
}
|
||||
|
@ -296,6 +298,12 @@ void runUI() {
|
|||
break;
|
||||
|
||||
case MEASURING:
|
||||
if (millis() < timer + 500) {
|
||||
// wait for solenoids to settle before averaging
|
||||
resamplePressure(pressureValue);
|
||||
|
||||
}
|
||||
|
||||
if (millis() >= timer + 3000) {
|
||||
sampledPressure = pressureValue;
|
||||
|
||||
|
@ -316,24 +324,19 @@ void runUI() {
|
|||
initialPressure = sampledPressure;
|
||||
|
||||
if (isInflating && (int) sampledPressure >= pressureSetPoint) {
|
||||
screenState = SAY_DONE;
|
||||
machineState = SAY_DONE;
|
||||
nextState = PRESSURE;
|
||||
} else if (isDeflating && (int) sampledPressure <= pressureSetPoint) {
|
||||
screenState = SAY_DONE;
|
||||
machineState = SAY_DONE;
|
||||
nextState = PRESSURE;
|
||||
} else {
|
||||
screenState = RUNNING;
|
||||
machineState = RUNNING;
|
||||
}
|
||||
|
||||
timer = millis();
|
||||
startTime = millis();
|
||||
}
|
||||
|
||||
if (millis() < timer + 500) {
|
||||
// wait for solenoids to settle before averaging
|
||||
resamplePressure(pressureValue);
|
||||
}
|
||||
|
||||
setSoleniod(SOLENOID_STOP);
|
||||
|
||||
oled.setCursor(0,0);
|
||||
|
@ -348,27 +351,27 @@ void runUI() {
|
|||
case RUNNING:
|
||||
if (enterButton == PRESSED) {
|
||||
setSoleniod(SOLENOID_STOP);
|
||||
screenState = SAY_CANCEL;
|
||||
machineState = SAY_CANCEL;
|
||||
nextState = PRESSURE;
|
||||
timer = millis();
|
||||
} else if (upButton == PRESSED) {
|
||||
setSoleniod(SOLENOID_STOP);
|
||||
screenState = SAY_CANCEL;
|
||||
machineState = SAY_CANCEL;
|
||||
nextState = PRESSURE;
|
||||
timer = millis();
|
||||
} else if (downButton == PRESSED) {
|
||||
setSoleniod(SOLENOID_STOP);
|
||||
screenState = SAY_CANCEL;
|
||||
machineState = SAY_CANCEL;
|
||||
nextState = PRESSURE;
|
||||
timer = millis();
|
||||
}
|
||||
|
||||
if (isInflating && millis() >= timer + 20000) {
|
||||
screenState = MEASURING;
|
||||
machineState = MEASURING;
|
||||
timer = millis();
|
||||
stopTime = millis();
|
||||
} else if (isDeflating && millis() >= timer + 10000) {
|
||||
screenState = MEASURING;
|
||||
machineState = MEASURING;
|
||||
timer = millis();
|
||||
stopTime = millis();
|
||||
}
|
||||
|
@ -403,7 +406,7 @@ void runUI() {
|
|||
|
||||
case SAY_DONE:
|
||||
if (millis() >= timer + 3000) {
|
||||
screenState = nextState;
|
||||
machineState = nextState;
|
||||
timer = millis();
|
||||
}
|
||||
|
||||
|
@ -417,7 +420,7 @@ void runUI() {
|
|||
|
||||
case SAY_CANCEL:
|
||||
if (millis() >= timer + 1000) {
|
||||
screenState = nextState;
|
||||
machineState = nextState;
|
||||
timer = millis();
|
||||
}
|
||||
|
||||
|
@ -431,7 +434,7 @@ void runUI() {
|
|||
|
||||
case SAY_HOLD:
|
||||
if (millis() >= timer + 500) {
|
||||
screenState = nextState;
|
||||
machineState = nextState;
|
||||
timer = millis();
|
||||
}
|
||||
|
||||
|
@ -445,7 +448,7 @@ void runUI() {
|
|||
|
||||
case SAY_TIMEOUT:
|
||||
if (millis() >= timer + 1000) {
|
||||
screenState = nextState;
|
||||
machineState = nextState;
|
||||
timer = millis();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user