-
Notifications
You must be signed in to change notification settings - Fork 3.1k
LED strip refactor #3158
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
LED strip refactor #3158
Conversation
lua_tests/mispec_pixbuf_1.lua
Outdated
|
||
buffer1:fill(10,22,54) | ||
buffer2:fill(10,27,55) | ||
buffer1:mix(-257,buffer1:dump(),255,buffer2:dump()) |
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.
Did you remove the string capability from pixbuf?
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, though perhaps for somewhat specious reasoning: it wasn't documented and the test was flirting with OOM.
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.
True, Maybe we should document it rather and if necessary split the tests in even more parts. As string buffers are allowed everywhere else it would be inconsistent if it wasn't here.
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.
"allowed everywhere else"?
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.
like in ws2812.write(), ws2812.buffer:set(), buffer:replace()
not documented and not implemented for ws2812.buffer:fill(), __concat() mix()
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.
Did I just write the mix des not support strings? Then why did this test ever run at all??
lua_tests/mispec_pixbuf_2.lua
Outdated
|
||
initBuffer(buffer1,7,8,9,12) | ||
initBuffer(buffer2,0,0,7,8) | ||
buffer1:shift(2) | ||
ok(equalsBuffer(buffer1, buffer2), "shift right") | ||
ok(buffer1 == buffer2, "shift right") |
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.
If we use our own == her we would need to add tests for == somewhere.
Else we test the operations with untested code (our ==)
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.
Well, these are tests of our ==
. But yes, maybe we should test for ~=
sometimes. Here and elsewhere, more tests are welcome.
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.
But still we should only test one aspect in one test and not use two untested components.
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.
In black-box testing, it's often not possible to "only test one aspect" at a time. Previously, this test depended on fill
(via initBuffer
), shift
, and dump
; now it depends on fill
, shift
, and eq
. I'm not opposed to having more tests, and even some that compare ==
on dump
output, but I don't think the lack of orthogonality is new as of this diff.
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.
True, but opposed to == there are tests for fill and shift.
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.
Thanks for the review. Standby for incoming changes.
lua_tests/mispec_pixbuf_1.lua
Outdated
|
||
buffer1:fill(10,22,54) | ||
buffer2:fill(10,27,55) | ||
buffer1:mix(-257,buffer1:dump(),255,buffer2:dump()) |
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, though perhaps for somewhat specious reasoning: it wasn't documented and the test was flirting with OOM.
lua_tests/mispec_pixbuf_2.lua
Outdated
|
||
initBuffer(buffer1,7,8,9,12) | ||
initBuffer(buffer2,0,0,7,8) | ||
buffer1:shift(2) | ||
ok(equalsBuffer(buffer1, buffer2), "shift right") | ||
ok(buffer1 == buffer2, "shift right") |
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.
Well, these are tests of our ==
. But yes, maybe we should test for ~=
sometimes. Here and elsewhere, more tests are welcome.
LROT_FUNCENTRY( __concat, pixbuf_concat_lua ) | ||
LROT_FUNCENTRY( __tostring, pixbuf_tostring_lua ) | ||
|
||
LROT_FUNCENTRY( dump, pixbuf_dump_lua ) |
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.
Do we need an RGB version here? Or is it good enough to treat string buffers as raw everywhere and leaving the details to the app developer.
Do we need conversion functions RGB <=> GBR
Should we allow for a format parameter whenever string buffers are used?
So many questions. Sorry. If you would prefer to postpone this to another PR that would be fine with me.
We should the include that PR into the next release though or have it without Lua code change requirements to users.
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 think dump
is mostly a debugging function, not something we expect people to use day-to-day.
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.
dump may also be used for persisting patterns (in a file)
lua_tests/mispec_pixbuf_1.lua
Outdated
|
||
buffer1:fill(10,22,54) | ||
buffer2:fill(10,27,55) | ||
buffer1:mix(-257,buffer1:dump(),255,buffer2:dump()) |
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.
True, Maybe we should document it rather and if necessary split the tests in even more parts. As string buffers are allowed everywhere else it would be inconsistent if it wasn't here.
lua_tests/mispec_pixbuf_2.lua
Outdated
|
||
initBuffer(buffer1,7,8,9,12) | ||
initBuffer(buffer2,0,0,7,8) | ||
buffer1:shift(2) | ||
ok(equalsBuffer(buffer1, buffer2), "shift right") | ||
ok(buffer1 == buffer2, "shift right") |
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.
But still we should only test one aspect in one test and not use two untested components.
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 just found an old open browser tab (I got tons of them) with the documentation of another led strip module: tm1829 led strips, which also should be adapted to use PixBuf as input.
I am deeply skeptical of the Also despite the documentation claiming that its input string is in RGB order, the code does not actually change the order of any bytes, so its claim of sending GRB is probably wrong. But the documentation may predate the conversion to not corrupt the input string, too, so... Anyway, I took a stab at converting it. |
dbbd0b6
to
dce58ac
Compare
dce58ac
to
55a4d83
Compare
Blocking on #3230 since I want to be able to test pixbufs on the host. |
Eh, nevermind. I'll just carry the local bits for host testing in my tree for a bit; no reason to block this. |
21ff0d0
to
9890313
Compare
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.
Still would like to have C functions to adjust channel order.
Using :map will be around 8 to 10 times slower.
But will be left for another PR then
tests/NTest_pixbuf.lua
Outdated
end) | ||
|
||
N.test('mix with strings correctly ', function() | ||
local buffer1 = pixbuf.newBuffer(1, 3) |
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.
this test should be removed as it does the same as the one above
ok(eq(buffer1:size(), 0), "sub empty") | ||
|
||
buffer1 = pixbuf.newBuffer(4, 4) | ||
initBuffer(buffer1,7,8,9,12) |
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.
One line missing here: test fails
initBuffer(buffer1,7,8,9,12) | |
buffer2 = ws2812.newBuffer(2, 4) | |
initBuffer(buffer1,7,8,9,12) |
docs/modules/pixbuf.md
Outdated
``` | ||
buffer:map(function(r,g,b) return g,r,b end) -- Change channel order | ||
buffer:map(function(r,g,b) return g,r,b end, nil, 2, 5) -- Change channel order for a subset of pixels | ||
outbuf:map(function(r,g,b) return b end, inbuf, 10, 20) -- Extract one channel for a subset of pixels |
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.
wouldn't this fail because there are less return values than channels? (unless outbuf only has 1 channel)
docs/modules/pixbuf.md
Outdated
#### Returns | ||
`buffer0` | ||
|
||
#### Example |
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.
After looking at the code I understand, but from the examples and description I won't be able to use this with more than a function as param.
Especially the fact that the channels of the second buffer are also passed and can have a different number.
51fa0a8
to
74a4051
Compare
Thanks. Does 74a4051 address your concerns? |
The new pixbuf module has more functionality than the ws2812-specific buffer it replaces. This is work in progress towards nodemcu#2916 While here, document the ws2812 UART-based overlapping with mainline execution. Fixes nodemcu#3140 This includes some untested hackery to keep the deprecated ws2812_effects compiling. We anticipate this module going away soon, however. See nodemcu#3122
These were never really driving the actual LEDs, which would be tricky to test. Convert to NTest and update
We were heading down the path of being a generic graphics library, which is not the goal.
A pure-C byte-order-swizzling operation is probably straightforward... what do you imagine its API should be? That is, how do you want to specify the mapping function? |
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.
Still would like to have C functions to adjust channel order.
Using :map will be around 8 to 10 times slower.A pure-C byte-order-swizzling operation is probably straightforward... what do you imagine its API should be? That is, how do you want to specify the mapping function?
Maybe the map method could take defined values instead of a function to select a C operation.
buf:map(RGBtoGRB, [buf1[, ilo[, ihi]]]) -- SwapRG or ToGRB might also be a naming. Base would always be RGB. Others have to use their brain to find the correct setting.
This would be nice if you have strips with different channels connected together. But it would require a second buffer which uses memory. It is also a rather exotic scenario, which leads me to
another solution. That would be to add the parameter to the write methods.
`ws2812.write(bug, SwapRG)
To be channel neutral we could also pass ints to determin the new position of the channels.
Either as separate values or as array.
{2,1,3} would be equivalent to the above RGBtoGRB. It would also allow for 3 and 4 channels
app/lua53/linit.c
Outdated
@@ -48,6 +48,9 @@ extern LROT_TABLE(co_funcs); | |||
extern LROT_TABLE(mathlib); | |||
extern LROT_TABLE(utf8); | |||
|
|||
extern LROT_TABLE(pixbuf_map); | |||
extern int luaopen_pixbuf(lua_State *); | |||
|
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.
Please also see Terrys comment #3230 (comment)
Should we have this in one PR for Lua 5.1 and Lua 5.3?
See #3230
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'll back the changes to this file out and we can deal with host-side deltas later.
74a4051
to
bdd14f8
Compare
Sorry for coming back to this but I'm confused. I was expecting some "Attention! This requires the pixbuf module"-style hints in the documentation of the affected modules but found none. I see that they all (unconditionally) |
There are several modules whose define is never used. Expect four the link magic which decides what goes on the firmware. If I'm not mistaken we always build all modules. Conditional include only is used if the behavior would change. But indeed some hints might make sense. |
Ideally, such intermodule dependencies would be handled by Kconfig (#3130). I'm rather buried at work right now, so may I ask someone else to update the docs in the interim? |
Thought about it again. |
That was my initial intention when I realised those hints wrt pixbuf were missing. Then I noticed that pixbuf is always compiled into the firmware as Now I don't know what the real issue is here: missing docs or missing define guards. |
The build will break if one of the other modules are enabled without LUA_USE_MODULES_PIXBUF. |
I think we're talking past each other, sorry.
It doesn't, that's my point 😉 I disabled pixbuf (i.e. use the default) but enabled apa102, ws2801, ws2812, and ws2812_effects as they import There's only a single occurrence of |
Yes, also checked and was surprised that it worked. It seems that the linker just pulls in the parts it needs. So I would guess that half the pixbuf module is linked. But haven't checked yet. EDIT: it seems that the whole module is pulled in. The trick is done in app/Makefile and the NODEMCU_MODULE macro in app/include/module.h I think the linker then also pulls in the required modules. So what do we want? |
Addresses #2916 (mostly, anyway). Leaves #3122 to be done, and doesn't change any of the color utils libraries.
I've moved the so-called "ws2812" tests, which were really just tests of its buffer, over to the generic
pixbuf
and this now passes those tests. While the ws2812_effects library is ported to work withpixbuf
objects and does compile, it is operationally untested (though I don't anticipate any real breakage).I have not actually attempted to use this to drive LEDs yet (ha) but the drivers are only lightly modified to use the new data structure, so I hope it should work fine.
dev
branch rather than formaster
.docs/*
.