From f654ae96f69dd592c72e04af46214b7f9a5ee72e Mon Sep 17 00:00:00 2001 From: "Sebastian H. Gabrielli" Date: Sat, 27 Apr 2024 14:55:44 +0200 Subject: [PATCH] Add case structure for better handling of future config params A case structure to send the correct config value has been added. --- prosjekt.X/command-handler.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/prosjekt.X/command-handler.c b/prosjekt.X/command-handler.c index ad91602..1de3001 100644 --- a/prosjekt.X/command-handler.c +++ b/prosjekt.X/command-handler.c @@ -164,23 +164,27 @@ uint8_t route_command(int pos) { return WRITE_CONFIG; case READ_CONFIG: { - // Validate that pos is within the valid range - if (pos >= 2) { return 0x00; } + switch (context.conf) { + case SAMPLE_TIME: + { + // Validate that pos is within the valid range + if (pos >= 2) { return 0x00; } + + // Config only has one parameter so we sent that parameter + // Create a union to store the data + union { + uint16_t value; + uint8_t bytes[2]; + } config_value; + config_value.value = config.ms_fanspeed_sample_rate; - // Config only has one parameter so we sent that parameter - // Create a union to store the data - union { - uint16_t value; - uint8_t bytes[2]; - } config_value; - config_value.value = config.ms_fanspeed_sample_rate; - - uint8_t data = config_value.bytes[1-pos]; - - // Return the corresponding data byte - return data; + // Return the corresponding data byte + return config_value.bytes[1-pos]; + } + break; + } } - break; + break; case READ_VOLTAGE: {