DisplayDriver: introduce drawTextRightAlign and drawTextLeftAlign
This commit is contained in:
committed by
Florent
parent
db7635102d
commit
18bfc2d81a
@@ -257,40 +257,27 @@ public:
|
|||||||
} else if (_page == HomePage::GPS) {
|
} else if (_page == HomePage::GPS) {
|
||||||
LocationProvider* nmea = sensors.getLocationProvider();
|
LocationProvider* nmea = sensors.getLocationProvider();
|
||||||
int y = 18;
|
int y = 18;
|
||||||
display.setCursor(0, y);
|
display.drawTextLeftAlign(0, y, _task->getGPSState() ? "gps on" : "gps off");
|
||||||
display.print(_task->getGPSState() ? "gps on" : "gps off");
|
|
||||||
if (nmea == NULL) {
|
if (nmea == NULL) {
|
||||||
y = y + 12;
|
y = y + 12;
|
||||||
display.setCursor(0, y);
|
display.drawTextLeftAlign(0, y, "Can't access GPS");
|
||||||
display.print("Can't access GPS");
|
|
||||||
} else {
|
} else {
|
||||||
char buf[50];
|
char buf[50];
|
||||||
strcpy(buf, nmea->isValid()?"fix":"no fix");
|
strcpy(buf, nmea->isValid()?"fix":"no fix");
|
||||||
display.setCursor(
|
display.drawTextRightAlign(display.width()-1, y, buf);
|
||||||
display.width()-display.getTextWidth(buf)-1, y);
|
|
||||||
display.print(buf);
|
|
||||||
y = y + 12;
|
y = y + 12;
|
||||||
display.setCursor(0,y);
|
display.drawTextLeftAlign(0, y, "sat");
|
||||||
display.print("sat");
|
|
||||||
sprintf(buf, "%d", nmea->satellitesCount());
|
sprintf(buf, "%d", nmea->satellitesCount());
|
||||||
display.setCursor(
|
display.drawTextRightAlign(display.width()-1, y, buf);
|
||||||
display.width()-display.getTextWidth(buf)-1, y);
|
|
||||||
display.print(buf);
|
|
||||||
y = y + 12;
|
y = y + 12;
|
||||||
display.setCursor(0,y);
|
display.drawTextLeftAlign(0, y, "pos");
|
||||||
display.print("pos");
|
|
||||||
sprintf(buf, "%.4f %.4f",
|
sprintf(buf, "%.4f %.4f",
|
||||||
nmea->getLatitude()/1000000., nmea->getLongitude()/1000000.);
|
nmea->getLatitude()/1000000., nmea->getLongitude()/1000000.);
|
||||||
display.setCursor(
|
display.drawTextRightAlign(display.width()-1, y, buf);
|
||||||
display.width()-display.getTextWidth(buf)-1, y);
|
|
||||||
display.print(buf);
|
|
||||||
y = y + 12;
|
y = y + 12;
|
||||||
display.setCursor(0,y);
|
display.drawTextLeftAlign(0, y, "alt");
|
||||||
display.print("alt");
|
|
||||||
sprintf(buf, "%.2f", nmea->getAltitude()/1000.);
|
sprintf(buf, "%.2f", nmea->getAltitude()/1000.);
|
||||||
display.setCursor(
|
display.drawTextRightAlign(display.width()-1, y, buf);
|
||||||
display.width()-display.getTextWidth(buf)-1, y);
|
|
||||||
display.print(buf);
|
|
||||||
y = y + 12;
|
y = y + 12;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -32,6 +32,15 @@ public:
|
|||||||
setCursor(mid_x - w/2, y);
|
setCursor(mid_x - w/2, y);
|
||||||
print(str);
|
print(str);
|
||||||
}
|
}
|
||||||
|
virtual void drawTextRightAlign(int x_anch, int y, const char* str) {
|
||||||
|
int w = getTextWidth(str);
|
||||||
|
setCursor(x_anch - w, y);
|
||||||
|
print(str);
|
||||||
|
}
|
||||||
|
virtual void drawTextLeftAlign(int x_anch, int y, const char* str) {
|
||||||
|
setCursor(x_anch, y);
|
||||||
|
print(str);
|
||||||
|
}
|
||||||
|
|
||||||
// convert UTF-8 characters to displayable block characters for compatibility
|
// convert UTF-8 characters to displayable block characters for compatibility
|
||||||
virtual void translateUTF8ToBlocks(char* dest, const char* src, size_t dest_size) {
|
virtual void translateUTF8ToBlocks(char* dest, const char* src, size_t dest_size) {
|
||||||
|
|||||||
Reference in New Issue
Block a user