UP tft bar
parent
11600e4153
commit
3334f19eb4
|
@ -348,6 +348,20 @@ void TFT_ShowNum(TFT_T *dev, uint16_t x, uint16_t y, uint32_t num, uint16_t len,
|
|||
**/
|
||||
void TFT_ShowPic(TFT_T *dev, uint16_t x0, uint16_t y0, uint16_t w, uint16_t h, TFT_Color_t *bmp);
|
||||
|
||||
/**
|
||||
* @brief 在屏幕上显示进度条
|
||||
* @param dev: [输入] TFT设备指针
|
||||
* @param x: [输入] 进度条左上角x坐标
|
||||
* @param y: [输入] 进度条左上角y坐标
|
||||
* @param width: [输入] 进度条宽度
|
||||
* @param height: [输入] 进度条高度
|
||||
* @param progress: [输入] 进度值,范围[0.0, 1.0]
|
||||
* @return void
|
||||
* @example TFT_ShowBar(&tft_device, 10, 20, 100, 10, 0.75);
|
||||
**/
|
||||
void TFT_ShowBar(TFT_T *dev, uint16_t x, uint16_t y, uint16_t width, uint16_t height, float progress);
|
||||
|
||||
|
||||
#ifdef LVGL_FONT
|
||||
|
||||
#include "lvgl_font.h"
|
||||
|
@ -364,8 +378,9 @@ void TFT_ShowPic(TFT_T *dev, uint16_t x0, uint16_t y0, uint16_t w, uint16_t h, T
|
|||
* @example TFT_DisplayString(&oled_device, &font_arial_16, "Hello World", 10, 20,bool mode);
|
||||
**/
|
||||
void TFT_DisplayString(TFT_T *dev, const lv_font_t *font, uint8_t *s, uint16_t x, uint16_t y);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -439,3 +439,36 @@ void TFT_ShowPic(TFT_T *dev, uint16_t x, uint16_t y, uint16_t width, uint16_t he
|
|||
bmp+=width;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t invertRGB565(uint16_t color) {
|
||||
// 分离颜色分量
|
||||
uint8_t r = (color >> 11) & 0x1F; // 取出红色分量
|
||||
uint8_t g = (color >> 5) & 0x3F; // 取出绿色分量
|
||||
uint8_t b = color & 0x1F; // 取出蓝色分量
|
||||
|
||||
// 取反颜色分量
|
||||
r = 31 - r;
|
||||
g = 63 - g;
|
||||
b = 31 - b;
|
||||
|
||||
// 重新组合颜色分量
|
||||
return (r << 11) | (g << 5) | b;
|
||||
}
|
||||
|
||||
void TFT_ShowBar(TFT_T *dev, uint16_t x, uint16_t y, uint16_t width, uint16_t height, float progress) {
|
||||
if (x + width > dev->width || y + height > dev->height || progress > 1)return;
|
||||
uint16_t xp = (width - x) * progress;
|
||||
TFT_Fill(dev, x, y, xp, height, POINT_COLOR);
|
||||
if (progress < 1)TFT_Fill(dev, xp, y, width, height, BACK_COLOR);
|
||||
if (height >= 12 && height < 32) {
|
||||
uint8_t tmp[7];
|
||||
uint16_t sp = (width - x) / 2 - 30;
|
||||
TFT_Color_t temp = POINT_COLOR;
|
||||
POINT_COLOR.u16 = invertRGB565(POINT_COLOR.u16);
|
||||
sprintf(tmp, "%05.2f%%", progress * 100);
|
||||
if (xp < sp)TFT_ShowString(dev, sp, y, tmp, (height >= 24) ? 24 : (height >= 16) ? 16 : 12, 0);
|
||||
else TFT_ShowString(dev, sp, y, tmp, (height >= 24) ? 24 : (height >= 16) ? 16 : 12, 1);
|
||||
POINT_COLOR = temp;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue