Browse Source

allow arbitrary value input

git-svn-id: https://bucket.mit.edu/svn/nilm/zoom@7173 ddd99763-3ecb-0310-9145-efcb8ce7c51f
tags/zoom-1.0
jim 14 years ago
parent
commit
dc0e311582
3 changed files with 34 additions and 2 deletions
  1. +17
    -0
      firmware/util.c
  2. +1
    -0
      firmware/util.h
  3. +16
    -2
      firmware/zoom.c

+ 17
- 0
firmware/util.c View File

@@ -25,3 +25,20 @@ uint8_t from_hex(uint8_t ch)
const uint8_t hex[16]={'0','1','2','3','4','5','6','7',
'8','9','a','b','c','d','e','f'};

/* Convert 4 ASCII hex digits into a 16-bit unsigned number.
Returns the number, or -1 if there's an error */
int32_t hex_to_u16(char x[4])
{
uint16_t v = 0;
uint8_t t;
int i;

for (i = 0; i < 4; i++) {
t = from_hex(x[i]);
if (t >= 16)
return -1;
v = (v << 4) | t;
}
return v;
}


+ 1
- 0
firmware/util.h View File

@@ -6,6 +6,7 @@
/* Convert from ascii hex digit to number */
uint8_t from_hex(uint8_t ch);
extern const uint8_t hex[16];
int32_t hex_to_u16(char x[4])

/* Array length */
#define array_len(x) (sizeof(x)/sizeof(x[0]))


+ 16
- 2
firmware/zoom.c View File

@@ -94,6 +94,8 @@ void run_debug(void)
{
uint16_t dac = 32768;
int16_t adc;
int32_t v;
char buf[4];
uart1_init(115200);

uart1_put_string("Zoom NILM Debug\r\n");
@@ -101,10 +103,10 @@ void run_debug(void)
while (1) {
dac_write(dac);
uart1_put_dec(dac);
uart1_put(' ');
uart1_put(' ');
adc = adc_get();
uart1_put_hex16(adc);
uart1_put(' ');
uart1_put(' ');
uart1_put_dec(adc);
uart1_crlf();
switch (uart1_get()) {
@@ -138,6 +140,18 @@ void run_debug(void)
uart1_crlf();
dac = 32768;
break;
case 'v':
case 'V':
buf[0] = uart1_get();
buf[1] = uart1_get();
buf[2] = uart1_get();
buf[3] = uart1_get();
v = hex_to_u16(buf);
if (v < 0)
uart1_put_string("bad value\r\n");
else
dac = v;
break;
}
}
}


Loading…
Cancel
Save