From cf331dc58ba26ddfcbd00e54dda70bbe0439b9c2 Mon Sep 17 00:00:00 2001 From: loodydo <30909547+loodydo@users.noreply.github.com> Date: Mon, 4 Jul 2022 13:16:29 -0600 Subject: [PATCH 1/3] Update Screen.cpp --- src/graphics/Screen.cpp | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index b8eb79178..97d258666 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -595,7 +595,7 @@ class Point void rotate(float radian) { float cos = cosf(radian), sin = sinf(radian); - float rx = x * cos - y * sin, ry = x * sin + y * cos; + float rx = x * cos + y * sin, ry = -x * sin + y * cos; x = rx; y = ry; @@ -609,8 +609,10 @@ class Point void scale(float f) { + //We use -f here to counter the flip that happens + //on the y axis when drawing and rotating on screen x *= f; - y *= f; + y *= -f; } }; @@ -682,16 +684,17 @@ static void drawNodeHeading(OLEDDisplay *display, int16_t compassX, int16_t comp drawLine(display, rightArrow, tip); } -// Draw the compass heading -static void drawCompassHeading(OLEDDisplay *display, int16_t compassX, int16_t compassY, float myHeading) +// Draw north +static void drawCompassNorth(OLEDDisplay *display, int16_t compassX, int16_t compassY, float myHeading) { - Point N1(-0.04f, -0.65f), N2(0.04f, -0.65f); - Point N3(-0.04f, -0.55f), N4(0.04f, -0.55f); + Point N1(-0.04f, 0.65f), N2(0.04f, 0.65f); + Point N3(-0.04f, 0.55f), N4(0.04f, 0.55f); Point *rosePoints[] = {&N1, &N2, &N3, &N4}; for (int i = 0; i < 4; i++) { - rosePoints[i]->rotate(myHeading); - rosePoints[i]->scale(-1 * COMPASS_DIAM); + // North on compass will be negative of heading + rosePoints[i]->rotate(-myHeading); + rosePoints[i]->scale(COMPASS_DIAM); rosePoints[i]->translate(compassX, compassY); } drawLine(display, N1, N3); @@ -762,7 +765,7 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_ if (ourNode && hasPosition(ourNode)) { Position &op = ourNode->position; float myHeading = estimatedHeading(DegD(op.latitude_i), DegD(op.longitude_i)); - drawCompassHeading(display, compassX, compassY, myHeading); + drawCompassNorth(display, compassX, compassY, myHeading); if (hasPosition(node)) { // display direction toward node @@ -775,10 +778,8 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_ else snprintf(distStr, sizeof(distStr), "%.1f km", d / 1000); - // FIXME, also keep the guess at the operators heading and add/substract - // it. currently we don't do this and instead draw north up only. float bearingToOther = - GeoCoord::bearing(DegD(p.latitude_i), DegD(p.longitude_i), DegD(op.latitude_i), DegD(op.longitude_i)); + GeoCoord::bearing(DegD(op.latitude_i), DegD(op.longitude_i), DegD(p.latitude_i), DegD(p.longitude_i)); float headingRadian = bearingToOther - myHeading; drawNodeHeading(display, compassX, compassY, headingRadian); } @@ -1665,4 +1666,4 @@ int Screen::handleUIFrameEvent(const UIFrameEvent *event) } } // namespace graphics -#endif // NO_SCREEN \ No newline at end of file +#endif // NO_SCREEN From 20d7d1b1621275df88706d3a42c8afeb204eb1cb Mon Sep 17 00:00:00 2001 From: loodydo <30909547+loodydo@users.noreply.github.com> Date: Sat, 9 Jul 2022 11:38:41 -0600 Subject: [PATCH 2/3] Update Screen.cpp Add option to switch between static/non-static North. --- src/graphics/Screen.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 97d258666..a62829052 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -64,6 +64,11 @@ namespace graphics static FrameCallback normalFrames[MAX_NUM_NODES + NUM_EXTRA_FRAMES]; static uint32_t targetFramerate = IDLE_FRAMERATE; static char btPIN[16] = "888888"; + +// This defines the layout of the compass. +// If true, North with remain static at the top of the compass. +// If false, your current heading is static at the top of the compass. +bool compassNorthTop = false; // This image definition is here instead of images.h because it's modified dynamically by the drawBattery function uint8_t imgBattery[16] = {0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xE7, 0x3C}; @@ -687,6 +692,10 @@ static void drawNodeHeading(OLEDDisplay *display, int16_t compassX, int16_t comp // Draw north static void drawCompassNorth(OLEDDisplay *display, int16_t compassX, int16_t compassY, float myHeading) { + //If north is supposed to be at the top of the compass we want rotation to be +0 + if(compassNorthTop) + myHeading = -0; + Point N1(-0.04f, 0.65f), N2(0.04f, 0.65f); Point N3(-0.04f, 0.55f), N4(0.04f, 0.55f); Point *rosePoints[] = {&N1, &N2, &N3, &N4}; @@ -780,8 +789,11 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_ float bearingToOther = GeoCoord::bearing(DegD(op.latitude_i), DegD(op.longitude_i), DegD(p.latitude_i), DegD(p.longitude_i)); - float headingRadian = bearingToOther - myHeading; - drawNodeHeading(display, compassX, compassY, headingRadian); + // If the top of the compass is a static north then bearingToOther can be drawn on the compass directly + // If the top of the compass is not a static north we need adjust bearingToOther based on heading + if(!compassNorthTop) + float bearingToOther = bearingToOther - myHeading; + drawNodeHeading(display, compassX, compassY, bearingToOther); } } if (!hasNodeHeading) From 9c21064634cd0c9293108fe491d4856d1107cd01 Mon Sep 17 00:00:00 2001 From: loodydo <30909547+loodydo@users.noreply.github.com> Date: Sat, 9 Jul 2022 11:47:50 -0600 Subject: [PATCH 3/3] Update Screen.cpp Fixed variable shadowing --- src/graphics/Screen.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index a62829052..7169bbe2d 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -792,7 +792,7 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_ // If the top of the compass is a static north then bearingToOther can be drawn on the compass directly // If the top of the compass is not a static north we need adjust bearingToOther based on heading if(!compassNorthTop) - float bearingToOther = bearingToOther - myHeading; + bearingToOther -= myHeading; drawNodeHeading(display, compassX, compassY, bearingToOther); } }