Skip to content

Commit c417ab1

Browse files
committed
altos: Make cmd number parsing functions return value
Don't use a global variable to hold the result. Signed-off-by: Keith Packard <[email protected]>
1 parent c6e5729 commit c417ab1

35 files changed

+195
-252
lines changed

src/cortexelf-v1/ao_cortexelf.c

+6-9
Original file line numberDiff line numberDiff line change
@@ -149,17 +149,16 @@ ao_fb_init(void)
149149
static void
150150
ao_video_toggle(void)
151151
{
152-
ao_cmd_decimal();
153-
if (ao_cmd_lex_i)
152+
uint16_t r = ao_cmd_decimal();
153+
if (r)
154154
ao_fb_init();
155-
ao_vga_enable(ao_cmd_lex_i);
155+
ao_vga_enable(r)
156156
}
157157

158158
static void
159159
ao_ball_toggle(void)
160160
{
161-
ao_cmd_decimal();
162-
ball_enable = ao_cmd_lex_i;
161+
ball_enable = ao_cmd_decimal();
163162
ao_wakeup(&ball_enable);
164163
}
165164

@@ -208,11 +207,9 @@ led_cmd(void)
208207
{
209208
uint8_t start;
210209
uint8_t value;
211-
ao_cmd_decimal();
212210

213-
start = ao_cmd_lex_i;
214-
ao_cmd_hex();
215-
value = ao_cmd_lex_i;
211+
start = ao_cmd_decimal();
212+
value = ao_cmd_hex();
216213
if (ao_cmd_status != ao_cmd_success)
217214
return;
218215
ao_as1107_write_8(start, value);

src/drivers/ao_btm.c

+12-7
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
int8_t ao_btm_stdio;
3333
uint8_t ao_btm_connected;
3434

35-
#define BT_DEBUG 0
35+
#define BT_DEBUG 1
3636

3737
#if BT_DEBUG
3838
char ao_btm_buffer[256];
@@ -76,6 +76,7 @@ ao_btm_dump(void)
7676
{
7777
int i;
7878
char c;
79+
uint16_t r;
7980

8081
for (i = 0; i < ao_btm_ptr; i++) {
8182
c = ao_btm_buffer[i];
@@ -85,22 +86,26 @@ ao_btm_dump(void)
8586
putchar(ao_btm_buffer[i]);
8687
}
8788
putchar('\n');
88-
ao_cmd_decimal();
89-
if (ao_cmd_status == ao_cmd_success && ao_cmd_lex_i)
89+
r = ao_cmd_decimal();
90+
if (ao_cmd_status == ao_cmd_success && r)
9091
ao_btm_ptr = 0;
9192
ao_cmd_status = ao_cmd_success;
9293
}
9394

9495
static void
9596
ao_btm_speed(void)
9697
{
97-
ao_cmd_decimal();
98-
if (ao_cmd_lex_u32 == 57600)
98+
switch (ao_cmd_decimal()) {
99+
case 57600:
99100
ao_serial_btm_set_speed(AO_SERIAL_SPEED_57600);
100-
else if (ao_cmd_lex_u32 == 19200)
101+
break;
102+
case 19200:
101103
ao_serial_btm_set_speed(AO_SERIAL_SPEED_19200);
102-
else
104+
break;
105+
default:
103106
ao_cmd_status = ao_cmd_syntax_error;
107+
break;
108+
}
104109
}
105110

106111
static uint8_t ao_btm_enable;

src/drivers/ao_cc1120.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -805,8 +805,7 @@ ao_radio_test_cmd(void)
805805
static uint8_t radio_on;
806806
ao_cmd_white();
807807
if (ao_cmd_lex_c != '\n') {
808-
ao_cmd_decimal();
809-
mode = (uint8_t) ao_cmd_lex_u32;
808+
mode = ao_cmd_decimal();
810809
}
811810
mode++;
812811
if ((mode & 2) && !radio_on) {

src/drivers/ao_cc115l.c

+2-4
Original file line numberDiff line numberDiff line change
@@ -700,10 +700,8 @@ ao_radio_test_cmd(void)
700700
uint8_t mode = 2;
701701
static uint8_t radio_on;
702702
ao_cmd_white();
703-
if (ao_cmd_lex_c != '\n') {
704-
ao_cmd_decimal();
705-
mode = (uint8_t) ao_cmd_lex_u32;
706-
}
703+
if (ao_cmd_lex_c != '\n')
704+
mode = ao_cmd_decimal();
707705
mode++;
708706
if ((mode & 2) && !radio_on) {
709707
#if HAS_MONITOR

src/drivers/ao_cc1200.c

+9-13
Original file line numberDiff line numberDiff line change
@@ -858,10 +858,8 @@ ao_radio_test_cmd(void)
858858
{
859859
uint8_t mode = 2;
860860
ao_cmd_white();
861-
if (ao_cmd_lex_c != '\n') {
862-
ao_cmd_decimal();
863-
mode = (uint8_t) ao_cmd_lex_u32;
864-
}
861+
if (ao_cmd_lex_c != '\n')
862+
mode = ao_cmd_decimal();
865863
mode++;
866864
if ((mode & 2))
867865
ao_radio_test_on();
@@ -1362,14 +1360,15 @@ ao_radio_aprs(void)
13621360
static void
13631361
ao_radio_strobe_test(void)
13641362
{
1363+
uint8_t addr;
13651364
uint8_t r;
13661365

1367-
ao_cmd_hex();
1366+
addr = ao_cmd_hex();
13681367
if (ao_cmd_status != ao_cmd_success)
13691368
return;
1370-
r = ao_radio_strobe(ao_cmd_lex_i);
1369+
r = ao_radio_strobe(addr);
13711370
printf ("Strobe %02x -> %02x (rdy %d state %d)\n",
1372-
ao_cmd_lex_i,
1371+
addr,
13731372
r,
13741373
r >> 7,
13751374
(r >> 4) & 0x7);
@@ -1381,14 +1380,12 @@ ao_radio_write_test(void)
13811380
uint16_t addr;
13821381
uint8_t data;
13831382

1384-
ao_cmd_hex();
1383+
addr = ao_cmd_hex();
13851384
if (ao_cmd_status != ao_cmd_success)
13861385
return;
1387-
addr = ao_cmd_lex_i;
1388-
ao_cmd_hex();
1386+
data = ao_cmd_hex();
13891387
if (ao_cmd_status != ao_cmd_success)
13901388
return;
1391-
data = ao_cmd_lex_i;
13921389
printf ("Write %04x = %02x\n", addr, data);
13931390
ao_radio_reg_write(addr, data);
13941391
}
@@ -1399,10 +1396,9 @@ ao_radio_read_test(void)
13991396
uint16_t addr;
14001397
uint8_t data;
14011398

1402-
ao_cmd_hex();
1399+
addr = ao_cmd_hex();
14031400
if (ao_cmd_status != ao_cmd_success)
14041401
return;
1405-
addr = ao_cmd_lex_i;
14061402
data = ao_radio_reg_read(addr);
14071403
printf ("Read %04x = %02x\n", addr, data);
14081404
}

src/drivers/ao_gps_ublox.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -783,12 +783,12 @@ ao_gps(void)
783783
#if AO_UBLOX_DEBUG
784784
static void ao_gps_option(void)
785785
{
786-
ao_cmd_hex();
786+
uint16_t r = ao_cmd_hex();
787787
if (ao_cmd_status != ao_cmd_success) {
788788
ao_cmd_status = ao_cmd_success;
789789
ao_gps_show();
790790
} else {
791-
ao_gps_dbg_enable = ao_cmd_lex_i;
791+
ao_gps_dbg_enable = r;
792792
printf ("gps debug set to %d\n", ao_gps_dbg_enable);
793793
}
794794
}

src/drivers/ao_lco.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,9 @@ ao_lco_main(void)
319319
void
320320
ao_lco_set_debug(void)
321321
{
322-
ao_cmd_decimal();
322+
uint16_t r = ao_cmd_decimal();
323323
if (ao_cmd_status == ao_cmd_success)
324-
ao_lco_debug = ao_cmd_lex_i != 0;
324+
ao_lco_debug = r != 0;
325325
}
326326

327327
const struct ao_cmds ao_lco_cmds[] = {

src/drivers/ao_lco_cmd.c

+4-8
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ static uint16_t tick_offset;
3333
static void
3434
lco_args(void)
3535
{
36-
ao_cmd_decimal();
37-
lco_box = ao_cmd_lex_i;
38-
ao_cmd_hex();
39-
lco_channels = ao_cmd_lex_i;
36+
lco_box = ao_cmd_decimal();
37+
lco_channels = ao_cmd_hex();
4038
}
4139

4240
static struct ao_pad_query ao_pad_query;
@@ -129,8 +127,7 @@ lco_fire_cmd(void)
129127
int8_t r;
130128

131129
lco_args();
132-
ao_cmd_decimal();
133-
secs = ao_cmd_lex_i;
130+
secs = ao_cmd_decimal();
134131
if (ao_cmd_status != ao_cmd_success)
135132
return;
136133
r = lco_query();
@@ -163,8 +160,7 @@ lco_static_cmd(void)
163160
int8_t r;
164161

165162
lco_args();
166-
ao_cmd_decimal();
167-
secs = ao_cmd_lex_i;
163+
secs = ao_cmd_decimal();
168164
if (ao_cmd_status != ao_cmd_success)
169165
return;
170166
r = lco_query();

src/drivers/ao_lco_two.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ ao_lco_main(void)
124124
void
125125
ao_lco_set_debug(void)
126126
{
127-
ao_cmd_decimal();
127+
uint16_t r = ao_cmd_decimal();
128128
if (ao_cmd_status == ao_cmd_success)
129-
ao_lco_debug = ao_cmd_lex_i;
129+
ao_lco_debug = r;
130130
}
131131

132132
const struct ao_cmds ao_lco_cmds[] = {

src/drivers/ao_mpu9250.c

+6-12
Original file line numberDiff line numberDiff line change
@@ -472,10 +472,9 @@ ao_mpu9250_read(void)
472472
uint8_t addr;
473473
uint8_t val;
474474

475-
ao_cmd_hex();
475+
addr = ao_cmd_hex();
476476
if (ao_cmd_status != ao_cmd_success)
477477
return;
478-
addr = ao_cmd_lex_i;
479478
ao_mpu9250_spi_get();
480479
val = _ao_mpu9250_reg_read(addr);
481480
ao_mpu9250_spi_put();
@@ -488,14 +487,12 @@ ao_mpu9250_write(void)
488487
uint8_t addr;
489488
uint8_t val;
490489

491-
ao_cmd_hex();
490+
addr = ao_cmd_hex();
492491
if (ao_cmd_status != ao_cmd_success)
493492
return;
494-
addr = ao_cmd_lex_i;
495-
ao_cmd_hex();
493+
val = ao_cmd_hex();
496494
if (ao_cmd_status != ao_cmd_success)
497495
return;
498-
val = ao_cmd_lex_i;
499496
printf("Addr %02x val %02x\n", addr, val);
500497
ao_mpu9250_spi_get();
501498
_ao_mpu9250_reg_write(addr, val);
@@ -508,10 +505,9 @@ ao_mpu9250_mag_read(void)
508505
uint8_t addr;
509506
uint8_t val;
510507

511-
ao_cmd_hex();
508+
addr = ao_cmd_hex();
512509
if (ao_cmd_status != ao_cmd_success)
513510
return;
514-
addr = ao_cmd_lex_i;
515511
ao_mpu9250_spi_get();
516512
val = _ao_mpu9250_mag_reg_read(addr);
517513
ao_mpu9250_spi_put();
@@ -524,14 +520,12 @@ ao_mpu9250_mag_write(void)
524520
uint8_t addr;
525521
uint8_t val;
526522

527-
ao_cmd_hex();
523+
addr = ao_cmd_hex();
528524
if (ao_cmd_status != ao_cmd_success)
529525
return;
530-
addr = ao_cmd_lex_i;
531-
ao_cmd_hex();
526+
val = ao_cmd_hex();
532527
if (ao_cmd_status != ao_cmd_success)
533528
return;
534-
val = ao_cmd_lex_i;
535529
printf("Addr %02x val %02x\n", addr, val);
536530
ao_mpu9250_spi_get();
537531
_ao_mpu9250_mag_reg_write(addr, val);

src/drivers/ao_pad.c

+7-11
Original file line numberDiff line numberDiff line change
@@ -509,16 +509,14 @@ ao_pad_manual(void)
509509
ao_cmd_white();
510510
if (!ao_match_word("DoIt"))
511511
return;
512-
ao_cmd_decimal();
512+
ignite = 1 << ao_cmd_decimal();
513513
if (ao_cmd_status != ao_cmd_success)
514514
return;
515-
ignite = 1 << ao_cmd_lex_i;
516-
ao_cmd_decimal();
515+
repeat = ao_cmd_decimal();
517516
if (ao_cmd_status != ao_cmd_success) {
518517
repeat = 1;
519518
ao_cmd_status = ao_cmd_success;
520-
} else
521-
repeat = ao_cmd_lex_i;
519+
}
522520
while (repeat-- > 0) {
523521
ao_pad_ignite = ignite;
524522
ao_wakeup(&ao_pad_ignite);
@@ -534,24 +532,22 @@ static struct ao_task ao_pad_monitor_task;
534532
void
535533
ao_pad_set_debug(void)
536534
{
537-
ao_cmd_decimal();
535+
uint16_t r = ao_cmd_decimal();
538536
if (ao_cmd_status == ao_cmd_success)
539-
ao_pad_debug = ao_cmd_lex_i != 0;
537+
ao_pad_debug = r != 0;
540538
}
541539

542540

543541
static void
544542
ao_pad_alarm_debug(void)
545543
{
546544
uint8_t which, value;
547-
ao_cmd_decimal();
545+
which = ao_cmd_decimal();
548546
if (ao_cmd_status != ao_cmd_success)
549547
return;
550-
which = ao_cmd_lex_i;
551-
ao_cmd_decimal();
548+
value = ao_cmd_decimal();
552549
if (ao_cmd_status != ao_cmd_success)
553550
return;
554-
value = ao_cmd_lex_i;
555551
printf ("Set %s to %d\n", which ? "siren" : "strobe", value);
556552
if (which)
557553
ao_siren(value);

src/drivers/ao_pca9922.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ ao_led_set_mask(uint8_t colors, uint8_t mask)
7272
static void
7373
ao_led_test(void)
7474
{
75-
ao_cmd_hexbyte();
75+
AO_LED_TYPE r = ao_cmd_hexbyte();
7676
if (ao_cmd_status != ao_cmd_success)
7777
return;
78-
ao_led_set(ao_cmd_lex_i);
79-
printf("LEDs set to %02x\n", ao_cmd_lex_i);
78+
ao_led_set(r);
79+
printf("LEDs set to %x\n", r);
8080
}
8181

8282
static const struct ao_cmds ao_led_cmds[] = {

src/drivers/ao_quadrature.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,7 @@ ao_quadrature_test(void)
170170
int8_t t = 0;
171171
#endif
172172

173-
ao_cmd_decimal();
174-
q = ao_cmd_lex_i;
173+
q = ao_cmd_decimal();
175174
if (q >= AO_QUADRATURE_COUNT)
176175
ao_cmd_status = ao_cmd_syntax_error;
177176
if (ao_cmd_status != ao_cmd_success)

src/drivers/ao_seven_segment.c

+2-4
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,8 @@ static void
209209
ao_seven_segment_show(void)
210210
{
211211
uint8_t digit, value;
212-
ao_cmd_decimal();
213-
digit = ao_cmd_lex_i;
214-
ao_cmd_decimal();
215-
value = ao_cmd_lex_i;
212+
digit = ao_cmd_decimal();
213+
value = ao_cmd_decimal();
216214
ao_seven_segment_set(digit, value);
217215
}
218216

src/drivers/ao_watchdog.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ ao_watchdog(void)
3838
static void
3939
ao_watchdog_set(void)
4040
{
41-
ao_cmd_hex();
41+
uint32_t r = ao_cmd_hex();
4242
if (ao_cmd_status == ao_cmd_success) {
43-
ao_watchdog_enabled = ao_cmd_lex_i != 0;
43+
ao_watchdog_enabled = r != 0;
4444
ao_wakeup(&ao_watchdog_enabled);
4545
}
4646
}

0 commit comments

Comments
 (0)