ESPUI icon indicating copy to clipboard operation
ESPUI copied to clipboard

updateTime() keeps firing the callback

Open jberezin opened this issue 1 year ago • 5 comments

First I have a button which triggers the updateTime function:

   switch (type)
    {
    case B_DOWN:
        Serial.println("Button DOWN");

        if (sender->id == accuSet)
        {
            // fire the time call back
            // Request an update to the time
            Serial.println("Triggering time callback");
            ESPUI.updateTime(timeId);

            // Will trigger timeCallback
        }
        break;

I have checked and that code is only called once but the timeCallback fires least once a second. So my code is working and the timeUpdate is working but I only want it to occur once. I didn't know this was happening until I put in some serial print statements because my code seemed to be working fine:

Select: ID: 4, Value: 2024-07-26T08:01:40.864Z utc time: 2024-07-26T08:01:40.864Z Select: ID: 4, Value: 2024-07-26T08:01:40.913Z utc time: 2024-07-26T08:01:40.913Z Select: ID: 4, Value: 2024-07-26T08:01:40.995Z utc time: 2024-07-26T08:01:40.995Z Select: ID: 4, Value: 2024-07-26T08:01:41.101Z utc time: 2024-07-26T08:01:41.101Z Select: ID: 4, Value: 2024-07-26T08:01:41.146Z utc time: 2024-07-26T08:01:41.146Z Select: ID: 4, Value: 2024-07-26T08:01:41.199Z utc time: 2024-07-26T08:01:41.199Z

I would like to know how to turn this off until the button which triggers the updateTime() is pressed again.

Thank you for any help here.

jberezin avatar Jul 26 '24 08:07 jberezin

I worked around this problem by creating a new variable and testing it in the callback and simply returning if I don't really need the current time of day. I also tried disabling the time control but that didn't work.

jberezin avatar Jul 31 '24 11:07 jberezin

It would be great if there was a response from the developer on this one. I had the same problem and solved with a variable that is always reset after the time value is updated. I see the complete example appears to trigger exactly the same behaviour you describe. Maybe it is the expected behaviour but if it is not it means there is some extra processing happening that might not need to be there. It would help if there was a comment in the ReadMe confirming the behaviour.

pgv123 avatar Nov 04 '24 09:11 pgv123

I was able to stop it by removing callback:

void timeCallback(Control *sender, int type) {
  if(type == TM_VALUE) { 
    Serial.println(sender->value);
    sender->callback = nullptr;
  }
}

eshatohhin avatar Nov 22 '24 09:11 eshatohhin

I was able to stop it by removing callback:

void timeCallback(Control *sender, int type) {
  if(type == TM_VALUE) { 
    Serial.println(sender->value);
    sender->callback = nullptr;
  }
}

Thanks, I will give that a try.

jberezin avatar Jan 20 '25 15:01 jberezin