Skip to content

Commit 12e9d05

Browse files
committed
fix: change tank id during verifying state
1 parent 7cc4073 commit 12e9d05

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

TissueProcessor/TissueProcessor.ino

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ const unsigned long MOVE_TIMEOUT_MS = 30UL * 1000UL; // 30 seconds - motion
9999

100100
const unsigned long MOTOR_SWITCH_DELAY_MS = 1000UL; // 1 second - motor swithc saf
101101
const unsigned long VERIFICATION_DELAY_MS = 2UL * 1000UL;
102-
const unsigned long TANK_SAMPLE_THRESHOLD = 50UL; // ms
103102
const unsigned long BUTTON_DELAY_MS = 3UL * 1000UL; // Idle state - 2 seconds
104103
const unsigned long DEBOUNCE_DELAY_MS = 20; // debounce time for sensors = 20 ms
105104
const uint8_t TANK_12 = 12;
@@ -131,7 +130,7 @@ bool sensorActive(uint8_t pin) { return digitalRead(pin) == LOW; }
131130
void syncTankID(bool firstTimeInit)
132131
{
133132
uint8_t currentRead = 0;
134-
for (uint8_t i = 0; i < 4; ++i)
133+
for (uint8_t i = 0; i < 4; i++)
135134
{
136135
uint8_t v = digitalRead(PIN_ID_BITS[i]);
137136
currentRead |= (v << i);
@@ -142,7 +141,7 @@ void syncTankID(bool firstTimeInit)
142141
tankStabilityTime = millis();
143142
tankChanged = false;
144143
}
145-
else if (lastStableTank != pendingTank && (millis() - tankStabilityTime) >= TANK_STABILITY_THRESHOLD)
144+
if (lastStableTank != pendingTank && (millis() - tankStabilityTime) >= TANK_STABILITY_THRESHOLD)
146145
{
147146
if (pendingTank < 1 || pendingTank > 12)
148147
{
@@ -559,6 +558,7 @@ enum MainState : id_t
559558

560559
// Forward declarations for predicate/process/event functions
561560
bool verifyingPredicate(id_t id);
561+
void verifyingProcess(id_t id);
562562
void verifyingActionChanged(EventArgs e);
563563

564564
bool unknownDirectionPredicate(id_t id);
@@ -613,7 +613,7 @@ void preRaisingActionChanged(EventArgs e);
613613
Transition transitions[] = {
614614
// S_VERIFYING: if sample is down -> continue as correct behavior
615615
// otherwise enter recovery mode
616-
{verifyingPredicate, S_IDLE, S_UNKNOWN_DIRECTION_RECOVERY, nullptr, verifyingActionChanged, VERIFICATION_DELAY_MS, PREDIC_TIMER},
616+
{verifyingPredicate, S_IDLE, S_UNKNOWN_DIRECTION_RECOVERY, verifyingProcess, verifyingActionChanged, VERIFICATION_DELAY_MS, PREDIC_TIMER},
617617

618618
// S_UNKNOWN_DIRECTION_RECOVERY: if sample up -> go to S_UP_RECOVERY
619619
// if not top and not down, so sample is on the middle position
@@ -685,14 +685,15 @@ bool verifyingPredicate(id_t id)
685685

686686
return true;
687687
}
688+
void verifyingProcess(id_t id)
689+
{
690+
syncTankID(True);
691+
}
688692

689693
void verifyingActionChanged(EventArgs e)
690694
{
691695
if (e.action == ENTRY)
692-
{
693-
syncTankID(True);
694696
lcdShowStatus(F("Initializing"), F("Wait 3 seconds"));
695-
}
696697
}
697698

698699
bool unknownDirectionPredicate(id_t id)

0 commit comments

Comments
 (0)