2024-03-06 12:20:10 +00:00
|
|
|
/*
|
|
|
|
|
* 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
|
|
|
|
|
|
2024-04-23 13:31:32 +00:00
|
|
|
#include "eeprom.h"
|
2024-04-16 13:30:38 +00:00
|
|
|
#include <avr/io.h>
|
2024-03-06 12:51:52 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <string.h>
|
2024-04-24 11:24:15 +00:00
|
|
|
#include "voltage.h"
|
|
|
|
|
#include "themistor-temp.h"
|
2024-04-23 13:31:32 +00:00
|
|
|
|
2024-03-06 12:20:10 +00:00
|
|
|
// Enum of all valid command types
|
|
|
|
|
typedef enum {
|
2024-04-24 13:43:27 +00:00
|
|
|
WRITE_CONFIG = 0x21, // Change the configuration
|
|
|
|
|
READ_CONFIG = 0x11, // Read, and print the current configuration
|
|
|
|
|
READ_VOLTAGE = 0x12, // Read, and print a voltage
|
|
|
|
|
READ_TERMPERATURE = 0x13, // Read, and print the temperature
|
|
|
|
|
READ_FAN_SPEED = 0x14, // Read, and print the current fan speed
|
|
|
|
|
READ_BULK_FAN_SPEED = 0x15, // Read, and print the stored back fan speed data
|
|
|
|
|
CLEAR_BULK_FAN_SPEED = 0x22, // Clear the buffer of stored fan speed data
|
|
|
|
|
UNKNOWN_COMMAND // An unrecognized command has been sent
|
2024-03-06 12:20:10 +00:00
|
|
|
} command_t;
|
|
|
|
|
|
|
|
|
|
// Enum of all valid voltage sources
|
|
|
|
|
typedef enum {
|
2024-03-06 12:51:52 +00:00
|
|
|
SRC_INTERNAL, // Internal volage
|
|
|
|
|
SRC_EXTRNAL, // External voltage
|
|
|
|
|
SRC_THERMISTOR, // Thermistor voltage
|
|
|
|
|
SRC_NONE // No voltage source selected
|
2024-03-06 12:20:10 +00:00
|
|
|
} src_voltage_t;
|
|
|
|
|
|
|
|
|
|
// Enum of all valid config options
|
|
|
|
|
// TODO: Move into config header file
|
|
|
|
|
typedef enum {
|
2024-04-27 12:52:46 +00:00
|
|
|
SAMPLE_TIME = 0x01, // Time between each fan speed sample
|
|
|
|
|
CNF_NONE, // No config option
|
2024-03-06 12:20:10 +00:00
|
|
|
} config_option_t;
|
|
|
|
|
|
|
|
|
|
// Enum of all valid fans
|
|
|
|
|
// TODO: Consider moving into it's own fan page
|
|
|
|
|
typedef enum {
|
2024-04-23 13:31:32 +00:00
|
|
|
FAN1 = 1, // The first fan
|
|
|
|
|
FAN2 = 2, // The second fan
|
2024-03-06 12:20:10 +00:00
|
|
|
FAN_NONE // No fan
|
|
|
|
|
} fans_t;
|
|
|
|
|
|
|
|
|
|
// Struct with command context
|
|
|
|
|
typedef struct {
|
|
|
|
|
command_t command; // The command to execute
|
2024-03-06 12:51:52 +00:00
|
|
|
src_voltage_t src_voltage; // The selected voltage source
|
|
|
|
|
fans_t fan; // The selected fan
|
2024-03-06 12:20:10 +00:00
|
|
|
config_option_t conf; // The configuration option to cange
|
2024-04-27 12:52:46 +00:00
|
|
|
uint16_t conf_val; // The value of the config option to change
|
2024-03-06 12:20:10 +00:00
|
|
|
} command_context_t;
|
|
|
|
|
|
2024-04-23 13:31:32 +00:00
|
|
|
// Fan history variables
|
|
|
|
|
extern volatile uint16_t fan1_history[512];
|
|
|
|
|
extern volatile uint16_t fan2_history[512];
|
2024-04-30 09:08:03 +00:00
|
|
|
// Fan history index variable
|
|
|
|
|
volatile uint16_t fan1_history_index = 0;
|
|
|
|
|
volatile uint16_t fan2_history_index = 0;
|
2024-04-23 13:31:32 +00:00
|
|
|
|
2024-04-27 12:52:46 +00:00
|
|
|
// Config
|
|
|
|
|
extern volatile config_t config;
|
|
|
|
|
extern volatile bool store_config;
|
|
|
|
|
|
2024-03-06 12:20:10 +00:00
|
|
|
// Parses the input string and outputs one of the valid commands
|
2024-04-16 13:30:38 +00:00
|
|
|
void parse_command(uint8_t *command, uint8_t command_len);
|
2024-03-06 12:20:10 +00:00
|
|
|
|
|
|
|
|
// Routes the provided command to the appropriate function to handle it
|
2024-04-16 14:20:32 +00:00
|
|
|
// 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.
|
2024-04-16 13:35:43 +00:00
|
|
|
uint8_t route_command(int pos);
|
2024-03-06 12:20:10 +00:00
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#endif /* COMMAND_HANDLER_H */
|