Fix autobahn segment display and calculation

This commit is contained in:
Thomas Hooge 2024-11-04 20:00:45 +01:00
parent 72acf9f585
commit 64cb33ba67
1 changed files with 29 additions and 18 deletions

View File

@ -46,7 +46,7 @@ class PageAutobahn : public Page{
// draw outline
getdisplay().drawLine(x0, y0, x1, y1, color);
getdisplay().drawLine(x1, y1, x2, y2, color);
getdisplay().drawLine(x2, y2, x3, y3, color);
getdisplay().drawLine(x2, y2, x3, y3, color);
getdisplay().drawLine(x3, y3, x0, y0, color);
}
}
@ -69,7 +69,7 @@ class PageAutobahn : public Page{
String backlightMode = config->getString(config->backlight);
String trackStep = config->getString(config->trackStep);
double seg_deg = trackStep.toFloat(); // degrees per display segment
double seg_step = trackStep.toFloat() * PI / 180;
// Optical warning by limit violation (unused)
if(String(flashLED) == "Limit Violation"){
@ -136,20 +136,26 @@ class PageAutobahn : public Page{
getdisplay().setCursor(360-w, 257);
getdisplay().print(sval_btw);
bool valid = bv_cog->valid && bv_btw->valid;
// autobahn view
// draw ship symbol (as bitmap)
getdisplay().drawXBitmap(184, 68, ship_bits, ship_width, ship_height, pixelcolor);
// draw next waypoint name
String sval_wpname = "Tonne 122";
String sval_wpname = "no data";
if (valid) {
sval_wpname = "Tonne 122";
}
getdisplay().setFont(&Ubuntu_Bold10pt7b);
getdisplay().getTextBounds(sval_wpname, 0, 150, &x, &y, &w, &h);
// TODO if text don't fix use smaller font size.
// if smallest size does not fit use 2 lines
// last resort: clip with ellipsis
getdisplay().setCursor(200 - w / 2, 60);
getdisplay().print(sval_wpname);
// draw course segments
@ -161,21 +167,26 @@ class PageAutobahn : public Page{
diff -= 360;
}
// default all segments activated
bool seg[6] = {true, true, true, true, true, true};
// as default all segments activated if valid calculation
// values are available
bool seg[6]; // segment layout: [2][1][0] | [3][4][5]
for (int i=0; i<6; i++) {
seg[i] = valid;
}
// number of inactive segments
int nseg = std::min(static_cast<int>(std::floor(std::abs(diff) / seg_deg)), 5);
int nseg = std::min(static_cast<int>(std::floor(std::abs(diff) / seg_step)), 5);
int order[6];
if (diff < 0) {
if (diff > 0) {
// right
order[0] = 6; order[1] = 5; order[2] = 4;
order[3] = 1; order[4] = 2; order[5] = 3;
}
else if (diff > 0) {
order[0] = 3; order[1] = 4; order[2] = 5;
order[3] = 0; order[4] = 1; order[5] = 2;
}
else if (diff < 0) {
// left
order[0] = 3; order[1] = 2; order[2] = 1;
order[3] = 4; order[4] = 5; order[5] = 6;
order[0] = 0; order[1] = 1; order[2] = 2;
order[3] = 3; order[4] = 4; order[5] = 5;
}
int i = 0;
while (nseg > 0) {
@ -185,13 +196,13 @@ class PageAutobahn : public Page{
}
// left segments
drawSegment(0, 54, 46, 24, 75, 24, 0, 90, pixelcolor, seg[0]);
drawSegment(0, 54, 46, 24, 75, 24, 0, 90, pixelcolor, seg[2]);
drawSegment(0, 100, 82, 24, 112, 24, 50, 100, pixelcolor, seg[1]);
drawSegment(60, 100, 117, 24, 147, 24, 110, 100, pixelcolor,seg[2]);
drawSegment(60, 100, 117, 24, 147, 24, 110, 100, pixelcolor,seg[0]);
// right segments
drawSegment(399, 54, 354, 24, 325, 24, 399, 90, pixelcolor, seg[3]);
drawSegment(340, 100, 283, 24, 253, 24, 290, 100, pixelcolor, seg[3]);
drawSegment(399, 100, 318, 24, 289, 24, 350, 100, pixelcolor, seg[4]);
drawSegment(340, 100, 283, 24, 253, 24, 290, 100, pixelcolor, seg[5]);
drawSegment(399, 54, 354, 24, 325, 24, 399, 90, pixelcolor, seg[5]);
// Key Layout
getdisplay().setFont(&Ubuntu_Bold8pt7b);