X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=arducontrol%2Fmonitor.c;h=920f56ded6ccb579d2a025880449cbe58b2edfc7;hb=7cbb1042ee8a255ed1d1e008ebee4bffe1137565;hp=de00fc1645b9ddc1258326eadcb2a880aaeb23d9;hpb=4150740d3a5c2384289865923cef08c5852cb520;p=model-railway-devices.git diff --git a/arducontrol/monitor.c b/arducontrol/monitor.c index de00fc1..920f56d 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 }; @@ -17,11 +17,9 @@ static volatile uint16_t input_voltage_sum = 0; static volatile uint8_t adc_state = 0; static volatile uint16_t adc_value = 0; -static uint16_t track_current_milliamps(void); -static uint16_t input_voltage_millivolts(void); - void monitor_init(void) { + DDRB |= 0x02; adc_init(); } @@ -42,14 +40,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 +71,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(); + uint16_t value = monitor_track_current(); + uint8_t reply[3]; reply[0] = TRACK_CURRENT; reply[1] = value>>8; reply[2] = value; @@ -96,12 +97,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(); + uint16_t value = monitor_input_voltage(); + uint8_t reply[3]; reply[0] = INPUT_VOLTAGE; reply[1] = value>>8; reply[2] = value; @@ -113,7 +113,7 @@ uint8_t monitor_command(const uint8_t *cmd_buf, uint8_t cmd_length) return COMMAND_OK; } -static uint16_t track_current_milliamps(void) +uint16_t monitor_track_current(void) { uint16_t value = track_current_sum; @@ -130,7 +130,7 @@ static uint16_t track_current_milliamps(void) } } -static uint16_t input_voltage_millivolts(void) +uint16_t monitor_input_voltage(void) { uint16_t value = input_voltage_sum;