Announcement

Collapse
No announcement yet.

Control winbutton status from a keypay

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

  • Control winbutton status from a keypay

    First post...
    I am using an UNO32 (MPIDE/Arduino) and uLCD-43PT. I am working on a project that requires a keypad at times and the touchscreen at other times. Here is the problem I am encountering.

    When using the keypad and a form with multiple buttons is loaded, I would like to change the color of the top left button on the screen to provide a visual reference of the current "cursor" position. If the "left", "right", "up" or "down" button on the keypad is pressed, I would like to be able to change the top left button back to a normal color and have the button corresponding to the direction change change it's color. Thereby representing the cursor moved the desired direction. Then, if the "enter" button is pressed, an event happens.

    I can make it so the button will change state, but then I have to set the button on events to none so I can change color (via state from 0 to 1) and the touch screen use goes out the window.

    I started to design this in Visi, but I am wanting to do page switching to speed up the change and not re-write the layout anytime the keypad is pressed and MPIDE/Visi doesn't do form changing (I think) without using on events.

    I thought about making images of the desired button changes and just changing between images, setting on events, but I would very quickly exceed the amount of storage and run out of timers.

    I thought about having a rectangle behind the top left button and moving via X/Y in the desired direction, but I am not able to find how using Genie and MPIDE/Arduino.

    I thought about enabling/disabling touch or on event depending on a log in level, but am not able to how to turn touch or event handling on/off with Genie from MPIDE. Am I missing or overlooking how.

    Any suggestions would be more than welcome.

  • #2


    Sorry, I can't quite follow what you are trying to do or why you are having problems doing it

    So the keypad is a real keypad and you want to display some sort of indication of it's action on the display?

    With the latest workshop you should be able to use user images (if it's just for display), or user buttons (if it needs to be touch detectable).

    Other than that I don't understand why you would be running out of storage and/or timers
    Mark

    Comment


    • #3


      The project I am working on uses it as both a display and a touch screen. The keypad is 3x4:

      I am trying to use:
      2 as up
      4 as left
      5 as enter
      6 as right
      8 as down

      for when touch is disabled. When touch is enabled I am wanting to maintain the buttons functionality.

      Another problem I am encountering is when I change a button's status from 0 to 1, it becomes a black box with a red X.
      Here is the current code in arduino:


      #define DisplaySerial Serial
      /* If you are not using hardware serial on pins 0 and 1 you can use this */
      /* hardware port for logging messages. To do this uncomment the following */
      //#define LOG_MESSAGES
      /* */
      /* Error Callback In order to drastically reduce the amount of error checking you need */
      /* to do a callback exists to perform 'standard' error handling when an */
      /* occurs. If you want to do your own handling set Callback4D to NULL */
      /* otherwise set it to the address of the error routine */

      /* Sketch Size! If you are logging messages, then you may exceed the maximum sketch */
      /* size for some of the smaller boards, you can comment out TEST_USD to */
      /* exclude tests that require a uSD card to run and/or TEST_OTHER to */
      /* exclude tests that do not require a uSD card to run. */
      #define TEST_USD
      #define TEST_OTHER
      /* */
      /* */
      /* The following files are needed on the uSD. */
      /* */
      /*********************************************************************************************/

      #include
      #include
      #include
      #include
      #include
      #include

      Picaso_Serial_4DLib Display(&DisplaySerial);

      //const char *atoz = {
      // "abcdefghijklmnopqrstuvwxyz"}; //set alphabet as recognized characters

      int currentScreen; //integer for tracking current screen displayed
      int currentButton; // integer for tracking current button
      int currentString; // integer for tracking current string
      int passWord =0; // integer for tracking password level login
      int passwordDigit0, passwordDigit1, passwordDigit2, passwordDigit3, passwordDigit4;
      int genUser; //general user login level
      int supUser; //supervisor user login level
      int techUser; //tech user login level, reserved for repair technicians
      int a,b,c,d,e,f,i,r,s,t,u,v =0; //int used to track data values

      /////*****Keypad*****/////
      const byte ROWS = 4; //defines number of rows on keypad
      const byte COLS = 3; //defines number of columns on keypad
      char keys[ROWS][COLS] = { // defines names of keys at specific row/column alignments
      {'1','2','3'},
      {'4','5','6'},
      {'7','8','9'},
      {'*','0','#'}
      };

      byte rowPins[ROWS] = {35,36,37,38}; //pins rows from keypad are connected to
      byte colPins[COLS] = {39,40,41}; // pins columns from keypad are connected to

      Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); //command to create the keypad from the above setup directions
      char key;
      /////*****Keypad****/////

      ////***Different page locations and assignments for current screen tracking
      void loadScreen() //function defining the startup/loading screen
      {
      genieWriteObject(GENIE_OBJ_FORM, 0x00, 1); //loads Form 0 (load screen)
      currentScreen = 0; //change the screen value to the current screen
      }

      void testScreen() //function defining the test screen
      { genieWriteObject(GENIE_OBJ_FORM, 0x01, 1); //then start test screen Form1
      currentScreen = 1; //change the screen value to the current screen
      }

      void loginScreen() //function defining the login screen
      { genieWriteObject(GENIE_OBJ_FORM, 0x02, 1); //then start login screen Form2
      currentScreen = 2; //change the screen value to the current screen
      currentString = 0;
      a = 1; b = 1; c = 1; d = 1; e = 1;
      genieWriteObject(GENIE_OBJ_STRINGS, 0x00, 1); genieWriteObject(GENIE_OBJ_STRINGS, 0x01, 0); genieWriteObject(GENIE_OBJ_STRINGS, 0x02, 0); genieWriteObject(GENIE_OBJ_STRINGS, 0x03, 0); genieWriteObject(GENIE_OBJ_STRINGS, 0x04, 0);
      }

      void menuScreen() //function defining the main menu screen
      { genieWriteObject(GENIE_OBJ_FORM, 0x03, 1); //then start main menu screen Form3
      currentScreen = 3; //change the screen value to the current screen
      }

      void statsScreen() //function defining the stats screen
      { genieWriteObject(GENIE_OBJ_FORM, 0x05, 1); //then start stats screen Form 5
      currentScreen = 5; //change the screen value to the current screen
      }

      //////****Screens****/////

      ////*****Setup function runs once at start up. All commands in function will be performed at start up.***/////////
      void setup()
      { genieBegin(GENIE_SERIAL, 9600); //Display Serial Baud

      // Serial.begin(115200); //USB Serial Baud

      //genieAttachEventHandler(myGenieEventHandler); //display event listener for Genie (Display) events

      keypad.addEventListener(keypadEvent); // Add an event listener.
      keypad.setHoldTime(750); // Default is 1000mS
      keypad.setDebounceTime(50); // Default is 50mS

      pinMode(13, OUTPUT); //set pin 13 mode to output
      digitalWrite(13, LOW); ///set digital output of pin 13 to low (Zero volts)

      static int startUp = 0; //startup cue

      if (startUp == 0)
      {
      loadScreen(); //run function loadScreen
      delay(2500); //wait 2.5 seconds before talking to display.
      testScreen(); //run function
      startUp = startUp + 1; //prevents continual startup
      delay(500);
      // Display.touch_Set(TOUCH_DISABLE); //disable touch screen

      } }
      ////*****Loop****////////
      void loop() //commands in this function repeat in a loop. Used to monitor events such as keypad and USB events.
      {
      key = keypad.getKey(); //Command to monitor keypad events

      genieDoEvents(); //Command to monitor genie events
      }

      /*void myGenieEventHandler(void) //defines handling of genie events and lights status LED as reading/writing
      { genieFrame Event;
      genieDequeueEvent(&Event);

      if(Event.reportObject.cmd == GENIE_REPORT_EVENT)
      {
      if (Event.reportObject.object == GENIE_OBJ_FORM)
      {
      if (Event.reportObject.index == 0)
      {
      digitalWrite(13, HIGH);
      }
      else if (Event.reportObject.index == 1)
      {
      digitalWrite(13, LOW);
      } } } }*/
      /////*****Loop*//////

      //****Soft button logic***/////
      void keypadEvent(KeypadEvent key)
      {
      if (currentScreen !=1 && '9' == key)
      {testScreen();}
      else if (currentScreen ==1 && '7' == key)
      {menuScreen();}
      else if (currentScreen ==1 && '5' == key)
      {loginScreen();}
      else if (currentScreen ==1 && '3' == key)
      {statsScreen();}
      else if (currentScreen ==1 && '9' == key)
      {}
      else if (currentScreen ==2 && '9' == key)
      {a = 0; b = 0; b = 0; d = 0; e = 0;
      testScreen();}
      else if (currentScreen ==3 && '9' == key)
      {testScreen();}
      else if (currentScreen ==5 && '9' == key)
      {testScreen();}
      else if (currentScreen ==5 && '7' == key)
      {menuScreen();}

      //******Softbutton logic for login screen
      else if (currentString == 0 && currentScreen == 2){
      switch (keypad.getState()){
      case PRESSED:
      switch(key){
      case '2': genieWriteObject(GENIE_OBJ_WINBUTTON, 0X38,1);if (a >=0 && a=2 && a=0 && b=2 && b=0 && c =2 && c =0 && d =2 && d =0 && e =2 && e

      Comment


      • #4


        Hi,
        Is it possible for you to post your Genie project as well? It will help us understand what you're trying to achieve. We also noticed that in your sketch you used both the Genie and Serial libraries at the same time, which you must not do. The following are additional information that may help you.
        The Genie library is used for interfacing an Arduino host to a 4D display module which contains a ViSi-Genie program. In other words, the display is programmed in the ViSi-Genie environment in Workshop.

        The Serial library is used for interfacing an Arduino host to a 4D display module which is configured as a serial slave device. When you create a new project in Workshop, the Choose-Your-Environment window gives a short description of each of the four environments.

        First, you have to choose the environment that you will use for your application - ViSi-Genie or Serial. The ViSi-Genie environment doesn't require any coding and allows for faster development. There are things that you can't do in ViSi Genie, however, like uSD card logging. The Serial environment is a lot more "powerful" but requires coding. For what you described in your first post (which I don't fully understand yet), I think you can use the ViSi-Genie environment.

        For using the Genie library, here are the relevant documents:

        Basic App notes:
        4D-AN-P4017 Connecting a 4D Display to an Arduino Host
        4D-AN-P4018 Writing to Genie Objects Using an Arduino Host

        Application-specific app notes:
        4D-AN-P4019 A Simple Digital Voltmeter Application using an Arduino Host
        4D-AN-P4010 Connection to an Arduino Host with Red-Green-Blue LED Control
        4D-AN-P4015 Displaying Temperature values from an Arduino Host

        You can find all the app notes here: http://www.4dsystems.com.au/appnotes/


        For using the Serial library, here are the relevant application notes:

        Basic App notes:
        4D-AN-M5001 Interfacing a 4D Display to Arduino
        4D-AN-M5002 Running BigDemo on the Arduino

        Application-specific app notes:

        4D-AN-P5001 Displaying Third Party Fonts

        Should you continue to encounter more problems, please send us your complete project. We trust however that you can learn a lot and figure things out by reading the basic app notes and playing with the attached projects.


        Regards.
        Doff

        Comment


        • #5


          What I gather from reading this and many other posts is if I create multiple forms in Visi, I can not change forms via a serial command similar to VisiGenie genieWriteObject(GENIE_OBJ_FORM, 0x00, 1). This is the start of the problems I am having. When I generate the code in Genie, it is too large. So large I cannot attach the zip folder. I attached the text of the objects.

          If I create the project in Visi (or convert Genie over to Visi by saving as a Visi project) I lose the ability to change forms (but the project is now small enough...wierd).

          Also, when using Genie, if I change a button's state from 0 to 1, it becomes a black box with a red X while changed.

          What I am trying to do is navigate multiple forms with rows/columns of buttons. When I move from one button to the next on the same form, I would like a visual reference (button changes color is preferred) that I have moved from one button to the next. If I press enter on the keypad, I then want to switch to a different form. Attached files Genie_objects_and_locations.txt (3.2 KB)

          Comment


          • #6


            Hi,

            What I gather from reading this and many other posts is if I create multiple forms in Visi, I can not change forms via a serial command similar to VisiGenie genieWriteObject(GENIE_OBJ_FORM, 0x00, 1).
            You can actually do this in ViSi if you understand the ViSi-Genie communications protocol and how to implement it. Another alternative is to create a simple two-form Genie project then convert it to ViSi. You can then look at the code and see how to switch between forms properly. I think however that this is not an easy way.

            When I generate the code in Genie, it is too large. So large I cannot attach the zip folder. I attached the text of the objects.
            If I create the project in Visi (or convert Genie over to Visi by saving as a Visi project) I lose the ability to change forms (but the project is now small enough...wierd).
            The size of your Genie project and that of its ViSi version should be the same unless you changed an option (inadvertently). Also, if you zip your project, try the File menu --> Zip Project option. Only the code and data files will be included in the zip file and not the generated graphics file (.gci). Looking at the text file you posted, your project contains a lot of winbuttons and strings. It shouldn't be that large unless you have video and sound files. Send to

            mark at 4dsystems dot com dot au
            doff at 4dsystems dot com dot au

            Also, when using Genie, if I change a button's state from 0 to 1, it becomes a black box with a red X while changed.
            Perhaps you are using a momentary button? If so you have to change it to a toggle button so you can enable or disable it by writing to it a value of 1 or 0. This is pointed out on page 9 of 4D-AN-P4018 Writing to Genie Objects Using an Arduino Host.

            What I am trying to do is navigate multiple forms with rows/columns of buttons. When I move from one button to the next on the same form, I would like a visual reference (button changes color is preferred) that I have moved from one button to the next. If I press enter on the keypad, I then want to switch to a different form.
            As suggested by ESPsupport, you can implement this in ViSi-Genie using the user button widget. The user button widget is documented in 4D-AN-D4006 ViSi-Genie User Button. On page 4 it says:

            A key feature of the user button is that the user can specify the image files to be used for each of the states. The simple project developed in this application note demonstrates the basic use of a user button. A user button can be configured to behave as a momentary button, a toggle button, or one among a group of buttons. Each of these configurations has its own application.
            You can use a group or matrix of user buttons for your application. Here is one way of doing it. I suggest you try this on a separate project first.

            1. Create a matrix of user buttons. Please see page 19 of 4D-AN-D4006 ViSi-Genie User Button if you don't know how to do this yet. You create three user buttons for instance, each of which will activate a form when the "Enter" button is pressed. Label each of the buttons accordingly. Make sure that the "UP" and "DOWN" states have different colors. This will be your "visual reference".
            2. Configure each of the buttons to report a message.
            3. Create another button - this will be the "Enter" button. You can use a momentary winbutton for this if you like. Configure this button to report a message when touched as well.
            4. Now you have three toggle user buttons which form a matrix. When one of these is touched, it changes its color and it reports a message. Also, the other two user buttons are automatically disabled (since you can only choose one form). You also have an enter button which is a momentary winbutton. This too will report a message when triggered.
            5. Create three blank forms. Each of the buttons will activate a form (just for testing).
            6. Now in your Arduino sketch you wait for any event from the four buttons.
            If the message comes from one of the three user buttons, just use a variable to store its index. This way, you will know which of the three buttons has recently been touched. For example lastTouch = indexOfLastMessage.
            If the message comes from the enter button, then you can use genieWriteObject(GENIE_OBJ_FORM, lastTouch, 1) to navigate to the desired form.
            7. Replicate this on the other forms. You will just have to know the indices of the buttons.

            Of course there are other details that you have to work out. The main idea is already in 4D-AN-D4006 ViSi-Genie User Button, you will just have to take it one step further for your application. Now if the above is in line with what you are trying to accomplish and you encounter difficulties in implementing it, we would be glad to give you a working example.

            App notes are here: http://www.4dsystems.com.au/appnotes/

            Regards
            Doff

            Comment


            • #7


              doff,
              Thank you for your help, I have it working now with Genie!

              Comment


              • #8


                One last question.

                Userbuttons have 4 states: up, up(touched), down, and down (touched).

                If I have a a matrix of userbuttons and different images for every state for every userbutton.

                Example:
                I am using a userbutton as a toggle, with states:
                off - displays the button with a red dot and a lightened "non-selected" mode
                off touched - displays the button with a red dot and a darkened "selected" mode
                on - displays the button with a green dot and a lightened "non-selected" mode
                on touched - displays the button with a green dot and a darkened "selected" mode

                Do I change between the states with the following:
                genieWriteObject(GENIE_OBJ_USERBUTTON, 0x01, 0x000)
                genieWriteObject(GENIE_OBJ_USERBUTTON, 0x01, 0x001)
                genieWriteObject(GENIE_OBJ_USERBUTTON, 0x01, 0x002)
                genieWriteObject(GENIE_OBJ_USERBUTTON, 0x01, 0x003)

                Comment


                • #9


                  Genie should manage a userbutton for you.

                  If you want to manage it yourself, maybe you should user a 'user images'.
                  Mark

                  Comment


                  • #10


                    I am trying to find a way to control the Visi-Genie on-screen keyboard via the Uno32. I have a physical (up, down, left, right, enter) push button key pad (metal dome). Is there a way to write to the keyboard to change the state of a key as the "cursor" moves in the direction pressed on the push button key pad? Then if enter is pressed, that key is selected?

                    Or is building the keypad out of 'user images/buttons' the only way.

                    Comment


                    • #11


                      Gee, sounds like a complicated way of doing things, why not just use what is already available? It would be much quicker, both to do and for user input.

                      You certainly can't do that in Genie and I can't see why it would be worthwhile allowing it.

                      If you drop back to ViSi (i.e. do the behind the scenes coding yourself) it could of course be done.

                      The Goldelox ViSi Keyboard sample code works that way, it uses the joystick to do just that. The Goldelox code will need quite a few changes to work on Picaso although it could be done.
                      Mark

                      Comment


                      • #12


                        I agree, using what is already there would be much easier! The project I am working on originally requested a touch screen, but that has since been dropped. Now I am using the keypad to control all functions.

                        Comment


                        • #13


                          The project I am working on originally requested a touch screen, but that has since been dropped.
                          Can you share the reasons why?
                          Mark

                          Comment


                          • #14


                            The use of a small touch screen was scrapped. So now I am trying to use what I already have to make the project work.

                            Comment

                            Working...
                            X