mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2025-12-18 07:07:41 +03:00
Fix progress bar overflow
This commit is contained in:
parent
01a6fc1a4a
commit
d552ace462
@ -34,9 +34,9 @@ void UploadFileScreen::render() const {
|
|||||||
renderer.drawCenteredText(SMALL_FONT_ID, pageHeight / 2 + 95, "UPLOADING");
|
renderer.drawCenteredText(SMALL_FONT_ID, pageHeight / 2 + 95, "UPLOADING");
|
||||||
|
|
||||||
if (currentUploadStatus == InProgress) {
|
if (currentUploadStatus == InProgress) {
|
||||||
|
const double complete = static_cast<double>(currentUploadCompleteSize) / static_cast<double>(currentUploadTotalSize);
|
||||||
renderer.drawRect(20, pageHeight / 2 + 110, pageWidth - 40, 50);
|
renderer.drawRect(20, pageHeight / 2 + 110, pageWidth - 40, 50);
|
||||||
renderer.fillRect(22, pageHeight / 2 + 112,
|
renderer.fillRect(22, pageHeight / 2 + 112, (pageWidth - 44) * complete, 46);
|
||||||
static_cast<size_t>(pageWidth - 44) * currentUploadCompleteSize / currentUploadTotalSize, 46);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer.displayBuffer();
|
renderer.displayBuffer();
|
||||||
@ -69,10 +69,12 @@ void UploadFileScreen::onFileUploadPart(AsyncWebServerRequest* request, const ui
|
|||||||
request->_tempFile.write(data, len);
|
request->_tempFile.write(data, len);
|
||||||
xSemaphoreGive(renderingMutex);
|
xSemaphoreGive(renderingMutex);
|
||||||
|
|
||||||
|
const int oldPercent = static_cast<double>(currentUploadCompleteSize) / static_cast<double>(currentUploadTotalSize) * 100;
|
||||||
currentUploadCompleteSize += len;
|
currentUploadCompleteSize += len;
|
||||||
|
const int newPercent = static_cast<double>(currentUploadCompleteSize) / static_cast<double>(currentUploadTotalSize) * 100;
|
||||||
|
|
||||||
// Only update the screen at most every 5% to avoid blocking the SPI channel
|
// Only update the screen at most every 5% to avoid blocking the SPI channel
|
||||||
if (currentUploadTotalSize > 0 && (currentUploadCompleteSize - len) * 100 / currentUploadTotalSize / 5 <
|
if (oldPercent / 5 < newPercent / 5) {
|
||||||
currentUploadCompleteSize * 100 / currentUploadTotalSize / 5) {
|
|
||||||
updateRequired = true;
|
updateRequired = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user