fix for storing settings

This commit is contained in:
Martin Brodbeck 2024-02-07 11:35:30 +01:00
parent 7133d96c55
commit 4fbb424e1d
3 changed files with 7 additions and 15 deletions

View file

@ -16,20 +16,11 @@ int main()
gpio_set_dir(LED_PIN, GPIO_OUT);
gpio_put(LED_PIN, 0);
Settings settings;
settings.mode = Mode::IAMBIC_A;
settings.wpm = 25;
Settings newSettings{read_settings()};
Settings settings{read_settings()};
printf("Iambic mode (loaded): %d\n", static_cast<int>(newSettings.mode));
printf("WPM (loaded): %d\n", newSettings.wpm);
if (settings.mode == Mode::IAMBIC_A && settings.wpm == 25)
{
gpio_put(LED_PIN, 1);
}
while (true)
{
sleep_ms(1000);

View file

@ -47,7 +47,8 @@ Settings read_settings()
memcpy(&settings, flash_target_contents, sizeof(struct Settings));
if(settings.magic_number != MAGIC_NUMBER) {
if (settings.magic_number != MAGIC_NUMBER)
{
settings = Settings();
gpio_put(LED_PIN, 1);
@ -62,9 +63,9 @@ Settings read_settings()
sleep_ms(1000);
gpio_put(LED_PIN, 0);
sleep_ms(250);
}
store_settings(settings);
}
return settings;
}

View file

@ -14,7 +14,7 @@ enum class Mode : uint8_t
struct Settings
{
uint16_t magic_number; // Bytes: 2
uint16_t magic_number{MAGIC_NUMBER}; // Bytes: 2
Mode mode{Mode::IAMBIC_B}; // Bytes: 1
uint8_t wpm{20}; // Bytes: 1
uint8_t dummy[FLASH_PAGE_SIZE - 4]{0}; // Sum : 4