Announcement

Collapse
No announcement yet.

Limp/dead mode

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

  • #16
    OH! I'll give you another good news, it wasnt working in original code either. (ERROR_TIMEOUT);
    i put the original library back as a test, with the resistors intact, and guess what, the loop() functions without lcd connected!
    so it looks like the resistors can fiix the timeout issue as well, but you still require a delay on startup unless you modify the H/CPP files like i did to work with it
    Last edited by tonton81; 22nd May 2016, 09:30 AM.

    Comment


    • #17
      oh! sorry i sent one line to add to the code:

      Code:
      void Genie::WaitForIdle (void) {
          uint16_t do_event_result;
          long timeout = millis() + Timeout;
      
          for ( ; millis() < timeout;) {
              do_event_result = DoEvents(false);
              // if there was a character received from the
              // display restart the timeout because doEvents
              // is in the process of receiving something
              if (do_event_result == GENIE_EVENT_RXCHAR) {
                  timeout = millis() + Timeout;
                  genieErrorCounter++;
                  if ( genieErrorCounter> 10 ) {
                     genieErrorCounter= 0;
                     return;
                    }
              }
      
              if (GetLinkState() == GENIE_LINK_IDLE) {
                  genieErrorCounter = 0;
                  return;
              }
          }
          while (deviceSerial->read() >= 0);
         deviceSerial->flush();
          EventQueue.rd_index = 0;
          EventQueue.wr_index = 0;
          EventQueue.n_events = 0;
          Timeouts = 0;
          LinkState = &LinkStates[0];
          *LinkState = GENIE_LINK_IDLE;
          Error = ERROR_TIMEOUT;
          handleError();
          return;
      }
      if you dont flush the buffer while it's disconnected it'll run a bit slower when hot plugged in due to the garbage collected on connectivity . and here's the new files:
      Attached Files
      Last edited by tonton81; 22nd May 2016, 09:32 AM.

      Comment


      • #18
        Cool, ill get someone to look at this in detail.
        Your first attempt meant the event handlers didnt work. Have you test that again?
        What if you disconnect the display while there are events in the queue... are they lost?
        Anything send to the LCD while its disconnected I assume are also lost (ie if you set a form)

        See if you can figure out how to set a flag if the library detects no display is connected, that would just finish it off.

        Lots of potential 'gotchas' here, so when we get a resource available we will go over this in detail, and if things are working right then we will certainly look at adopting things into the main library. Needs lots of testing and to figure out what the compromises are though.
        James

        Comment


        • #19
          yes, the event handler is working in this
          the buffer queue is wiped out when the timeout occurs (lcd missing), starts a new when connected. If this isn't done, the display doesnt run at full speed and potentially stall since the buffer has garbage in it

          yes, anything sent to display while it's disconnected is simply ignored and moved on without affecting your other code

          the timeout pretty much says that the display is not there, my idea was to attack that section and study it, print to monitor and see what is going on, I was going to monitor the ACKs for availability of display before processing code, but, after manipulating the timeout objects, they more or less do it inline without any extra code, however, like i said, the fall-out timeout does not occur mostly ever due to the fact that the uart sends garbage to the port from floating line that the library still tries to figure out, the resistors prevent that and actually make the original library (and the modded one) work efficiently and fixes the broken timeout function.
          Last edited by tonton81; 22nd May 2016, 09:41 AM.

          Comment


          • #20
            i keep 2 files in my folder, original and genieMod, if i need to test either of them, i just override and upload as needed, but the resistors are definately needed to make the library timeouts work

            Comment


            • #21
              Code:
                           if ( genieErrorCounter> 10 ) {                genieErrorCounter= 0;
              This area here is where I did the event handler testing: This value is always 1 when data is sent to lcd, followed by idle link which returns it to 0. When the lcd is not connected, it keeps incrementing, so initially i set it 2. However, when testing event handler, it didnt work. When I increased the counter to a value of 10, event handler worked, so my guess is there is more increments when reading due to the frame data BEFORE the idle link is set. 10 seems to be more than enough as i am getting the object, index, and event data, and when the idle link is set, counter is reset before return;. seeing as I use this counter to prevent lockups, and the numbers can go up fast, if you do have event issues you could set it to 25 for example and it'll go away. Seems to process the RX data so, if you have issues with reporting, increasing this number will help and you shouldnt see any difference if you set it higher, i set it to 50 just now and there is no difference, the events come in, the counter is there just for protection
              Last edited by tonton81; 22nd May 2016, 10:01 AM.

              Comment


              • #22
                you know what, i added the counter before i did the resistor mod, i just wiped it out and it works without it
                less code!

                Code:
                void Genie::WaitForIdle (void) {
                    uint16_t do_event_result;
                    long timeout = millis() + Timeout;
                
                    for ( ; millis() < timeout;) {
                        do_event_result = DoEvents(false);
                        // if there was a character received from the
                        // display restart the timeout because doEvents
                        // is in the process of receiving something
                        if (do_event_result == GENIE_EVENT_RXCHAR) {
                            timeout = millis() + Timeout;
                        }
                
                        if (GetLinkState() == GENIE_LINK_IDLE) {
                            return;
                        }
                    }
                    while (deviceSerial->read() >= 0); // clear RX buffer
                    deviceSerial->flush(); // clear TX buffer
                    EventQueue.rd_index = 0; // flush EventQueue
                    EventQueue.wr_index = 0; // flush EventQueue
                    EventQueue.n_events = 0; // flush EventQueue
                    Timeouts = 0; // reset Timeouts
                    LinkState = &LinkStates[0]; // clear LinkState
                    *LinkState = GENIE_LINK_IDLE; // set Link Idle
                    Error = ERROR_TIMEOUT;
                    handleError();
                    return;
                }
                Looks like since the resistor fixed the timeouts, the buffer cleansing before hookup did the rest in the timeout section...

                this is the new files with counter removed, all functions tested still work as expected

                only the code above in green was added to the library, identifying it's purpose as well.
                Attached Files
                Last edited by tonton81; 31st May 2016, 09:32 AM.

                Comment


                • #23
                  here is a 10 second unplug video i made for you: https://www.youtube.com/watch?v=VeD7...ature=youtu.be
                  button pressing on corner of lcd reports object, index, and eventdata: https://www.youtube.com/watch?v=IktT...ature=youtu.be
                  Last edited by tonton81; 22nd May 2016, 10:25 AM.

                  Comment


                  • #24
                    Click image for larger version

Name:	IMG_2141[1].JPG
Views:	10
Size:	2.37 MB
ID:	52666

                    Here is the LCD shield mod, 2 x 10K ohm resistors to GND, you can wire your center pins of RX/TX to mega2560 RX1/TX1 port etc or put the jumper to use UART0.
                    Tested and working using the original and modded library

                    Comment


                    • #25
                      RX1/TX1 of arduino hooked up using jumper wires with the modded shield:

                      Click image for larger version

Name:	IMG_2142[1].JPG
Views:	8
Size:	2.43 MB
ID:	52668

                      Comment


                      • #26
                        Here is the 2nd shield I have put the resistors on, this time not covering the printed labels, sorry i dont have any surface mount 10k ohms on hand :P

                        Click image for larger version

Name:	IMG_2144[1].JPG
Views:	8
Size:	2.24 MB
ID:	52683

                        Comment


                        • #27
                          James, I have a gift for you, a good 2-way test using calculator demo, and hot plugging, no 3500 delay, and the loop() runs full speed no blocking, even without lcd

                          https://www.youtube.com/watch?v=H_xb...ature=youtu.be
                          Last edited by tonton81; 23rd May 2016, 11:51 AM.

                          Comment


                          • #28
                            Looks like it is working well. Nice work.
                            James

                            Comment


                            • #29
                              1) I did another test which tested the power down ability of the display, instead of sleeping via contrast 0, with the display still connected to the IO lines of the microcontroller, i drop just the power line (VCC) to display, making it turn off, good. Apply VCC back to the display, responds as expected as well. Used the calculator demo as a test to verify 2 way communication.

                              So cutting power and applying power work, without restarting microcontroller code.
                              This is also a benefit as powering off also disables the touch ability, preventing unnecessary taps or extra sleep forms being made for touch response.
                              I've tested it using a PRMA1A05 reed relay, using a GPIO to power up/ power down LCD at will. Go green yay!

                              2) Another test I will do is commenting out the RESETLINE and it's 100ms delay, to test HOST boot with LCD without resets

                              Code:
                              //  pinMode(RESETLINE, OUTPUT);  // Set D4 on Arduino to Output (4D Arduino Adaptor V2 - Display Reset)
                              //  digitalWrite(RESETLINE, 0);  // Reset the Display via D4
                              //  delay(100);
                              //  digitalWrite(RESETLINE, 1);  // unReset the Display via D4
                              //  delay (3500); //let the display start up after the reset (This is important)
                              The Result: works as expected, using the calculator demo as a test

                              It looks like we can gain an extra GPIO pin now for other use (instead of reset) on our precious MCUs

                              These are still tests I'm doing based on the last mod, no current changes have been made since

                              Also did a full HOST/display powerdown and startup using demo.

                              As of now, theres only TX/RX,VCC, and GND from display for my tests
                              The RESETLINE (since i am not using shield) is tied directly to VCC wire (always pulled high).
                              For the SHIELD, if you really wanted, you could take the RES jumper off, and put a jumper wire from that middle pin and wire it to the VCC of the host to keep it always HIGH, so the display will be in a working state when powered.

                              So, by freeing up the reset line in my tests, I am reusing the freed GPIO for the 5v reed relay which can fully turn on/off the lcd without touching the contrasts,
                              benefit of this can also be less host code, as when setting a contrast it's recommended to set it once only not repeatedly, however, digitalWrite(4, HIGH) //(ON) and digitalWrite(4, LOW) //(OFF) is indeed a 1 line solution without flooding the UART line <-- this only happens when you dont do it once, setting a contrast in the loop repeatedly is really a waste of resources and may potentially cause overflow if the buffer isn't read on-time.


                              Tony
                              Last edited by tonton81; 2nd June 2016, 09:19 AM.

                              Comment


                              • #30
                                That reset, and full power, delay-less boot stuff is optional, of course, up to the end user to accomplish, other than ommitting the 5 lines above (and it's global RESETLINE variable)
                                The benefit is for the end user who wants those additional features, but they won't work without the last library mod posted in post #22, and the 10k resistor pull-down mod (mandatory) in posts: 10, 24, and 26, depending on if your using a shield or not.
                                Last edited by tonton81; 2nd June 2016, 09:31 AM.

                                Comment

                                Working...
                                X