【开源获奖案例】智能猫粮控制系统

描述

本期为大家推送迪文开发者论坛的获奖开源案例:智能猫粮控制系统。工程师使用迪文智能屏实现了监测猫粮的温度、湿度、余量,保存猫咪吃粮记录等功能,并别出心裁的设计了一套水墨画风格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};

 

 

            setNum = placeGramNum;

 

 

            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);

 

 

    }

 

 

}

 

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分