mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-30 11:23:53 +00:00
Fix #233 - init distance string before drawing it
(and violating my own "no formatting checkins with other changes" rule to restore proper indentation for this file)
This commit is contained in:
parent
ac135be8cd
commit
a595fc4642
@ -55,7 +55,7 @@ static FrameCallback normalFrames[MAX_NUM_NODES + NUM_EXTRA_FRAMES];
|
|||||||
static uint32_t targetFramerate = IDLE_FRAMERATE;
|
static uint32_t targetFramerate = IDLE_FRAMERATE;
|
||||||
static char btPIN[16] = "888888";
|
static char btPIN[16] = "888888";
|
||||||
|
|
||||||
uint8_t imgBattery[16] = { 0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xE7, 0x3C };
|
uint8_t imgBattery[16] = {0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xE7, 0x3C};
|
||||||
|
|
||||||
static void drawBootScreen(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
|
static void drawBootScreen(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
|
||||||
{
|
{
|
||||||
@ -69,10 +69,11 @@ static void drawBootScreen(OLEDDisplay *display, OLEDDisplayUiState *state, int1
|
|||||||
display->drawString(64 + x, SCREEN_HEIGHT - FONT_HEIGHT_16, "meshtastic.org");
|
display->drawString(64 + x, SCREEN_HEIGHT - FONT_HEIGHT_16, "meshtastic.org");
|
||||||
display->setFont(ArialMT_Plain_10);
|
display->setFont(ArialMT_Plain_10);
|
||||||
const char *region = xstr(HW_VERSION);
|
const char *region = xstr(HW_VERSION);
|
||||||
if(*region && region[3] == '-') // Skip past 1.0- in the 1.0-EU865 string
|
if (*region && region[3] == '-') // Skip past 1.0- in the 1.0-EU865 string
|
||||||
region += 4;
|
region += 4;
|
||||||
char buf[16];
|
char buf[16];
|
||||||
snprintf(buf, sizeof(buf), "%s", xstr(APP_VERSION)); // Note: we don't bother printing region or now, it makes the string too long
|
snprintf(buf, sizeof(buf), "%s",
|
||||||
|
xstr(APP_VERSION)); // Note: we don't bother printing region or now, it makes the string too long
|
||||||
display->drawString(SCREEN_WIDTH - 20, 0, buf);
|
display->drawString(SCREEN_WIDTH - 20, 0, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,8 +92,8 @@ static void drawFrameBluetooth(OLEDDisplay *display, OLEDDisplayUiState *state,
|
|||||||
display->setFont(ArialMT_Plain_10);
|
display->setFont(ArialMT_Plain_10);
|
||||||
char buf[30];
|
char buf[30];
|
||||||
const char *name = "Name: ";
|
const char *name = "Name: ";
|
||||||
strcpy(buf,name);
|
strcpy(buf, name);
|
||||||
strcat(buf,getDeviceName());
|
strcat(buf, getDeviceName());
|
||||||
display->drawString(64 + x, 48 + y, buf);
|
display->drawString(64 + x, 48 + y, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,9 +174,10 @@ static uint32_t drawRows(OLEDDisplay *display, int16_t x, int16_t y, const char
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Draw power bars or a charging indicator on an image of a battery, determined by battery charge voltage or percentage.
|
// Draw power bars or a charging indicator on an image of a battery, determined by battery charge voltage or percentage.
|
||||||
static void drawBattery(OLEDDisplay *display, int16_t x, int16_t y, uint8_t *imgBuffer, PowerStatus *powerStatus) {
|
static void drawBattery(OLEDDisplay *display, int16_t x, int16_t y, uint8_t *imgBuffer, PowerStatus *powerStatus)
|
||||||
static const uint8_t powerBar[3] = { 0x81, 0xBD, 0xBD };
|
{
|
||||||
static const uint8_t lightning[8] = { 0xA1, 0xA1, 0xA5, 0xAD, 0xB5, 0xA5, 0x85, 0x85 };
|
static const uint8_t powerBar[3] = {0x81, 0xBD, 0xBD};
|
||||||
|
static const uint8_t lightning[8] = {0xA1, 0xA1, 0xA5, 0xAD, 0xB5, 0xA5, 0x85, 0x85};
|
||||||
// Clear the bar area on the battery image
|
// Clear the bar area on the battery image
|
||||||
for (int i = 1; i < 14; i++) {
|
for (int i = 1; i < 14; i++) {
|
||||||
imgBuffer[i] = 0x81;
|
imgBuffer[i] = 0x81;
|
||||||
@ -183,17 +185,19 @@ static void drawBattery(OLEDDisplay *display, int16_t x, int16_t y, uint8_t *img
|
|||||||
// If charging, draw a charging indicator
|
// If charging, draw a charging indicator
|
||||||
if (powerStatus->charging) {
|
if (powerStatus->charging) {
|
||||||
memcpy(imgBuffer + 3, lightning, 8);
|
memcpy(imgBuffer + 3, lightning, 8);
|
||||||
// If not charging, Draw power bars
|
// If not charging, Draw power bars
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
if(powerStatus->batteryChargePercent >= 25 * i) memcpy(imgBuffer + 1 + (i * 3), powerBar, 3);
|
if (powerStatus->batteryChargePercent >= 25 * i)
|
||||||
|
memcpy(imgBuffer + 1 + (i * 3), powerBar, 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
display->drawFastImage(x, y, 16, 8, imgBuffer);
|
display->drawFastImage(x, y, 16, 8, imgBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw nodes status
|
// Draw nodes status
|
||||||
static void drawNodes(OLEDDisplay *display, int16_t x, int16_t y, int nodesOnline, int nodesTotal) {
|
static void drawNodes(OLEDDisplay *display, int16_t x, int16_t y, int nodesOnline, int nodesTotal)
|
||||||
|
{
|
||||||
char usersString[20];
|
char usersString[20];
|
||||||
sprintf(usersString, "%d/%d", nodesOnline, nodesTotal);
|
sprintf(usersString, "%d/%d", nodesOnline, nodesTotal);
|
||||||
display->drawFastImage(x, y, 8, 8, imgUser);
|
display->drawFastImage(x, y, 8, 8, imgUser);
|
||||||
@ -201,16 +205,41 @@ static void drawNodes(OLEDDisplay *display, int16_t x, int16_t y, int nodesOnlin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Draw GPS status summary
|
// Draw GPS status summary
|
||||||
static void drawGPS(OLEDDisplay *display, int16_t x, int16_t y, GPS *gps) {
|
static void drawGPS(OLEDDisplay *display, int16_t x, int16_t y, GPS *gps)
|
||||||
if(!gps->isConnected) { display->drawString(x, y - 2, "No GPS"); return; }
|
{
|
||||||
display->drawFastImage(x, y, 6, 8, gps->hasLock() ? imgPositionSolid : imgPositionEmpty );
|
if (!gps->isConnected) {
|
||||||
if(!gps->hasLock()) { display->drawString(x + 8, y - 2, "No sats"); return; }
|
display->drawString(x, y - 2, "No GPS");
|
||||||
if(gps->dop <= 100) { display->drawString(x + 8, y - 2, "Ideal"); return; }
|
return;
|
||||||
if(gps->dop <= 200) { display->drawString(x + 8, y - 2, "Exc."); return; }
|
}
|
||||||
if(gps->dop <= 500) { display->drawString(x + 8, y - 2, "Good"); return; }
|
display->drawFastImage(x, y, 6, 8, gps->hasLock() ? imgPositionSolid : imgPositionEmpty);
|
||||||
if(gps->dop <= 1000) { display->drawString(x + 8, y - 2, "Mod."); return; }
|
if (!gps->hasLock()) {
|
||||||
if(gps->dop <= 2000) { display->drawString(x + 8, y - 2, "Fair"); return; }
|
display->drawString(x + 8, y - 2, "No sats");
|
||||||
if(gps->dop > 0) { display->drawString(x + 8, y - 2, "Poor"); return; }
|
return;
|
||||||
|
}
|
||||||
|
if (gps->dop <= 100) {
|
||||||
|
display->drawString(x + 8, y - 2, "Ideal");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (gps->dop <= 200) {
|
||||||
|
display->drawString(x + 8, y - 2, "Exc.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (gps->dop <= 500) {
|
||||||
|
display->drawString(x + 8, y - 2, "Good");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (gps->dop <= 1000) {
|
||||||
|
display->drawString(x + 8, y - 2, "Mod.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (gps->dop <= 2000) {
|
||||||
|
display->drawString(x + 8, y - 2, "Fair");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (gps->dop > 0) {
|
||||||
|
display->drawString(x + 8, y - 2, "Poor");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ported from my old java code, returns distance in meters along the globe
|
/// Ported from my old java code, returns distance in meters along the globe
|
||||||
@ -421,11 +450,10 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_
|
|||||||
snprintf(lastStr, sizeof(lastStr), "%u hours ago", agoSecs / 60 / 60);
|
snprintf(lastStr, sizeof(lastStr), "%u hours ago", agoSecs / 60 / 60);
|
||||||
|
|
||||||
static char distStr[20];
|
static char distStr[20];
|
||||||
*distStr = 0; // might not have location data
|
strcpy(distStr, "? km"); // might not have location data
|
||||||
float headingRadian;
|
float headingRadian;
|
||||||
NodeInfo *ourNode = nodeDB.getNode(nodeDB.getNodeNum());
|
NodeInfo *ourNode = nodeDB.getNode(nodeDB.getNodeNum());
|
||||||
const char *fields[] = {username, distStr, signalStr, lastStr, NULL};
|
const char *fields[] = {username, distStr, signalStr, lastStr, NULL};
|
||||||
drawColumns(display, x, y, fields);
|
|
||||||
|
|
||||||
// coordinates for the center of the compass/circle
|
// coordinates for the center of the compass/circle
|
||||||
int16_t compassX = x + SCREEN_WIDTH - COMPASS_DIAM / 2 - 1, compassY = y + SCREEN_HEIGHT / 2;
|
int16_t compassX = x + SCREEN_WIDTH - COMPASS_DIAM / 2 - 1, compassY = y + SCREEN_HEIGHT / 2;
|
||||||
@ -448,9 +476,12 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_
|
|||||||
// Debug info for gps lock errors
|
// Debug info for gps lock errors
|
||||||
// DEBUG_MSG("ourNode %d, ourPos %d, theirPos %d\n", !!ourNode, ourNode && hasPosition(ourNode), hasPosition(node));
|
// DEBUG_MSG("ourNode %d, ourPos %d, theirPos %d\n", !!ourNode, ourNode && hasPosition(ourNode), hasPosition(node));
|
||||||
|
|
||||||
display->drawString(compassX - FONT_HEIGHT/4, compassY - FONT_HEIGHT/2, "?");
|
display->drawString(compassX - FONT_HEIGHT / 4, compassY - FONT_HEIGHT / 2, "?");
|
||||||
display->drawCircle(compassX, compassY, COMPASS_DIAM / 2);
|
display->drawCircle(compassX, compassY, COMPASS_DIAM / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Must be after distStr is populated
|
||||||
|
drawColumns(display, x, y, fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
@ -719,7 +750,10 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16
|
|||||||
snprintf(channelStr, sizeof(channelStr), "#%s", channelName.c_str());
|
snprintf(channelStr, sizeof(channelStr), "#%s", channelName.c_str());
|
||||||
|
|
||||||
// Display power status
|
// Display power status
|
||||||
if (powerStatus.haveBattery) drawBattery(display, x, y + 2, imgBattery, &powerStatus); else display->drawFastImage(x, y + 2, 16, 8, powerStatus.usb ? imgUSB : imgPower);
|
if (powerStatus.haveBattery)
|
||||||
|
drawBattery(display, x, y + 2, imgBattery, &powerStatus);
|
||||||
|
else
|
||||||
|
display->drawFastImage(x, y + 2, 16, 8, powerStatus.usb ? imgUSB : imgPower);
|
||||||
// Display nodes status
|
// Display nodes status
|
||||||
drawNodes(display, x + (SCREEN_WIDTH * 0.25), y + 2, nodesOnline, nodesTotal);
|
drawNodes(display, x + (SCREEN_WIDTH * 0.25), y + 2, nodesOnline, nodesTotal);
|
||||||
// Display GPS status
|
// Display GPS status
|
||||||
@ -732,16 +766,16 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16
|
|||||||
display->drawLogBuffer(x, yo);
|
display->drawLogBuffer(x, yo);
|
||||||
}
|
}
|
||||||
|
|
||||||
//adjust Brightness cycle trough 1 to 254 as long as attachDuringLongPress is true
|
// adjust Brightness cycle trough 1 to 254 as long as attachDuringLongPress is true
|
||||||
void Screen::adjustBrightness(){
|
void Screen::adjustBrightness()
|
||||||
if (brightness == 254)
|
{
|
||||||
{
|
if (brightness == 254) {
|
||||||
brightness = 0;
|
brightness = 0;
|
||||||
} else {
|
} else {
|
||||||
brightness++;
|
brightness++;
|
||||||
}
|
}
|
||||||
int width = brightness / (254.00 / SCREEN_WIDTH);
|
int width = brightness / (254.00 / SCREEN_WIDTH);
|
||||||
dispdev.drawRect( 0, 30, SCREEN_WIDTH, 4);
|
dispdev.drawRect(0, 30, SCREEN_WIDTH, 4);
|
||||||
dispdev.fillRect(0, 31, width, 2);
|
dispdev.fillRect(0, 31, width, 2);
|
||||||
dispdev.display();
|
dispdev.display();
|
||||||
dispdev.setBrightness(brightness);
|
dispdev.setBrightness(brightness);
|
||||||
|
Loading…
Reference in New Issue
Block a user