Skip to content

Commit 8ce107e

Browse files
author
David Betz
committed
Fix a few minor bugs in the test programs.
1 parent 0e22344 commit 8ce107e

File tree

3 files changed

+90
-28
lines changed

3 files changed

+90
-28
lines changed

esp-link-stuff/status.c

Lines changed: 83 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -77,39 +77,95 @@ static void ICACHE_FLASH_ATTR setLed(int on) {
7777
#endif
7878
}
7979

80-
static uint8_t ledState = 0;
80+
/*
81+
82+
Five States of Wireless System
83+
84+
In the description, bold is the wireless mode, small text indicates connectivity or lack
85+
thereof, and after hyphen (-) indicates LED behavior and the timing I used in the video
86+
below.
87+
88+
STA (no IP address) [Not wirelessly accessible] - OFF constantly
89+
STA (has IP address) [Wirelessly accessible] - OFF 4000 ms, ON 25 ms
90+
AP (has IP address) [Wirelessly accessible]* - ON constantly
91+
STA+AP (no IP on STA, IP on AP) [Wirelessly accessible]* - OFF 2000 ms, ON 2000 ms
92+
STA+AP (has IP on STA and AP) [Wirelessly accessible]* - OFF 2000 ms, ON 25 ms,
93+
OFF 150 ms, ON 2000 ms
94+
95+
*In AP mode, there is always an IP address associated with the module because it itself
96+
is serving as the gateway.
97+
98+
*/
99+
100+
static uint8_t ledPhase = 0;
81101

82102
// Timer callback to update the LED
83103
static void ICACHE_FLASH_ATTR ledTimerCb(void *v) {
84-
int time = 1000;
85-
86-
if (wifiState == wifiGotIP) {
87-
// connected, all is good, solid light with a short dark blip every 3 seconds
88-
ledState = 1-ledState;
89-
time = ledState ? 2900 : 100;
90-
} else if (wifiState == wifiIsConnected) {
91-
// waiting for DHCP, go on/off every second
92-
ledState = 1 - ledState;
93-
time = 1000;
94-
} else {
95-
// not connected
104+
int state = 0;
105+
int time = 1000;
106+
96107
switch (wifi_get_opmode()) {
97-
case 1: // STA
98-
ledState = 0;
99-
break;
100-
case 2: // AP
101-
ledState = 1-ledState;
102-
time = ledState ? 50 : 1950;
103-
break;
104-
case 3: // STA+AP
105-
ledState = 1-ledState;
106-
time = ledState ? 50 : 950;
107-
break;
108+
case STATION_MODE:
109+
switch (ledPhase) {
110+
case 0:
111+
case 2:
112+
state = 0;
113+
time = 4000;
114+
break;
115+
case 1:
116+
case 3:
117+
if (wifiState == wifiGotIP)
118+
state = 1;
119+
else
120+
state = 0;
121+
time = 25;
122+
break;
123+
}
124+
break;
125+
case SOFTAP_MODE:
126+
state = 1;
127+
time = 2000;
128+
break;
129+
case STATIONAP_MODE:
130+
if (wifiState == wifiGotIP) {
131+
switch (ledPhase) {
132+
case 0:
133+
state = 0;
134+
time = 2000;
135+
break;
136+
case 1:
137+
state = 1;
138+
time = 25;
139+
break;
140+
case 2:
141+
state = 0;
142+
time = 150;
143+
break;
144+
case 3:
145+
state = 1;
146+
time = 2000;
147+
break;
148+
}
149+
}
150+
else {
151+
switch (ledPhase) {
152+
case 0:
153+
case 2:
154+
state = 0;
155+
break;
156+
case 1:
157+
case 3:
158+
state = 1;
159+
break;
160+
}
161+
time = 2000;
162+
}
163+
break;
108164
}
109-
}
110165

111-
setLed(ledState);
112-
os_timer_arm(&ledTimer, time, 0);
166+
setLed(state);
167+
ledPhase = (ledPhase + 1) % 4;
168+
os_timer_arm(&ledTimer, time, 0);
113169
}
114170

115171
// change the wifi state indication

tests/robot-ws.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ int main(void)
7272
if (process_robot_command(arg[0]) != 0)
7373
dprint(debug, "Unknown robot command: '%c'\n", arg[0]);
7474
break;
75+
case 'S':
76+
dprint(debug, "Send completed\n");
77+
break;
7578
case 'N':
7679
break;
7780
default:

tests/robot.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ int main(void)
3939
init_robot();
4040

4141
// request("SET:cmd-pause-time,5");
42-
request(CMD_START CMD_SET "cmd-pause-time,5" CMD_END);
42+
request(CMD_SET "cmd-pause-time,5" CMD_END);
4343
waitFor(CMD_START "=S,0\r");
4444

4545
request("LISTEN:HTTP,/robot*");
@@ -90,6 +90,9 @@ int main(void)
9090
reply(handle, 404, "unknown");
9191
}
9292
break;
93+
case 'S':
94+
dprint(debug, "Send completed\n");
95+
break;
9396
case 'N':
9497
break;
9598
default:

0 commit comments

Comments
 (0)