diff --git a/openrtx/include/interfaces/graphics.h b/openrtx/include/interfaces/graphics.h index dd7d43be..5808b973 100644 --- a/openrtx/include/interfaces/graphics.h +++ b/openrtx/include/interfaces/graphics.h @@ -303,25 +303,16 @@ void gfx_drawBattery(point_t start, uint16_t width, uint16_t height, uint8_t per void gfx_drawSmeter(point_t start, uint16_t width, uint16_t height, float rssi, float squelch, color_t color); /** - * Function to draw Smeter of arbitrary size. + * Function to draw Smeter + level meter of arbitrary size. * Version without squelch bar for digital protocols * Starting coordinates are relative to the top left point. * @param start: Smeter start point, in pixel coordinates. * @param width: Smeter width * @param height: Smeter height * @param rssi: rssi level in dBm - */ -void gfx_drawSmeterNoSquelch(point_t start, uint16_t width, uint16_t height, float rssi); - -/** - * Function to draw level meter of arbitrary size. - * Starting coordinates are relative to the top left point. - * @param start: level meter start point, in pixel coordinates. - * @param width: level meter width - * @param height: level meter height * @param level: level in range {0, 255} */ -void gfx_drawLevelMeter(point_t start, uint16_t width, uint16_t height, uint8_t level); +void gfx_drawSmeterLevel(point_t start, uint16_t width, uint16_t height, float rssi, uint8_t level); /** * Function to draw GPS SNR bar graph of arbitrary size. diff --git a/openrtx/include/ui.h b/openrtx/include/ui.h index 2ba848c3..d2605530 100644 --- a/openrtx/include/ui.h +++ b/openrtx/include/ui.h @@ -121,6 +121,7 @@ typedef struct layout_t uint16_t line3_h; uint16_t menu_h; uint16_t bottom_h; + uint16_t bottom_pad; uint16_t status_v_pad; uint16_t horizontal_pad; uint16_t text_v_offset; diff --git a/openrtx/src/graphics.c b/openrtx/src/graphics.c index 5db7f9f7..97d8099c 100644 --- a/openrtx/src/graphics.c +++ b/openrtx/src/graphics.c @@ -403,7 +403,6 @@ point_t gfx_printBuffer(point_t start, fontSize_t size, textAlign_t alignment, uint16_t line_size = get_line_size(f, buf, len); uint16_t reset_x = get_reset_x(alignment, line_size, start.x); start.x = reset_x; - // Save initial start.y value to calculate vertical size uint16_t saved_start_y = start.y; uint16_t line_h = 0; @@ -612,14 +611,14 @@ void gfx_drawBattery(point_t start, uint16_t width, uint16_t height, * Function to draw RSSI-meter of arbitrary size * starting coordinates are relative to the top left point. * - * 1 2 3 4 5 6 7 8 9 +10 +20| + * * * * * * * * * * * *| + * *************** <-- Squelch | + * *************** | * ****************************************** | * ****************************************** <- RSSI | * ****************************************** | <-- Height (px) * ****************************************** | - * **************** <-- Squelch | - * *************** | - * * * * * * * * * * * *| + * 1 2 3 4 5 6 7 8 9 +10 +20| * _________________________________________________________________ * * ^ @@ -635,54 +634,62 @@ void gfx_drawSmeter(point_t start, uint16_t width, uint16_t height, float rssi, color_t yellow = {250, 180, 19 , 255}; color_t red = {255, 0, 0 , 255}; + fontSize_t font = FONT_SIZE_5PT; + uint8_t font_height = gfx_getFontHeight(font); + uint16_t bar_height = (height - 3 - font_height); + // S-level marks and numbers - for(int i = 0; i < 11; i++) + for(int i = 0; i < 12; i++) { color_t color = (i % 3 == 0) ? yellow : white; color = (i > 9) ? red : color; point_t pixel_pos = {start.x + i * (width - 1) / 11, start.y}; + gfx_setPixel(pixel_pos, color); + pixel_pos.y += height; if (i == 10) { pixel_pos.x -= 8; - gfx_print(pixel_pos, FONT_SIZE_5PT, TEXT_ALIGN_LEFT, color, "+%d", i); + gfx_print(pixel_pos, font, TEXT_ALIGN_LEFT, color, "+%d", i); + } + else if(i == 11){ + pixel_pos.x -= 10; + gfx_print(pixel_pos, font, TEXT_ALIGN_LEFT, red, "+20"); } else - gfx_print(pixel_pos, FONT_SIZE_5PT, TEXT_ALIGN_LEFT, color, "%d", i); + gfx_print(pixel_pos, font, TEXT_ALIGN_LEFT, color, "%d", i); if (i == 10) { pixel_pos.x += 8; } - pixel_pos.y += height; - gfx_setPixel(pixel_pos, color); } - point_t pixel_pos = {start.x + width - 11, start.y}; - gfx_print(pixel_pos, FONT_SIZE_5PT, TEXT_ALIGN_LEFT, red, "+20"); - pixel_pos.x += 10; - pixel_pos.y += height; - gfx_setPixel(pixel_pos, red); - + // Squelch bar + uint16_t squelch_height = bar_height / 3 ; + uint16_t squelch_width = width * squelch; + point_t squelch_pos = {start.x, start.y + 2}; + gfx_drawRect(squelch_pos, squelch_width, squelch_height, color, true); + // RSSI bar - uint16_t rssi_height = height * 2 / 3; + uint16_t rssi_height = bar_height * 2 / 3; float s_level = (127.0f + rssi) / 6.0f; uint16_t rssi_width = (s_level < 0.0f) ? 0 : (s_level * (width - 1) / 11); rssi_width = (s_level > 10.0f) ? width : rssi_width; - point_t rssi_pos = { start.x, start.y + 1 }; + point_t rssi_pos = { start.x, start.y + 2 + squelch_height}; gfx_drawRect(rssi_pos, rssi_width, rssi_height, white, true); - - // Squelch bar - uint16_t squelch_height = height / 3 - 1; - uint16_t squelch_width = width * squelch; - point_t squelch_pos = { start.x, start.y + 1 + rssi_height }; - gfx_drawRect(squelch_pos, squelch_width, squelch_height, color, true); } /* - * Function to draw RSSI-meter of arbitrary size + * Function to draw RSSI-meter with level-meter of arbitrary size * Version without squelch bar for digital protocols * starting coordinates are relative to the top left point. * + * * * * * *| * ****************************************** | - * ****************************************** <- RSSI | + * ****************************************** <- level | + * ****************************************** | + * ****************************************** | + * * * * * *| * ****************************************** | <-- Height (px) + * ****************************************** <- RSSI | + * ****************************************** | * ****************************************** | * 1 2 3 4 5 6 7 8 9 +10 +20| * _________________________________________________________________ @@ -693,81 +700,57 @@ void gfx_drawSmeter(point_t start, uint16_t width, uint16_t height, float rssi, * Width (px) * */ -void gfx_drawSmeterNoSquelch(point_t start, uint16_t width, uint16_t height, float rssi) +void gfx_drawSmeterLevel(point_t start, uint16_t width, uint16_t height, float rssi, + uint8_t level) { + color_t red = {255, 0, 0 , 255}; + color_t green = {0, 255, 0, 255}; color_t white = {255, 255, 255, 255}; color_t yellow = {250, 180, 19 , 255}; - color_t red = {255, 0, 0 , 255}; fontSize_t font = FONT_SIZE_5PT; uint8_t font_height = gfx_getFontHeight(font); + uint16_t bar_height = (height - 6 - font_height) / 2; + + // Level meter marks + for(int i = 0; i <= 4; i++) + { + point_t pixel_pos = {start.x + i * (width - 1) / 4, start.y}; + gfx_setPixel(pixel_pos, white); + pixel_pos.y += (bar_height + 3); + gfx_setPixel(pixel_pos, white); + } + // Level bar + uint16_t level_width = (level / 255 * width); + point_t level_pos = { start.x, start.y + 2 }; + gfx_drawRect(level_pos, level_width, bar_height, green, true); + // RSSI bar + float s_level = (127.0f + rssi) / 6.0f; + uint16_t rssi_width = (s_level < 0.0f) ? 0 : (s_level * (width - 1) / 11); + rssi_width = (s_level > 10.0f) ? width : rssi_width; + point_t rssi_pos = {start.x, start.y + 5 + bar_height}; + gfx_drawRect(rssi_pos, rssi_width, bar_height, white, true); // S-level marks and numbers - for(int i = 0; i < 11; i++) + for(int i = 0; i < 12; i++) { color_t color = (i % 3 == 0) ? yellow : white; color = (i > 9) ? red : color; - point_t pixel_pos = {start.x + i * (width - 1) / 11, start.y}; - pixel_pos.y += ((height - 1) + font_height); + point_t pixel_pos = {start.x + i * (width - 1) / 11, + start.y + height}; if (i == 10) { pixel_pos.x -= 8; gfx_print(pixel_pos, font, TEXT_ALIGN_LEFT, color, "+%d", i); } + else if(i == 11){ + pixel_pos.x -= 10; + gfx_print(pixel_pos, font, TEXT_ALIGN_LEFT, red, "+20"); + } else gfx_print(pixel_pos, font, TEXT_ALIGN_LEFT, color, "%d", i); if (i == 10) { pixel_pos.x += 8; } } - - point_t pixel_pos = {start.x + width - 11, start.y}; - pixel_pos.y += ((height - 1) + font_height); - gfx_print(pixel_pos, font, TEXT_ALIGN_LEFT, red, "+20"); - - // RSSI bar - uint16_t rssi_height = height - 4; - float s_level = (127.0f + rssi) / 6.0f; - uint16_t rssi_width = (s_level < 0.0f) ? 0 : (s_level * (width - 1) / 11); - rssi_width = (s_level > 10.0f) ? width : rssi_width; - point_t rssi_pos = { start.x, start.y + 1 }; - gfx_drawRect(rssi_pos, rssi_width, rssi_height, white, true); -} - -/* - * Function to draw level meter of arbitrary size - * starting coordinates are relative to the top left point. - * - * * * * * *| - * ****************************************** | - * ****************************************** <- level | - * ****************************************** | <-- Height (px) - * ****************************************** | - * * * * * *| - * _________________________________________________________________ - * - * ^ - * | - * - * Width (px) - * - */ -void gfx_drawLevelMeter(point_t start, uint16_t width, uint16_t height, uint8_t level) -{ - color_t white = {255, 255, 255, 255}; - - // S-level marks and numbers - for(int i = 0; i <= 4; i++) - { - point_t pixel_pos = {start.x + i * (width - 1) / 4, start.y}; - gfx_setPixel(pixel_pos, white); - pixel_pos.y += (height - 1); - gfx_setPixel(pixel_pos, white); - } - - // Level bar - uint16_t level_height = height - 4; - uint16_t level_width = (level / 255 * width); - point_t level_pos = { start.x, start.y + 2 }; - gfx_drawRect(level_pos, level_width, level_height, white, true); } /* diff --git a/openrtx/src/ui/ui.c b/openrtx/src/ui/ui.c index ed8ea54d..a6ee04c0 100644 --- a/openrtx/src/ui/ui.c +++ b/openrtx/src/ui/ui.c @@ -208,7 +208,7 @@ layout_t _ui_calculateLayout() const uint16_t line2_h = 20; const uint16_t line3_h = 40; const uint16_t menu_h = 16; - const uint16_t bottom_h = 20; + const uint16_t bottom_h = 23; const uint16_t bottom_pad = top_pad; const uint16_t status_v_pad = 2; const uint16_t small_line_v_pad = 2; @@ -243,7 +243,7 @@ layout_t _ui_calculateLayout() const uint16_t line2_h = 10; const uint16_t line3_h = 16; const uint16_t menu_h = 10; - const uint16_t bottom_h = 8; + const uint16_t bottom_h = 15; const uint16_t bottom_pad = 0; const uint16_t status_v_pad = 1; const uint16_t small_line_v_pad = 1; @@ -321,6 +321,7 @@ layout_t _ui_calculateLayout() line3_h, menu_h, bottom_h, + bottom_pad, status_v_pad, horizontal_pad, text_v_offset, diff --git a/openrtx/src/ui/ui_main.c b/openrtx/src/ui/ui_main.c index f00e7b92..6ed84de3 100644 --- a/openrtx/src/ui/ui_main.c +++ b/openrtx/src/ui/ui_main.c @@ -150,33 +150,26 @@ void _ui_drawMainBottom() // Squelch bar float rssi = last_state.rssi; float squelch = last_state.sqlLevel / 16.0f; - point_t meter_pos = { layout.horizontal_pad, - layout.bottom_pos.y + - layout.status_v_pad + - layout.text_v_offset - - layout.bottom_h }; - uint16_t meter_height = layout.bottom_h - 1; + uint16_t meter_width = SCREEN_WIDTH - 2 * layout.horizontal_pad; + uint16_t meter_height = layout.bottom_h; + point_t meter_pos = { layout.horizontal_pad, + SCREEN_HEIGHT - meter_height - layout.bottom_pad}; switch(last_state.channel.mode) { case FM: gfx_drawSmeter(meter_pos, - SCREEN_WIDTH - 2 * layout.horizontal_pad, + meter_width, meter_height, rssi, squelch, - color_white); + yellow_fab413); break; case DMR: - meter_height = (meter_height / 2); - gfx_drawLevelMeter(meter_pos, - SCREEN_WIDTH - 2 * layout.horizontal_pad, - meter_height, - 255); - meter_pos.y += meter_height; - gfx_drawSmeterNoSquelch(meter_pos, - SCREEN_WIDTH - 2 * layout.horizontal_pad, - meter_height, - rssi); + gfx_drawSmeterLevel(meter_pos, + meter_width, + meter_height, + rssi, + 255); break; } } diff --git a/openrtx/src/ui/ui_menu.c b/openrtx/src/ui/ui_menu.c index 4b2ce940..23b637b4 100644 --- a/openrtx/src/ui/ui_menu.c +++ b/openrtx/src/ui/ui_menu.c @@ -25,6 +25,9 @@ #include #include +/* UI main screen helper functions, their implementation is in "ui_main.c" */ +extern void _ui_drawMainBottom(); + void _ui_drawMenuList(uint8_t selected, int (*getCurrentEntry)(char *buf, uint8_t max_len, uint8_t index)) { point_t pos = layout.line1_pos; @@ -591,37 +594,8 @@ bool _ui_drawMacroMenu() { yellow_fab413, "9 "); gfx_print(layout.line3_pos, layout.top_font, TEXT_ALIGN_RIGHT, color_white, "Sav"); - // Smeter bar - float rssi = last_state.rssi; - float squelch = last_state.sqlLevel / 16.0f; - point_t meter_pos = { layout.horizontal_pad, - layout.bottom_pos.y + - layout.status_v_pad + - layout.text_v_offset - - layout.bottom_h }; - uint16_t meter_height = layout.bottom_h - 1; - switch(last_state.channel.mode) - { - case FM: - gfx_drawSmeter(meter_pos, - SCREEN_WIDTH - 2 * layout.horizontal_pad, - meter_height, - rssi, - squelch, - yellow_fab413); - break; - case DMR: - meter_height = (meter_height / 2); - gfx_drawLevelMeter(meter_pos, - SCREEN_WIDTH - 2 * layout.horizontal_pad, - meter_height, - 255); - meter_pos.y += meter_height; - gfx_drawSmeterNoSquelch(meter_pos, - SCREEN_WIDTH - 2 * layout.horizontal_pad, - meter_height, - rssi); - break; - } + + // Draw S-meter bar + _ui_drawMainBottom(); return true; }