Skip to content

Commit e966b80

Browse files
committed
Nicer IP Address display
1 parent 1d0d3f5 commit e966b80

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

Firmware/RTK_Everywhere/Display.ino

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,36 +1767,46 @@ void paintConnectingToNtripCaster()
17671767
printTextwithKerning("Connecting", textX, textY, textKerning);
17681768
}
17691769

1770-
// Scroll through IP address. Wipe with spaces both ends.
1770+
// Shuttle through IP address
17711771
void paintIPAddress()
17721772
{
1773-
char ipAddress[32];
1774-
snprintf(ipAddress, sizeof(ipAddress), " %d.%d.%d.%d ",
1773+
char ipAddress[16];
1774+
snprintf(ipAddress, sizeof(ipAddress), "%d.%d.%d.%d",
17751775
#ifdef COMPILE_ETHERNET
17761776
ETH.localIP()[0], ETH.localIP()[1], ETH.localIP()[2], ETH.localIP()[3]);
17771777
#else // COMPILE_ETHERNET
17781778
0, 0, 0, 0);
17791779
#endif // COMPILE_ETHERNET
17801780

1781-
static uint8_t ipAddressPosition = 0;
1782-
1783-
// Check if IP address is all single digits and can be printed without scrolling
1784-
if (strlen(ipAddress) <= 21)
1785-
ipAddressPosition = 7;
1786-
1787-
// Print seven characters of IP address
1788-
char printThis[9];
1789-
snprintf(printThis, sizeof(printThis), "%c%c%c%c%c%c%c", ipAddress[ipAddressPosition + 0],
1790-
ipAddress[ipAddressPosition + 1], ipAddress[ipAddressPosition + 2], ipAddress[ipAddressPosition + 3],
1791-
ipAddress[ipAddressPosition + 4], ipAddress[ipAddressPosition + 5], ipAddress[ipAddressPosition + 6]);
1792-
17931781
oled->setFont(QW_FONT_5X7); // Set font to smallest
17941782
oled->setCursor(0, 3);
1795-
oled->print(printThis);
17961783

1797-
ipAddressPosition++; // Increment the print position
1798-
if (ipAddress[ipAddressPosition + 7] == 0) // Wrap
1799-
ipAddressPosition = 0;
1784+
// If we can print the full IP address without shuttling
1785+
if (strlen(ipAddress) <= 7)
1786+
{
1787+
oled->print(ipAddress);
1788+
}
1789+
else
1790+
{
1791+
// Print as many characters as we can. Shuttle back and forth to display all.
1792+
static int startPos = 0;
1793+
char printThis[7 + 1];
1794+
int extras = strlen(ipAddress) - 7;
1795+
int shuttle[(2 * extras) + 2]; // Wait for a double state at each end
1796+
shuttle[0] = 0;
1797+
int x;
1798+
for (x = 0; x <= extras; x++)
1799+
shuttle[x + 1] = x;
1800+
shuttle[extras + 2] = extras;
1801+
x += 2;
1802+
for (int y = extras - 1; y > 0; y--)
1803+
shuttle[x++] = y;
1804+
if (startPos >= (2 * extras) + 2)
1805+
startPos = 0;
1806+
snprintf(printThis, sizeof(printThis), &ipAddress[shuttle[startPos]]);
1807+
startPos++;
1808+
oled->print(printThis);
1809+
}
18001810
}
18011811

18021812
void paintMACAddress4digit(uint8_t xPos, uint8_t yPos)

0 commit comments

Comments
 (0)