-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sometimes CO2 value prints to wrong place on ESP32 display #145
Comments
Looks like it has something to do with the web server. |
… to wrong place on TTGO T-Display melkati#145)
Last night I started to investigate the bug. My first step was to add a trace each time the CO2 value was displayed on the screen. My surprise was that it was repainted a thousand times in a row, even if the value had not changed. I created the variable co2_displayed to store the value displayed on the screen and added the condition to the ShowCO2 loop so that it is only executed when co2 != co2_displayed When entering the menu you have to set co2_displayed = 0 to display the value when exiting. By doing this the bug has disappeared !!! I think the same should be implemented for the rest of the values: temperature, humidity, battery, etc. The less the processor has to do, the less it will consume. |
Thank you, Sergio. It can be a good workaround but I think it is not the root cause of the issue. The issue looks related to the web server #145 (comment). Since I wrote that another user reported the same. Also, it looks like it doesn't happen os ESP32 S3, so it may be memory related. Under the hood CO2 Gadget only prints on screen what is needed and when is needed, I think there is no need to save on display prints (it does not affect power consumption either). Anyway, it can be a good workaround until we find the root cause. I was thinking on redrawing the screen after a request to the web server (this will fix any issue related to this) or your fix (will only fix this case and needs a lot of new code - and more as we continue including things as the PM sensors and more data to show). I don't know yet witch one to implement... 🤔 With this fix the issue can look like it's fixed but only because it is more difficult to coincide a web request with a display update. If it coincides this will not solve the underlying issue and the screen will be corrupted). We have time until the next release to decide... |
I just discovered it also happens on the ST7789_240x320 variant. Looks to be worse. It suggests a memory problem as it leaves less free memory (having a display with more resolution it uses more memory). It doesn't even load the page preferences.html. I would like to avoid changing partitions, while possible, for backwards compatibility. |
You say that "Under the hood CO2 Gadget only prints on screen what is needed and when is needed" but when I traced showCO2() function yesterday is executed in every main loop(). Yesterday also I detected that bug only occurs when internal web server load a page. If you reload webpage bug is reproduced. Enter and exit menu to reload display, refresh webpage and bug is showed again. I hope you can find the root of bug. |
Everything in CO2 Gadget is executed always in the loop. It's intended that way, as it's completely event-driven. What I mean is that CO2 Gadgets uses sprites so it only updates the "live" parts of the display. This will improv with time as not everything is converted to sprites yet. If you include this code to measure the time it takes for a block of code to execute:
And you call it on the display loop as:
You will find out that it takes just 72ms to update the display:
Yes, we can optimize even more the display updating but, in my opinion, it's not needed right now as it will need a lot of code for no obvious benefit.
That is what I just told you:
Maybe I should do some testing with optimized partitions to test if the issue goes away. I'm still yest to see this happening in a ESP32 S3 with different partitions that leaves a lot more free memory... The issue with changing partitions is that we lose backwards compatibility and users will have to configure CO2 Gadget again from scratch (maybe we can add a backup and restore for settings in the preferences web page (already planned). |
Finally, I found out the cause of this bug! It's a memory problem where, if CO2 Gadget sending a web request (the web server is very memory hungry), there is not memory left to create the sprite, so printing defaults to 0, 0 (upper left corner). You can test it with this modified version of the showCO2() function:
Then if you request a web page from the web server, as /preferences.html, you can see in the log:
Now I have to investigate why the web server is so memory hungry and why the sprite is not created (as 40-50KB should be more than enough to create the sprite, I guess). It will continue... |
I just uploaded the fix to the development branch. I plan to have a new release version very soon as it was a stopper to it. |
New BETA version of CO2 Gadget v0.9.030The new beta version of CO2 Gadget is now available with important new features and some fixes. As important new features to highlight: ✔️ Support for buzzer. Configurable in number of beeps, time between beeps. repetitions, etc. In addition, among the fixes that have been implemented, the following stand out: ✔️ Corrects the screen that "got dirty" sometimes. It's available to test on TTGO T-Display boards (normal and sandwich ) at: https://emariete.com/en/co2-meter-gadget/#CO2_Gadget_Version_Beta-Desarrollo Feedback will be greatly appreciated. 😉 |
I rewrote the function that prints the CO2 value to the display and probably oversight it. I will modify this. Thank you very much for reporting. |
The fix is implemented in the last development branch code c5728b0. I'll include it in the next binary (easy web install) soon. Check for version > v0.9.32 |
It doesn't happen on T-Display S3.
I tried reducing font 90 to 88 but did not fix it.
It never happened to @Coscolin with same version and hardware as me and nobody else reported this.
The text was updated successfully, but these errors were encountered: