1010#include "gui_style.h"
1111#include "icons.h"
1212#include "menu/message_dialog.h"
13+ #include "ntp.h"
1314#include "nvs.h"
1415#include "pax_gfx.h"
1516#include "pax_matrix.h"
1819#include "sdkconfig.h"
1920#include "settings_clock_timezone.h"
2021#include "timezone.h"
21- // #include "shapes/pax_misc.h"
2222
2323static const char * TAG = "clock" ;
2424
@@ -163,48 +163,6 @@ void adjust_date_time(uint8_t selection, int8_t delta) {
163163 bsp_rtc_set_time (new_time );
164164}
165165
166- static bool get_ntp (void ) {
167- nvs_handle_t nvs_handle ;
168- esp_err_t res = nvs_open ("system" , NVS_READWRITE , & nvs_handle );
169- if (res != ESP_OK ) {
170- ESP_LOGE (TAG , "Failed to open NVS namespace" );
171- return false;
172- }
173- uint8_t enabled = false;
174- res = nvs_get_u8 (nvs_handle , "ntp" , & enabled );
175- if (res != ESP_OK ) {
176- ESP_LOGE (TAG , "Failed to get NVS entry" );
177- nvs_close (nvs_handle );
178- return false;
179- }
180- res = nvs_commit (nvs_handle );
181- if (res != ESP_OK ) {
182- ESP_LOGE (TAG , "Failed to commit to NVS" );
183- }
184- nvs_close (nvs_handle );
185- return (enabled & 1 );
186- }
187-
188- static void set_ntp (bool enabled ) {
189- nvs_handle_t nvs_handle ;
190- esp_err_t res = nvs_open ("system" , NVS_READWRITE , & nvs_handle );
191- if (res != ESP_OK ) {
192- ESP_LOGE (TAG , "Failed to open NVS namespace" );
193- return ;
194- }
195- res = nvs_set_u8 (nvs_handle , "ntp" , enabled ? 1 : 0 );
196- if (res != ESP_OK ) {
197- ESP_LOGE (TAG , "Failed to set NVS entry" );
198- nvs_close (nvs_handle );
199- return ;
200- }
201- res = nvs_commit (nvs_handle );
202- if (res != ESP_OK ) {
203- ESP_LOGE (TAG , "Failed to commit to NVS" );
204- }
205- nvs_close (nvs_handle );
206- }
207-
208166static void get_timezone (const timezone_t * * zone ) {
209167 char timezone_name [32 ] = {0 };
210168 timezone_nvs_get ("system" , "timezone" , timezone_name , sizeof (timezone_name ));
@@ -229,7 +187,7 @@ void menu_settings_clock(pax_buf_t* buffer, gui_theme_t* theme) {
229187
230188 get_timezone (& zone );
231189
232- bool ntp = get_ntp ();
190+ bool ntp = ntp_get_enabled ();
233191
234192 uint8_t selection = 0 ;
235193 render (buffer , theme , position , zone , ntp , false, true, selection );
@@ -275,7 +233,7 @@ void menu_settings_clock(pax_buf_t* buffer, gui_theme_t* theme) {
275233 case BSP_INPUT_NAVIGATION_KEY_SELECT :
276234 // Toggle NTP
277235 ntp = !ntp ;
278- set_ntp (ntp );
236+ ntp_set_enabled (ntp );
279237 render (buffer , theme , position , zone , ntp , false, true, selection );
280238 break ;
281239 default :
0 commit comments