Merge branch 'feat-additional-compensation' of https://github.com/jpirnay/crosspoint-reader into mybuild
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
#include "KOReaderSyncActivity.h"
|
||||
|
||||
#include <GfxRenderer.h>
|
||||
#include <HalClock.h>
|
||||
#include <I18n.h>
|
||||
#include <Logging.h>
|
||||
#include <WiFi.h>
|
||||
#include <esp_sntp.h>
|
||||
|
||||
#include "KOReaderCredentialStore.h"
|
||||
#include "KOReaderDocumentId.h"
|
||||
@@ -13,43 +13,6 @@
|
||||
#include "components/UITheme.h"
|
||||
#include "fontIds.h"
|
||||
|
||||
namespace {
|
||||
void syncTimeWithNTP() {
|
||||
// Stop SNTP if already running (can't reconfigure while running)
|
||||
if (esp_sntp_enabled()) {
|
||||
esp_sntp_stop();
|
||||
}
|
||||
|
||||
// Configure SNTP
|
||||
esp_sntp_setoperatingmode(ESP_SNTP_OPMODE_POLL);
|
||||
esp_sntp_setservername(0, "pool.ntp.org");
|
||||
esp_sntp_init();
|
||||
|
||||
// Wait for time to sync (with timeout)
|
||||
int retry = 0;
|
||||
const int maxRetries = 50; // 5 seconds max
|
||||
while (sntp_get_sync_status() != SNTP_SYNC_STATUS_COMPLETED && retry < maxRetries) {
|
||||
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||
retry++;
|
||||
}
|
||||
|
||||
if (retry < maxRetries) {
|
||||
LOG_DBG("KOSync", "NTP time synced");
|
||||
} else {
|
||||
LOG_DBG("KOSync", "NTP sync timeout, using fallback");
|
||||
}
|
||||
}
|
||||
void wifiOff() {
|
||||
if (esp_sntp_enabled()) {
|
||||
esp_sntp_stop();
|
||||
}
|
||||
WiFi.disconnect(false);
|
||||
delay(100);
|
||||
WiFi.mode(WIFI_OFF);
|
||||
delay(100);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void KOReaderSyncActivity::onWifiSelectionComplete(const bool success) {
|
||||
if (!success) {
|
||||
LOG_DBG("KOSync", "WiFi connection failed, exiting");
|
||||
@@ -70,7 +33,7 @@ void KOReaderSyncActivity::onWifiSelectionComplete(const bool success) {
|
||||
requestUpdate(true);
|
||||
|
||||
// Sync time with NTP before making API requests
|
||||
syncTimeWithNTP();
|
||||
HalClock::syncNtp();
|
||||
|
||||
{
|
||||
RenderLock lock(*this);
|
||||
@@ -187,7 +150,7 @@ void KOReaderSyncActivity::performUpload() {
|
||||
const auto result = KOReaderSyncClient::updateProgress(progress);
|
||||
|
||||
if (result != KOReaderSyncClient::OK) {
|
||||
wifiOff();
|
||||
HalClock::wifiOff(true);
|
||||
{
|
||||
RenderLock lock(*this);
|
||||
state = SYNC_FAILED;
|
||||
@@ -197,7 +160,7 @@ void KOReaderSyncActivity::performUpload() {
|
||||
return;
|
||||
}
|
||||
|
||||
wifiOff();
|
||||
HalClock::wifiOff(true);
|
||||
{
|
||||
RenderLock lock(*this);
|
||||
state = UPLOAD_COMPLETE;
|
||||
@@ -232,7 +195,7 @@ void KOReaderSyncActivity::onEnter() {
|
||||
void KOReaderSyncActivity::onExit() {
|
||||
Activity::onExit();
|
||||
|
||||
wifiOff();
|
||||
HalClock::wifiOff(true);
|
||||
}
|
||||
|
||||
void KOReaderSyncActivity::closeCancelled() {
|
||||
|
||||
Reference in New Issue
Block a user