feat: 优化界面设计与传感器功能

主要更改包括:

1. 传感器功能改进:
   - 实现水位传感器状态变化检测,正确处理有水/无水状态
   - 优化温湿度数据显示,使用更清晰的格式

2. LCD界面优化:
   - 适配80*160屏幕尺寸,调整所有页面布局
   - 温湿度页面:使用"C"作为温度单位,优化显示位置
   - 食物重量页面:调整显示位置,简化状态文本
   - 水位页面:替换圆形图标为矩形背景,提升视觉效果
   - 系统状态页面:简化状态文本,优化布局
   - 统一标题栏设计,添加分隔线

3. 功能增强:
   - 实现ST7735_DrawLine函数,用于绘制分隔线
   - 实现ST7735_FillCircle函数,用于图形绘制
   - 添加步进电机驱动代码,支持电机控制

4. 其他优化:
   - 修复未使用变量的编译警告
   - 调整字体大小和显示位置,提高可读性
   - 优化颜色方案,提升视觉体验

这些更改使界面更加美观、清晰,同时增强了系统的功能和稳定性。
This commit is contained in:
2026-02-24 23:41:40 +08:00
parent addfb3faad
commit 97d6d10731
10 changed files with 823 additions and 43 deletions

View File

@@ -59,6 +59,9 @@ HAL_StatusTypeDef MP3_Init(void)
HAL_StatusTypeDef ret1 = MP3_SendCommand(init_cmd1, sizeof(init_cmd1));
elog_d("MP3", "开启声音命令返回值: %d", ret1);
// 设置为低音量-测试用
MP3_SetVolume(2);
// 延时等待模块响应
HAL_Delay(100);

View File

@@ -554,6 +554,108 @@ void ST7735_InvertColors(bool invert) {
ST7735_Unselect();
}
/**
* 在ST7735液晶显示屏上绘制一条直线
*
* @param x0 直线起始点的X坐标
* @param y0 直线起始点的Y坐标
* @param x1 直线结束点的X坐标
* @param y1 直线结束点的Y坐标
* @param color 直线的颜色
*/
void ST7735_DrawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color) {
// 检查坐标是否超出显示屏边界
if ((x0 >= ST7735_WIDTH) || (y0 >= ST7735_HEIGHT) || (x1 >= ST7735_WIDTH) || (y1 >= ST7735_HEIGHT))
return;
// 选择显示屏以进行操作
ST7735_Select();
// 使用Bresenham算法绘制直线
int16_t dx = abs((int16_t)x1 - (int16_t)x0);
int16_t dy = abs((int16_t)y1 - (int16_t)y0);
int16_t sx = (x0 < x1) ? 1 : -1;
int16_t sy = (y0 < y1) ? 1 : -1;
int16_t err = dx - dy;
int16_t current_x = x0;
int16_t current_y = y0;
while (1) {
// 绘制当前点
ST7735_DrawPixel(current_x, current_y, color);
// 检查是否到达终点
if (current_x == x1 && current_y == y1)
break;
// 计算下一步
int16_t e2 = 2 * err;
if (e2 > -dy) {
err -= dy;
current_x += sx;
}
if (e2 < dx) {
err += dx;
current_y += sy;
}
}
// 取消选择显示屏,结束操作
ST7735_Unselect();
}
/**
* 在ST7735液晶显示屏上绘制一个填充圆
*
* @param x 圆心的X坐标
* @param y 圆心的Y坐标
* @param radius 圆的半径
* @param color 填充颜色
*/
void ST7735_FillCircle(uint16_t x, uint16_t y, uint16_t radius, uint16_t color) {
// 检查坐标是否超出显示屏边界
if ((x >= ST7735_WIDTH) || (y >= ST7735_HEIGHT))
return;
// 选择显示屏以进行操作
ST7735_Select();
// 使用中点圆算法绘制填充圆
int16_t x_pos = radius;
int16_t y_pos = 0;
int16_t err = 1 - radius;
while (x_pos >= y_pos) {
// 绘制水平扫描线
if ((y + y_pos) < ST7735_HEIGHT) {
ST7735_FillRectangle(x - x_pos, y + y_pos, 2 * x_pos + 1, 1, color);
}
if ((y - y_pos) >= 0 && y_pos != 0) {
ST7735_FillRectangle(x - x_pos, y - y_pos, 2 * x_pos + 1, 1, color);
}
if ((y + x_pos) < ST7735_HEIGHT && x_pos != y_pos) {
ST7735_FillRectangle(x - y_pos, y + x_pos, 2 * y_pos + 1, 1, color);
}
if ((y - x_pos) >= 0 && x_pos != y_pos) {
ST7735_FillRectangle(x - y_pos, y - x_pos, 2 * y_pos + 1, 1, color);
}
// 计算下一步
if (err < 0) {
y_pos++;
err += 2 * y_pos + 1;
} else {
x_pos--;
err += 2 * (y_pos - x_pos) + 1;
y_pos++;
}
}
// 取消选择显示屏,结束操作
ST7735_Unselect();
}
/**
* @brief 设置ST7735显示器的伽马曲线
*

View File

@@ -315,6 +315,16 @@ extern "C"
// 解释:此函数用于在显示屏上的指定位置绘制图像,图像数据以数组形式提供
void ST7735_DrawImage(uint16_t x, uint16_t y, uint16_t w, uint16_t h, const uint16_t *data);
// 在指定位置绘制一条直线
// 参数x0 - 直线起始X坐标y0 - 直线起始Y坐标x1 - 直线结束X坐标y1 - 直线结束Y坐标color - 直线颜色
// 解释此函数用于在显示屏上绘制一条直线使用Bresenham算法实现
void ST7735_DrawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color);
// 绘制一个填充圆
// 参数x - 圆心X坐标y - 圆心Y坐标radius - 圆的半径color - 填充颜色
// 解释:此函数用于在显示屏上绘制一个填充的圆形
void ST7735_FillCircle(uint16_t x, uint16_t y, uint16_t radius, uint16_t color);
// 反转显示屏颜色
// 参数invert - 是否反转颜色true/false
// 解释:此函数用于反转显示屏上的颜色,可用于显示反转效果