Announcement

Collapse
No announcement yet.

Read winbutton in while function

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

  • Read winbutton in while function

    In my project i have 3 win button. First > Up , Second > Down , Third > RH request. Up and Down is work perfect but rh is not work. My rh button function is = when i click rh button, button always send "rh request" and if i click another button it should stop.
    I write a code but my code doesnt work. It always sending rh request but when i click another button rh not stop. Sometimes it's stoping but lcd is freezing and reseting.

    My Code:
    #include <genieArduino.h>
    Genie genie;
    int rha=0;

    #define RESETLINE 4
    void setup()
    {
    Serial.begin(9600);
    genie.Begin(Serial);
    genie.AttachEventHandler(myGenieEventHandler);
    pinMode(RESETLINE, OUTPUT);
    digitalWrite(RESETLINE, 1);
    delay(100);
    digitalWrite(RESETLINE, 0);
    delay (3500);
    genie.WriteContrast(1);
    genie.WriteStr(0, GENIE_VERSION);
    }

    ////////////////////////////////////////////////////////////////////
    void loop()
    {
    static long waitPeriod = millis();
    genie.DoEvents();
    if (millis() >= waitPeriod) {
    waitPeriod = millis() + 50; }
    }
    /////////////////////////////////////////////////////////////////////

    void myGenieEventHandler(void)
    {
    start:

    genieFrame Event;
    genie.DequeueEvent(&Event);

    if (Event.reportObject.object == GENIE_OBJ_WINBUTTON)
    {

    if (Event.reportObject.index == 2) // index= 2 UP
    {
    Serial.println("UP");
    }

    if (Event.reportObject.index == 3) // index= 3 DOWN
    {
    Serial.println("DOWN");
    }

    if (Event.reportObject.index == 4) // index= 4 RH
    {
    rha=0
    while (rha<1)
    {
    genie.DoEvents();

    if (Event.reportObject.index == 2 || Event.reportObject.index == 3)
    {
    rha++;
    goto start;
    }
    else
    {
    Serial.println("RH request");
    }
    }

    }

    }
    }

    How can i solve this problem.
    Note: I have Pro licence so you can advice me magic event etc.

  • #2
    dont run doevents within the handler. are you looking for when the user lets go? if so in workshop set the winbutton to BOTH and look for genie.GetEventData(&Event) of the userbutton event, if it's equal to 0, user let go, if its 1, user is holding it

    never run while loops in handler either

    Tony

    Comment


    • bkz124
      bkz124 commented
      Editing a comment
      I change winbotton momentary to BOTH but how can i use "genie.GetEventData(&Event)" ? I dont understand.

    • bkz124
      bkz124 commented
      Editing a comment
      How will i change my code?

  • #3
    I delete all RH function and i changed.

    Code:
    if (Event.reportObject.object == GENIE_OBJ_USERBUTTON)
    {
    if(Event.reportObject.index == 0)
    {
    boolean button1=genie.GetEventData(&Event);
    if(button1==1)
    {
    counter++;
    if(counter%2==1)
    {
    Serial.println("RH request");
    }
    else
    {

    }
    }
    But i can only 1 RH request. I want RH request every 100ms. If I changed "if" to "while", i m taking RH request every 100ms but i cant stop loop now :D.

    Please can you help to change code?
    Last edited by bkz124; 4th July 2017, 08:27 PM.

    Comment


    • #4
      Actually i made this program with keypad. This code working. Can u please help ??

      if(Value==53) // Button 5 - Ride Height
      {
      rha=0;

      while(rha<1) // Ride Height Signal stay in active until press another key.
      {

      keypadValue = Serial.read();
      int rhb= keypadValue;

      if(rhb==49 || rhb==50 || rhb==56 || rhb==55 || rhb==57)
      {
      rha++; //For stop the while loop
      goto start; //Return to startposition
      }

      else {
      Serial.println("Ride Height Request");
      }
      Last edited by bkz124; 4th July 2017, 10:56 PM.

      Comment


      • bkz124
        bkz124 commented
        Editing a comment
        I need function like Serial.read();

    • #5
      you cant serial read, but geteventdata returns 1(pressed) and 0(let go) you can set a variable there to say its pressed, make a global like buttonpressed=0; then have geteventdata set it when its pressed or not, then in your loop do your statements there, but DONT while loop, it wont work, you can set millis to toggle every 100ms if buttonpressed == 1 until genie gets the event for the let go

      Comment


      • #6
        I think you dont understand me. I apply your suggestion but your solition doesnt work. I changed momentary off because buttonpressed=1 until i press again. Now i can use "if" function for loop. But program read my first buttonpress. Then program write Rh request every 100ms. But if i clicked rh button again program doesnt stop. Again im saying program read only once. If my code is wrong please write correct code. Thank you again for answering.
        Code.
        if (Event.reportObject.object == GENIE_OBJ_USERBUTTON)
        {
        if(Event.reportObject.index==0)
        {
        here: // i use this code because if im not using this code show only 1 RH request
        buttonpressed=genie.GetEventData(&Event);
        if(buttonpressed==1)
        {
        Serial.println("RH Request");
        delay(100)
        goto here;
        }
        }
        }
        Please try this in your program its very simple only 2 button. if you solve problem then send me code please. I'am stuck.

        Equipment:
        Arduino Mega
        uLCD 43PT
        Last edited by bkz124; 5th July 2017, 05:36 PM.

        Comment


        • #7
          Hello,

          I don't think your goto is helping with the problem. Your code could be just looping around and unable to procees any other events. Is it possible to check this once and avoid using goto's.

          Best regards

          Paul

          Comment


          • #8
            Okay i avoid using goto's but now i cant send RH request every 100ms.
            Also i need help for up and down function. How to use HOLD key function? I think need magic event but i didnt find magic event code.

            Comment


            • #9
              Thank u all for answer but your answers wrong. I found solution on my own. Anyone who have this problem, can send me a message for solution.

              Have a nice day

              Berkcan

              Comment


              • James_4DSystems
                James_4DSystems commented
                Editing a comment
                Why are you wanting people to message you for a solution? Why don't you post your solution here, so if anyone encounters the same problem, then it is in the same forum thread.

            • #10
              From what I can see of your posts, you are using Serial to talk to the display, and you are also using Serial to do prints to your Terminal console. That will never work, as the display will also be receiving your prints like "RH Request" and it will not understand. You cannot use the same serial port to talk to the display, and talk to something else like the Terminal.

              If you havent already, I suggest you have a read here:

              http://forum.4dsystems.com.au/forum/...and-4d-display
              James

              Comment


              • #11
                seems I left out the genie.DoEvents(); command...things are working somewhat OK now....

                Comment


                • tonton81
                  tonton81 commented
                  Editing a comment
                  you posted on the wrong thread

                  Tony
              Working...
              X