@@ -101,6 +101,18 @@ void Binary_Lighting_Output_Blink_Warn_Handler(uint32_t object_instance)
101101 LOG_INF ("Binary Lighting Output[%lu]: Blink Warning" , (unsigned long )object_instance );
102102}
103103
104+ /**
105+ * @brief Callback data for WriteProperty restore iterator
106+ * @param write_function The WriteProperty function to call
107+ * @param context The context to pass to the WriteProperty function
108+ * @return true if the WriteProperty succeeded
109+ */
110+ static bool Settings_Restore_Callback (BACNET_WRITE_PROPERTY_DATA * wp_data , void * context )
111+ {
112+ (void )context ;
113+ return Device_Write_Property (wp_data );
114+ }
115+
104116/**
105117 * @brief BACnet Project Initialization Handler
106118 * @param context [in] The context to pass to the callback function
@@ -109,35 +121,6 @@ void Binary_Lighting_Output_Blink_Warn_Handler(uint32_t object_instance)
109121static void BACnet_Lighting_Device_Init_Handler (void * context )
110122{
111123 BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE member ;
112- uint32_t array_index = BACNET_ARRAY_ALL ;
113- bool status = false;
114- int i ;
115- int32_t channel_writeable_property_list [] = {
116- /* list of properties to set via WriteProperty */
117- PROP_PRESENT_VALUE , PROP_OUT_OF_SERVICE , PROP_LIST_OF_OBJECT_PROPERTY_REFERENCES ,
118- PROP_CHANNEL_NUMBER , PROP_CONTROL_GROUPS ,
119- };
120- int32_t lighting_output_writeable_property_list [] = {
121- /* list of properties to set via WriteProperty */
122- PROP_OUT_OF_SERVICE ,
123- PROP_DEFAULT_FADE_TIME ,
124- PROP_DEFAULT_RAMP_RATE ,
125- PROP_DEFAULT_STEP_INCREMENT ,
126- PROP_TRANSITION ,
127- PROP_PRESENT_VALUE ,
128- PROP_RELINQUISH_DEFAULT ,
129- PROP_BLINK_WARN_ENABLE ,
130- PROP_EGRESS_TIME ,
131- PROP_DEFAULT_FADE_TIME ,
132- PROP_DEFAULT_RAMP_RATE ,
133- PROP_LIGHTING_COMMAND_DEFAULT_PRIORITY ,
134- PROP_DEFAULT_STEP_INCREMENT ,
135- PROP_TRANSITION };
136- int32_t device_writeable_property_list [] = {
137- /* list of properties to set via WriteProperty */
138- PROP_OBJECT_IDENTIFIER ,
139- PROP_OBJECT_NAME ,
140- };
141124
142125 (void )context ;
143126 LOG_INF ("BACnet Stack Initialized" );
@@ -164,33 +147,10 @@ static void BACnet_Lighting_Device_Init_Handler(void *context)
164147 member .deviceIdentifier .instance = Device_Instance ;
165148 Channel_Reference_List_Member_Element_Set (Channel_Instance , 1 , & member );
166149 /* restore any property values previously stored via WriteProperty */
167- for (i = 0 ; i < ARRAY_SIZE (device_writeable_property_list ); i ++ ) {
168- status = bacnet_settings_write_property_restore (
169- OBJECT_DEVICE , BACNET_MAX_INSTANCE , device_writeable_property_list [i ],
170- array_index , Device_Write_Property_Local );
171- if (!status ) {
172- /* no settings stored for this property, use defaults */
173- }
174- }
175- for (i = 0 ; i < ARRAY_SIZE (lighting_output_writeable_property_list ); i ++ ) {
176- status = bacnet_settings_write_property_restore (
177- OBJECT_LIGHTING_OUTPUT , Lighting_Instance ,
178- lighting_output_writeable_property_list [i ], array_index ,
179- Lighting_Output_Write_Property );
180- if (!status ) {
181- /* no settings stored for this property, use defaults */
182- }
183- }
184- for (i = 0 ; i < ARRAY_SIZE (channel_writeable_property_list ); i ++ ) {
185- status = bacnet_settings_write_property_restore (
186- OBJECT_CHANNEL , Channel_Instance , channel_writeable_property_list [i ],
187- array_index , Channel_Write_Property );
188- if (!status ) {
189- /* no settings stored for this property, use defaults */
190- }
191- }
192- /* These writable property values are stored WriteProperty.
193- Set this callback after init to prevent recursion. */
150+ bacnet_settings_init ();
151+ bacnet_settings_write_property_restore (& Settings_Restore_Callback , NULL );
152+ /* writable property values are stored with WriteProperty.
153+ Set this callback after restore to prevent recursion. */
194154 bacnet_basic_store_callback_set (bacnet_settings_basic_store );
195155 /* lighting output callbacks */
196156 Lighting_Output_Write_Present_Value_Callback_Set (Lighting_Output_Tracking_Value_Handler );
0 commit comments