hi3861软件

This commit is contained in:
2025-10-18 16:05:39 +08:00
parent 3d7a4dcb4d
commit 30edbda7de
36 changed files with 1888 additions and 1785 deletions

64
display_helper.c Normal file
View File

@@ -0,0 +1,64 @@
#include "display_helper.h"
#include "chinese_char_map.h"
#include "json_parser.h"
#include "oled_ssd1306.h"
#include <string.h>
#include <stdio.h>
// 显示混合字符串(中文+英文数字)
void DisplayMixedString(uint8_t start_x, uint8_t start_y, const char* text) {
if (!text) {
return;
}
uint8_t x = start_x;
uint8_t y = start_y;
int i = 0;
int text_len = strlen(text);
printf("DisplayMixedString: Processing text '%s' (length: %d)\r\n", text, text_len);
while (i < text_len) {
// 检查是否为UTF-8中文字符通常以0xE开头的3字节序列
if ((unsigned char)text[i] >= 0xE0 && i + 2 < text_len) {
// 提取3字节的UTF-8中文字符
char chinese_char[4] = {0};
chinese_char[0] = text[i];
chinese_char[1] = text[i + 1];
chinese_char[2] = text[i + 2];
chinese_char[3] = '\0';
printf("Found Chinese char: %02X %02X %02X\r\n",
(unsigned char)chinese_char[0],
(unsigned char)chinese_char[1],
(unsigned char)chinese_char[2]);
// 查找字符在fonts3数组中的索引
int font_index = FindChineseCharIndex(chinese_char);
if (font_index >= 0) {
printf("Displaying Chinese char at index %d, position (%d, %d)\r\n", font_index, x, y);
OledShowChinese3(x, y, font_index);
x += 16; // 中文字符宽度为16像素
} else {
printf("Chinese char not found in font table, displaying as '?'\r\n");
// 如果找不到字符,显示问号
OledShowString(x, y, "?", FONT8x16);
x += 8; // 英文字符宽度为8像素
}
i += 3; // 跳过3字节的UTF-8字符
} else {
// 处理ASCII字符英文、数字、符号
char ascii_char[2] = {text[i], '\0'};
printf("Found ASCII char: '%c' (0x%02X)\r\n", text[i], (unsigned char)text[i]);
OledShowString(x, y, ascii_char, FONT8x16);
x += 8; // 英文字符宽度为8像素
i++;
}
// 检查是否需要换行假设屏幕宽度为128像素
if (x >= 120) {
x = start_x;
y += 2; // 每行高度为2个单位16像素
}
}
}