Announcement

Collapse
No announcement yet.

Detecting 4dbutton on status

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

  • Detecting 4dbutton on status

    Greetings, is there a way to detect wether a 4d button - button01 is on without touching the display.

    When you set the button to 'on' in the momentary properties. (The light is on) I don't see any references to accessing it in the many app notes.

    In the events tab for the form and for the button there is only report message which I already use for the buttons.

    What I was trying to do in visi genie is when I load a form I want to see all the buttons that are on etc without touching the display.

    Regards
    Dave

  • #2
    Code:
    genie.ReadObject(GENIE_OBJ_4DBUTTON, 0);
    put this anywhere when you want to read the button status.
    0 being the index of the first(0) button, button1 is going to be 1.

    your response in the event handler will be 1 (pressed) or 0 (released)

    Code:
      if ( Event.reportObject.cmd == GENIE_REPORT_EVENT && Event.reportObject.object == GENIE_OBJ_4DBUTTON ) {
        if ( Event.reportObject.index == 0 ) {
          uint8_t button_status = genie.GetEventData(&Event);
        }

    Comment


    • #3
      Thank you for your help tonton81. I have been using the display for 3+ years in an auto application so I need to be careful of current drains etc. I switch everything off to save power. On restart I have a Menu that comes up where I use the 4d buttons. Some I use as a default - then that button will be on. The red ring on the button shows up, momentary set to on.

      The idea is that when the form loads I want to be able to read that button and see whether it is on or not, I do not want to press a button/screen. Similar to checking if a tick is present in a checkbox in Windows etc. I have gone through the app notes and do not find anything relating to that - only the press events which I am presently using.

      Thanks

      Comment


      • #4
        the above is what your looking for for momemtary on and off status. its the same thing as pressed/not pressed.

        Comment


        • #5
          tonton81, I appreciate your help. Put a couple of 4d buttons on a form. Put 1 or 2 in momentary as on. 1 as no. 1 as yes.

          Goto GTX - change to the form which has the buttons. Here you can see the buttons that are on are highlighted in blue. They have been polled already.

          You can query the button state and also set the state. Which is what I am trying to do. The app notes that I have say it is not recommended to poll a button but rather rely on the on changed event. I agree on that. I want arduino to check the state of each button and carry on from there, without me touching the screen.

          But on startup - power on I want to poll the buttons, as it will only be read once and then revert to the on changed events etc. Maybe to change a button state programatic ally as well. As it says in the documentation let the display hold all of the memory intensive stuff.

          That was my idea/plan. I did not want to add a sd card drive to the arduino as the display already has that otherwise it is simpler using a samung note 4 and android.

          Thanks
          Dave
          Attached Files
          Last edited by HobieDave; 26th May 2017, 06:59 AM. Reason: Old age has caught up with me. Forgot a thing or two.

          Comment


          • #6
            like i said, follow the steps above. You may do your request in setup() function so it runs once when the mcu boots up, the display will give the arduino the button states after DoEvents() is triggered in loop. This isn't polling, your sending a request to read it's state, once. Polling is repeatedly reading it's state, which, is still doable and works fine, just a waste of cpu... Your requesting the state on startup, follow the steps outlined before.

            Comment


            • #7
              tonton81, I apologise, I just reread the whole page and I see that I did not inform you that the code only returns a 1 no matter the state of the button. In gtx it has the capability to do that but is not accessible to program. In app note 32 it says

              The host sends a READ_OBJ command specifically asking for the value (or
              status) of the second 4D button object. The display module then responds
              with the current value of that 4D button. Etc.

              But the graphic above it says on the read obj n/a as the result which confused me because here they say two different things. That's when I asked for help. I only program once or twice every two years so each time I have to relearn everything. As a mechanic the above statement says to me it can be done and the evidence is in gtx - the buttons in blue, but the graphic above it says no and in gtx the values received do not change either. Same values that i received from my code and yours. Very confusing and seems I have wasted a lot of time and yours on a non functional idea.

              In the ViSi Genie ref manual it says

              When reporting an Event or responding to query from Host:
              For Toggle:
              If 4D Button is OFF, when released: Value(lsb) = 0
              If 4D Button is ON, when released: Value(lsb) = 1
              For Matrix:
              When 4D Button is released: Value(lsb) = 1
              For Momentary:
              When 4D Button is released: Value(lsb) = 0
              Notes Note: It is not recommended for the host to poll momentary type 4D

              Again here it says responding to query from host, but here it says When released. How does one do it. I have attached my code to check maybe I missed something.......

              Thanks
              Dave
              Attached Files

              Comment


              • #8
                Code:
                void myGenieEventHandler(void)
                { // Start of event handler
                  genieFrame Event;
                  genie.DequeueEvent(&Event);
                
                  // Code from tonton81 - 4d forum
                  if (Event.reportObject.cmd == GENIE_REPORT_EVENT && Event.reportObject.object == GENIE_OBJ_4DBUTTON) {
                    if (Event.reportObject.index == btnNumber) {
                      uint8_t button_status = genie.GetEventData(&Event);
                      genie.WriteStr( 4,  button_status);
                    }
                  }
                }  // End of event handler
                sorry my mistake, your reading an object so it's not "GENIE_REPORT_EVENT", it should be "GENIE_REPORT_OBJ" (for manually reading since it's not an event)

                Code:
                void myGenieEventHandler(void)
                { // Start of event handler
                  genieFrame Event;
                  genie.DequeueEvent(&Event);
                
                  // Code from tonton81 - 4d forum
                  if (Event.reportObject.cmd == GENIE_REPORT_OBJ && Event.reportObject.object == GENIE_OBJ_4DBUTTON) {
                    if (Event.reportObject.index == btnNumber) {
                      uint8_t button_status = genie.GetEventData(&Event);
                      genie.WriteStr( 4,  button_status);
                    }
                  }
                }  // End of event handler
                You may additionally make it work for both events and reporting object by dropping the command lookup in the function:

                Code:
                void myGenieEventHandler(void)
                { // Start of event handler
                  genieFrame Event;
                  genie.DequeueEvent(&Event);
                
                  // Code from tonton81 - 4d forum
                  if (Event.reportObject.object == GENIE_OBJ_4DBUTTON) {
                    if (Event.reportObject.index == btnNumber) {
                      uint8_t button_status = genie.GetEventData(&Event);
                      genie.WriteStr( 4,  button_status);
                    }
                  }
                }  // End of event handler
                and to make it a bit cleaner:

                Code:
                void myGenieEventHandler(void) { // Start of event handler
                  genieFrame Event;
                  genie.DequeueEvent(&Event);
                  // Code from tonton81 - 4d forum
                  if (Event.reportObject.object == GENIE_OBJ_4DBUTTON && (Event.reportObject.index == btnNumber) ) {
                    uint8_t button_status = genie.GetEventData(&Event);
                    genie.WriteStr( 4,  button_status);
                  }
                }  // End of event handler
                Tony

                additionally: this wont work:

                Code:
                onOff = genie.ReadObject(GENIE_OBJ_4DBUTTON, btnNumber);
                this will never get the value, it will only be picked up next cycle of DoEvents();
                so just doin setup():

                Code:
                genie.ReadObject(GENIE_OBJ_4DBUTTON, btnNumber);
                and follow the functions above to retrieve it.
                I didn't see any String widgets in your workshop file, and it didnt load properly in my IDE

                uint8_t button_status = genie.GetEventData(&Event);

                that variable will have the button value ready for you.

                you may put your onOff code in the event function if needed, and remove "genie.WriteStr( 3, onOff); " from setup:

                Code:
                void myGenieEventHandler(void) { // Start of event handler
                  genieFrame Event;
                  genie.DequeueEvent(&Event);
                  // Code from tonton81 - 4d forum
                  if (Event.reportObject.object == GENIE_OBJ_4DBUTTON && (Event.reportObject.index == btnNumber) ) {
                    uint8_t onOff = genie.GetEventData(&Event);
                    genie.WriteStr( 3, onOff);                              
                    uint8_t button_status = genie.GetEventData(&Event);
                    genie.WriteStr( 4,  button_status);
                  }
                Last edited by tonton81; 28th May 2017, 12:04 AM.

                Comment


                • #9
                  Tonton81 thank you so much. It is good to see that I was incorrect and that that functionality is available, and will work on the user buttons etc as well. I know that I am lacking some horsepower upstairs, there were only two options which I tried all combinations and failed.

                  In the reference manual for the report object they say example but there is nothing there, pity. It wouldn't have been arduino code anyway. I checked all the code examples that I had downloaded and did not find it anywhere. Is there an arduino reference for the 4d displays that we can refer to. Just need to know the correct syntax to use etc. I do understand that not everyone is using their displays exclusively on arduino.

                  Always easy after the fact - using a ulcd43pt and I work exclusively in landscape mode. I also did an ide upgrade to the latest version thinking that may help - better inline help etc. I broke one of my first diagnostic rules here. My apologies.

                  Once again, thank you for the time, effort and for nailing it.

                  Regards
                  Dave

                  Comment

                  Working...
                  X