|
Step 2: Adding Setting Initialization |
Top Previous Next |
This sample project is published on our website under the name "test_stg_lib".
Non-volatile settings must be initialized at some point. In our sample project, we check the "health" of settings upon boot using stg_check_all(). Should any setting turn out to be invalid, we initialize all settings with stg_restore_multiple(). Granted, this is a very crude way of handling setting initialization, but it works just fine for a simple project like ours.
We also provided a way to initialize the settings at any time -- just press the MD button for more than 2 seconds, then release.
Only main.tbs changes in this step:
main.tbs: |
include "global.tbh"
'==================================================================== sub on_sys_init() dim x as en_stg_status_codes dim stg_name as string(STG_MAX_SETTING_NAME_LEN)
if stg_start()<>EN_STG_STATUS_OK then sys.halt
x=stg_check_all(stg_name) select case x case EN_STG_STATUS_OK: '--- all good ---
case EN_STG_STATUS_INVALID, EN_STG_STATUS_FAILURE: if stg_restore_multiple(EN_STG_INIT_MODE_NORMAL)<>EN_STG_STATUS_OK then sys.halt
case else: 'some other trouble sys.halt end select end sub
'-------------------------------------------------------------------- sub on_button_released() if button.time>4 then if stg_restore_multiple(EN_STG_INIT_MODE_NORMAL)<>EN_STG_STATUS_OK then sys.halt sys.reboot end if end sub
|