Skip to content

Commit d280122

Browse files
committed
Zero control state when connection faults occur
1 parent 19c01c3 commit d280122

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

gizmo.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ unsigned long nextStatusReportAt;
7474
bool loadConfig(String);
7575
void loadConfigFromSerial();
7676
void checkIfShouldConfig();
77+
void zeroizeCState();
7778

7879
bool netLinkOk();
7980
void netLinkResetWiznet();
@@ -121,16 +122,34 @@ void ConfigureWiznetReset(byte rst) {
121122
pinWiznetReset = rst;
122123
}
123124

124-
void GizmoSetup() {
125-
// Ensure that the cstate values for axis data start at a reasonable
126-
// zero point. This prevents machines from running off into the
127-
// wild blue yonder.
125+
126+
void zeroizeCState() {
127+
cstate.Button0 = false;
128+
cstate.Button1 = false;
129+
cstate.Button2 = false;
130+
cstate.Button3 = false;
131+
cstate.Button4 = false;
132+
cstate.Button5 = false;
133+
cstate.Button6 = false;
134+
cstate.Button7 = false;
135+
cstate.Button8 = false;
136+
cstate.Button9 = false;
137+
cstate.Button10 = false;
138+
cstate.Button11 = false;
139+
128140
cstate.Axis0 = 127;
129141
cstate.Axis1 = 127;
130142
cstate.Axis2 = 127;
131143
cstate.Axis3 = 127;
132144
cstate.Axis4 = 127;
133145
cstate.Axis5 = 127;
146+
}
147+
148+
void GizmoSetup() {
149+
// Ensure that the cstate values for axis data start at a reasonable
150+
// zero point. This prevents machines from running off into the
151+
// wild blue yonder.
152+
zeroizeCState();
134153

135154
pinMode(pinStatusPwrBoard, INPUT);
136155
pinMode(pinStatusPwrPico, INPUT);
@@ -579,6 +598,7 @@ void netStateRun() {
579598
netState = NET_CONNECT_MQTT;
580599
status.SetControlConnected(false);
581600
Serial.printf("GIZMO_MQTT_CTRL_TIMEOUT %d\r\n", (millis() - nextControlPacketDueBy));
601+
zeroizeCState();
582602
return;
583603
}
584604

0 commit comments

Comments
 (0)