diff --git a/prosjekt.X/command-handler.c b/prosjekt.X/command-handler.c index 8da542d..d109bdc 100644 --- a/prosjekt.X/command-handler.c +++ b/prosjekt.X/command-handler.c @@ -138,7 +138,32 @@ uint8_t route_command(int pos) { case READ_CONFIG: return READ_CONFIG; case READ_VOLTAGE: - return READ_VOLTAGE; + { + // Create a union to store the data + union { + int16_t v; + uint8_t bytes[2]; + } voltage; + + // Figure out which voltage source to read + switch (context.src_voltage) { + case SRC_INTERNAL: + voltage.v = internal_voltage_read(); + break; + case SRC_EXTRNAL: + voltage.v = external_voltage_read(); + break; + case SRC_THERMISTOR: + voltage.v = thermistor_voltage_read(); + break; + default: + return 0xFF; + break; + } + + // Send the data + return voltage.bytes[pos]; + } case READ_TERMPERATURE: { uint16_t v_therm = thermistor_voltage_read();