Add case structure for better handling of future config params

A case structure to send the correct config value has been added.
This commit is contained in:
Sebastian H. Gabrielli 2024-04-27 14:55:44 +02:00
parent dd624d4d48
commit f654ae96f6

View File

@ -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:
{