Merge I2C command handler into main #18
@ -38,7 +38,7 @@ void parse_command(uint8_t command[], uint8_t command_len) {
|
|||||||
context.command = WRITE_CONFIG;
|
context.command = WRITE_CONFIG;
|
||||||
break;
|
break;
|
||||||
case 0x22: // Clear stored fan speed data
|
case 0x22: // Clear stored fan speed data
|
||||||
context.command = READ_BULK_FAN_SPEED;
|
context.command = CLEAR_BULK_FAN_SPEED;
|
||||||
break;
|
break;
|
||||||
default: // Unrecognized command
|
default: // Unrecognized command
|
||||||
context.command = UNKNOWN_COMMAND;
|
context.command = UNKNOWN_COMMAND;
|
||||||
@ -89,7 +89,6 @@ void parse_command(uint8_t command[], uint8_t command_len) {
|
|||||||
case 0x14: // Read current fan speed
|
case 0x14: // Read current fan speed
|
||||||
case 0x15: // Read bulk fan speed
|
case 0x15: // Read bulk fan speed
|
||||||
case 0x22: // Clear stored fan speed data
|
case 0x22: // Clear stored fan speed data
|
||||||
context.command = READ_BULK_FAN_SPEED;
|
|
||||||
if (param == 0x01) {
|
if (param == 0x01) {
|
||||||
context.fan = FAN1;
|
context.fan = FAN1;
|
||||||
} else if (param == 0x02) {
|
} else if (param == 0x02) {
|
||||||
@ -193,6 +192,14 @@ uint8_t route_command(int pos) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case CLEAR_BULK_FAN_SPEED:
|
||||||
|
// Overwrite the content of the desired fan array with zeroes
|
||||||
|
if (context.fan == FAN1) {
|
||||||
|
memset(fan1_history, 0, sizeof(fan1_history));
|
||||||
|
} else if (context.fan == FAN2) {
|
||||||
|
memset(fan2_history, 0, sizeof(fan2_history));
|
||||||
|
}
|
||||||
|
break;
|
||||||
case UNKNOWN_COMMAND:
|
case UNKNOWN_COMMAND:
|
||||||
default:
|
default:
|
||||||
return 0xFF;
|
return 0xFF;
|
||||||
|
|||||||
@ -21,13 +21,13 @@ extern "C" {
|
|||||||
|
|
||||||
// Enum of all valid command types
|
// Enum of all valid command types
|
||||||
typedef enum {
|
typedef enum {
|
||||||
WRITE_CONFIG, // Change the configuration
|
WRITE_CONFIG = 0x21, // Change the configuration
|
||||||
READ_CONFIG, // Read, and print the current configuration
|
READ_CONFIG = 0x11, // Read, and print the current configuration
|
||||||
READ_VOLTAGE, // Read, and print a voltage
|
READ_VOLTAGE = 0x12, // Read, and print a voltage
|
||||||
READ_TERMPERATURE, // Read, and print the temperature
|
READ_TERMPERATURE = 0x13, // Read, and print the temperature
|
||||||
READ_FAN_SPEED, // Read, and print the current fan speed
|
READ_FAN_SPEED = 0x14, // Read, and print the current fan speed
|
||||||
READ_BULK_FAN_SPEED, // Read, and print the stored back fan speed data
|
READ_BULK_FAN_SPEED = 0x15, // Read, and print the stored back fan speed data
|
||||||
CLEAR_BULK_FAN_SPEED, // Clear the buffer of stored fan speed data
|
CLEAR_BULK_FAN_SPEED = 0x22, // Clear the buffer of stored fan speed data
|
||||||
UNKNOWN_COMMAND // An unrecognized command has been sent
|
UNKNOWN_COMMAND // An unrecognized command has been sent
|
||||||
} command_t;
|
} command_t;
|
||||||
|
|
||||||
|
|||||||
@ -67,7 +67,23 @@ void i2c_stop_handler() {
|
|||||||
if (last_action_write) {
|
if (last_action_write) {
|
||||||
// Parse the received command data
|
// Parse the received command data
|
||||||
parse_command(i2c_recv, i2c_recv_len);
|
parse_command(i2c_recv, i2c_recv_len);
|
||||||
|
|
||||||
|
if (i2c_recv[0] == 0x22) {
|
||||||
|
route_command(0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Write only commands need to be routed now
|
||||||
|
switch (i2c_recv[0]) {
|
||||||
|
WRITE_CONFIG:
|
||||||
|
CLEAR_BULK_FAN_SPEED:
|
||||||
|
route_command(0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// Reset the buffer for future transmissions
|
// Reset the buffer for future transmissions
|
||||||
i2c_reset_recv();
|
i2c_reset_recv();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user