Announcement

Collapse
No announcement yet.

Multiple Displays and Multiple Forms Using a Teensy 4.1 as Arduino

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

  • James_4DSystems
    replied
    Hello.

    Ill try and explain it again.

    The handler in the Arduino, is to 'handle' events which come from the specific display it is for.
    You have 2 displays, Top Display, and Bottom Display.
    So any events that come from the Top Display, such as a touch to a 4D Button, would trigger the Top Displays handler in the arduino code, to trigger. You then 'handle' the event in the Handler, and do what is appropriate for that single event.

    So if you touch a button on Top Display, then your Top Display's handler then needs to decrypt the message that comes in, and do whatever is appropriate.
    If you touch something on the Bottom Display, then the Bottom Display's handler needs to handle it.
    Only the appropriate handler will fire depending on what display you triggered the event on.

    If you want the Top Display's button to make the Bottom display do something, then the Top Displays handler needs to have code which will cause the Bottom display to do something.

    I hope that is clear.

    I will have a look at your code now.

    Leave a comment:


  • Riptor919
    replied
    So i have tried coding a bit more like you said but the screens still don't change form properly. Maybe you can spot what's wrong with my code. I attached the report message to all of the forms in the 4DWS Program, and got rid of the nested if branches where it was inappropriate. I am still confused on when i should include something in the top display handler or bottom display handler? that doesn't make any sense to me so i just assumed the bottom display and blocked out most of the lower display code for the handler there
    Attached Files

    Leave a comment:


  • Riptor919
    commented on 's reply
    thank you i will send an update with the ws4 file tomorrow sorry for the confusion

  • James_4DSystems
    replied
    Sorry that was incredibly hard to understand, so no I don't follow you 100%.

    Regardless, when you do something on the display and a Reported Message is in the Event handler of a button etc, the Arduino code will jump to the myGenieEventHandler function for that display, check the event and exit the handler within milliseconds, it does not sit there and hang around. So if you are thinking it will do the index == 0 operation and then wait there and then do the index == 2 operation, then you are mistaken, that is not how it works.
    The code flows extremely fast and will loop around and around the main loop and only jump into the event handler 1 single time for 1 single event that happens from the display, and then it goes back to the main loop again, until another event happens and triggers the handler.

    I cannot see how the 4Dbutton index can be 2 and then 0 in the exact same event. That is not how it works. The nested code for 0 will never execute in my eyes. It will do the 2 code when you do 4Dbutton2, set the top display to form 1, and then quit the handler. Likewise for the same code you have in the bottom display handler. Even if you next time round trigger the 4Dbutton index of 2, it will never execute as you code is checking for 0, it can not reach the 2 code. Nested code here is not correct.

    If you change the form from the display, using ActivateFormX in the Event tab of WS4, then nothing happens in the Arduino myGenieEventHanlder code. If you want something to happen in the Arduino code then you need to put a reported Message even on the Form itself, so when the display changes the form to say Form2, then Form2 Reported Event will fire which you can capture in the event handler, telling the Arduino that the display has changed Form. This will only Fire if the display changes the form though (ie setting the ActivateFormX event and having the Form as Reported Message), it will not fire if you get the Arduino code to change the Form, as the Form Reported Message will not fire in that situation..

    You haven't sent your WS4 code, which I am guessing has changed, so its very hard to follow even with your docx file you attached.

    Anyway, I hope the above helps.

    Regards
    James

    Leave a comment:


  • Riptor919
    replied
    So i get what you are saying, but i wrote in my code is actually what i meant to do so here is my thought process: if the user clicks 4dButton2 it takes them to Form0 on the Bottom display which was done already within 4DWS program via Form0Activate on the events for that button (keyboard and the 2 buttons RESET and MAIN MENU), and form 1 on the top display (SET Frequency and SWAP Frequency) which i seem to only be able to do with code and not inherently on 4DWS since i would be trying to change the form of a different display and that is not inherent to the events tab for a Button only for the current display you are on right? So now we are within that nested if statement (display2 is the top display which i have changed to easier naming scheme in my updated code) and on the new form0 on the bottom display and form 1 for the top display right? so now if the user presses 4DButton0(which is only on form 0 of the bottom display/display1), then it will reset the ILedDigit widgets on the top display on form 1. So do you understand now what i am meaning to do i had a feeling the code was weird but i am not sure how to properly deal with the 2 displays in the correct way i guess. I will attach my updated code i have not really changed anything but the naming of the displays. Know that the Bottom display (BotDisplay) is the 32DCT-CLB-AR and the top display (TopDisplay) is the 24D-CLB which is not touch screen so i am basically wanting to just write to that one and control it using buttons on the lower display at the discretion of the user. If you need any clarification let me know and i will happily do so. Thanks again!! This diagram might help you understand what i am doing here!
    Attached Files
    Last edited by Riptor919; 17 July 2021, 04:58 AM.

    Leave a comment:


  • James_4DSystems
    replied
    Originally posted by Riptor919 View Post
    So if I am using two event handlers (as I should right?) for the two different displays, how should i set up the code as far as where I say change the form at this certain index button press? if I want to change the display2 form but I click a button on display 1 to do so, would that be within eventhandler1 (display1 handler) or eventhandler2 (display2 handler)? a bit confused by this and I just tried to code it and it failed to do anything on display2 (top screen)
    Well the event handler is the function which handles the received data from a specific display. So if you push the button on display1, then you handle the code in display1's handler as that is what is triggered when you push the button on display1. Obviously display 2's handler wont be triggered if you push a button on display 1.

    Having a quick look at your code, the nested code you have doesn't look right.

    Code:
    if (Event.reportObject.index == 2)    // MAIN MENU -- FREQUENCY button -- Already includes a change of form to Form0 as Event
          {
            display2.WriteObject(GENIE_OBJ_FORM, 1, 0);
    
            if (Event.reportObject.index == 0)    // RESET Button on 4D Display
            {
              // RESET BOTH Digit Objects to all zeros
              Serial.println("RESETTING FREQUENCIES");
              ClearLedDigits0();
              ClearLedDigits1();
            }
    
          }
    if the index is 2, then its 2, it is never going to be 0 after being 2 (ie the code further nested in here, so that code will never execute).
    I assume you more intended to do this:

    Code:
          if (Event.reportObject.index == 0)    // RESET Button on 4D Display
          {
            // RESET BOTH Digit Objects to all zeros
            Serial.println("RESETTING FREQUENCIES");
            ClearLedDigits0();
            ClearLedDigits1();
          }
          if (Event.reportObject.index == 2)    // MAIN MENU -- FREQUENCY button -- Already includes a change of form to Form0 as Event
          {
            display2.WriteObject(GENIE_OBJ_FORM, 1, 0);
          }
    I'm not sure if you intended this or not, but you have display2 in your handler for display1, in all the cases, and then also display2 in display2's handler.

    Have a look anyway, and if you are still stuck, please send your full code for both displays, and your arduino ino again, and ill try and simulate it here myself.

    Regards

    Leave a comment:


  • Riptor919
    replied
    So if I am using two event handlers (as I should right?) for the two different displays, how should i set up the code as far as where I say change the form at this certain index button press? if I want to change the display2 form but I click a button on display 1 to do so, would that be within eventhandler1 (display1 handler) or eventhandler2 (display2 handler)? a bit confused by this and I just tried to code it and it failed to do anything on display2 (top screen)
    Attached Files
    Last edited by Riptor919; 15 July 2021, 06:37 AM.

    Leave a comment:


  • Riptor919
    commented on 's reply
    Very helpful thank you!!

  • James_4DSystems
    replied
    Hello,

    If you want to change forms from your arduino code, then yes you use the WriteObject command, pointing to the GENIE_OBJ_FORM object, writing the form index, and without any value as that field is not used for Form changes.

    display1.WriteObject(GENIE_OBJ_FORM, 1, 0); // Display 1 Form 1
    display1.WriteObject(GENIE_OBJ_FORM, 2, 0); // Display 1 Form 2
    display2.WriteObject(GENIE_OBJ_FORM, 5, 0); // Display 2 Form 5
    etc

    I would suggest you don't use Hex in case it trips you up as you get passed 9, due to hexadecimal going 0x0A, 0x0B, 0x0C etc too.

    You don't need any Event for form changes from the Arduino code. Events are for telling the Arduino when something happens on the display, such as a button push.
    However you have said you want it to happen on button pushes, so you could set up a Reported Message on the button, and then in your myGenieEventHandler capture that event for the button, and change the form from the handler.

    Or another way is have the button change the form for you, in the display, directly. You don't need to do this via the Arduino if you don't want. Just set the display event to be Form1Activate, etc, or whatever the form number it is you want it to change to that is present in your project. The Arduino wont know what form you are on, but that isn't necessarily a problem unless you are writing to objects that are only on the current form etc.

    Regarding the internal LED digit, again you don't need an Event on this as you are not sending from the display to the Arduino, you are wanting Arduino to display. So you simply write the data to the LED Digits object using the WriteIntLedDigits function. You can find all this in the readme of the genieArduno library on Github. https://github.com/4dsystems/ViSi-Genie-Arduino-Library

    display1.WriteIntLedDigits(0, 100); // Display 1 Internal LED Digits 0, Value of 100

    I hope that helps

    Regards

    Leave a comment:


  • Multiple Displays and Multiple Forms Using a Teensy 4.1 as Arduino

    Hi so I have made some good progress on my project but would am stuck on exactly how I would code form changes using buttons on a 32DCT-CLB-AR correlating to specific forms on a 24D-CLB display which is going to be placed right above it and both are wired to the Teensy. I know it might involve using the WriteObject() function something like this display1/display2.WriteObject(GENIE_OBJ_FORM, 0x00, ) unsure of what to really put in the last parameter. Do you think that something like this would best be achieved using a form number array and essentially just indexing it whenever I click a certain button? Also I am a a bit confused on what to do within the 4DWS code as far as do I need to change event settings for something in order for it to correspond to commands to change forms from a different display? I'll attach everything I have here so far.

    Also, another question I have is if I have say an Internal LED Digits widget on the 24D-CLB and I want it to be just reading data that i write to it from some Arduino code and not from an input widget is that possible because I sit there thinking what is should assign as the event but I really just need the 24D-CLB to be reading what I send to it not necessarily things that are from an input widget more like serial data or just serial data that I've deconstructed on the Arduino side and simplified to send over to the display. Any questions just let me know!
    Attached Files
Working...
X