diff --git a/prosjekt.X/eeprom.h b/prosjekt.X/eeprom.h index 098074b..517fad9 100644 --- a/prosjekt.X/eeprom.h +++ b/prosjekt.X/eeprom.h @@ -23,7 +23,7 @@ extern "C" { // Struct for information on the controller. typedef struct { - uint8_t fanSpeed; + uint16_t ms_fanspeed_sample_rate; } config_t; // Check if EEPROM is ready to be written in diff --git a/prosjekt.X/i2c.c b/prosjekt.X/i2c.c index a29dc84..43f65ab 100644 --- a/prosjekt.X/i2c.c +++ b/prosjekt.X/i2c.c @@ -68,7 +68,7 @@ void i2c_stop_handler() { // Parse the received command data 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); } } diff --git a/prosjekt.X/main.c b/prosjekt.X/main.c index e8b06f4..35b71c9 100644 --- a/prosjekt.X/main.c +++ b/prosjekt.X/main.c @@ -27,18 +27,30 @@ volatile uint16_t fan1_history[512] = {1, 2, 3, 4}; 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() { + // Initialize functionality init_uart((uint16_t)9600); ADC0_init(); init_led(); init_i2c(); stdout = &USART_stream; + // Read the stored config struct + config = read_struct_from_EEPROM(); + PORTB.DIRSET = PIN3_bm; sei(); while (1) { - ; + // If we have made a config change, store it. + if (store_config) { + write_struct_from_EEPROM(config); + store_config = false; + } } }