Also save to NVS from time to time
This commit is contained in:
parent
a3799b02a0
commit
8ac36022e0
|
@ -1 +1 @@
|
|||
455
|
||||
457
|
||||
|
|
|
@ -90,6 +90,14 @@ void Animation_Poll(void)
|
|||
NVS_Data->animation_step_top,
|
||||
LightSensor_RelativeBrightness);
|
||||
LED_Commit();
|
||||
|
||||
static unsigned int store_counter = 0;
|
||||
store_counter++;
|
||||
if(store_counter >= ANIMATION_NVS_STORE_INTERVAL * ANIMATION_REFRESH_RATE)
|
||||
{
|
||||
store_counter = 0;
|
||||
NVS_Save(false);
|
||||
}
|
||||
}
|
||||
|
||||
void TIM17_IRQHandler(void)
|
||||
|
|
|
@ -15,6 +15,10 @@
|
|||
#define ANIMATION_CYCLE_TIME_TOP \
|
||||
(8 * 24 * 60 * 60)
|
||||
|
||||
// Interval for saving the current animation step to NVS (in seconds)
|
||||
#define ANIMATION_NVS_STORE_INTERVAL \
|
||||
(60 * 60)
|
||||
|
||||
extern const unsigned int Animation_LEDOrder[LED_COUNT];
|
||||
|
||||
void Animation_Init(void);
|
||||
|
|
|
@ -26,13 +26,13 @@ int main(void)
|
|||
if(LightSensor_RelativeBrightness == 0 && !powered_down)
|
||||
{
|
||||
LED_Suspend();
|
||||
NVS_Save();
|
||||
NVS_Save(true);
|
||||
powered_down = true;
|
||||
}
|
||||
if(powered_down && LightSensor_RelativeBrightness > 0)
|
||||
{
|
||||
powered_down = false;
|
||||
NVS_Save();
|
||||
NVS_Save(true);
|
||||
LED_WakeUp();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -148,7 +148,7 @@ bool NVS_Load(void)
|
|||
}
|
||||
}
|
||||
|
||||
void NVS_Save(void)
|
||||
void NVS_Save(bool erase_if_needed)
|
||||
{
|
||||
NVS_UnlockFlash();
|
||||
|
||||
|
@ -160,6 +160,10 @@ void NVS_Save(void)
|
|||
if(current_block == NULL || next_block > NVS_Area + NVS_BLOCK_COUNT
|
||||
|| !NVS_BlockEmpty(next_block))
|
||||
{
|
||||
if(!erase_if_needed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
NVS_EraseArea();
|
||||
next_block = &NVS_Area[0];
|
||||
current_block = NULL;
|
||||
|
|
|
@ -17,7 +17,8 @@ extern NVS_Data_t *const NVS_Data;
|
|||
// defaults were restored instead
|
||||
bool NVS_Load(void);
|
||||
|
||||
// Stores the current contents of NVS_Data to flash
|
||||
void NVS_Save(void);
|
||||
// Stores the current contents of NVS_Data to flash. Pass `false` as a parameter
|
||||
// to skip saving unless it can be done without a flash page erase.
|
||||
void NVS_Save(bool erase_if_needed);
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue