No announcement yet.

Switch forms with the 4D Workshop IDE (Extended Graphics)

  • Filter
  • Time
  • Show
Clear All
new posts

  • Switch forms with the 4D Workshop IDE (Extended Graphics)

    i work with a 4Duino and the normal 4D Workshop IDE (Extended Graphics), my problem is:

    How can i switch forms with a winbutton (or any other button) without the feature of creating events (acitivate x form) in my software.

    Regards Julian

  • #2
    Dear Schwendele,

    Thank you for using our products. Can you try this code? Attached is the Zipped Project file.

    // Define LOG_MESSAGES to a serial port to send SPE errors messages to. Do not use the same Serial port as SPE
    //#define LOG_MESSAGES Serial

    %%Display%%.DefineResetLine ; // *Replaced* at compile time with define for reset line connected to the display
    %%Display%%.DefineDisplaySerialx ; // *Replaced* at compile time with define the Serial Port connected to the display

    #include "Form-WinbuttonConst.h"

    %%Display%%.IncludeSerial_4DLib ; // *Replaced* at compile time with an Include the Serial Library relevant to the display
    %%Display%%.IncludeSerial_Const4D ; // *Replaced* at compile time with an Include the Constants file relevant to the display

    %%Display%%.AssignDisplaySerialtoLibrary ; // *Replaced* at compile time with an Assign of the correct Serial port to the correct library

    // Uncomment to use ESP8266
    //#define ESPRESET 17
    //#include <SoftwareSerial.h>
    //#define ESPserial SerialS
    //SoftwareSerial SerialS(8, 9) ;
    // Uncomment next 2 lines to use ESP8266 with ESP8266 library from
    //#include "ESP8266.h"
    //ESP8266 wifi(SerialS,19200);

    // routine to handle Serial errors
    void mycallback(int ErrCode, unsigned char Errorbyte)
    #ifdef LOG_MESSAGES
    const char *Error4DText[] = {"OK\0", "Timeout\0", "NAK\0", "Length\0", "Invalid\0"} ;
    LOG_MESSAGES.print(F("Serial 4D Library reports error ")) ;
    LOG_MESSAGES.print(Error4DText[ErrCode]) ;
    if (ErrCode == Err4D_NAK)
    LOG_MESSAGES.print(F(" returned data= ")) ;
    LOG_MESSAGES.println(Errorbyte) ;
    LOG_MESSAGES.println(F("")) ;
    while (1) ; // you can return here, or you can loop
    // Pin 13 has an LED connected on most Arduino boards. Just give it a name
    #define led 13
    while (1)
    digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
    delay(200); // wait for a second
    digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
    delay(200); // wait for a second
    // end of routine to handle Serial errors

    word hndl ;
    int n;
    int status;
    int x,y;

    void setup()
    // Ucomment to use the Serial link to the PC for debugging
    // Serial.begin(115200) ; // serial to USB port
    // Note! The next statement will stop the sketch from running until the serial monitor is started
    // If it is not present the monitor will be missing the initial writes
    // while (!Serial) ; // wait for serial to be established

    pinMode(RESETLINE, OUTPUT); // Display reset pin
    %%Display%%.Toggle_Reset_On ; // *Replaced* at compile time with correct rest on logic for the attached display
    delay(100); // wait for it to be recognised
    %%Display%%.Toggle_Reset_Off ; // *Replaced* at compile time with correct rest off logic for the attached display
    // Uncomment when using ESP8266
    // pinMode(ESPRESET, OUTPUT); // ESP reset pin
    // digitalWrite(ESPRESET, 1); // Reset ESP
    // delay(100); // wait for it t
    // digitalWrite(ESPRESET, 0); // Release ESP reset
    delay(3000) ; // give display time to startup

    // now start display as Serial lines should have 'stabilised'
    %%Display%%.DisplaySerial.Begin_Speed ; // *Replaced* at compile time with command to start the serial port at the correct speed
    Display.TimeLimit4D = 5000 ; // 5 second timeout on all commands
    Display.Callback4D = mycallback ;

    // uncomment if using ESP8266
    // ESPserial.begin(115200) ; // assume esp set to 115200 baud, it's default setting
    // what we need to do is attempt to flip it to 19200
    // the maximum baud rate at which software serial actually works
    // if we run a program without resetting the ESP it will already be 19200
    // and hence the next command will not be understood or executed
    // ESPserial.println("AT+UART_CUR=19200,8,1,0,0\r\n") ;
    // ESPserial.end() ;
    // delay(10) ; // Necessary to allow for baud rate changes
    // ESPserial.begin(19200) ; // start again at a resonable baud rate
    Display.gfx_ScreenMode(PORTRAIT) ; // change manually if orientation change
    if (!(Display.file_Mount()))
    Display.putstr("Drive not mounted...");
    //hFontn = Display.file_LoadImageControl("NoName2.dnn", "NoName2.gnn", 1); // Open handle to access uSD fonts, uncomment if required and change nn to font number
    //hstrings = Display.file_Open("Form-Win.txf", 'r') ; // Open handle to access uSD strings, uncomment if required
    hndl = Display.file_LoadImageControl("Form-Win.dat", "Form-Win.gci", 1);
    // put your setup code here, to run once:
    Display.img_ClearAttributes(hndl, iWinbutton1, I_TOUCH_DISABLE); // Winbutton1 set to enable touch, only need to do this once
    Display.img_ClearAttributes(hndl, iWinbutton2, I_TOUCH_DISABLE); // Winbutton1 set to enable touch, only need to do this once

    Display.img_Show(hndl, iWinbutton1); // Winbutton1 show button, only do this once

    Display.img_SetWord(hndl, iWinbutton1, IMAGE_INDEX, 0); // Winbutton1 where state is 0 for up and 1 for down
    Display.img_SetWord(hndl, iWinbutton2, IMAGE_INDEX, 0); // Winbutton1 where state is 0 for up and 1 for down

    Display.img_Show(hndl,iWinbutton1) ; // Winbutton1

    Display.img_Show(hndl,iStatictext1) ; // Statictext1


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

    void loop()
    // put your main code here, to run repeatedly:
    x = Display.touch_Get(TOUCH_GETX);
    y = Display.touch_Get(TOUCH_GETY);
    if(x>=68 && x<=189 && y>=204 && y<=260)
    Display.img_Show(hndl,iStatictext2) ; // Statictext1 Form2
    Display.img_SetWord(hndl,iWinbutton2, IMAGE_INDEX, 0); // Winbutton2 where state is 0 for up and 1 for down
    Display.img_Show(hndl,iWinbutton2) ; // Winbutton2
    if(x>=60 && x<=180 && y>=104 && y<=160)

    Display.img_Show(hndl,iStatictext1) ; // Statictext1 Form1
    Display.img_SetWord(hndl,iWinbutton1, IMAGE_INDEX, 0); // Winbutton1 where state is 0 for up and 1 for down
    Display.img_Show(hndl,iWinbutton1) ; // Winbutton1

    // Display.txt_MoveCursor(0,0);
    // Display.print(n);


    Best regards,
    Attached Files


    • nher
      nher commented
      Editing a comment
      I downloaded the zip file, opened the uSD Arduino project, Comp'nLoaded the file easily. I've re-inserted the uSD card from my PC to my 4Duino, and I'm getting a '-1' appear on my display. There are no buttons. Nothing but a black screen and the '-1'. Any kind of help on this issue is appreciated. Thanks!

      Also, is this the only way to move between Forms using the 4Duino?

  • #3
    Thanks for the quick answer. That worked well.


    • #4
      now there is a new problem. As i create my two forms to switch over and over, the button of the former page still exist not visible but touchable. When i touched on the side of the page where the button is on the other page, the button reacts.
      So my question can i disable a single button and then after that able that button again?

      Best regards Julian Schwendele


      • #5
        Or how can i just enable and disable the buttons on the form where i am.


        • #6
          Hi Schwendele,

          You could do something like this one: (you could try doing it in 4Duino)

          Visi Form Switch:

          It uses a function where it has commands that disables the winbuttons from a previous form. Try appending the "Display." to make it work in 4Duino =). You could also try and use it as a basis to diable it on the current form.

          Best regards,


          • #7

            I tried the same example. When I open the example provided in the zip file (FormSwitch.4Dg or FormSwitch.4DViSi), it opens in Workshop 4 but I can't change the Display type in the Project to 4Duino.

            Click image for larger version

Name:	capture.JPG
Views:	124
Size:	26.9 KB
ID:	70767

            I am using the free version of Workshop 4.

            Any advice please?


            • John Kevin
              John Kevin commented
              Editing a comment

              There is no option for that.

              As Joseph has mentioned, try to copy the code on the app note and append the "Display."

              Additionally, have you tried the attached program on post#2? That should demonstrate how to use a switch form on the 4Duino.

              I hope this helps.

              Best Regards,

          • #8
            Hi John

            Thank you for the feedback. I'm not sure how to append the "Display."
            The program starts as follows:

            #platform "uLCD-32PTU"

            // Program Skeleton 1.2 generated 7/8/2015 2:30:34 PM

            #inherit "4DGL_16bitColours.fnc"

            #inherit ""

            #inherit ""

            func main()

            etc etc...


            • #9

              It would be easier to download the example in post #2. Converting the program from the uLCD-32PTU is quite a task and very different from the 4Duino code example.

              I have attached a copy below.

              Best regards

              Attached Files


              • #10
                Thank you Paul

                I re-tried the example but it doesn't display the button or the text for some reason.
                I eventually figured it out. Thank you for helping me get on the right track.

                I've attached a video of my example of the Form Switching, with simulated values.

                FormSwitching on 4Duino.mp4 (5.6MB file)

                Kind regards
                Attached Files
                Last edited by jdjager; 30 December 2019, 03:37 AM.