Announcement

Collapse
No announcement yet.

Wrap String Index for StringNext back to 0

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

  • Wrap String Index for StringNext back to 0

    Hello,

    I also have a Visi Genie project and a few strings.
    For a string "wrap" I could imagine some Magic Code.

    With Labels / Strings I placed a variable string (Strings1) on a Form and created 5 string entries [0..4] with the String Editor.
    In addition, one user button is placed which acts with Userbutton / Events / OnChanged = Strings1Next on the variable string.

    Is it possible to "wrap" from entry 4 to entry 0 with Magic Code after the user button has been pressed several times?

    Similar:
    if (Strings1Pos > 4)
    Strings1Pos := 0 ;
    endif

    Edit: Where and how should the Magic Code be inserted?
    As Magic Code or Magic Object and on which Form / Insertion Point?

    Thanks and best regards.
    Last edited by DisplayEnthusiast; 1 February 2021, 01:17 AM.

  • #2
    Hi DisplayEnthusiast,

    You may try to use a combination of MagicEvent and MagicCode. In your MagicCode, you may put the code that you have mentioned above.
    Attached is a sample code for you to try which uses both MagicEvent and MagicCode.
    MagicCode is in Form0 with an Insertion Point Constant/Global/Data. To know more about Insertion Points, you may read Genie Magic Objects Section in the VISI-GENIE REFERENCE MANUAL.

    Hope this helps and Best Regards,
    Eran
    Attached Files
    Eran

    Comment


    • #3
      Hi Eran,

      Thank you for your information. Will be happy to try your sample code. I'll get back in touch.

      Thank you very much and Best Regards.

      Comment


      • #4
        Hi DisplayEnthusiast,

        Please don't hesitate to ask if you have clarifications about the sample code or if you encounter any problem.

        Best Regards,
        Eran

        Comment


        • #5
          Hi Eran,

          Thank you for your sample code. It works perfectly.
          Is there a way to read back the "actual" index of a (variable) String object?
          (User button input changed the display of the (variable) String => Which String index is currently displayed?)

          Similar:
          index := ReadObject(tStrings, x); // MagicCode ?

          I searched in workshop4 IDE ViSi-Genie Reference Manual and 4DGL Graphics Language Reference Manual,
          but can't find it.

          Edit: Eran, please also give me a tip on how to read and set the string index from the host computer side.
          I use the geniePi.c library.

          Thank you very much in advance and Best Regards.
          Last edited by DisplayEnthusiast; 2 February 2021, 02:06 AM.

          Comment


          • #6
            Hi DisplayEnthusiast,

            When you say index, do you mean the state/frame of your Strings0 object? For example when the String "ONE" is showing, it should return 0 since it is the first frame in your Strings0 Object.

            If that is the case, then you may use below workaround using Magic Code:
            1. Upon changing from one index to another, save the new index in a variable.
            2. Create a function that would return the index value;
            3. When you want to know the index, call the function.

            I have attached a sample code for you to try.

            Also, you may check this application note about using geniePi library: ViSi Genie – Connecting a 4D Display to the Raspberry Pi (4dsystems.com.au)
            To set the string to a specific state/frame, you may use genieWriteObj(GENIE_OBJ_STRINGS,0,1); //0 - String object index, 1 - state/frame

            Hope this helps and Best Regards,
            Attached Files
            Eran

            Comment


            • #7
              Hi Eran,

              Thanks again for your sample code and the helpful tips. This makes it much more comprehensible.
              I'm still getting into it and I'll try it out immediately.

              Thank you for your great support.

              Greetings and thank you very much for your complete and detailed help!
              Last edited by DisplayEnthusiast; 5 February 2021, 08:50 PM.

              Comment


              • #8
                Hi DisplayEnthusiast,

                I'm glad that I could be of help. If you encounter any issues, please don't hesitate to ask.

                Best Regards,
                Eran

                Comment


                • #9
                  Hi Eran,

                  I ask you for further help.
                  The Visi Genie project with some strings and some Magic Code for a GEN4-43DCT-CLB-SB touch display works fundamentally thanks to your support.

                  After inserting more Magic Code (from your forum), a sleep functionality also works. sys_Sleep() and sys_SetTimer (TIMER0, sleepTime) are used. The time-controlled shutdown of the display and waking up by touch works fine.

                  But after waking up, the display no longer receives any data, i.e. no strings are displayed, no button or slider triggers an action on the host. It behaves like this, i.e. whether no host application is running anymore. Despite only Sleep no DeepSleep!

                  I tried this MagicCode1 (MainLoop):

                  if(com_Error())
                  com_Reset();
                  com_Sync();
                  endif

                  but no avail.

                  The physical connection display-/-host (based on a gen4-PA mini board) remains even after the sleep, this has been checked with lsusb.

                  1) Where, on display or host, and how does communication need to be reactivated ?
                  2) How can the host application wake up the display based on the geniePi.c library (with genieSetup("/dev/ttyUSB0", 115200)) ?

                  Thank you very much and Best Regards.

                  Comment


                  • #10
                    Hi DisplayEnthusiast,

                    If the sys_Sleep() function is not working ideally in your situation, perhaps I could suggest using the gfx_Contrast(0) function + timeout. With this method, you would create a timer with sys_SetTimer, and then check whether it has expired and if so, change the display brightness to 0. Then when the display is touched, the timeout is reset and the gfx_Contrast is set back to whatever it was previously.

                    Let me know if you need more information on how to implement this method,
                    Adem

                    Comment


                    • #11
                      Hi Adem,

                      Thank you for your suggestion.

                      What do you think about energy consumption? Sleep() is better than Contrast(0)?
                      But Contrast/Brightness(0) is also good.

                      Please help me with the realization, because a simple replacement of sys_Sleep() with gfx_Contrast() does not work and
                      I do not know a query of the contrast/brightness value set by the user previously.
                      After a touch, the previously adjusted brightness should be restored.

                      Thank you very much and Best Regards.

                      Comment


                      • #12
                        Hi Eran,

                        I ask you for further help.
                        The Visi Genie project with some strings and some Magic Code for a GEN4-43DCT-CLB-SB touch display works fundamentally thanks to your support.

                        After inserting more Magic Code (thanks to your forum), a sleep functionality also works. sys_Sleep() and sys_SetTimer (TIMER0, sleepTime) are used. The time-controlled shutdown of the display and waking up by touch works fine.

                        But after waking up, the display no longer receives any data, i.e. no strings are displayed, no button or slider triggers an action on the host. It behaves like this, i.e. whether no host application is running anymore. Despite only Sleep no DeepSleep!

                        I tried this MagicCode1 (MainLoop):

                        if(com_Error())
                        com_Reset();
                        com_Sync();
                        endif

                        but no avail.

                        The physical connection display-/-host (based on a gen4-PA mini board) remains even after the sleep, this has been checked with lsusb.

                        1) Where, on display or host, and how does communication need to be reactivated ?
                        2) How can the host application wake up the display based on the geniePi.c library (with genieSetup("/dev/ttyUSB0", 115200)) ?
                        3) I do not know a query of the contrast/brightness value set by the user previously. After a touch, the previously adjusted brightness should be restored.

                        Thank you very much and Best Regards.

                        Comment


                        • #13
                          Hi Adem,
                          Hi Eran,

                          in search of a solution, I ask for your support.

                          The timer controlled contrast control works with Diablo Internal Functions. However, how can the contrast / brightness be set back to the previous value set by the user, after a touch press.

                          On the host side, the contrast value was set with genieWriteContrast(). How do I get to this contrast value on the Diablo side. Unfortunately, there is no function as gfx_Get(CONTRAST). - Wouldn't that be a good idea?

                          I ask you for a suggestion as to which function the contrast value could be transferred from the host to the display and how this contrast value becomes available on the display page.

                          Thank you very much and Best Regards.

                          Comment


                          • #14
                            Hi DisplayEnthusiast,

                            For gfx_Sleep, can I try suggesting you reinitialize your uSD card.

                            As for gfx_Contrast, the range is 0-15, so just set it to the value you feel is best, the default brightness however is gfx_Contrast(7).

                            Please let me know how it goes.

                            Regards,
                            Adem

                            Comment


                            • #15
                              Hi Adem,

                              Please send me the info to: How can the contrast / brightness be set back to the previous value set by the user, after a touch press?
                              On the host side, the contrast value was set with genieWriteContrast(). How do I get to this contrast value on the Diablo side.

                              I ask you for a suggestion as to which function the contrast value could be transferred from the host to the display and how this contrast value becomes available on the display page.

                              Thank you very much and Best Regards.

                              Comment

                              Working...
                              X