s00500 / ESPUI

A simple web user interface library for ESP32 and ESP8266
https://valencia.lbsfilm.at/midterm-presentation/
Other
923 stars 174 forks source link

Enable and disable controls #154

Closed iangray001 closed 2 years ago

iangray001 commented 2 years ago

Allow controls to be enabled and disabled programmatically. The controls update visually to show their interactive status. Screenshot 2022-01-31 at 22 37 12

README has been updated to document the API additions.

I did make a few implementation decisions here. The main one being that when disabled, a control will grey out, but the panel does not (it keeps its "Peterriver" colour etc.). This is mainly for flexibility and to support grouped controls. The README explains how to also grey the panel (as in the above screenshot) using Inline Styles.

Closes issue #56.

nodoubtman commented 2 years ago

@iangray001 thank you :)

thomastech commented 2 years ago

@iangray001 Hello Ian,

I installed the PR today and have been experiencing an odd problem. Controls randomly become disabled. I didn't make any changes to my app, just updated the lib with PR #154, recompiled my ESP32 project, and ran it.

I don't have a reliable way to invoke the bug, so information is limited for now. At this point all I know is that it just happens randomly. So far I've had buttons and Text Inputs become disabled. Reboot and issue goes away, until the next time. Very hard to reproduce.

As I learn more I will let you know. If you have any things for me to try then ping me.

EDIT: I've also discovered that using two browser windows at the same time has problems with keeping sync. None of my Option Selects remain synced. This also affects some switches, but not all. This is a new issue that appeared after installing this PR (issue not experienced with your Jan-20-2022 ESPUI build).

And while I was having the randomly disabled control problem I also had two browsers running. So maybe these issues are related somehow.

I've reverted back to the Jan-20 build so I can continue working on my project. But if you need me to test something then let me know and I will re-install this PR.

iangray001 commented 2 years ago

So I've worked out the controls being disabled thing, I hadn't initialised the enabled value. That is in the latest commit on my repo. I'll get it pulled in soon. The reason you were having difficulty debugging it is because it was affected by the random contents of memory from previous runs!

The issue with clients getting out of sync actually isn't my fault ;) This commit seems to be the problem. Specifically this line.

I'm not sure what is going on here, more investigation required, but I have reverted this line and it seems to be working again on my end.

thomastech commented 2 years ago

@iangray001 Many thanks! Feedback below:

  1. PR #162 fixes the randomly disabled controls.

  2. Reverting the offending line # 1006 in espui.cpp (from the Emulation PR #155) fixes the random client sync failure issue. I think this also resolved the random page timeouts I've been seeing (not previously reported, didn't want to load you up with more things to fix). But like my other recent ESPUI problems, this occurs randomly, so I can't confirm it is fully solved. Fingers crossed.

iangray001 commented 2 years ago

I've thought more about that line and I now understand why it is a bug. The issue is that if clients come and go then IDs can be assigned with higher and higher IDs whilst the total count might remain low. For example you might end up with 2 clients, but with IDs 4 and 5. The committer has presumed that IDs will always be less than count(), and so clients fail to get updated.

I'm going to revert that, and a similar line elsewhere. I'll stick it on my existing PR.

thomastech commented 2 years ago

The issue is that if clients come and go then IDs can be assigned with higher and higher IDs whilst the total count might remain low.

Hmm, that seems to explain one of my recent observations. Newly connected web clients would sync correctly while older web clients would often not remain in sync. But very random behavior since some controls would still sync.

No two sessions were the same; I hate random bugs.