本帖最后由 大明哥 于 2025-4-3 08:06 编辑
AI deepseek 大模型 + 迪文屏
效果演示如下: https://v.youku.com/video?vid=XNjQ2NTIyMzA1Ng%3D%3D
具体硬件框架如下: AI模块板子 + 迪文屏幕,中间通讯通过串口进行通讯控制
界面如下:
屏幕主要程序如下:
#defineMAX_PACKETS 20 // 预设最大包数量
typedefstruct { unsigned char *indata; // 数据指针 int length; // 包长度 } Packet;
int split_packets(constunsigned char *indata, int data_len, Packet *packets, int *packet_count) { int positions[MAX_PACKETS] = {0}; int count = 0; int i;
// 查找所有包头位置 for ( i = 0; i <= data_len - 2&& count < MAX_PACKETS; ) { if (indata == 0x5A &&indata[i+1] == 0xA5) { positions[count++] = i; i += 2; // 跳过包头 } else { i++; } } if (count == 0) return -1;
// 分割数据到静态数组 *packet_count = count; for ( i = 0; i < count; i++) { int start = positions; int end = (i < count-1) ?positions[i+1] : data_len; packets.indata = indata + start; packets.length = end - start; } return 0; }
#defineOutGbkLen 256 unsignedchar HuanBuffdata[1024]; voidHandleRecData(unsigned char *inputdata,unsigned char len) { char emotions=0; char emoarr[2];
memset(HuanBuffdata,0,sizeof(HuanBuffdata)); memcpy(HuanBuffdata,inputdata,len);
switch(HuanBuffdata[2]) { case 1://表情 if(HuanBuffdata[3]>20) emotions=0; else emotions=HuanBuffdata[3];
emoarr[0]=0; emoarr[1]=emotions+1; write_dgusii_vp(0x3000,emoarr,1); break;
case 2://网络状态
break;
case 3://通知消息 write_dgusii_vp(0x2000,&HuanBuffdata[3],strlen(&HuanBuffdata[3])/2); break;
case 4://聊天信息 write_dgusii_vp(0x4000,&HuanBuffdata[3],strlen(&HuanBuffdata[3])/2); break; } }
voidDispDataHandle(void) { int i ; int data_len = uart4_rx_count;
Packet packets[MAX_PACKETS]; // 栈内存分配 int packet_count;
if (split_packets(Uart4_Rx, data_len,packets, &packet_count) == 0) { for ( i = 0; i < packet_count; i++) { HandleRecData(packets.indata,packets.length); } } }
AI 板子程序如下:AI 代码比较复杂,大家可以慢慢研究 打开如下目录: xiaozhi-esp32\main\boards\xingzhi-cube-dwin-wifi
voidXINGZHI_1_54_TFT_LcdDisplay::SetChatMessage(const char* role, const char* content) { DisplayLockGuard lock(this); if(chat_message_label_ == nullptr) { return; } lv_label_set_text(chat_message_label_, content);
char senddata[10]; int i=0; memset(senddata,0,sizeof(senddata)); senddata[i++]=0x5a; senddata[i++]=0xa5; senddata[i++]=0x4; uart_write_bytes(USART_UX,senddata,i);
uint16_t unicode_string[256]; // 足够大的缓冲区 memset(unicode_string,0,sizeof(unicode_string)); uint32_tretlen=utf8_to_unicode((const uint8_t*)content,strlen(content),unicode_string); uint8_t gbk_string[256]; // 足够大的缓冲区 UnicodeToGbk(unicode_string,gbk_string,sizeof(gbk_string)); uart_write_bytes(USART_UX,gbk_string,strlen((char *)gbk_string)); }
voidXINGZHI_1_54_TFT_LcdDisplay::SetStatus(const char* status) { DisplayLockGuard lock(this); if (status_label_ ==nullptr) { return; } lv_label_set_text(status_label_, status); lv_obj_clear_flag(status_label_, LV_OBJ_FLAG_HIDDEN); lv_obj_add_flag(notification_label_, LV_OBJ_FLAG_HIDDEN);
char senddata[10];int i=0; memset(senddata,0,sizeof(senddata)); senddata[i++]=0x5a; senddata[i++]=0xa5; senddata[i++]=0x3; uart_write_bytes(USART_UX,senddata,i);
uint16_t unicode_string[256]; // 足够大的缓冲区 memset(unicode_string,0,sizeof(unicode_string)); uint32_tretlen=utf8_to_unicode((const uint8_t*)status,strlen(status),unicode_string); uint8_t gbk_string[256]; // 足够大的缓冲区 UnicodeToGbk(unicode_string,gbk_string,sizeof(gbk_string)); uart_write_bytes(USART_UX,gbk_string,strlen((char *)gbk_string));
}
在 xiaozhi-esp32.zip.001.zip xiaozhi-esp32.zip.002.zip xiaozhi-esp32.zip.003.zip xiaozhi-esp32.zip.004.zip 这两个AI源码包比较大,所以分了4包上传,下载后去.zip 后缀,然后再进行解压即可
|