]> git.tdb.fi Git - model-railway-devices.git/blobdiff - arducontrol/monitor.c
Make current and voltage readings public to other modules
[model-railway-devices.git] / arducontrol / monitor.c
index b87e73ed7370413eeed407ff35b8fcd8ffe75c36..920f56ded6ccb579d2a025880449cbe58b2edfc7 100644 (file)
@@ -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,9 +17,6 @@ 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;
@@ -74,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;
@@ -101,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;
@@ -118,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;
 
@@ -135,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;