43
43
#include < app/util/attribute-storage.h>
44
44
#include < lib/support/TypeTraits.h>
45
45
46
+ #include < app/DeferredAttributePersistenceProvider.h>
46
47
#include < credentials/DeviceAttestationCredsProvider.h>
47
48
#include < credentials/examples/DeviceAttestationCredsExample.h>
48
49
@@ -72,6 +73,7 @@ using namespace ::chip::DeviceLayer;
72
73
static uint8_t countdown = 0 ;
73
74
74
75
namespace {
76
+ constexpr EndpointId kLightEndpointId = 1 ;
75
77
TaskHandle_t sAppTaskHandle ;
76
78
QueueHandle_t sAppEventQueue ;
77
79
@@ -93,6 +95,25 @@ StaticTask_t appTaskStruct;
93
95
Clusters::Identify::EffectIdentifierEnum sIdentifyEffect = Clusters::Identify::EffectIdentifierEnum::kStopEffect ;
94
96
chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider ;
95
97
98
+ // Define a custom attribute persister which makes actual write of the attribute value
99
+ // to the non-volatile storage only when it has remained constant for 5 seconds. This is to reduce
100
+ // the flash wearout when the attribute changes frequently as a result of commands.
101
+ // DeferredAttribute object describes a deferred attribute, but also holds a buffer with a value to
102
+ // be written, so it must live so long as the DeferredAttributePersistenceProvider object.
103
+ //
104
+ DeferredAttribute gPersisters [] = { DeferredAttribute (ConcreteAttributePath (kLightEndpointId , Clusters::ColorControl::Id,
105
+ Clusters::ColorControl::Attributes::CurrentX::Id)),
106
+ DeferredAttribute (ConcreteAttributePath (kLightEndpointId , Clusters::ColorControl::Id,
107
+ Clusters::ColorControl::Attributes::CurrentY::Id)),
108
+ DeferredAttribute (ConcreteAttributePath (kLightEndpointId , Clusters::LevelControl::Id,
109
+ Clusters::LevelControl::Attributes::CurrentLevel::Id))
110
+
111
+ };
112
+
113
+ DeferredAttributePersistenceProvider gDeferredAttributePersister (Server::GetInstance().GetDefaultAttributePersister(),
114
+ Span<DeferredAttribute>(gPersisters , 3 ),
115
+ System::Clock::Milliseconds32(5000 ));
116
+
96
117
/* *********************************************************
97
118
* Identify Callbacks
98
119
*********************************************************/
@@ -250,6 +271,8 @@ void AppTask::InitServer(intptr_t arg)
250
271
251
272
chip::Server::GetInstance ().Init (initParams);
252
273
274
+ app::SetAttributePersistenceProvider (&gDeferredAttributePersister );
275
+
253
276
#if CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY
254
277
chip::app::DnssdServer::Instance ().SetExtendedDiscoveryTimeoutSecs (extDiscTimeoutSecs);
255
278
#endif
0 commit comments