-
Notifications
You must be signed in to change notification settings - Fork 24
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
Improved WS2812B support, fixed library import from 2 different trees, added demo to control neopixels with on/off and brightness control from tux touch pads #32
base: master
Are you sure you want to change the base?
Conversation
led.py: - had outdated import code, fixed comments - import configuration.main or File "<stdin>", line 1, in <module> File "examples/badge_np.py", line 41, in run File "/lib/aiko/led.py", line 142, in initialise AttributeError: 'module' object has no attribute 'main' - added length_get needed by demoe code - added write needed by demo code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yay demos!
lib/aiko/led.py
Outdated
# import aiko.led | ||
# aiko.led.initialise() | ||
# aiko.led.pixel(aiko.led.red, 0, True) | ||
# from lib.aiko import led | ||
# led.initialise() | ||
# led.pixel(aiko.led.red, 0, True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kinda fascinated… aiko.led
is imported and initialised by main.py
, so we could kinda eliminate those lines; what do we get from the switch from aiko.led.pixel
to led.pixel
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes and no, I ran this code from repl where it was not visible. There are some weird visibility issues between what's visible from repl and from code run by main.py.
I've had a lot of issues with led.dim being a different value when set from MQTT, or from code. I'm still trying to figure out why, it's very perplexing.
If you are experienced with micropython namespace issues, let me know and I'll share more details.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely clear on it either, it strikes me. I'd swear aiko
is always imported on my REPL. Perhaps that's more to do the with limits of the soft reset inflicted by Control-D, though. (I've also noticed poor or zero reliability of MQTT hook-up after ^D, which I need to nut out.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, clear now: we've got the double import problem (see PR-level convo here) and when main.py
runs it's doing so with the same globals as the REPL. So, straight after booting you can see aiko
, application
, common
, configuration
, plugins
, and a bunch of others even though you didn't import them. ^D kicks it all off again.
lib/aiko/led.py
Outdated
def length_get(): | ||
return length | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aiko.led.length
works… sure, it's not at all encapsulated, but bytes are scarce, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, this was also to try namespace stuff, but this one is entirely useless, I removed it in my version.
I'll push my updated version. If you have this working, please let me know if you can figure out why setting up dim values from MQTT, affects the brightness of leds also toggled via MQTT, but not when the LEDs are set by led.pixel(color, i, True) |
led_py: Allow setting dimming from code and reading it back fill by default updates the strip, that's likely what's expected length_get was a test, removed added led:debug to see why dim has a different value from MQTT than when set by code badge_np: - added threading support so that it can be run from the main loop as an application - added color chase - added touch pad support (right tux) - Added toggling left tux LED form code
@garthk please have a look at the latest version I just pushed. I was discussing this with @geekscape : my current code outputs this: the middle 'dim 0.6' happens because I sent this MQTT: so, dim has 2 values depending on where it's set from. Interesting repl sees the version that is set by MQTT:
Does this make sense to you Garth? |
dim global variable in led.py was configured to have a separate value in the aiko net MQTT thread, and the main thread. This means that example code calling lib/led.py to set pixels, got a different dimming value than the same pixels set by the same led.py when they were set from the MQTT thread. Workaround is to store the dim value in configuration/main.py which is imported in memory before the threads happen, and that namespace is effectively shared between the different threads, so it can be used to share data. Using configuration/led.py would not work as it is not imported in memeory before aiko forks off the net/MQTT thread.
ok, I managed to fix the namespace problem I could tell was there the entire time |
OMG, I couldn't get setting the title working either and I found out that
is not the same as
They both work, but the first one creates a different namespace for all global variables, while he 2nd one does not and the global variables are shared between threads. @geekscape I should add that the default files use both interchangeably, when mixing them, in fact introduces this very unclear bug I hit: |
Mixing both causes 2 different namespaces and the global variables aren't shared between access methods and background methods that actually update the hardware, causing massive confusion. Now that the very weird bug is found, no need to store 'dim' in configuration.main.dim Also update oled.py to fix the import and usage comments.
Oh, of course. |
Ha! Saved myself a bunch of time explaining it: it's already described as the double import trap in an article explaining how Python module resolution works. If we remove |
Yes, thanks for confirming what too me way too long to find out. I can see sys.path being helpful, but here is made things much much worse. Even Andy used both forms, causing an unsafe mix, and ultimately bugs like the ones I ended up hitting. |
Front pad: brighter Rear pad: dimmer both pads: toggle on/off led.py: added reset_dim and change_dim.
@garthk I think I fixed all the issues, it works as intended now. Would you mind trying it out to see if it works for you? @geekscape the code should be good for review and merge if it looks good to you |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't gone over the OLED stuff yet.
Co-authored-by: Garth Kidd <[email protected]>
Co-authored-by: Garth Kidd <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to stop bike-shedding, now. :)
Thanks for the review. Let's now see what @geekscape says since I think he wants to personally review stuff like that before it goes in :) |
Hi @geekscape , how's life? :) |
No description provided.