Compare commits
No commits in common. "ae1c50ee09f2a64f93c0e17cbeefae3c338c1ea7" and "b8d19731ad2e057a084b955c5ec77f68f30b0ecf" have entirely different histories.
ae1c50ee09
...
b8d19731ad
@ -54,7 +54,7 @@ void parse_command(uint8_t command[], uint8_t command_len) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate that we have a second parameter, else requirements for command are
|
// Validate that we have a first parameter, else requirements for command are
|
||||||
// not fulfilled. return unknown command.
|
// not fulfilled. return unknown command.
|
||||||
if (command_len < 2) {
|
if (command_len < 2) {
|
||||||
context.command = UNKNOWN_COMMAND;
|
context.command = UNKNOWN_COMMAND;
|
||||||
@ -69,11 +69,7 @@ void parse_command(uint8_t command[], uint8_t command_len) {
|
|||||||
// Configuration parameters
|
// Configuration parameters
|
||||||
case 0x11: // Read config
|
case 0x11: // Read config
|
||||||
case 0x21: // Write config
|
case 0x21: // Write config
|
||||||
if (param == 0x01) {
|
// TODO: Handle parameters for config
|
||||||
context.conf = SAMPLE_TIME;
|
|
||||||
} else {
|
|
||||||
context.conf = CNF_NONE;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Voltage parameters
|
// Voltage parameters
|
||||||
@ -108,9 +104,9 @@ void parse_command(uint8_t command[], uint8_t command_len) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////
|
////////////////////////////////
|
||||||
// Third parameter selection //
|
// Second parameter selection //
|
||||||
/////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
||||||
// Check if the command does not require a second parameter. If it does not,
|
// Check if the command does not require a second parameter. If it does not,
|
||||||
// return. Only config write requires a second parameter.
|
// return. Only config write requires a second parameter.
|
||||||
@ -118,7 +114,7 @@ void parse_command(uint8_t command[], uint8_t command_len) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate that we have a third parameter, else requirements for command are
|
// Validate that we have a first parameter, else requirements for command are
|
||||||
// not fulfilled. return unknown command.
|
// not fulfilled. return unknown command.
|
||||||
if (command_len < 3) {
|
if (command_len < 3) {
|
||||||
context.command = UNKNOWN_COMMAND;
|
context.command = UNKNOWN_COMMAND;
|
||||||
@ -128,31 +124,7 @@ void parse_command(uint8_t command[], uint8_t command_len) {
|
|||||||
// Store the parameter
|
// Store the parameter
|
||||||
param = command[2];
|
param = command[2];
|
||||||
|
|
||||||
context.conf = param;
|
// TODO: Handle the config parameters
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
// Fourth parameter selection //
|
|
||||||
////////////////////////////////
|
|
||||||
|
|
||||||
// Validate that we have a fourth parameter, else requirements for command are
|
|
||||||
// not fulfilled. return unknown command. Second parameter is u16, thus two bytes.
|
|
||||||
if (command_len < 4) {
|
|
||||||
context.command = UNKNOWN_COMMAND;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Extract the value
|
|
||||||
union {
|
|
||||||
uint16_t value;
|
|
||||||
uint8_t bytes[2];
|
|
||||||
} config_value;
|
|
||||||
|
|
||||||
config_value.bytes[0] = command[3];
|
|
||||||
config_value.bytes[1] = command[4];
|
|
||||||
|
|
||||||
// Store the value
|
|
||||||
context.conf_val = config_value.value;
|
|
||||||
|
|
||||||
// exit
|
// exit
|
||||||
return;
|
return;
|
||||||
@ -161,40 +133,9 @@ void parse_command(uint8_t command[], uint8_t command_len) {
|
|||||||
uint8_t route_command(int pos) {
|
uint8_t route_command(int pos) {
|
||||||
switch (context.command) {
|
switch (context.command) {
|
||||||
case WRITE_CONFIG:
|
case WRITE_CONFIG:
|
||||||
switch (context.conf) {
|
return WRITE_CONFIG;
|
||||||
case SAMPLE_TIME:
|
|
||||||
// Overwrite the config value
|
|
||||||
config.ms_fanspeed_sample_rate = context.conf_val;
|
|
||||||
|
|
||||||
// Set the flag to store it in the EEPROM
|
|
||||||
store_config = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case READ_CONFIG:
|
case READ_CONFIG:
|
||||||
{
|
return READ_CONFIG;
|
||||||
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;
|
|
||||||
|
|
||||||
// Return the corresponding data byte
|
|
||||||
return config_value.bytes[1-pos];
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case READ_VOLTAGE:
|
case READ_VOLTAGE:
|
||||||
{
|
{
|
||||||
// Create a union to store the data
|
// Create a union to store the data
|
||||||
|
|||||||
@ -42,8 +42,7 @@ typedef enum {
|
|||||||
// Enum of all valid config options
|
// Enum of all valid config options
|
||||||
// TODO: Move into config header file
|
// TODO: Move into config header file
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SAMPLE_TIME = 0x01, // Time between each fan speed sample
|
CNF_NONE, // No config option
|
||||||
CNF_NONE, // No config option
|
|
||||||
} config_option_t;
|
} config_option_t;
|
||||||
|
|
||||||
// Enum of all valid fans
|
// Enum of all valid fans
|
||||||
@ -60,17 +59,13 @@ typedef struct {
|
|||||||
src_voltage_t src_voltage; // The selected voltage source
|
src_voltage_t src_voltage; // The selected voltage source
|
||||||
fans_t fan; // The selected fan
|
fans_t fan; // The selected fan
|
||||||
config_option_t conf; // The configuration option to cange
|
config_option_t conf; // The configuration option to cange
|
||||||
uint16_t conf_val; // The value of the config option to change
|
// TODO: Add config value field for writing
|
||||||
} command_context_t;
|
} command_context_t;
|
||||||
|
|
||||||
// Fan history variables
|
// Fan history variables
|
||||||
extern volatile uint16_t fan1_history[512];
|
extern volatile uint16_t fan1_history[512];
|
||||||
extern volatile uint16_t fan2_history[512];
|
extern volatile uint16_t fan2_history[512];
|
||||||
|
|
||||||
// Config
|
|
||||||
extern volatile config_t config;
|
|
||||||
extern volatile bool store_config;
|
|
||||||
|
|
||||||
// Parses the input string and outputs one of the valid commands
|
// Parses the input string and outputs one of the valid commands
|
||||||
void parse_command(uint8_t *command, uint8_t command_len);
|
void parse_command(uint8_t *command, uint8_t command_len);
|
||||||
|
|
||||||
|
|||||||
@ -23,7 +23,7 @@ extern "C" {
|
|||||||
|
|
||||||
// Struct for information on the controller.
|
// Struct for information on the controller.
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint16_t ms_fanspeed_sample_rate;
|
uint8_t fanSpeed;
|
||||||
} config_t;
|
} config_t;
|
||||||
|
|
||||||
// Check if EEPROM is ready to be written in
|
// Check if EEPROM is ready to be written in
|
||||||
|
|||||||
@ -68,7 +68,7 @@ void i2c_stop_handler() {
|
|||||||
// 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] == CLEAR_BULK_FAN_SPEED || i2c_recv[0] == WRITE_CONFIG) {
|
if (i2c_recv[0] == 0x22) {
|
||||||
route_command(0);
|
route_command(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,30 +27,18 @@
|
|||||||
volatile uint16_t fan1_history[512] = {1, 2, 3, 4};
|
volatile uint16_t fan1_history[512] = {1, 2, 3, 4};
|
||||||
volatile uint16_t fan2_history[512] = {2, 3, 4, 5};
|
volatile uint16_t fan2_history[512] = {2, 3, 4, 5};
|
||||||
|
|
||||||
// Default config is 500ms sample rate
|
|
||||||
volatile config_t config = { 500 };
|
|
||||||
volatile bool store_config = false;
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
// Initialize functionality
|
|
||||||
init_uart((uint16_t)9600);
|
init_uart((uint16_t)9600);
|
||||||
ADC0_init();
|
ADC0_init();
|
||||||
init_led();
|
init_led();
|
||||||
init_i2c();
|
init_i2c();
|
||||||
stdout = &USART_stream;
|
stdout = &USART_stream;
|
||||||
|
|
||||||
// Read the stored config struct
|
|
||||||
config = read_struct_from_EEPROM();
|
|
||||||
|
|
||||||
PORTB.DIRSET = PIN3_bm;
|
PORTB.DIRSET = PIN3_bm;
|
||||||
|
|
||||||
sei();
|
sei();
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
// If we have made a config change, store it.
|
;
|
||||||
if (store_config) {
|
|
||||||
write_struct_from_EEPROM(config);
|
|
||||||
store_config = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user