本期為大家推送迪文開發者論壇的獲獎開源案例:智能貓糧控制系統。工程師使用迪文智能屏實現了監測貓糧的溫度、濕度、余量,保存貓咪吃糧記錄等功能,并別出心裁的設計了一套水墨畫風格UI,以及手指觸摸時的水墨點擊效果,增強觸摸的視覺反饋。
方案簡介
UI圖片素材
迪文智能屏是基于圖片完成UI開發,需根據屏幕顯示內容提前準備好圖片、音頻等素材。
界面開發
DGUS軟件是通過圖層疊加來還原UI效果,將準備好的素材在DGUS軟件中組合成完整的畫面,并設置好顯示、觸摸功能。
實現點擊特效和音效
通過51程序來獲取觸摸位置,實現按壓效果跟隨手指移動,同時實現按鍵伴音音效。
(1)檢測觸摸位置代碼并播放音頻:
void TouchDetect()
{
u16 Va[3] = 0;
u8 i = 0;
for(i = 0;i < 3;i++)
{
Va[i] = Read_Dgus(0x0016 + i);
if(Va[0] == 0x5A01)
{
}
else
{
break;
}
}
if(i != 0) //第一次點擊進入
{
u16 play[2] = {0x0001, 0x4000};
touchAnimationFlag = 1;
touchAnimationCnt = 0;
touchPosX = Va[1];
touchPosY = Va[2];
write_dgus_vp(0x00A0, play, 2);
}
}
(2)觸摸特效顯示的代碼如下:
void TouchStart()
{
if(touchAnimationFlag == 1)
{
if(touchAnimationCnt == 0)
{
Write_Dgus(0x5011, touchPosX - 100);
Write_Dgus(0x5012, touchPosY - 100);
}
Write_Dgus(0x5000, touchAnimationCnt);
touchAnimationCnt++;
if(touchAnimationCnt == 6)
{
touchAnimationFlag = 0;
Write_Dgus(0x5011, 1024);
Write_Dgus(0x5012, 600);
}
}
}
實現貓糧自動出糧
接下來是通過屏幕設定對應的參數,然后數據通過ESP32傳輸到貓糧控制器,實現貓糧的自動出糧功能,具體代碼如下所示:
//獲取按鍵狀態
void get_key_status()
{
int i = 0;
//u16 Va=Read_Dgus(addr);
u16 Va=Read_Dgus(0x1000);
if(Va != 0x0000)
{
//狀態頁
if(Va == 0x0103) //放置g數量
{
u16 switchpage[2] = {0x5A01, 19};
backPage = 1; //返回狀態頁
Write_Dgus(0x4000 + 0, setNum % 10);
Write_Dgus(0x4000 + 2, setNum / 10 % 10);
Write_Dgus(0x4000 + 4, setNum / 100 % 10);
Write_Dgus(0x4000 + 6, setNum / 1000 % 10);
write_dgus_vp(0x0084, switchpage, 2);
}
else if(Va == 0x0102)
{
OneSendData3(placeGramNum); //放置一次糧
}
else if(Va == 0x0101) //設置頁面
{
u16 switchpage[2] = {0x5A01, 3};
for(i = 0;i < 6;i++)
{
if(i == 0)
{
Write_Dgus(0x3070 + i * 0x10 + 0, currentTime[i] % 10);
Write_Dgus(0x3070 + i * 0x10 + 2, currentTime[i] / 10 % 10);
Write_Dgus(0x3070 + i * 0x10 + 4, currentTime[i] / 100 % 10);
Write_Dgus(0x3070 + i * 0x10 + 6, currentTime[i] / 1000 % 10);
}
else
{
Write_Dgus(0x3070 + i * 0x10 + 0, currentTime[i] % 10);
Write_Dgus(0x3070 + i * 0x10 + 2, currentTime[i] / 10 % 10);
}
}
write_dgus_vp(0x0084, switchpage, 2); //進入設置頁
}
else if(Va == 0x0100) //記錄頁面
{
u16 switchpage[2] = {0x5A01, 2};
for(i = 0;i < 6;i++)
{
if(i == 0)
{
Write_Dgus(0x2000 + i * 0x10 + 0, eatFeedList[0][i] % 10);
Write_Dgus(0x2000 + i * 0x10 + 2, eatFeedList[0][i] / 10 % 10);
Write_Dgus(0x2000 + i * 0x10 + 4, eatFeedList[0][i] / 100 % 10);
Write_Dgus(0x2000 + i * 0x10 + 6, eatFeedList[0][i] / 1000 % 10);
}
else
{
Write_Dgus(0x2000 + i * 0x10 + 0, eatFeedList[0][i] % 10);
Write_Dgus(0x2000 + i * 0x10 + 2, eatFeedList[0][i] / 10 % 10);
}
}
write_dgus_vp(0x0084, switchpage, 2); //進入記錄頁
}
//記錄頁
else if(Va == 0x0201) //記錄頁面上一個
{
if(lookEatCnt > 0)
{
lookEatCnt--;
for(i = 0;i < 6;i++)
{
if(i == 0)
{
Write_Dgus(0x2000 + i * 0x10 + 0, eatFeedList[lookEatCnt][i] % 10);
Write_Dgus(0x2000 + i * 0x10 + 2, eatFeedList[lookEatCnt][i] / 10 % 10);
Write_Dgus(0x2000 + i * 0x10 + 4, eatFeedList[lookEatCnt][i] / 100 % 10);
Write_Dgus(0x2000 + i * 0x10 + 6, eatFeedList[lookEatCnt][i] / 1000 % 10);
}
else
{
Write_Dgus(0x2000 + i * 0x10 + 0, eatFeedList[lookEatCnt][i] % 10);
Write_Dgus(0x2000 + i * 0x10 + 2, eatFeedList[lookEatCnt][i] / 10 % 10);
}
}
}
}
else if(Va == 0x0202) //記錄頁面下一個
{
if(lookEatCnt < eatCnt - 1)
{
lookEatCnt++;
for(i = 0;i < 6;i++)
{
if(i == 0)
{
Write_Dgus(0x2000 + i * 0x10 + 0, eatFeedList[lookEatCnt][i] % 10);
Write_Dgus(0x2000 + i * 0x10 + 2, eatFeedList[lookEatCnt][i] / 10 % 10);
Write_Dgus(0x2000 + i * 0x10 + 4, eatFeedList[lookEatCnt][i] / 100 % 10);
Write_Dgus(0x2000 + i * 0x10 + 6, eatFeedList[lookEatCnt][i] / 1000 % 10);
}
else
{
Write_Dgus(0x2000 + i * 0x10 + 0, eatFeedList[lookEatCnt][i] % 10);
Write_Dgus(0x2000 + i * 0x10 + 2, eatFeedList[lookEatCnt][i] / 10 % 10);
}
}
}
}
//設置頁
else if(Va == 0x0302)
{
if(timeMode == 1)
{
timeMode = 0;
Write_Dgus(0x3A12, 139);
}
}
else if(Va == 0x0303)
{
if(timeMode == 0)
{
timeMode = 1;
Write_Dgus(0x3A12, 242);
}
}
else if(Va >= 0x0304 && Va <= 0x0309)
{
u16 switchpage[2] = {0x5A01, 19};
backPage = 3;
backNum = Va;
setNum = timrIntervalHour[Va - 0x0304];
Write_Dgus(0x4000 + 0, setNum % 10);
Write_Dgus(0x4000 + 2, setNum / 10 % 10);
Write_Dgus(0x4000 + 4, setNum / 100 % 10);
Write_Dgus(0x4000 + 6, setNum / 1000 % 10);
write_dgus_vp(0x0084, switchpage, 2);
}
else if(Va >= 0x030A && Va <= 0x030F)
{
u16 switchpage[2] = {0x5A01, 19};
backPage = 3;
backNum = Va;
setNum = currentTime[Va - 0x030A];
Write_Dgus(0x4000 + 0, setNum % 10);
Write_Dgus(0x4000 + 2, setNum / 10 % 10);
Write_Dgus(0x4000 + 4, setNum / 100 % 10);
Write_Dgus(0x4000 + 6, setNum / 1000 % 10);
write_dgus_vp(0x0084, switchpage, 2);
}
//調節數據頁
else if(Va == 0x0400) //確定
{
u16 switchpage[2] = {0x5A01, 0x0000};
switchpage[1] = backPage;
if(backPage == 1) //返回狀態頁
{
placeGramNum = setNum;
Write_Dgus(0x1140 + 0, placeGramNum % 10);
Write_Dgus(0x1140 + 2, placeGramNum / 10 % 10);
}
else if(backPage == 3)
{
if(backNum >= 0x0304 && backNum <= 0x0309)
{
u16 select = 0;
select = (backNum - 0x0304) * 0x10;
timrIntervalHour[backNum - 0x0304] = setNum;
Write_Dgus(0x3010 + select + 0, setNum % 10);
Write_Dgus(0x3010 + select + 2, setNum / 10 % 10);
}
else if(backNum >= 0x030A && backNum <= 0x030F)
{
u16 select = 0;
select = (backNum - 0x0304) * 0x10;
currentTime[backNum - 0x030A] = setNum;
if(backNum == 0x030A)
{
Write_Dgus(0x3010 + select + 0, setNum % 10);
Write_Dgus(0x3010 + select + 2, setNum / 10 % 10);
Write_Dgus(0x3010 + select + 4, setNum / 100 % 10);
Write_Dgus(0x3010 + select + 6, setNum / 1000 % 10);
}
else
{
Write_Dgus(0x3010 + select + 0, setNum % 10);
Write_Dgus(0x3010 + select + 2, setNum / 10 % 10);
}
}
}
write_dgus_vp(0x0084, switchpage, 2);
}
else if(Va == 0x0401) //退出
{
u16 switchpage[2] = {0x5A01, 0x0000};
switchpage[1] = backPage;
write_dgus_vp(0x0084, switchpage, 2);
}
else if(Va == 0x0402) //數值增加
{
setNum++;
Write_Dgus(0x4000 + 0, setNum % 10);
Write_Dgus(0x4000 + 2, setNum / 10 % 10);
Write_Dgus(0x4000 + 4, setNum / 100 % 10);
Write_Dgus(0x4000 + 6, setNum / 1000 % 10);
}
else if(Va == 0x0403) //數值減少
{
if(setNum > 0)
setNum--;
Write_Dgus(0x4000 + 0, setNum % 10);
Write_Dgus(0x4000 + 2, setNum / 10 % 10);
Write_Dgus(0x4000 + 4, setNum / 100 % 10);
Write_Dgus(0x4000 + 6, setNum / 1000 % 10);
}
Write_Dgus(0x1000, 0);
}
}
-
控制系統
+關注
關注
41文章
6604瀏覽量
110576 -
監測
+關注
關注
2文章
3593瀏覽量
44505 -
觸摸
+關注
關注
7文章
198瀏覽量
64211 -
開源
+關注
關注
3文章
3309瀏覽量
42471
發布評論請先 登錄
相關推薦
評論