Announcement

Collapse
No announcement yet.

gen4-iod Workshop 4 how to change Form?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • gen4-iod Workshop 4 how to change Form?

    Hi,

    I'm trying to do this on a GEN4-IOD-32T: user click a button on Form1, then it should change the viewed page to Form2.

    HTML Code:
    gfx.Open4dGFX("filename");   // Opens filename.dat
    gfx.imageTouchEnable(iWinbutton1, true); // Enable Button 1
    
    if (gfx.touch_Update()) { // Update touch parameter values
    if (gfx.touch_GetPen() == TOUCH_PRESSED) {
    switch(gfx.imageTouched()){
    case iWinbutton1:
    gfx.println("Button 1 how can I change the screen to Form2 from here?");
    break;
    }
    }
    }
    

  • #2
    Hi,

    The best way to do this is with functions that have all the gfx objects commands that can be called.

    Code:
    #include "ESP8266WiFi.h"
    #include "GFX4d.h"
    
    GFX4d gfx = GFX4d();
    
    #include "NoName1Const.h" // Note. This file will not be created if there are no generated graphics
    int frame;
    int state;
    int currentForm = 1;
    
    void setup()
    {
    gfx.begin();
    gfx.Cls();
    gfx.ScrollEnable(false);
    gfx.BacklightOn(true);
    gfx.Orientation(PORTRAIT);
    gfx.SmoothScrollSpeed(5);
    gfx.touch_Set(TOUCH_ENABLE);
    gfx.TextColor(WHITE, BLACK); gfx.Font(2); gfx.TextSize(1);
    gfx.Open4dGFX("NoName1"); // Opens DAT and GCI files for read using filename without extension. Note! Workshop generates files with Short filenames
    gfx.imageTouchEnable(iWinbutton1, true); // Enable Button 1
    gfx.UserImages(iWinbutton1,0) ; // Winbutton1 show initialy, if required
    } // end Setup **do not alter, remove or duplicate this line**
    
    void loop()
    {
    if (gfx.touch_Update()) { // Update touch parameter values
    if (gfx.touch_GetPen() == TOUCH_PRESSED) {
    switch(gfx.imageTouched()){
    case iWinbutton1:
    ShowForm2();
    break;
    }
    }
    }
    if(currentForm == 2){
    // code for form 2
    }
    // put your main code here, to run repeatedly:
    yield(); // Required for ESP
    }
    
    void ShowForm2(){
    gfx.UserImages(iGauge1, frame) ; // where frame is 0 to 100 (for a displayed 0 to 100)
    gfx.UserImages(iGauge2, frame) ; // where frame is 0 to 100 (for a displayed 0 to 100)
    currentForm = 2;
    }
    
    void ShowForm3(){
    gfx.UserImages(iCoolgauge1, frame) ; // where frame is 0 to 100 (for a displayed 0 to 100)
    currentForm = 3;
    }
    You can then use the currentForm variable to keep track of which form you have selected and run code for when that form is selected.

    I hope this helps

    Best regards

    Paul

    Comment

    Working...
    X