Prepare for write config

This commit is contained in:
Sebastian H. Gabrielli 2024-04-24 15:50:40 +02:00
parent b8d19731ad
commit fb24365469
3 changed files with 15 additions and 3 deletions

View File

@ -23,7 +23,7 @@ extern "C" {
// Struct for information on the controller. // Struct for information on the controller.
typedef struct { typedef struct {
uint8_t fanSpeed; uint16_t ms_fanspeed_sample_rate;
} config_t; } config_t;
// Check if EEPROM is ready to be written in // Check if EEPROM is ready to be written in

View File

@ -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] == 0x22) { if (i2c_recv[0] == CLEAR_BULK_FAN_SPEED || i2c_recv[0] == WRITE_CONFIG) {
route_command(0); route_command(0);
} }
} }

View File

@ -27,18 +27,30 @@
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;
}
} }
} }