diff --git a/openrtx/include/interfaces/graphics.h b/openrtx/include/interfaces/graphics.h index bf0ee09a..d2f31bee 100644 --- a/openrtx/include/interfaces/graphics.h +++ b/openrtx/include/interfaces/graphics.h @@ -204,6 +204,7 @@ void gfx_drawVLine(uint16_t x, uint16_t width, color_t color); /** * Draw a rectangle of specified width, height and color. + * @param start: screen position of the rectangle, in pixels * @param width: rectangle width, in pixels, borders included. * @param height: rectangle height, in pixels, borders included. * @param color: border and fill color, in color_t format. @@ -211,6 +212,14 @@ void gfx_drawVLine(uint16_t x, uint16_t width, color_t color); */ void gfx_drawRect(point_t start, uint16_t width, uint16_t height, color_t color, bool fill); +/** + * Draw the outline of a circle of specified radius and color. + * @param start: screen position of the center of the circle, in pixels + * @param r: circle radius, in pixels, border included. + * @param color: border color, in color_t format. + */ +void gfx_drawCircle(point_t start, uint16_t r, color_t color); + /** * Prints text on the screen. * @param start: text line start point, in pixel coordinates. @@ -261,4 +270,13 @@ void gfx_drawSmeter(point_t start, uint16_t width, uint16_t height, float rssi, */ void gfx_drawGPSgraph(point_t start, uint16_t width, uint16_t height, sat_t *sats); +/** + * Function to draw a compass of arbitrary size. + * Starting coordinates are relative to the top left point. + * @param start: Compass start point, in pixel coordinates. + * @param width: Compass radius + * @param sats: pointer to the array of satellites data + */ +void gfx_drawGPScompass(point_t start, uint16_t radius, sat_t *sats); + #endif /* GRAPHICS_H */ diff --git a/openrtx/src/graphics.c b/openrtx/src/graphics.c index 807682ca..412b9732 100644 --- a/openrtx/src/graphics.c +++ b/openrtx/src/graphics.c @@ -228,6 +228,65 @@ void gfx_drawRect(point_t start, uint16_t width, uint16_t height, color_t color, } } +void gfx_drawCircle(point_t start, uint16_t r, color_t color) +{ + int16_t f = 1 - r; + int16_t ddF_x = 1; + int16_t ddF_y = -2 * r; + int16_t x = 0; + int16_t y = r; + + point_t pos = start; + pos.y += r; + gfx_setPixel(pos, color); + pos.y -= 2 * r; + gfx_setPixel(pos, color); + pos.y += r; + pos.x += r; + gfx_setPixel(pos, color); + pos.x -= 2 * r; + gfx_setPixel(pos, color); + + while (x < y) + { + if (f >= 0) + { + y--; + ddF_y += 2; + f += ddF_y; + } + + x++; + ddF_x += 2; + f += ddF_x; + + pos.x = start.x + x; + pos.y = start.y + y; + gfx_setPixel(pos, color); + pos.x = start.x - x; + pos.y = start.y + y; + gfx_setPixel(pos, color); + pos.x = start.x + x; + pos.y = start.y - y; + gfx_setPixel(pos, color); + pos.x = start.x - x; + pos.y = start.y - y; + gfx_setPixel(pos, color); + pos.x = start.x + y; + pos.y = start.y + x; + gfx_setPixel(pos, color); + pos.x = start.x - y; + pos.y = start.y + x; + gfx_setPixel(pos, color); + pos.x = start.x + y; + pos.y = start.y - x; + gfx_setPixel(pos, color); + pos.x = start.x - y; + pos.y = start.y - x; + gfx_setPixel(pos, color); + } +} + void gfx_drawHLine(uint16_t y, uint16_t height, color_t color) { point_t start = {0, y}; @@ -568,3 +627,15 @@ void gfx_drawGPSgraph(point_t start, gfx_drawLine(start, left_line_end, white); gfx_drawLine(right_line_start, right_line_end, white); } + +void gfx_drawGPScompass(point_t start, + uint16_t radius, + sat_t *sats) +{ + color_t white = {255, 255, 255, 255}; + + point_t n_pos = {start.x + radius, start.y + 3}; + gfx_print(n_pos, "N", FONT_SIZE_5PT, TEXT_ALIGN_LEFT, white); + point_t circle_pos = {start.x + radius + 1, start.y + radius + 3}; + gfx_drawCircle(circle_pos, radius, white); +} diff --git a/openrtx/src/ui/ui_menu.c b/openrtx/src/ui/ui_menu.c index 63aaf246..7b972ddb 100644 --- a/openrtx/src/ui/ui_menu.c +++ b/openrtx/src/ui/ui_menu.c @@ -294,6 +294,9 @@ void _ui_drawMenuGPS(ui_state_t* ui_state) last_state.gps_data.altitude); gfx_print(layout.bottom_pos, data_buf, layout.bottom_font, TEXT_ALIGN_CENTER, color_white); + // Draw compass + point_t compass_pos = {layout.horizontal_pad * 2, SCREEN_HEIGHT / 2}; + gfx_drawGPScompass(compass_pos, SCREEN_WIDTH / 9, last_state.gps_data.satellites); // Draw satellites bar graph point_t bar_pos = {layout.line3_pos.x + SCREEN_WIDTH * 1 / 3, SCREEN_HEIGHT / 2}; gfx_drawGPSgraph(bar_pos,