X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=arducontrol%2Fmonitor.c;h=7966c3da40eb0e46cac63c4282924b9dc5995c32;hb=49c7ae4a26f8dd7d09872b6b5e4c107ef33b4560;hp=de00fc1645b9ddc1258326eadcb2a880aaeb23d9;hpb=4150740d3a5c2384289865923cef08c5852cb520;p=model-railway-devices.git diff --git a/arducontrol/monitor.c b/arducontrol/monitor.c index de00fc1..7966c3d 100644 --- a/arducontrol/monitor.c +++ b/arducontrol/monitor.c @@ -7,7 +7,7 @@ static uint16_t track_current_samples[16] = { 0 }; static uint8_t track_current_head = 0; static volatile uint16_t track_current_sum = 0; -static uint16_t overcurrent_limit = 8796; +static uint16_t overcurrent_limit = 9707; static uint8_t overcurrent_sent = 0; static uint16_t input_voltage_samples[16] = { 0 }; @@ -22,6 +22,7 @@ static uint16_t input_voltage_millivolts(void); void monitor_init(void) { + DDRB |= 0x02; adc_init(); } @@ -42,14 +43,18 @@ void monitor_check(void) if(track_current_sum>overcurrent_limit) { output_set_power(0); + PORTB |= 0x02; if(!overcurrent_sent) { overcurrent_sent = 1; interface_send1(OVERCURRENT); } } - else + else if(overcurrent_sent && output_is_power_on()) + { + PORTB &= ~0x02; overcurrent_sent = 0; + } } else if(adc_state==4) { @@ -69,12 +74,11 @@ uint8_t monitor_command(const uint8_t *cmd_buf, uint8_t cmd_length) { if(cmd_buf[0]==READ_TRACK_CURRENT) { - uint8_t reply[3]; - if(cmd_length!=1) return LENGTH_ERROR; uint16_t value = track_current_milliamps(); + uint8_t reply[3]; reply[0] = TRACK_CURRENT; reply[1] = value>>8; reply[2] = value; @@ -96,12 +100,11 @@ uint8_t monitor_command(const uint8_t *cmd_buf, uint8_t cmd_length) } else if(cmd_buf[0]==READ_INPUT_VOLTAGE) { - uint8_t reply[3]; - if(cmd_length!=1) return LENGTH_ERROR; uint16_t value = input_voltage_millivolts(); + uint8_t reply[3]; reply[0] = INPUT_VOLTAGE; reply[1] = value>>8; reply[2] = value;