void ShowMessageLBJ(POCSAG_RESULT* POCSAG_Msg,float rssi,uint8_t lqi) { char MessageLBJ[4][7] = {{0},{0},{0},{0}} char MessageLBJ[3][7] = {{0},{0},{0}}; for(uint8_t i = 0;i < 5;i++) { strncpy(MessageLBJ[i],POCSAG_Msg->txtMsg+i5,5); } OLED_ShowString(68,0,MessageLBJ[0],16); OLED_Display_16x16(1,0,MessageLBJ[0]); OLED_Display_16x16(28,2,MessageLBJ[1][2],16); OLED_Display_16x16(38,2,MessageLBJ[1][3],16); OLED_Display_16x16(78,2,MessageLBJ[2],16); OLED_Display_16x16(18,4,MessageLBJ[3],16); OLED_ShowString(58,6,Link_Info[0],16); OLED_ShowString(148,6,Link_Info[1],16); } 这个是STM32F103C8T6和ssd1306的显示函数,现在是收到消息直接显示,不会息屏,能不能帮我把它修改为收到消息后常亮6秒,如果有新消息就替换显示
时间: 2024-03-08 08:45:45 浏览: 60
好的,我可以帮你修改这个函数来实现你的需求。你可以试试以下这个修改后的函数:
```
void ShowMessageLBJ(POCSAG_RESULT* POCSAG_Msg,float rssi,uint8_t lqi) {
static uint32_t last_display_time = 0;
static uint8_t current_message_index = 0;
static char MessageLBJ[4][7] = {{0},{0},{0},{0}};
static char MessageLBJ_temp[3][7] = {{0},{0},{0}};
uint32_t current_time = HAL_GetTick();
// Copy the message into the buffer
for(uint8_t i = 0;i < 5;i++) {
strncpy(MessageLBJ[i],POCSAG_Msg->txtMsg+i*5,5);
}
// If there is a new message, display it and reset the timer
if(current_message_index == 0 || strcmp(MessageLBJ[0], MessageLBJ_temp[0]) != 0) {
OLED_Clear();
OLED_ShowString(68,0,MessageLBJ[0],16);
OLED_Display_16x16(1,0,MessageLBJ[0]);
OLED_Display_16x16(28,2,MessageLBJ[1][2],16);
OLED_Display_16x16(38,2,MessageLBJ[1][3],16);
OLED_Display_16x16(78,2,MessageLBJ[2],16);
OLED_Display_16x16(18,4,MessageLBJ[3],16);
OLED_ShowString(58,6,Link_Info[0],16);
OLED_ShowString(148,6,Link_Info[1],16);
last_display_time = current_time;
current_message_index = 0;
memcpy(MessageLBJ_temp, MessageLBJ, sizeof(MessageLBJ));
}
// If there is no new message, check if it's time to turn off the OLED
else {
if(current_time - last_display_time > 6000) {
OLED_Clear();
current_message_index++;
if(current_message_index >= 4) {
current_message_index = 0;
}
OLED_ShowString(68,0,MessageLBJ[current_message_index],16);
OLED_Display_16x16(1,0,MessageLBJ[current_message_index]);
OLED_Display_16x16(28,2,MessageLBJ[current_message_index+1][2],16);
OLED_Display_16x16(38,2,MessageLBJ[current_message_index+1][3],16);
OLED_Display_16x16(78,2,MessageLBJ[current_message_index+2],16);
OLED_Display_16x16(18,4,MessageLBJ[current_message_index+3],16);
OLED_ShowString(58,6,Link_Info[0],16);
OLED_ShowString(148,6,Link_Info[1],16);
last_display_time = current_time;
}
}
}
```
这个函数会保存上一次显示的时间和当前显示的消息的索引。当有新消息时,它会清空 OLED 并显示新消息,然后重置计时器和消息索引。在没有新消息的情况下,它会检查计时器是否超过 6 秒,并在超过 6 秒后自动熄灭 OLED。如果有新消息,它会重新开始计时,并显示新消息。你可以根据需要更改计时器的时间限制。
阅读全文