kopia lustrzana https://github.com/OpenRTX/OpenRTX
Improve battery icon drawing implementation
Fix a bug where the signature of the battery draw function was not present, causing a build error. Now the battery size and position is screen size independent and should work for all layouts.replace/1fc4943755e5037647d7270fecaf3fbaf1ab4b63
rodzic
f1400ac528
commit
1ee4744cb7
|
@ -219,4 +219,14 @@ void gfx_drawRect(point_t start, uint16_t width, uint16_t height, color_t color,
|
||||||
*/
|
*/
|
||||||
void gfx_print(point_t start, const char *text, fontSize_t size, textAlign_t alignment, color_t color);
|
void gfx_print(point_t start, const char *text, fontSize_t size, textAlign_t alignment, color_t color);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to draw battery of arbitrary size.
|
||||||
|
* Starting coordinates are relative to the top left point.
|
||||||
|
* @param start: battery icon start point, in pixel coordinates.
|
||||||
|
* @param width: battery icon width
|
||||||
|
* @param height: battery icon height
|
||||||
|
* @param percentage: battery charge percentage
|
||||||
|
*/
|
||||||
|
void gfx_drawBattery(point_t start, uint16_t width, uint16_t height, float percentage);
|
||||||
|
|
||||||
#endif /* GRAPHICS_H */
|
#endif /* GRAPHICS_H */
|
||||||
|
|
|
@ -274,14 +274,14 @@ void gfx_print(point_t start, const char *text, fontSize_t size, textAlign_t ali
|
||||||
* Function to draw battery of arbitrary size
|
* Function to draw battery of arbitrary size
|
||||||
* starting coordinates are relative to the top left point.
|
* starting coordinates are relative to the top left point.
|
||||||
*
|
*
|
||||||
* ****************** |
|
* **************** |
|
||||||
* * * |
|
* * * |
|
||||||
* * ******* * |
|
* * ******* * |
|
||||||
* * ******* ** |
|
* * ******* ** |
|
||||||
* * ******* ** | <-- Height (px)
|
* * ******* ** | <-- Height (px)
|
||||||
* * ******* * |
|
* * ******* * |
|
||||||
* * * |
|
* * * |
|
||||||
* ****************** |
|
* **************** |
|
||||||
*
|
*
|
||||||
* __________________
|
* __________________
|
||||||
*
|
*
|
||||||
|
@ -292,18 +292,20 @@ void gfx_print(point_t start, const char *text, fontSize_t size, textAlign_t ali
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void gfx_drawBattery(point_t start, uint16_t width, uint16_t height, float percentage) {
|
void gfx_drawBattery(point_t start, uint16_t width, uint16_t height, float percentage) {
|
||||||
printf("AFTER: %f\n", percentage);
|
|
||||||
color_t white = {255, 255, 255};
|
color_t white = {255, 255, 255};
|
||||||
color_t green = {0, 255, 0 };
|
color_t green = {0, 255, 0 };
|
||||||
color_t yellow = {250, 180, 19 };
|
color_t yellow = {250, 180, 19 };
|
||||||
color_t red = {255, 0, 0 };
|
color_t red = {255, 0, 0 };
|
||||||
color_t black = {0, 0, 0 };
|
color_t black = {0, 0, 0 };
|
||||||
|
|
||||||
|
// Cap percentage to 1
|
||||||
|
percentage = (percentage > 1.0f) ? 1.0f : percentage;
|
||||||
|
|
||||||
// Select color according to percentage
|
// Select color according to percentage
|
||||||
color_t bat_color = yellow;
|
color_t bat_color = yellow;
|
||||||
if (percentage < 0.2)
|
if (percentage < 0.3)
|
||||||
bat_color = red;
|
bat_color = red;
|
||||||
else if (percentage > 0.8)
|
else if (percentage > 0.7)
|
||||||
bat_color = green;
|
bat_color = green;
|
||||||
|
|
||||||
// Draw the battery outline
|
// Draw the battery outline
|
||||||
|
@ -324,7 +326,7 @@ void gfx_drawBattery(point_t start, uint16_t width, uint16_t height, float perce
|
||||||
gfx_setPixel(bottom_right, black);
|
gfx_setPixel(bottom_right, black);
|
||||||
|
|
||||||
// Draw the button
|
// Draw the button
|
||||||
point_t button_start = {start.x + width, start.y + (height / 2) - 2};
|
point_t button_start = {start.x + width, start.y + height / 2 - 2};
|
||||||
point_t button_end = {start.x + width, start.y + (height / 2) + 2};
|
point_t button_end = {start.x + width, start.y + height / 2 + 1};
|
||||||
gfx_drawLine(button_start, button_end, white);
|
gfx_drawLine(button_start, button_end, white);
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,6 +76,8 @@ typedef struct layout_t
|
||||||
{
|
{
|
||||||
uint16_t top_h;
|
uint16_t top_h;
|
||||||
uint16_t bottom_h;
|
uint16_t bottom_h;
|
||||||
|
uint16_t vertical_pad;
|
||||||
|
uint16_t horizontal_pad;
|
||||||
point_t top_pos;
|
point_t top_pos;
|
||||||
point_t line1_pos;
|
point_t line1_pos;
|
||||||
point_t line2_pos;
|
point_t line2_pos;
|
||||||
|
@ -103,13 +105,13 @@ layout_t _ui_calculateLayout()
|
||||||
|
|
||||||
// Height and padding shown in diagram at beginning of file
|
// Height and padding shown in diagram at beginning of file
|
||||||
const uint16_t top_h = 16;
|
const uint16_t top_h = 16;
|
||||||
const uint16_t top_pad = 4;
|
const uint16_t bottom_h = top_h;
|
||||||
const uint16_t line1_h = 32;
|
const uint16_t line1_h = 32;
|
||||||
const uint16_t line2_h = 32;
|
const uint16_t line2_h = 32;
|
||||||
const uint16_t line3_h = 32;
|
const uint16_t line3_h = 32;
|
||||||
const uint16_t line_pad = 8;
|
const uint16_t line_pad = 8;
|
||||||
const uint16_t bottom_h = top_h;
|
const uint16_t vertical_pad = 4;
|
||||||
const uint16_t bottom_pad = 4;
|
const uint16_t horizontal_pad = 4;
|
||||||
|
|
||||||
// Top bar font: 8 pt
|
// Top bar font: 8 pt
|
||||||
const fontSize_t top_font = FONT_SIZE_8PT;
|
const fontSize_t top_font = FONT_SIZE_8PT;
|
||||||
|
@ -125,13 +127,13 @@ layout_t _ui_calculateLayout()
|
||||||
|
|
||||||
// Height and padding shown in diagram at beginning of file
|
// Height and padding shown in diagram at beginning of file
|
||||||
const uint16_t top_h = 13;
|
const uint16_t top_h = 13;
|
||||||
const uint16_t top_pad = 4;
|
const uint16_t bottom_h = top_h;
|
||||||
const uint16_t line1_h = 15;
|
const uint16_t line1_h = 15;
|
||||||
const uint16_t line2_h = 15;
|
const uint16_t line2_h = 15;
|
||||||
const uint16_t line3_h = 15;
|
const uint16_t line3_h = 15;
|
||||||
const uint16_t line_pad = 15;
|
const uint16_t line_pad = 15;
|
||||||
const uint16_t bottom_h = top_h;
|
const uint16_t vertical_pad = 4;
|
||||||
const uint16_t bottom_pad = 11;
|
const uint16_t horizontal_pad = 4;
|
||||||
|
|
||||||
// Top bar font: 8 pt
|
// Top bar font: 8 pt
|
||||||
const fontSize_t top_font = FONT_SIZE_6PT;
|
const fontSize_t top_font = FONT_SIZE_6PT;
|
||||||
|
@ -146,13 +148,13 @@ layout_t _ui_calculateLayout()
|
||||||
|
|
||||||
// Height and padding shown in diagram at beginning of file
|
// Height and padding shown in diagram at beginning of file
|
||||||
const uint16_t top_h = 8;
|
const uint16_t top_h = 8;
|
||||||
const uint16_t top_pad = 0;
|
const uint16_t bottom_h = 0;
|
||||||
const uint16_t line1_h = 20;
|
const uint16_t line1_h = 20;
|
||||||
const uint16_t line2_h = 20;
|
const uint16_t line2_h = 20;
|
||||||
const uint16_t line3_h = 0;
|
const uint16_t line3_h = 0;
|
||||||
const uint16_t line_pad = 2;
|
const uint16_t line_pad = 2;
|
||||||
const uint16_t bottom_h = 0;
|
const uint16_t vertical_pad = 0;
|
||||||
const uint16_t bottom_pad = 0;
|
const uint16_t horizontal_pad = 0;
|
||||||
|
|
||||||
// Top bar font: 8 pt
|
// Top bar font: 8 pt
|
||||||
const fontSize_t top_font = FONT_SIZE_1;
|
const fontSize_t top_font = FONT_SIZE_1;
|
||||||
|
@ -168,16 +170,18 @@ layout_t _ui_calculateLayout()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Calculate printing positions
|
// Calculate printing positions
|
||||||
point_t top_pos = {0, top_h - top_pad};
|
point_t top_pos = {0, top_h - vertical_pad};
|
||||||
point_t line1_pos = {0, top_h + line1_h - line_pad};
|
point_t line1_pos = {0, top_h + line1_h - line_pad};
|
||||||
point_t line2_pos = {0, top_h + line1_h + line2_h - line_pad};
|
point_t line2_pos = {0, top_h + line1_h + line2_h - line_pad};
|
||||||
point_t line3_pos = {0, top_h + line1_h + line2_h + line3_h - line_pad};
|
point_t line3_pos = {0, top_h + line1_h + line2_h + line3_h - line_pad};
|
||||||
point_t bottom_pos = {0, top_h + line1_h + line2_h + line3_h + bottom_h - bottom_pad};
|
point_t bottom_pos = {0, top_h + line1_h + line2_h + line3_h + bottom_h - vertical_pad};
|
||||||
|
|
||||||
layout_t new_layout =
|
layout_t new_layout =
|
||||||
{
|
{
|
||||||
top_h,
|
top_h,
|
||||||
bottom_h,
|
bottom_h,
|
||||||
|
vertical_pad,
|
||||||
|
horizontal_pad
|
||||||
top_pos,
|
top_pos,
|
||||||
line1_pos,
|
line1_pos,
|
||||||
line2_pos,
|
line2_pos,
|
||||||
|
@ -211,9 +215,10 @@ void _ui_drawTopBar(state_t* state)
|
||||||
|
|
||||||
// Print battery icon on top bar, use 4 px padding
|
// Print battery icon on top bar, use 4 px padding
|
||||||
float percentage = state->v_bat / MAX_VBAT;
|
float percentage = state->v_bat / MAX_VBAT;
|
||||||
printf("BEFORE: %f\n", percentage);
|
uint16_t bat_width = SCREEN_WIDTH / 9;
|
||||||
point_t bat_pos = {SCREEN_WIDTH - 24, layout.top_pos.y - 10};
|
uint16_t bat_height = layout.top_h - layout.vertical_pad / 2;
|
||||||
gfx_drawBattery(bat_pos, 19, 12, 0.5f);
|
point_t bat_pos = {SCREEN_WIDTH - bat_width - layout.horizontal_pad, 1};
|
||||||
|
gfx_drawBattery(bat_pos, bat_width, bat_height, percentage);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _ui_drawVFO(state_t* state)
|
void _ui_drawVFO(state_t* state)
|
||||||
|
|
|
@ -85,6 +85,6 @@
|
||||||
#define FLASH_SDI GPIOB,5
|
#define FLASH_SDI GPIOB,5
|
||||||
|
|
||||||
/* Maximum battery voltage */
|
/* Maximum battery voltage */
|
||||||
#define MAX_VBAT 8.2f
|
#define MAX_VBAT 8.4f
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -50,4 +50,4 @@
|
||||||
#define PTT_SW "PTT_SW",11
|
#define PTT_SW "PTT_SW",11
|
||||||
|
|
||||||
/* Maximum battery voltage */
|
/* Maximum battery voltage */
|
||||||
#define MAX_VBAT 8.5f
|
#define MAX_VBAT 8.4f
|
||||||
|
|
Ładowanie…
Reference in New Issue