//
// NB! This is a file generated from the .4Dino file, changes will be lost
//     the next time the .4Dino file is built
//

// When using Arduino, you need to set the correct include file and class initialization to match your display.
// To save the hassle of doing this is manually, it is recommended to use Workshop4.

#include "gfx4desp32_ESP32_P4_70CT.h"

gfx4desp32_ESP32_P4_70CT gfx = gfx4desp32_ESP32_P4_70CT();

#include "KeyboardDemoConst.h"    // Note. This file will not be created if there are no generated graphics

// Uncomment if using GC* in program flash.
#include "KeyboardDemoGCx.h"     // Note. This file will be generated when graphics destination program flash

void setup()
{
  gfx.begin();
  gfx.Cls();
  gfx.ScrollEnable(false);
  gfx.BacklightOn(true);
  gfx.Orientation(PORTRAIT);
  gfx.SmoothScrollSpeed(5);
  gfx.TextColor(WHITE, BLACK); gfx.Font(2);  gfx.TextSize(1);
// Uncomment one of the three followin statements depending on the type of graphics file you are using GCI, GCJ, or GC* in program flash.
//gfx.Open4dGFX("KeyboardDemo"); // Opens DAT and GCI files for read using filename without extension.
//gfx.Open4dGFX("KeyboardDemo.gcj"); // Opens GCJ file for read using complete filename.
  gfx.Open4dGFX(KeyboardDemo, KeyboardDemo_size); // Opens GCJ from program space using array name and size
//gfx.Open4dGFX(KeyboardDemo_dat, KeyboardDemo_dat_size, KeyboardDemo_gci, KeyboardDemo_gci_size); // Opens DAT/GCI from program space using array name and size
  gfx.touch_Set(TOUCH_ENABLE);                // Global touch enabled
  gfx.imageTouchEnableRange(iKeyboard1_0, iKeyboard1_11, true, KEYPAD) ;   // init_Keyboard1 enable touch on keys (on Form1)
  gfx.imageTouchEnable(iKeyboard1, false) ;                  // init_Keyboard1 disable touch on full keyboard (on Form1)
  gfx.UserImages(iKeyboard1,0) ;                             // init_Keyboard1 show initially, if required (on Form1)
} // end Setup **do not alter, remove or duplicate this line**

void loop()
{
  // put your main code here, to run repeatedly:
  int itouched, val, key;
  if(gfx.touch_Update())
  {
    itouched = gfx.imageTouched() ;
    switch (itouched)
    {                                                         // start touched selection **do not alter, remove or duplicate this line**
      // case statements for Knobs and Sliders go here
      default :                                               // end touched selection **do not alter, remove or duplicate this line**
        int button = gfx.ImageTouchedAuto();    // use default for keyboards and buttons
        val = gfx.getImageValue(button);
        switch (button)
        {                                                     // start button selection **do not alter, remove or duplicate this line**
          // case, one for each button or keyboard, default should end up as -1
          case iKeyboard1_0 ... iKeyboard1_11 :                                      // process_Keyboard1 process Keyboard (on Form1)
            key  = gfx.DecodeKeypad(iKeyboard1, button, iKeyboard1keystrokes, oKeyboard1);
            // process key pressed
            switch (key) {

              case '0' ... '9':
              case '*':
                gfx.putch(key);
                break;
              default: // must be Clear since it is the only other key
                // Pattern is ignored on this platform
                gfx.RectangleFilled(0, 0, 239, 154, BLACK) ;  // Rectangle1
                gfx.MoveTo(0,0);

                break;
            }
            break;
          default:
            break ;

        }                                                     // end button selection **do not alter, remove or duplicate this line**
    }
  }
}

