// Retail pour gates (dyj) - stage-gate rehearsal
// Planning aid only; not an inspection signoff.
// Electrical gates grounded in NEC (NFPA 70) provisions for concealed wiring.
const char* stages[] = {
"forms",
"footing_elec",
"footing_inspect",
"footing_pour",
"stem_walls",
"underslab_plumb",
"underslab_elec",
"rough_elec_inspect",
"slab_prep",
"slab_inspect",
"slab_pour",
"steel_delivery"
};
const int stageCount = sizeof(stages) / sizeof(stages[0]);
const char* necNotes[] = {
"",
"NEC 300.4(A) wiring in concrete; NEC 300.15 protection",
"",
"",
"",
"",
"NEC 300.21 cable protection; NEC 300.24 physical damage",
"NEC 300.28 wiring in concrete; NEC 314.29 boxes in concrete",
"",
"",
"",
""
};
int nextStage = 0;
bool held = false;
int heldIdx = -1;
void setup() {
Serial.begin(115200);
Serial.println("=== Retail pour gates (dyj) - stage-gate rehearsal ===");
Serial.println("Planning aid only; not an inspection signoff.");
Serial.println("Type 'help' for commands.");
}
void help() {
Serial.println("--- Commands ---");
Serial.println(" status Show current stage and gate state");
Serial.println(" reset Reset to stage 0 (forms)");
Serial.println(" <stage_name> Accept a stage (must be next in sequence)");
Serial.println(" pass <stage_name> Pass an inspection (releases held work)");
Serial.println(" fail <stage_name> Fail an inspection (holds work)");
Serial.println(" help Show this help");
Serial.println("--- NEC gate notes ---");
Serial.println(" footing_elec: NEC 300.4(A), 300.15");
Serial.println(" underslab_elec: NEC 300.21, 300.24");
Serial.println(" rough_elec_inspect: NEC 300.28, 314.29");
}
void status() {
if (nextStage >= stageCount) {
Serial.println("All stages complete - steel delivery reached.");
return;
}
Serial.print("next: ");
Serial.println(stages[nextStage]);
if (held) {
Serial.print("HELD at: ");
Serial.println(stages[heldIdx]);
Serial.println("Work is held. Type 'pass " + String(stages[heldIdx]) + "' to release.");
} else {
Serial.println("Gate is open.");
}
}
bool isInspect(int i) { return i == 2 || i == 7 || i == 9; }
void loop() {
if (!Serial.available()) return;
String cmd = Serial.readStringUntil('\n');
cmd.trim();
if (cmd.length() == 0) return;
if (cmd == "help") { help(); return; }
if (cmd == "reset") { nextStage = 0; held = false; heldIdx = -1; Serial.println("reset"); return; }
if (cmd == "status") { status(); return; }
if (nextStage >= stageCount) {
Serial.println("All stages complete. Type 'reset' to start a new rehearsal.");
return;
}
int idx = -1;
for (int i = 0; i < stageCount; i++) {
if (cmd == stages[i]) { idx = i; break; }
}
if (cmd.startsWith("pass ")) {
String sn = cmd.substring(5);
sn.trim();
int pidx = -1;
for (int i = 0; i < stageCount; i++) {
if (sn == stages[i]) { pidx = i; break; }
}
if (pidx == -1) { Serial.println("unknown stage"); return; }
if (!isInspect(pidx)) { Serial.println("not an inspection stage"); return; }
if (held && pidx == heldIdx) {
held = false; heldIdx = -1;
Serial.print("passed: "); Serial.println(sn);
Serial.println("Work released. Proceed to next stage.");
return;
}
if (pidx == nextStage) {
nextStage++;
Serial.print("passed: "); Serial.println(sn);
if (nextStage >= stageCount) Serial.println("All stages complete - steel delivery reached.");
return;
}
Serial.println("REFUSED: out of order. Next stage is " + String(stages[nextStage]) + ".");
return;
}
if (cmd.startsWith("fail ")) {
String sn = cmd.substring(5);
sn.trim();
int fidx = -1;
for (int i = 0; i < stageCount; i++) {
if (sn == stages[i]) { fidx = i; break; }
}
if (fidx == -1) { Serial.println("unknown stage"); return; }
if (!isInspect(fidx)) { Serial.println("not an inspection stage"); return; }
if (fidx == nextStage) {
held = true; heldIdx = fidx;
Serial.print("failed: "); Serial.println(sn);
Serial.println("Work held. Correct the deficiency and reinspect.");
return;
}
Serial.println("REFUSED: out of order. Next stage is " + String(stages[nextStage]) + ".");
return;
}
if (idx == -1) { Serial.println("unknown command"); return; }
if (held) {
if (idx == heldIdx) {
Serial.println("Work is held. Type 'pass " + String(stages[heldIdx]) + "' to release after reinspection.");
} else {
Serial.println("REFUSED: work is held at " + String(stages[heldIdx]) + ". Release the hold first.");
}
return;
}
if (idx != nextStage) {
Serial.println("REFUSED: out of order. Next stage is " + String(stages[nextStage]) + ".");
return;
}
nextStage++;
Serial.print("accepted: ");
Serial.println(cmd);
if (necNotes[idx][0] != '\0') {
Serial.print(" NEC gate: ");
Serial.println(necNotes[idx]);
}
if (nextStage >= stageCount) {
Serial.println("All stages complete - steel delivery reached.");
}
}