Announcement

Collapse
No announcement yet.

Limp/dead mode

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

  • tonton81
    replied
    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, 08:41 AM.

    Leave a comment:


  • James_4DSystems
    replied
    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.

    Leave a comment:


  • tonton81
    replied
    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, 08:32 AM.

    Leave a comment:


  • tonton81
    replied
    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, 08:30 AM.

    Leave a comment:


  • tonton81
    replied
    this is the test arduino code:
    Code:
    #include <genieArduino.h>
    Genie genie;
    
    void setup() {
      Serial.begin(115200);
      Serial1.begin(200000);
      genie.Begin(Serial1);
      genie.AttachEventHandler(myGenieEventHandler);
      pinMode(23, OUTPUT); digitalWrite(23, 0); delay(100); digitalWrite(23, 1); // RESET DISPLAY
    //  delay(3500); <-- removed :)
      genie.WriteContrast(15);
    }
    
    void loop() {
      genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0 , random(50));
      genie.DoEvents();
      Serial.print('\t');
      Serial.print('\t');
      Serial.print('\t');
      Serial.println(random(10, 99));
    }
    
    void myGenieEventHandler(void) {
      genieFrame Event;
      genie.DequeueEvent(&Event);
      Serial.println(Event.reportObject.object);
      Serial.println(Event.reportObject.index);
      Serial.println(genie.GetEventData(&Event));
    }

    Leave a comment:


  • tonton81
    replied
    ill try that now and ill re-edit this post**

    1) hot unplug > 10 secs == works.
    2) boot up arduino, THEN plug in lcd == works.

    the first video shows the 2 resistors i added, the code will not work without it as the uart pins float, and prevents the ERROR_TIMEOUT from triggering because:

    Code:
            if (do_event_result == GENIE_EVENT_RXCHAR) {
                timeout = millis() + Timeout;
    that is taking priority over timing out due to the random data from a floating line, so it never reaches the timeout error. lots of debugging but i figured it out
    once the lcd is disconnected, the lines get pulled low, forcing the pins in a known state and processing the ERROR_TIMEOUT to actually work better.
    Last edited by tonton81; 22nd May 2016, 08:11 AM.

    Leave a comment:


  • James_4DSystems
    replied
    Interesting stuff.
    That hotplugging test, can you unplug for >10 seconds, rather than just plugging it back in straight away?
    Can you start your sketch with the display unplugged and then plug it in once the sketch has started?
    Curious what the results are.
    That first video is like 2 seconds long, I have no idea what it is trying to show.

    Leave a comment:


  • tonton81
    replied
    10K resistor benchtest: https://youtu.be/1eRAKZJ1ZHQ
    hotplugging 4 times: https://youtu.be/JBxP0Xa5LVE
    hotplug twice while background random numbers print to serial monitor, showing loop function still running normally: https://youtu.be/E2A6NPt4GXY
    button press responses: https://youtu.be/m8Fc0VqIMGI
    Last edited by tonton81; 22nd May 2016, 08:01 AM.

    Leave a comment:


  • tonton81
    replied
    Don't forget to remove the delay in your sketch.

    Tested working:

    1) no delays now (as opposed to my last attempt at 200ms).
    2) non-blocking other code, whether lcd connected or not your sketch can do other stuff.
    3) responses now work as opposed to my last attempt.
    4) no need to modify your sketch, this runs inline the library to save you some recode work, just get rid of the delay!
    5) hot plugging works as well.
    Last edited by tonton81; 22nd May 2016, 07:38 AM.

    Leave a comment:


  • tonton81
    replied
    OK, i got a little bored today so i decided to do a new mod which works for hotplugging, no delay after reset, and deals with receiving responses as well!
    I will post the mods and the 2 files as well if anyone wants to play with it. You will require 2 pull down resistors on the UART line to force an error state when lcd is disconnected, as the wire will act as an antenna causing the error frame to process as valid data. The resistors are 10K ohm. Click image for larger version

Name:	shieldless4dresistormod.png
Views:	11
Size:	907.6 KB
ID:	52647


    The code will not fully function without the resisters to put the uart floating pins in a known state, this is required.

    2 files will need to be edited. I will list the modifications in BOLD for your viewing curiosity.

    in genieArduino.h:

    modify these 2 lines:

    Code:
    #define TIMEOUT_PERIOD 100
    #define RESYNC_PERIOD 0
    Then go down a few pages of the same file and look for:

    Code:
    // Global error variable
    int Error;
    int genieErrorCounter = 0; // This needs to be added.
    Save file and exit.



    in genieArduino.cpp

    Goto this function:

    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++;  //ADD THIS LINE
                if ( genieErrorCounter> 10 ) {  //ADD THIS LINE
                   genieErrorCounter= 0;  //ADD THIS LINE
                   return;  //ADD THIS LINE
                  }  //ADD THIS LINE
            }
    
            if (GetLinkState() == GENIE_LINK_IDLE) {
              genieErrorCounter = 0;  //ADD THIS LINE
                return;
            }
        }
      while (deviceSerial->read() >= 0);  //ADD THIS LINE
        EventQueue.rd_index = 0;  //ADD THIS LINE
        EventQueue.wr_index = 0;  //ADD THIS LINE
        EventQueue.n_events = 0;  //ADD THIS LINE
        Timeouts = 0;  //ADD THIS LINE
        LinkState = &LinkStates[0];  //ADD THIS LINE
        *LinkState = GENIE_LINK_IDLE;  //ADD THIS LINE
        Error = ERROR_TIMEOUT;
        handleError();
        return;
    }
    Attached Files
    Last edited by tonton81; 22nd May 2016, 07:29 AM.

    Leave a comment:


  • tonton81
    replied
    the event handler doesnt seem to be working either with this mod, output only, besides on a serial line is bi-directional and no acks/naks should be needed unless it's i2c, even _some_ spi devices dont need acks/naks. Usually the data is discarded if it's not useful to the device since there is no error checking with serial, but at least I've inspired a possible fix for someone more capable than i am to code :P

    Leave a comment:


  • ESPsupport
    replied
    At first look it looks like your mod is stopping the code waiting for the ACK from the display.

    If this is indeed what it is doing it can only lead to problems.

    Leave a comment:


  • James_4DSystems
    replied
    Hi tonton81

    Yes alot of that is already known, and some of it is in the Sticky at the top of the Arduino section on the forum.

    Thanks for the information you have provided. We have already added this onto the list of things to look at once a resource is available. I will note down this topic as a point of reference.
    Great news about the reduction in delay you have found though with the modifications you have made. We will certainly study this closely, and see what (if any) other things may be affected, positive or negative.

    Many thanks for your input. Its suggested input like this which helps make a better product.

    Regards

    Leave a comment:


  • tonton81
    replied
    also know this, that the more objects you write, the more delays it causes, a workaround that is I make the host work by current form selection, why write data when the page isn't loaded on lcd?
    if you do this you won't experience much, if any delays, you won't get actually ANY delays if you do this, the delay is only by accessing the genie.Write objects. So writing them as form dependant can be more efficient, plus this type of concept above will add hot plug, fast start, and anti-lockup features at same time

    Leave a comment:


  • tonton81
    replied
    This is the video posted with random data being output to several ints at same time during hot plugging
    note that this is without rebooting the host.
    https://www.youtube.com/watch?v=VVPc...ature=youtu.be

    Leave a comment:

Working...
X