fix for storing settings
This commit is contained in:
parent
7133d96c55
commit
4fbb424e1d
3 changed files with 7 additions and 15 deletions
|
@ -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);
|
||||
|
|
|
@ -44,10 +44,11 @@ void store_settings(Settings &settings)
|
|||
Settings read_settings()
|
||||
{
|
||||
Settings 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);
|
||||
store_settings(settings);
|
||||
}
|
||||
|
||||
return settings;
|
||||
}
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue