//============================================================================
// Some demo routines for Crystalfontz CFA10099 EVE accelerated displays.
//===========================================================================

#include <Arduino.h>
#include <SPI.h>
#include <stdarg.h>

// Definitions for our display.
#include "CFA10109_defines.h"
#include "CFAF240320A0_024Sx.h"

#include "LEK_GPS_240X320.h"
#include "LEK_DISH.h"

#if BUILD_SD
#include <SD.h>
#endif

#include "EVE_defines.h"
#include "EVE_base.h"
#include "EVE_draw.h"
//Demonstrations of various EVE functions
#include "demos.h"

extern int gpsSatellites;

//============================================================================
#if (0 != LOGO_DEMO)

//Remember where we put the logo image data in RAM_G
uint32_t
  Logo_RAM_G_Address;

//Remember how big the Logo image is.
uint32_t
  Logo_Width;
uint32_t
  Logo_Height;


uint16_t Initialize_Logo_Demo(uint16_t FWol,
                              uint32_t *RAM_G_Unused_Start)
  {


  //Remember where we put the logo in RAM_G so we can access it later.
  Logo_RAM_G_Address=*RAM_G_Unused_Start;
    
//----------------------BACKGND LOGO-------------------------------
  //Load and INFLATE our 8-bit A2R2G2B2 (lossless) image into RAM_G
  //You have to know before hand how big the logo is. The INFLATE
  //is not aware of the content or format of the data.
  Logo_Width=BACKGND_LOGO_WIDTH_ARGB2;
  Logo_Height=BACKGND_LOGO_HEIGHT_ARGB2;


  FWol=EVE_Inflate_to_RAM_G(FWol,
                            LEK_GPS_240X320_LOGO,
                            BACKGND_LOGO_SIZE_ARGB2,
                            RAM_G_Unused_Start);
  //Pass our updated offset back to the caller
  return(FWol);
  }
//----------------------------------------------------------------------------


uint16_t Add_Logo_To_Display_List(uint16_t FWol)
  {
  //========== PUT LOGO ON SCREEN ==========
  // Set the drawing color to white
  FWol=EVE_Cmd_Dat_0(FWol, EVE_ENC_COLOR_RGB(0xFF,0xFF,0xFF));
  //Solid color -- not transparent
  FWol=EVE_Cmd_Dat_0(FWol, EVE_ENC_COLOR_A(255));
  //Point to the uncompressed logo in RAM_G
  FWol=EVE_Cmd_Dat_0(FWol, EVE_ENC_BEGIN(EVE_BEGIN_BITMAPS));
  FWol=EVE_Cmd_Dat_0(FWol, EVE_ENC_BITMAP_SOURCE(Logo_RAM_G_Address));

#if 1==LOGO_PNG_0_ARGB2_1
  //ARGB2 comes in as EVE_FORMAT_ARGB2, 1 byte per pixel
  FWol=EVE_Cmd_Dat_0(FWol, EVE_ENC_BITMAP_LAYOUT(EVE_FORMAT_ARGB2,Logo_Width,Logo_Height));
#endif // 1==LOGO_PNG_0_ARGB2_1

  //Render the bitmap to the current frame


  FWol=EVE_Cmd_Dat_0(FWol,
                     EVE_ENC_VERTEX2F((LCD_WIDTH-Logo_Width)*(16/2),
                            (LCD_HEIGHT-Logo_Height)*(16/2)));   
                         
  FWol=EVE_Cmd_Dat_0(FWol, EVE_ENC_END());

  //Pass our updated offset back to the caller
  return(FWol);
  }
//------------------------------------------------------------------------------------------------------------------

  #endif // (0 != LOGO_DEMO)





//===========================================================================================================
#if (0 != IMAGE_DEMO)

//Remember where we put the logo image data in RAM_G
uint32_t
  Image_RAM_G_Address;

//Remember how big the Logo image is.
uint32_t
  Image_Width;
uint32_t
  Image_Height;


uint16_t Initialize_Image_Demo(uint16_t FWol,
                              uint32_t *RAM_G_Unused_Start)
  {


  //Remember where we put the logo in RAM_G so we can access it later.
  Image_RAM_G_Address=*RAM_G_Unused_Start;

//----------------------IMAGE LOAD-------------------------------
  //Load and INFLATE our 8-bit A2R2G2B2 (lossless) image into RAM_G
  //You have to know before hand how big the logo is. The INFLATE
  //is not aware of the content or format of the data.
  Image_Width=DISH_LOGO_WIDTH_ARGB2;
  Image_Height=DISH_LOGO_HEIGHT_ARGB2;


  FWol=EVE_Inflate_to_RAM_G(FWol,
                            LEK_DISH_LOGO,
                            DISH_LOGO_SIZE_ARGB2,
                            RAM_G_Unused_Start);
  //Pass our updated offset back to the caller
  return(FWol);

  
  }
  

  uint16_t Add_Image_To_Display_List(uint16_t FWol)
  {
  //========== PUT IMAGE ON SCREEN ==========
  // Set the drawing color to white
  FWol=EVE_Cmd_Dat_0(FWol, EVE_ENC_COLOR_RGB(0xFF,0xFF,0xFF));
  //Solid color -- not transparent
  FWol=EVE_Cmd_Dat_0(FWol, EVE_ENC_COLOR_A(255));
  //Point to the uncompressed logo in RAM_G

 //gpsSatellites = 6;
 

//*************************** 1 *********************************************

if (gpsSatellites == 0) {

  

        return(FWol);
   
    }
 else {
  
  FWol=EVE_Cmd_Dat_0(FWol, EVE_ENC_BEGIN(EVE_BEGIN_BITMAPS));
  FWol=EVE_Cmd_Dat_0(FWol, EVE_ENC_BITMAP_SOURCE(Image_RAM_G_Address));
  
   
  //ARGB2 comes in as EVE_FORMAT_ARGB2, 1 byte per pixel
  FWol=EVE_Cmd_Dat_0(FWol, EVE_ENC_BITMAP_LAYOUT(EVE_FORMAT_ARGB2,Image_Width,Image_Height));

  //Render the bitmap to the current frame

  FWol=EVE_Cmd_Dat_0(FWol,
                     EVE_ENC_VERTEX2F(225,3400));                             
                         
  FWol=EVE_Cmd_Dat_0(FWol, EVE_ENC_END());

   }
  
//***************************** 2 *********************************************

  if (gpsSatellites >= 2) {
  
  
  FWol=EVE_Cmd_Dat_0(FWol, EVE_ENC_BEGIN(EVE_BEGIN_BITMAPS));
  FWol=EVE_Cmd_Dat_0(FWol, EVE_ENC_BITMAP_SOURCE(Image_RAM_G_Address));
  FWol=EVE_Cmd_Dat_0(FWol, EVE_ENC_BITMAP_LAYOUT(EVE_FORMAT_ARGB2,Image_Width,Image_Height));
  FWol=EVE_Cmd_Dat_0(FWol,
                     EVE_ENC_VERTEX2F(825,3400));// location,location,location :>)                             
                         
  FWol=EVE_Cmd_Dat_0(FWol, EVE_ENC_END());

  }
  
 //*********************************************************************************

//***************************** 3 *********************************************

  if (gpsSatellites >= 3) {  
  
  FWol=EVE_Cmd_Dat_0(FWol, EVE_ENC_BEGIN(EVE_BEGIN_BITMAPS));
  FWol=EVE_Cmd_Dat_0(FWol, EVE_ENC_BITMAP_SOURCE(Image_RAM_G_Address));
  FWol=EVE_Cmd_Dat_0(FWol, EVE_ENC_BITMAP_LAYOUT(EVE_FORMAT_ARGB2,Image_Width,Image_Height));
  FWol=EVE_Cmd_Dat_0(FWol,
                     EVE_ENC_VERTEX2F(1425,3400));// location,location,location :>)                             
                         
  FWol=EVE_Cmd_Dat_0(FWol, EVE_ENC_END());

  }
  
 //*********************************************************************************

//***************************** 4 *********************************************

  if (gpsSatellites >= 4) {  
  
  FWol=EVE_Cmd_Dat_0(FWol, EVE_ENC_BEGIN(EVE_BEGIN_BITMAPS));
  FWol=EVE_Cmd_Dat_0(FWol, EVE_ENC_BITMAP_SOURCE(Image_RAM_G_Address));
  FWol=EVE_Cmd_Dat_0(FWol, EVE_ENC_BITMAP_LAYOUT(EVE_FORMAT_ARGB2,Image_Width,Image_Height));
  FWol=EVE_Cmd_Dat_0(FWol,
                     EVE_ENC_VERTEX2F(2025,3400));// location,location,location :>)                             
                         
  FWol=EVE_Cmd_Dat_0(FWol, EVE_ENC_END());

  }
  
 //*********************************************************************************


//***************************** 5 *********************************************

  if (gpsSatellites >= 5) {

  FWol=EVE_Cmd_Dat_0(FWol, EVE_ENC_BEGIN(EVE_BEGIN_BITMAPS));
  FWol=EVE_Cmd_Dat_0(FWol, EVE_ENC_BITMAP_SOURCE(Image_RAM_G_Address));
  FWol=EVE_Cmd_Dat_0(FWol, EVE_ENC_BITMAP_LAYOUT(EVE_FORMAT_ARGB2,Image_Width,Image_Height));
  FWol=EVE_Cmd_Dat_0(FWol,
                     EVE_ENC_VERTEX2F(2625,3400));// location,location,location :>)                             
                         
  FWol=EVE_Cmd_Dat_0(FWol, EVE_ENC_END());

  }
  
 //*********************************************************************************



//******************************** + **********************************************

   if (gpsSatellites >= 6) { 
       
        
        //Set font color to black
        FWol=EVE_Cmd_Dat_0(FWol,
                             EVE_ENC_COLOR_RGB(0x00,0x00,0x00));                        

                // display # of satellites from GPS
        FWol=EVE_PrintF(FWol,
                          214,  //X
                          228,  //Y
                          31,         //Font
                          EVE_OPT_CENTER, //Options
                          "",
                          "+");  
   }                     
//***********************************************************************************
 



 
  //Pass our updated offset back to the caller
  return(FWol);

  
  }
//----------------------------------------------------------------------------



  #endif // (0 != IMAGE_DEMO)
//============================================================================
