MCPcopy Create free account
hub / github.com/crosspoint-reader/crosspoint-reader / loop

Method loop

src/activities/network/CalibreConnectActivity.cpp:102–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100}
101
102void CalibreConnectActivity::loop() {
103 if (mappedInput.wasPressed(MappedInputManager::Button::Back)) {
104 exitRequested = true;
105 }
106
107 if (webServer && webServer->isRunning()) {
108 const unsigned long timeSinceLastHandleClient = millis() - lastHandleClientTime;
109 if (lastHandleClientTime > 0 && timeSinceLastHandleClient > 100) {
110 LOG_DBG("CAL", "WARNING: %lu ms gap since last handleClient", timeSinceLastHandleClient);
111 }
112
113 esp_task_wdt_reset();
114 constexpr int MAX_ITERATIONS = 80;
115 for (int i = 0; i < MAX_ITERATIONS && webServer->isRunning(); i++) {
116 webServer->handleClient();
117 if ((i & 0x07) == 0x07) {
118 esp_task_wdt_reset();
119 }
120 if ((i & 0x0F) == 0x0F) {
121 yield();
122 if (mappedInput.wasPressed(MappedInputManager::Button::Back)) {
123 exitRequested = true;
124 break;
125 }
126 }
127 }
128 lastHandleClientTime = millis();
129
130 const auto status = webServer->getWsUploadStatus();
131 bool changed = false;
132 if (status.inProgress) {
133 if (status.received != lastProgressReceived || status.total != lastProgressTotal ||
134 status.filename != currentUploadName) {
135 lastProgressReceived = status.received;
136 lastProgressTotal = status.total;
137 currentUploadName = status.filename;
138 changed = true;
139 }
140 } else if (lastProgressReceived != 0 || lastProgressTotal != 0) {
141 lastProgressReceived = 0;
142 lastProgressTotal = 0;
143 currentUploadName.clear();
144 changed = true;
145 }
146 // Only update lastCompleteAt if the server has a NEW value (not one we already processed)
147 // This prevents restoring an old value after the 6s timeout clears it
148 if (status.lastCompleteAt != 0 && status.lastCompleteAt != lastProcessedCompleteAt) {
149 lastCompleteAt = status.lastCompleteAt;
150 lastCompleteName = status.lastCompleteName;
151 lastProcessedCompleteAt = status.lastCompleteAt; // Mark this value as processed
152 changed = true;
153 }
154 if (lastCompleteAt > 0 && (millis() - lastCompleteAt) >= 6000) {
155 lastCompleteAt = 0;
156 lastCompleteName.clear();
157 // Note: we DON'T reset lastProcessedCompleteAt here, so we won't re-process the old server value
158 changed = true;
159 }

Callers

nothing calls this directly

Calls 5

isRunningMethod · 0.80
handleClientMethod · 0.80
getWsUploadStatusMethod · 0.80
wasPressedMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected