Skip to content

Commit 81ce858

Browse files
committed
Fix display of long SSIDs or IPs
1 parent 0fcc249 commit 81ce858

File tree

1 file changed

+55
-54
lines changed

1 file changed

+55
-54
lines changed

Firmware/RTK_Surveyor/Display.ino

Lines changed: 55 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ static uint32_t blinking_icons;
6868
static uint32_t icons;
6969
static uint32_t iconsRadio;
7070

71-
unsigned long ipDisplayTimer = 0;
72-
bool ipDisplayFirstHalf = false;
71+
unsigned long ssidDisplayTimer = 0;
72+
bool ssidDisplayFirstHalf = false;
7373

7474
// Fonts
7575
#include <res/qw_fnt_5x7.h>
@@ -1655,31 +1655,51 @@ void displayWiFiConfig()
16551655
int yPos = WiFi_Symbol_Height + 2;
16561656
int fontHeight = 8;
16571657

1658+
const int displayMaxCharacters = 10; //Characters before pixels start getting cut off. 11 characters can cut off a few pixels.
1659+
16581660
printTextCenter("SSID:", yPos, QW_FONT_5X7, 1, false); //text, y, font type, kerning, inverted
16591661

16601662
yPos = yPos + fontHeight + 1;
16611663

1662-
if (settings.wifiConfigOverAP == true)
1663-
printTextCenter("RTK Config", yPos, QW_FONT_5X7, 1, false);
1664-
else
1664+
//Toggle display back and forth for long SSIDs and IPs
1665+
//Run the timer no matter what, but load firstHalf/lastHalf with the same thing if strlen < maxWidth
1666+
if (millis() - ssidDisplayTimer > 2000)
16651667
{
1666-
//Convert current SSID to string
1667-
char mySSID[50] = {'\0'};
1668+
ssidDisplayTimer = millis();
1669+
1670+
if (ssidDisplayFirstHalf == false)
1671+
ssidDisplayFirstHalf = true;
1672+
else
1673+
ssidDisplayFirstHalf = false;
1674+
}
1675+
1676+
//Convert current SSID to string
1677+
char mySSID[50] = {'\0'};
1678+
16681679
#ifdef COMPILE_WIFI
1669-
sprintf(mySSID, "%s", WiFi.SSID());
1680+
sprintf(mySSID, "%s", WiFi.SSID().c_str());
16701681
#else
1671-
sprintf(mySSID, "%s", "Not Compiled");
1682+
sprintf(mySSID, "%s", "!Compiled");
16721683
#endif
1673-
//Trim to a max length of 11
1674-
if (strlen(mySSID) > 11)
1675-
{
1676-
char mySSIDshort[50] = {'\0'};
1677-
strncpy(mySSIDshort, mySSID, 11);
1678-
printTextCenter(mySSIDshort, yPos, QW_FONT_5X7, 1, false);
1679-
}
1680-
else
1681-
printTextCenter(mySSID, yPos, QW_FONT_5X7, 1, false);
1682-
}
1684+
1685+
char mySSIDFront[displayMaxCharacters + 1]; //1 for null terminator
1686+
char mySSIDBack[displayMaxCharacters + 1]; //1 for null terminator
1687+
1688+
//Trim SSID to a max length
1689+
strncpy(mySSIDFront, mySSID, displayMaxCharacters);
1690+
1691+
if (strlen(mySSID) > displayMaxCharacters)
1692+
strncpy(mySSIDBack, mySSID + (strlen(mySSID) - displayMaxCharacters), displayMaxCharacters);
1693+
else
1694+
strncpy(mySSIDBack, mySSID, displayMaxCharacters);
1695+
1696+
mySSIDFront[displayMaxCharacters] = '\0';
1697+
mySSIDBack[displayMaxCharacters] = '\0';
1698+
1699+
if (ssidDisplayFirstHalf == true)
1700+
printTextCenter(mySSIDFront, yPos, QW_FONT_5X7, 1, false);
1701+
else
1702+
printTextCenter(mySSIDBack, yPos, QW_FONT_5X7, 1, false);
16831703

16841704
yPos = yPos + fontHeight + 3;
16851705
printTextCenter("IP:", yPos, QW_FONT_5X7, 1, false);
@@ -1697,43 +1717,24 @@ void displayWiFiConfig()
16971717
char myIP[20] = {'\0'};
16981718
sprintf(myIP, "%d.%d.%d.%d", myIpAddress[0], myIpAddress[1], myIpAddress[2], myIpAddress[3]);
16991719

1700-
if (strlen(myIP) <= 11)
1701-
printTextCenter(myIP, yPos, QW_FONT_5X7, 1, false);
1720+
char myIPFront[displayMaxCharacters + 1]; //1 for null terminator
1721+
char myIPBack[displayMaxCharacters + 1]; //1 for null terminator
1722+
1723+
strncpy(myIPFront, myIP, displayMaxCharacters);
1724+
1725+
if (strlen(myIP) > displayMaxCharacters)
1726+
strncpy(myIPBack, myIP + (strlen(myIP) - displayMaxCharacters), displayMaxCharacters);
17021727
else
1703-
{
1704-
//Toggle the IP display back and forth
1705-
if (millis() - ipDisplayTimer > 2000)
1706-
{
1707-
ipDisplayTimer = millis();
1708-
if (ipDisplayFirstHalf == false)
1709-
{
1710-
//Display the first half of the IP address up to 11 characters
1711-
ipDisplayFirstHalf = true;
1712-
}
1713-
else
1714-
{
1715-
//Display the 2nd half of the IP address up to 11 characters
1716-
ipDisplayFirstHalf = false;
1717-
}
1718-
}
1728+
strncpy(myIPBack, myIP, displayMaxCharacters);
1729+
1730+
myIPFront[displayMaxCharacters] = '\0';
1731+
myIPBack[displayMaxCharacters] = '\0';
1732+
1733+
if (ssidDisplayFirstHalf == true)
1734+
printTextCenter(myIPFront, yPos, QW_FONT_5X7, 1, false);
1735+
else
1736+
printTextCenter(myIPBack, yPos, QW_FONT_5X7, 1, false);
17191737

1720-
if (ipDisplayFirstHalf == true)
1721-
{
1722-
//Display the first half of the IP address up to 11 characters
1723-
char myIPFront[12]; //1 for null terminator
1724-
strncpy(myIPFront, myIP, 11);
1725-
myIPFront[11] = '\0';
1726-
printTextCenter(myIPFront, yPos, QW_FONT_5X7, 1, false);
1727-
}
1728-
else
1729-
{
1730-
//Display the 2nd half of the IP address up to 11 characters
1731-
char myIPBack[12]; //1 for null terminator
1732-
strncpy(myIPBack, myIP + (strlen(myIP) - 11), 11);
1733-
myIPBack[11] = '\0';
1734-
printTextCenter(myIPBack, yPos, QW_FONT_5X7, 1, false);
1735-
}
1736-
}
17371738
#else
17381739
printTextCenter("!Compiled", yPos, QW_FONT_5X7, 1, false);
17391740
#endif

0 commit comments

Comments
 (0)