V1.5: OLED防烧屏偏移加大到0~24px,按内容宽度自动钳位,左侧腾空列全清空

This commit is contained in:
helei 2026-08-22 20:01:47 +08:00
parent ebc1ca5255
commit 1198ca6763
4 changed files with 21 additions and 4 deletions

View File

@ -287,6 +287,18 @@ void oled_xoff(uint8_t px)
s_col += px;
}
/*==== 文本像素宽度:汉字/全角 16pxASCII 8px ====*/
uint8_t oled_text_w(const char *s)
{
const uint8_t *p = (const uint8_t *)s;
uint32_t w = 0;
while (*p) {
if (p[0] >= 0xa1 && p[1] >= 0xa1) { w += 16; p += 2; }
else { w += 8; p += 1; }
}
return (uint8_t)(w > 128 ? 128 : w);
}
/*==== 整行显示:计算像素宽度,不足 128px 用空格补齐(覆盖上次内容)====*/
void oled_print_line(const char *s)
{

View File

@ -13,7 +13,8 @@ void oled_init(void); /* GPIO +
void oled_clear(void); /* 全屏清屏 */
void oled_off(void); /* 关显示0xAE黑屏断电前调用 */
void oled_locate(uint8_t row, uint8_t col8); /* 定位row 0~3col8 为 8 像素单位 0~15 */
void oled_xoff(uint8_t px); /* 在当前列基础上右移 px 像素(防烧屏偏移用) */
void oled_xoff(uint8_t px);
uint8_t oled_text_w(const char *gbk_str); /* 文本像素宽度汉字16/ASCII8 */ /* 在当前列基础上右移 px 像素(防烧屏偏移用) */
void oled_print(const char *gbk_str); /* 从当前位置显示 GBK 字符串 */
void oled_print_line(const char *gbk_str); /* 整行显示:不足 128px 用空格补齐覆盖旧内容 */

View File

@ -247,9 +247,12 @@ void app_oled_presched_tick(void)
/* 写一整行(带防烧屏偏移):先写空格清掉左移腾出的列,再从偏移处写内容 */
static void oled_row(uint8_t row, uint8_t xoff, const char *s)
{
/* 按内容宽度钳位:内容宽就少移,保证不超出右边界 */
uint8_t w = oled_text_w(s);
if (xoff > 0 && (uint16_t)xoff + w > 128) xoff = 128 - w;
if (xoff) {
oled_locate(row, 0);
oled_print(" "); /* 清掉左侧腾出的列,防止残留 */
for (uint8_t c = 0; c < xoff; c += 8) oled_print(" "); /* 清空左侧腾出的列,防残留 */
oled_locate(row, 0);
}
oled_locate(row, 0);
@ -260,8 +263,8 @@ static void oled_row(uint8_t row, uint8_t xoff, const char *s)
static void oled_home_refresh(uint32_t up_ms)
{
char buf[24];
/* 防烧屏:每 10s 换一档水平偏移0/2/4px */
uint8_t xoff = (uint8_t)((HAL_GetTick() / 10000u) % 3u) * 2u;
/* 防烧屏:每 10s 换一档水平偏移0~24px按内容宽度自动钳位 */
uint8_t xoff = (uint8_t)((HAL_GetTick() / 10000u) % 5u) * 6u;
if (g_net_mqtt_ready) {
/*---- 已联网界面 ----*/

View File

@ -201,3 +201,4 @@
根治字节中断+软件超时方案的丢帧/停摆问题;实测秒回/慢回全部一次成功。
过程DWT 硬件观察点抓到合法写点无误,定位为原中断接收路径在特定时序下字节丢失
- 恢复 OLED 防烧屏像素偏移每10s 右移 0/2/4px并修复左侧残留移位前先写空格清腾空列
- OLED 偏移幅度加大到 0~24px5 档),按内容宽度自动钳位不越界,左侧腾空列全量清空