altos: Allow negative values for pyro configuration data
authorKeith Packard <keithp@keithp.com>
Thu, 4 Sep 2014 05:58:22 +0000 (22:58 -0700)
committerKeith Packard <keithp@keithp.com>
Thu, 4 Sep 2014 05:58:22 +0000 (22:58 -0700)
All of the integer pyro configuration parameters may be negative, so
parse that correctly.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/kernel/ao_pyro.c

index 154edad5f0f7e4436361644d52705efa941e3c0f..3044d56517aa06fceaf198fb31a4165e5d6b9370 100644 (file)
@@ -499,13 +499,26 @@ ao_pyro_set(void)
                }
                pyro_tmp.flags |= ao_pyro_values[v].flag;
                if (ao_pyro_values[v].offset != NO_VALUE) {
+                       uint8_t negative = 0;
+                       ao_cmd_white();
+                       if (ao_cmd_lex_c == '-') {
+                               negative = 1;
+                               ao_cmd_lex();
+                       }
                        ao_cmd_decimal();
                        if (ao_cmd_status != ao_cmd_success)
                                return;
-                       if (ao_pyro_values[v].flag & AO_PYRO_8_BIT_VALUE)
+                       if (ao_pyro_values[v].flag & AO_PYRO_8_BIT_VALUE) {
+                               if (negative) {
+                                       ao_cmd_status = ao_cmd_syntax_error;
+                                       return;
+                               }
                                *((uint8_t *) ((char *) &pyro_tmp + ao_pyro_values[v].offset)) = ao_cmd_lex_i;
-                       else
+                       } else {
+                               if (negative)
+                                       ao_cmd_lex_i = -ao_cmd_lex_i;
                                *((int16_t *) ((char *) &pyro_tmp + ao_pyro_values[v].offset)) = ao_cmd_lex_i;
+                       }
                }
        }
        _ao_config_edit_start();