Add RSSI and squelch graphic representation

Replaced bottom bar with graphic squelch and rssi representation.
replace/b6a7b992c803c345a740bda751bf1a3fb471144c
Niccolò Izzo 2021-01-29 11:20:35 +01:00
rodzic 2fa5b7a6e6
commit 421ff0e448
3 zmienionych plików z 78 dodań i 16 usunięć

Wyświetl plik

@ -238,4 +238,15 @@ void gfx_printError(const char *text, fontSize_t size);
*/
void gfx_drawBattery(point_t start, uint16_t width, uint16_t height, float percentage);
/**
* Function to draw Smeter of arbitrary size.
* 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
* @param squelch: squelch level in percentage
*/
void gfx_drawSmeter(point_t start, uint16_t width, uint16_t height, float rssi, float squelch);
#endif /* GRAPHICS_H */

Wyświetl plik

@ -203,6 +203,8 @@ void gfx_drawLine(point_t start, point_t end, color_t color)
void gfx_drawRect(point_t start, uint16_t width, uint16_t height, color_t color, bool fill)
{
if(!initialized) return;
if(width == 0) return;
if(height == 0) return;
uint16_t x_max = start.x + width - 1;
uint16_t y_max = start.y + height - 1;
bool perimeter = 0;
@ -437,3 +439,56 @@ void gfx_drawBattery(point_t start, uint16_t width, uint16_t height, float perce
point_t button_end = {start.x + width, start.y + height / 2 + (height / 8)};
gfx_drawLine(button_start, button_end, white);
}
/*
* Function to draw RSSI-meter of arbitrary size
* starting coordinates are relative to the top left point.
*
* * * * * * * *|
* ***************************************** |
* ****************************************** <- RSSI |
* ****************************************** | <-- Height (px)
* ****************************************** |
* **************** <-- Squelch |
* *************** |
* * * * * * * *|
* ___________________________________________________________________
*
* ^
* |
*
* Width (px)
*
*/
void gfx_drawSmeter(point_t start, uint16_t width, uint16_t height, float rssi, float squelch) {
color_t white = {255, 255, 255, 255};
color_t yellow = {250, 180, 19 , 255};
color_t red = {255, 0, 0 , 255};
// S-level dots
for(int i = 0; i < 11; i++) {
color_t color = (i % 3 == 0) ? yellow : white;
color = (i > 9) ? red : color;
point_t pixel_pos = {i * (width - 1) / 11, start.y};
gfx_setPixel(pixel_pos, color);
pixel_pos.y += height;
gfx_setPixel(pixel_pos, color);
}
point_t pixel_pos = {width - 1, start.y};
gfx_setPixel(pixel_pos, red);
pixel_pos.y += height;
gfx_setPixel(pixel_pos, red);
// RSSI bar
uint16_t rssi_height = 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);
point_t rssi_pos = { start.x, start.y + 1 };
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, white, true);
}

Wyświetl plik

@ -165,20 +165,16 @@ void _ui_drawVFOMiddleInput(state_t* last_state, ui_state_t* ui_state)
}
}
void _ui_drawVFOBottom()
void _ui_drawBottom(state_t *last_state)
{
gfx_print(layout.bottom_left, "VFO", layout.bottom_font,
TEXT_ALIGN_LEFT, color_white);
gfx_print(layout.bottom_left, "OpenRTX", layout.bottom_font,
TEXT_ALIGN_CENTER, color_white);
}
void _ui_drawMEMBottom()
{
gfx_print(layout.bottom_left, "MEM", layout.bottom_font,
TEXT_ALIGN_LEFT, color_white);
gfx_print(layout.bottom_left, "OpenRTX", layout.bottom_font,
TEXT_ALIGN_CENTER, color_white);
// Squelch bar
float rssi = last_state->rssi;
float squelch = last_state->sqlLevel / 16.0f;
point_t smeter_pos = { 0, layout.bottom_left.y +
layout.status_v_pad +
layout.text_v_offset -
layout.bottom_h };
gfx_drawSmeter(smeter_pos, SCREEN_WIDTH, layout.bottom_h - 1, rssi, squelch);
}
void _ui_drawMainVFO(state_t* last_state)
@ -187,7 +183,7 @@ void _ui_drawMainVFO(state_t* last_state)
_ui_drawMainBackground();
_ui_drawMainTop(last_state);
_ui_drawVFOMiddle(last_state);
_ui_drawVFOBottom();
_ui_drawBottom(last_state);
}
void _ui_drawMainVFOInput(state_t* last_state, ui_state_t* ui_state)
@ -196,7 +192,7 @@ void _ui_drawMainVFOInput(state_t* last_state, ui_state_t* ui_state)
_ui_drawMainBackground();
_ui_drawMainTop(last_state);
_ui_drawVFOMiddleInput(last_state, ui_state);
_ui_drawVFOBottom();
_ui_drawBottom(last_state);
}
void _ui_drawMainMEM(state_t* last_state)
@ -205,5 +201,5 @@ void _ui_drawMainMEM(state_t* last_state)
_ui_drawMainBackground();
_ui_drawMainTop(last_state);
_ui_drawMEMMiddle(last_state);
_ui_drawMEMBottom();
_ui_drawBottom(last_state);
}