system/application_settings/main.c

/*
* EVALUATION AND USE OF THIS SOFTWARE IS SUBJECT TO THE TERMS AND
* CONDITIONS OF THE CONTROLLING LICENSE AGREEMENT FOUND AT LICENSE.md
* IN THIS SDK. IF YOU DO NOT AGREE TO THE LICENSE TERMS AND CONDITIONS,
* PLEASE RETURN ALL SOURCE FILES TO SILICON LABORATORIES.
* (c) Copyright 2018, Silicon Laboratories Inc. All rights reserved.
*/
/*
* Documentation for this app is available online.
* See https://docs.silabs.com/gecko-os/4/standard/latest/sdk/examples/system/application-settings
*/
#include "gos.h"
#define STARTUP_SETTINGS_MAGIC_NUMBER 0x00010000 // version 1.0.0
#define APPLICATION_START_LINE "\r\nApplication Settings example starting ..."
/*************************************************************************************************/
void gos_app_init(void)
{
gos_result_t result;
GOS_LOG(APPLICATION_START_LINE);
GOS_LOG("Loading application settings if required");
// Load all settings that require a save and reboot to take effect
// Note, if the settings have been previously loaded (i.e. the 'magic number' is the same)
// then the following call does nothing.
// If the magic number is different, this will load the settings, save to nvm, and reboot.
// A factory reset or changing the 'magic number' is required to reload the settings
if (GOS_FAILED(result, gos_load_app_settings_once("one_time_settings.ini", STARTUP_SETTINGS_MAGIC_NUMBER)))
{
GOS_LOG("Failed to load 'one_time_settings.ini', error: %d", result);
}
GOS_LOG("Loading run-time settings always");
// Load all settings that are only required at runtime.
// Unless gos_settings_save() is later called, these settings will be cleared
// on reset or reboot.
// Note that this is for demonstration purposes only.
// nvm_settings.ini and runtime_settings.ini could be merged
// and only call gos_load_app_settings_once() to gain nearly identical functionality.
if (GOS_FAILED(result, gos_load_app_settings("runtime_settings.ini")))
{
GOS_LOG("Failed to load 'runtime_settings.ini', error: %d", result);
}
GOS_LOG("Success, issue a factory reset to revert settings");
}