| 57 | } |
| 58 | |
| 59 | void ClockSyncActivity::runSync() { |
| 60 | if (WiFi.status() != WL_CONNECTED) { |
| 61 | LOG_INF("CLK", "Manual sync requested but WiFi is not connected after selection"); |
| 62 | state = NO_WIFI; |
| 63 | requestUpdate(); |
| 64 | return; |
| 65 | } |
| 66 | |
| 67 | const bool ok = halClock.syncFromNTP(); |
| 68 | if (!ok) { |
| 69 | state = FAILED; |
| 70 | requestUpdate(); |
| 71 | return; |
| 72 | } |
| 73 | |
| 74 | // Mark as synced so the auto-sync hook stops firing on future WiFi connects. |
| 75 | SETTINGS.clockHasBeenSynced = 1; |
| 76 | SETTINGS.saveToFile(); |
| 77 | |
| 78 | // Read the freshly synced time back for the user-facing confirmation. |
| 79 | char buf[9]; |
| 80 | if (halClock.formatTime(buf, sizeof(buf), SETTINGS.clockUtcOffsetQ, SETTINGS.clockFormat == 1)) { |
| 81 | snprintf(syncedTime, sizeof(syncedTime), "%s", buf); |
| 82 | } |
| 83 | state = SUCCESS; |
| 84 | requestUpdate(); |
| 85 | } |
| 86 | |
| 87 | void ClockSyncActivity::loop() { |
| 88 | if (state == SYNCING) { |
nothing calls this directly
no test coverage detected