/* * File: command-handler.h * Author: Sebastian H. Gabrielli * * Created on March 6, 2024, 12:43 PM */ #ifndef COMMAND_HANDLER_H #define COMMAND_HANDLER_H #ifdef __cplusplus extern "C" { #endif #include "eeprom.h" #include #include #include #include "voltage.h" #include "themistor-temp.h" // Enum of all valid command types typedef enum { WRITE_CONFIG, // Change the configuration READ_CONFIG, // Read, and print the current configuration READ_VOLTAGE, // Read, and print a voltage READ_TERMPERATURE, // Read, and print the temperature READ_FAN_SPEED, // Read, and print the current fan speed READ_BULK_FAN_SPEED, // Read, and print the stored back fan speed data CLEAR_BULK_FAN_SPEED, // Clear the buffer of stored fan speed data UNKNOWN_COMMAND // An unrecognized command has been sent } command_t; // Enum of all valid voltage sources typedef enum { SRC_INTERNAL, // Internal volage SRC_EXTRNAL, // External voltage SRC_THERMISTOR, // Thermistor voltage SRC_NONE // No voltage source selected } src_voltage_t; // Enum of all valid config options // TODO: Move into config header file typedef enum { CNF_NONE, // No config option } config_option_t; // Enum of all valid fans // TODO: Consider moving into it's own fan page typedef enum { FAN1 = 1, // The first fan FAN2 = 2, // The second fan FAN_NONE // No fan } fans_t; // Struct with command context typedef struct { command_t command; // The command to execute src_voltage_t src_voltage; // The selected voltage source fans_t fan; // The selected fan config_option_t conf; // The configuration option to cange // TODO: Add config value field for writing } command_context_t; // Fan history variables extern volatile uint16_t fan1_history[512]; extern volatile uint16_t fan2_history[512]; // Parses the input string and outputs one of the valid commands void parse_command(uint8_t *command, uint8_t command_len); // Routes the provided command to the appropriate function to handle it // If the command is a read command it then returns the current byte. // The position is the byte to read when multiple bytes are being read. uint8_t route_command(int pos); #ifdef __cplusplus } #endif #endif /* COMMAND_HANDLER_H */