Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
cs_FactoryReset.h
Go to the documentation of this file.
1/*
2 * Author: Crownstone Team
3 * Copyright: Crownstone (https://crownstone.rocks)
4 * Date: Aug 4, 2016
5 * License: LGPLv3+, Apache License 2.0, and/or MIT (triple-licensed)
6 */
7
8#pragma once
9
10#include <cstdint>
11
12#include "drivers/cs_Timer.h"
14
15// All the classes that are expected to factory reset.
18#if BUILD_MICROAPP_SUPPORT == 1
19 FACTORY_RESET_BIT_MICROAPP,
20#endif
21#if BUILD_MESHING == 1 && MESH_PERSISTENT_STORAGE == 1
22 FACTORY_RESET_BIT_MESH,
23#endif
25};
26#define FACTORY_RESET_MASK_ALL ((1 << FACTORY_RESET_NUM_BITS) - 1)
27
29public:
32 static FactoryReset instance;
33 return instance;
34 }
35
36 void init();
37
38 /* Function to recover: no need to be admin to call this */
39 bool recover(uint32_t resetCode);
40
41 /* Function to go into factory reset mode */
42 bool factoryReset(uint32_t resetCode);
43
44 /* Function to actually wipe the memory */
45 void finishFactoryReset(uint8_t deviceType);
46
47 /* Enable/disable ability to recover */
48 void enableRecovery(bool enable);
49
50 /* Static function for the timeout */
51 static void staticTimeout(FactoryReset* ptr) { ptr->timeout(); }
52
53 /* Static function for the timeout */
54 static void staticProcess(FactoryReset* ptr) { ptr->process(); }
55
59 void handleEvent(event_t& event);
60
61private:
63
64 inline bool validateResetCode(uint32_t resetCode);
67 void timeout();
68 void process();
70
72 uint32_t _rtcStartTime;
73
74 // Used to check if all classes are factory reset.
76
79
82};
Event listener.
Definition: cs_EventListener.h:17
Definition: cs_FactoryReset.h:28
void resetTimeout()
void onClassFactoryResetDone(const FactoryResetClassBit bit)
bool _recoveryEnabled
Definition: cs_FactoryReset.h:71
void handleEvent(event_t &event)
Handle events.
app_timer_id_t _recoveryProcessTimerId
Definition: cs_FactoryReset.h:81
uint32_t _rtcStartTime
Definition: cs_FactoryReset.h:72
uint8_t _successfullyFactoryResetBitmask
Definition: cs_FactoryReset.h:75
void process()
void enableRecovery(bool enable)
bool validateResetCode(uint32_t resetCode)
bool recover(uint32_t resetCode)
static void staticTimeout(FactoryReset *ptr)
Definition: cs_FactoryReset.h:51
app_timer_t _recoveryDisableTimerData
Definition: cs_FactoryReset.h:77
bool factoryReset(uint32_t resetCode)
app_timer_id_t _recoveryDisableTimerId
Definition: cs_FactoryReset.h:78
void timeout()
static void staticProcess(FactoryReset *ptr)
Definition: cs_FactoryReset.h:54
app_timer_t _recoveryProcessTimerData
Definition: cs_FactoryReset.h:80
static FactoryReset & getInstance()
Gets a static singleton (no dynamic memory allocation)
Definition: cs_FactoryReset.h:31
void finishFactoryReset(uint8_t deviceType)
bool performFactoryReset()
Author: Crownstone Team Copyright: Crownstone (https://crownstone.rocks) Date: Oct 9,...
Definition: cs_Event.h:26
FactoryResetClassBit
Definition: cs_FactoryReset.h:16
@ FACTORY_RESET_BIT_STATE
Definition: cs_FactoryReset.h:17
@ FACTORY_RESET_NUM_BITS
Definition: cs_FactoryReset.h:24