Add signal strength widget to calibre sync too
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
#include <WiFi.h>
|
||||
#include <esp_task_wdt.h>
|
||||
|
||||
#include "activities/network/SignalStrengthWidget.h"
|
||||
|
||||
#include "MappedInputManager.h"
|
||||
#include "WifiSelectionActivity.h"
|
||||
#include "components/UITheme.h"
|
||||
@@ -29,6 +31,8 @@ void CalibreConnectActivity::onEnter() {
|
||||
lastCompleteName.clear();
|
||||
lastCompleteAt = 0;
|
||||
lastProcessedCompleteAt = 0;
|
||||
currentRssi = 0;
|
||||
lastRssiUpdateTime = 0;
|
||||
exitRequested = false;
|
||||
|
||||
if (WiFi.status() != WL_CONNECTED) {
|
||||
@@ -126,6 +130,12 @@ void CalibreConnectActivity::loop() {
|
||||
}
|
||||
lastHandleClientTime = millis();
|
||||
|
||||
if (millis() - lastRssiUpdateTime > 5000) {
|
||||
lastRssiUpdateTime = millis();
|
||||
currentRssi = WiFi.RSSI();
|
||||
requestUpdate();
|
||||
}
|
||||
|
||||
const auto status = webServer->getWsUploadStatus();
|
||||
bool changed = false;
|
||||
if (status.inProgress) {
|
||||
@@ -190,8 +200,15 @@ void CalibreConnectActivity::render(RenderLock&&) {
|
||||
|
||||
const int textX = contentRect.x + metrics.contentSidePadding;
|
||||
const int textWidth = contentRect.width - metrics.contentSidePadding * 2;
|
||||
int y = metrics.topPadding + metrics.headerHeight + metrics.tabBarHeight + metrics.verticalSpacing * 4;
|
||||
int y = metrics.topPadding + metrics.headerHeight + metrics.tabBarHeight + metrics.verticalSpacing * 2;
|
||||
const auto heightText12 = renderer.getTextHeight(UI_12_FONT_ID);
|
||||
const auto lineHeightSmall = renderer.getLineHeight(SMALL_FONT_ID);
|
||||
|
||||
const int signalHeight = 22;
|
||||
drawWifiSignalStrength(renderer, textX, y, textWidth, signalHeight, currentRssi);
|
||||
renderer.drawText(SMALL_FONT_ID, textX, y + signalHeight + 2, rssiLabel(currentRssi).c_str());
|
||||
y += signalHeight + lineHeightSmall + metrics.verticalSpacing * 3;
|
||||
|
||||
renderer.drawText(UI_12_FONT_ID, textX, y, tr(STR_CALIBRE_SETUP), true, EpdFontFamily::BOLD);
|
||||
y += heightText12 + metrics.verticalSpacing * 2;
|
||||
|
||||
|
||||
@@ -26,6 +26,8 @@ class CalibreConnectActivity final : public Activity {
|
||||
std::string lastCompleteName;
|
||||
unsigned long lastCompleteAt = 0;
|
||||
unsigned long lastProcessedCompleteAt = 0; // Track which server value we've already processed
|
||||
int currentRssi = 0;
|
||||
unsigned long lastRssiUpdateTime = 0;
|
||||
bool exitRequested = false;
|
||||
|
||||
void renderServerRunning() const;
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "NetworkModeSelectionActivity.h"
|
||||
#include "WifiSelectionActivity.h"
|
||||
#include "activities/network/CalibreConnectActivity.h"
|
||||
#include "activities/network/SignalStrengthWidget.h"
|
||||
#include "components/UITheme.h"
|
||||
#include "fontIds.h"
|
||||
#include "util/QrUtils.h"
|
||||
@@ -377,66 +378,6 @@ void CrossPointWebServerActivity::render(RenderLock&&) {
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
StrId getRssiQualityStrId(int rssi) {
|
||||
if (rssi <= -90) {
|
||||
return StrId::STR_SIGNAL_QUALITY_POOR;
|
||||
}
|
||||
if (rssi <= -75) {
|
||||
return StrId::STR_SIGNAL_QUALITY_WEAK;
|
||||
}
|
||||
if (rssi <= -60) {
|
||||
return StrId::STR_SIGNAL_QUALITY_GOOD;
|
||||
}
|
||||
return StrId::STR_SIGNAL_QUALITY_EXCELLENT;
|
||||
}
|
||||
|
||||
int rssiToSignalBars(int rssi) {
|
||||
if (rssi <= -90) {
|
||||
return 1;
|
||||
}
|
||||
if (rssi <= -75) {
|
||||
return 2;
|
||||
}
|
||||
if (rssi <= -60) {
|
||||
return 3;
|
||||
}
|
||||
return 4;
|
||||
}
|
||||
|
||||
void drawSignalStrength(const GfxRenderer& renderer, const Rect& bounds, int rssi) {
|
||||
const int x = bounds.x;
|
||||
const int y = bounds.y;
|
||||
const int width = bounds.width;
|
||||
const int height = bounds.height;
|
||||
const int barCount = 4;
|
||||
const int gap = 6;
|
||||
const int barWidth = std::min(10, (width - (barCount - 1) * gap) / barCount);
|
||||
const int totalWidth = barCount * barWidth + (barCount - 1) * gap;
|
||||
const int startX = x + (width - totalWidth) / 2;
|
||||
const int maxBarHeight = height - 8;
|
||||
const int bars = rssi == 0 ? 0 : rssiToSignalBars(rssi);
|
||||
const int baseY = y + height - 2;
|
||||
for (int i = 0; i < barCount; ++i) {
|
||||
const int barHeight = ((i + 1) * maxBarHeight) / barCount;
|
||||
const int barX = startX + i * (barWidth + gap);
|
||||
const int barY = baseY - barHeight;
|
||||
renderer.drawRect(barX, barY, barWidth, barHeight, true);
|
||||
if (i < bars) {
|
||||
renderer.fillRect(barX + 1, barY + 1, barWidth - 2, barHeight - 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string rssiLabel(int rssi) {
|
||||
if (rssi == 0) {
|
||||
return std::string(tr(STR_NO_SIGNAL));
|
||||
}
|
||||
const char* quality = I18N.get(getRssiQualityStrId(rssi));
|
||||
std::string label = std::string(tr(STR_RSSI)) + ": " + std::to_string(rssi) + " dBm (" + quality + ")";
|
||||
return label;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void CrossPointWebServerActivity::renderServerRunning() const {
|
||||
@@ -489,8 +430,7 @@ void CrossPointWebServerActivity::renderServerRunning() const {
|
||||
const int signalHeight = 22;
|
||||
const int signalWidth = contentRect.width - metrics.contentSidePadding * 2;
|
||||
const int signalY = startY + 120;
|
||||
const Rect signalBounds(contentRect.x + metrics.contentSidePadding, signalY, signalWidth, signalHeight);
|
||||
drawSignalStrength(renderer, signalBounds, 0);
|
||||
drawWifiSignalStrength(renderer, contentRect.x + metrics.contentSidePadding, signalY, signalWidth, signalHeight, 0);
|
||||
renderer.drawCenteredText(SMALL_FONT_ID, signalY + signalHeight + 2, tr(STR_HOTSPOT_MODE));
|
||||
} else {
|
||||
startY += metrics.verticalSpacing * 2;
|
||||
@@ -523,8 +463,7 @@ void CrossPointWebServerActivity::renderServerRunning() const {
|
||||
const int signalHeight = 22;
|
||||
const int signalWidth = contentRect.width - metrics.contentSidePadding * 2;
|
||||
const int signalY = startY + height10 + metrics.verticalSpacing * 2;
|
||||
const Rect signalBounds(contentRect.x + metrics.contentSidePadding, signalY, signalWidth, signalHeight);
|
||||
drawSignalStrength(renderer, signalBounds, currentRssi);
|
||||
drawWifiSignalStrength(renderer, contentRect.x + metrics.contentSidePadding, signalY, signalWidth, signalHeight, currentRssi);
|
||||
renderer.drawCenteredText(SMALL_FONT_ID, signalY + signalHeight + 2, rssiLabel(currentRssi).c_str(), true);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <GfxRenderer.h>
|
||||
#include <I18n.h>
|
||||
#include <string>
|
||||
|
||||
inline StrId getRssiQualityStrId(int rssi) {
|
||||
if (rssi <= -90) {
|
||||
return StrId::STR_SIGNAL_QUALITY_POOR;
|
||||
}
|
||||
if (rssi <= -75) {
|
||||
return StrId::STR_SIGNAL_QUALITY_WEAK;
|
||||
}
|
||||
if (rssi <= -60) {
|
||||
return StrId::STR_SIGNAL_QUALITY_GOOD;
|
||||
}
|
||||
return StrId::STR_SIGNAL_QUALITY_EXCELLENT;
|
||||
}
|
||||
|
||||
inline void drawWifiSignalStrength(const GfxRenderer& renderer, int x, int y, int width, int height, int rssi) {
|
||||
const int barCount = 4;
|
||||
const int gap = 6;
|
||||
const int barWidth = std::min(10, (width - (barCount - 1) * gap) / barCount);
|
||||
const int totalWidth = barCount * barWidth + (barCount - 1) * gap;
|
||||
const int startX = x + (width - totalWidth) / 2;
|
||||
const int maxBarHeight = height - 8;
|
||||
const int bars = rssi == 0 ? 0 : (rssi <= -90 ? 1 : (rssi <= -75 ? 2 : (rssi <= -60 ? 3 : 4)));
|
||||
const int baseY = y + height - 2;
|
||||
for (int i = 0; i < barCount; ++i) {
|
||||
const int barHeight = ((i + 1) * maxBarHeight) / barCount;
|
||||
const int barX = startX + i * (barWidth + gap);
|
||||
const int barY = baseY - barHeight;
|
||||
renderer.drawRect(barX, barY, barWidth, barHeight, true);
|
||||
if (i < bars) {
|
||||
renderer.fillRect(barX + 1, barY + 1, barWidth - 2, barHeight - 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline std::string rssiLabel(int rssi) {
|
||||
if (rssi == 0) {
|
||||
return std::string(tr(STR_NO_SIGNAL));
|
||||
}
|
||||
const char* quality = I18N.get(getRssiQualityStrId(rssi));
|
||||
return std::string(tr(STR_RSSI)) + ": " + std::to_string(rssi) + " dBm (" + quality + ")";
|
||||
}
|
||||
Reference in New Issue
Block a user