Merge I2C command handler into main #18

Merged
sebgab merged 15 commits from output-fan-data-over-i2c into main 2024-04-30 08:37:29 +00:00
Showing only changes of commit f654ae96f6 - Show all commits

View File

@ -164,23 +164,27 @@ uint8_t route_command(int pos) {
return WRITE_CONFIG; return WRITE_CONFIG;
case READ_CONFIG: case READ_CONFIG:
{ {
// Validate that pos is within the valid range switch (context.conf) {
if (pos >= 2) { return 0x00; } 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 // Return the corresponding data byte
// Create a union to store the data return config_value.bytes[1-pos];
union { }
uint16_t value; break;
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;
} }
break; break;
case READ_VOLTAGE: case READ_VOLTAGE:
{ {