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_set_dir(LED_PIN, GPIO_OUT);
gpio_put(LED_PIN, 0); gpio_put(LED_PIN, 0);
Settings settings; Settings settings{read_settings()};
settings.mode = Mode::IAMBIC_A;
settings.wpm = 25;
Settings newSettings{read_settings()};
printf("Iambic mode (loaded): %d\n", static_cast<int>(newSettings.mode)); printf("Iambic mode (loaded): %d\n", static_cast<int>(newSettings.mode));
printf("WPM (loaded): %d\n", newSettings.wpm); printf("WPM (loaded): %d\n", newSettings.wpm);
if (settings.mode == Mode::IAMBIC_A && settings.wpm == 25)
{
gpio_put(LED_PIN, 1);
}
while (true) while (true)
{ {
sleep_ms(1000); sleep_ms(1000);

View file

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

View file

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