UP tft bar

main
JiXieShi 2024-09-17 20:37:51 +08:00
parent 11600e4153
commit 3334f19eb4
2 changed files with 49 additions and 1 deletions

View File

@ -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); 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 #ifdef LVGL_FONT
#include "lvgl_font.h" #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); * @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); void TFT_DisplayString(TFT_T *dev, const lv_font_t *font, uint8_t *s, uint16_t x, uint16_t y);
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -439,3 +439,36 @@ void TFT_ShowPic(TFT_T *dev, uint16_t x, uint16_t y, uint16_t width, uint16_t he
bmp+=width; 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;
}
}