Add signal strength widget to calibre sync too
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user