//
// 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 "KnobAndDigitsDemoConst.h"    // Note. This file will not be created if there are no generated graphics

// Uncomment if using GC* in program flash.
 #include "KnobAndDigitsDemoGCx.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("KnobAndDigitsDemo"); // Opens DAT and GCI files for read using filename without extension.
//gfx.Open4dGFX("KnobAndDigitsDemo.gcj"); // Opens GCJ file for read using complete filename.
gfx.Open4dGFX(KnobAndDigitsDemo, KnobAndDigitsDemo_size); // Opens GCJ from program space using array name and size
//gfx.Open4dGFX(KnobAndDigitsDemo_dat, KnobAndDigitsDemo_dat_size, KnobAndDigitsDemo_gci, KnobAndDigitsDemo_gci_size); // Opens DAT/GCI from program space using array name and size
  gfx.touch_Set(TOUCH_ENABLE);                // Global touch enabled

  gfx.imageTouchEnable(iSmartKnob1, true) ;                  // init_SmartKnob1 enable touch of widget (on Form1)

  // Center widgets to accomodate all screen sizes
  int disp_Width = gfx.getWidth();
  int disp_Height = gfx.getHeight();
  int led_Width = gfx.imageGetWord(iLeddigits1, IMAGE_WIDTH);
  int led_Height = gfx.imageGetWord(iLeddigits1, IMAGE_HEIGHT);
  int knob_Width = gfx.imageGetWord(iSmartKnob1, IMAGE_WIDTH);
  int knob_Height = gfx.imageGetWord(iSmartKnob1, IMAGE_HEIGHT);
  gfx.imageSetWord(iLeddigits1, IMAGE_XPOS, (disp_Width / 2) - (led_Width / 2));
  gfx.imageSetWord(iLeddigits1, IMAGE_YPOS, (disp_Height / 2) - led_Height - 30);
  gfx.imageSetWord(iiLeddigits1, IMAGE_XPOS, (disp_Width / 2) - (led_Width / 2));
  gfx.imageSetWord(iiLeddigits1, IMAGE_YPOS, (disp_Height / 2)- led_Height - 30);
  gfx.imageSetWord(iSmartKnob1, IMAGE_XPOS, (disp_Width / 2) - (knob_Width / 2));
  gfx.imageSetWord(iSmartKnob1, IMAGE_YPOS, (disp_Height / 2) + 30);
  // end of centre widgets

  gfx.UserImages(iSmartKnob1,0) ;                            // init_SmartKnob1 show initially, if required (on Form1)

  gfx.UserImage(iLeddigits1);                                // init_Leddigits1 show all digits at 0, only do this once
} // end Setup **do not alter, remove or duplicate this line**

void loop()
{
  // put your main code here, to run repeatedly:
  int itouched, val ;
  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
      case iSmartKnob1 :                                      // process_SmartKnob1 process (on Form1)
        val = gfx.imageAutoKnob(iSmartKnob1, gfx.touch_GetX(), gfx.touch_GetY(), 45, 315, 0, 100);
        // process smart knob based on val
        gfx.LedDigitsDisplay(val, iiLeddigits1, 3, 1, 159, 0) ;  // Leddigits1
        break ;
      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
        }                                                     // end button selection **do not alter, remove or duplicate this line**
    }
  }
}

