[Award-winning case] Intelligent Cat Food Control System

——From DWIN Developer Forum

In this issue, we will introduce to you the award-winning open source case from the DWIN Developer Forum: Intelligent Cat Food Control System. Engineers used the DWIN smart screen to monitor the temperature, humidity, and remaining amount of cat food, and to save the cat's food eating records. They also uniquely designed a set of ink painting style UI, as well as an ink click effect when touched by a finger, to enhance the visual perception of touch feedback.

Introduction:

1.UI picture material

DWIN smart screen completes UI development based on pictures, audio and other materials need to be prepared in advance according to the screen display content.

asv (2)

2.Interface development

The DGUS software restores the UI effect through layer overlay, combines the prepared materials into a complete picture in the DGUS software, and sets the display and touch functions.

asv (1)

3. Implement click effects and sound effects

The touch position is obtained through the 51 program, the pressing effect follows the movement of the finger, and the key accompaniment sound effect is also achieved.

(1) Detect touch location code and play audio:

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)  //First click to enter

    {

        u16 play[2] = {0x0001, 0x4000};

        touchAnimationFlag = 1;

        touchAnimationCnt = 0;

        touchPosX = Va[1];

        touchPosY = Va[2];

        write_dgus_vp(0x00A0, play, 2);

    }

}

 

(2) The code for touch effect display is as follows:

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

        }

    }

    

}

 

4. The next step is to set the corresponding parameters through the screen, and then transmit the data to the cat food controller through ESP32 to realize the automatic feeding function of cat food. The specific code is as follows:

//Get button status

void get_key_status()

{

    int i = 0;

    //u16 Va=Read_Dgus(addr);

    u16  Va=Read_Dgus(0x1000);

    if(Va != 0x0000)

    {        

        //Status page   

        if(Va == 0x0103)    //Place the number of g

        {

            u16 switchpage[2] = {0x5A01, 19};

            setNum = placeGramNum;

            backPage = 1;   //Return to status page

            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); //Place cat foodonce

        }

        else if(Va == 0x0101)   //Setting page

        {

            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);    //Enter the settings page

        }

        else if(Va == 0x0100)   //Record page

        {

            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);    //Enter record page

        }

        //Record page

        else if(Va == 0x0201)   //Record page previous page

        {

            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)   //Record page next page

        {

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

                    }

                }

            }

        }

        //Setting page

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

        }

        //Adjust data page

        else if(Va == 0x0400)   //Confirm

        {   

            u16 switchpage[2] = {0x5A01, 0x0000};

            switchpage[1] = backPage;

            if(backPage == 1)   //Return to status page

            {

                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)   //Back

        {   

            u16 switchpage[2] = {0x5A01, 0x0000};

            switchpage[1] = backPage;

            write_dgus_vp(0x0084, switchpage, 2);

        }

        else if(Va == 0x0402)   //Numerical increase

        {

            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)   //Numerical decrease

        {

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

    }

}


Post time: Sep-19-2023