/********************************************/
/*Application Screen                        */
/*PIC32MX795F512L-80I/PF                    */
/********************************************/

#include <xc.h>
#include "App_Screen.h"
#include "HX8357B.h"
#include "Strings.h"
#include "REN71V30.h"
#include "Binary2ASCIIHex.h"
#include "Touch.h"
#include "Delay.h"

void App_Screen(void)
{    
    //Draw header
    Header();
    HX8357B_Rect(0, 480, 40, 42, 0x0);     
    
    back_color = 0xffff;
    
    //Write command for DSP
    REN71V30_WR(0, 0x00);
    
    //System is ready to exchange data with the DSP 
    Write_String(10, 50, 0x105d, 74, SYSTEM_STRING, SYSTEM_STRING_OFFSET);
    
    //System is ready to exchange data with the DSP 
    Write_String(10, 100, 0x105d, 75, SYSTEM_STRING, SYSTEM_STRING_OFFSET);
    
    //System is ready to exchange data with the DSP 
    Write_String(10, 150, 0x105d, 77, SYSTEM_STRING, SYSTEM_STRING_OFFSET);
    
    //Button
    HX8357B_Rect(150, 340, 185, 230, 0x0);
    HX8357B_Rect(145, 335, 180, 225, 0x2CED);
    back_color = 0x2CED;
    Write_String(200, 190, 0, 76, SYSTEM_STRING, SYSTEM_STRING_OFFSET);
    back_color = 0xffff;
    REN71V30_WR(2, 0);
    
    int a = 0;
    int i;
    
    while (1)
    {
        REN71V30_RD(0);
        Binary2ASCIIHex(mdata_71v30);
        WriteChar(10, 75, d_hex[1], 0x0);
        WriteChar(25, 75, d_hex[0], 0x0);

        REN71V30_RD(1);
        Binary2ASCIIHex(mdata_71v30);
        WriteChar(10, 125, d_hex[1], 0x0);
        WriteChar(25, 125, d_hex[0], 0x0);
          
        REN71V30_RD(2);
        Binary2ASCIIHex(mdata_71v30);
        WriteChar(10, 175, d_hex[1], 0x0);
        WriteChar(25, 175, d_hex[0], 0x0);
        
        
//        REN71V30_WR(2, 1);
//        for(i=0;i<1000;i++)
//        {
//            Delay(30000);
//        }
//        REN71V30_WR(2, 0);
//        for(i=0;i<1000;i++)
//        {
//            Delay(30000);
//        }
//          
        //Get file button
        if((data_x > 145 ) && (data_x < 335) && (data_y < 225) && (data_y > 180))
        {
            for(i=0;i<1000;i++)
            {
                Delay(30000);
            }
            if(a == 0)
            {
                REN71V30_WR(2, 1);
                a = 1;
            }
            else
            {
                REN71V30_WR(2, 0);
                a = 0;
            }
        
            
                     
        }
    }
}

