From 822845cc7abc45ca2187b0a42a91b8ca7761c49e Mon Sep 17 00:00:00 2001 From: "Sebastian H. Gabrielli" Date: Wed, 24 Apr 2024 13:40:45 +0200 Subject: [PATCH] Read temperature command works --- prosjekt.X/command-handler.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) 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();