-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
ws2812 effects library #2215
ws2812 effects library #2215
Conversation
app/include/user_modules.h
Outdated
@@ -28,7 +28,8 @@ | |||
//#define LUA_USE_MODULES_BME280 | |||
//#define LUA_USE_MODULES_BME680 | |||
//#define LUA_USE_MODULES_COAP | |||
//#define LUA_USE_MODULES_CRON | |||
//#define LUA_USE_MODULES_COLOR_UTILS | |||
#define LUA_USE_MODULES_CRON |
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 disable module again.
app/include/user_modules.h
Outdated
@@ -48,7 +49,7 @@ | |||
#define LUA_USE_MODULES_MQTT | |||
#define LUA_USE_MODULES_NET | |||
#define LUA_USE_MODULES_NODE | |||
#define LUA_USE_MODULES_OW | |||
//#define LUA_USE_MODULES_OW |
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 enable module again.
app/include/user_modules.h
Outdated
@@ -68,7 +69,7 @@ | |||
//#define LUA_USE_MODULES_SWITEC | |||
// #define LUA_USE_MODULES_TCS34725 | |||
//#define LUA_USE_MODULES_TM1829 | |||
#define LUA_USE_MODULES_TLS | |||
//#define LUA_USE_MODULES_TLS |
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 enable module again.
docs/en/modules/color-utils.md
Outdated
The color_utils module provides some basic color transformations useful for color LEDs. It is used by the WS2812_EFFECTS module. | ||
|
||
|
||
## color\_utils.hsv2grb() |
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.
What's the purpose of the backslash here and below?
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.
my one editor had an issue without the backslash, but Atom doesn't - I will remove them all.
state->speed = SPEED_DEFAULT; | ||
state->mode_delay = DELAY_DEFAULT; | ||
state->brightness = BRIGHTNESS_DEFAULT; | ||
state->buffer = buffer; |
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.
You'll need to luaL_ref()
the buffer object to prevent it from being garbage collected after this function exits.
app/modules/ws2812_effects.c
Outdated
static int ws2812_effects_set_mode(lua_State* L) { | ||
|
||
luaL_argcheck(L, state != NULL, 1, LIBRARY_NOT_INITIALIZED_ERROR_MSG); | ||
const int mode = luaL_checkinteger(L, 1); |
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.
Quoting luaL_checkoption()
:
The usual convention in Lua libraries is to use strings instead of numbers to select options.
I know that our firmware is not 100% consistent here, but please think about turning the mode argument into string for the above reason. See file
, gpio
and other modules for how to use it.
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 am fine with adjusting this, I just "cloned" the way it is done in the ws2812 module itself (for fading and single/dual mode). This was the closest thing to look at
docs/en/modules/ws2812-effects.md
Outdated
- `effect_param` is an optional effect parameter. See the effect modes for further explanations. It can be an integer value or a string. | ||
|
||
#### Returns | ||
`nil` |
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 add an example that shows how to use the functions.
First of all, I like these additions to enhance the RGB capabilities of the firmware. My main concern is that we're missing a more generic model. So far there's the buffer class being part of the ws2812 module with some basic functions and effects. Now there's another module adding effects to the buffer objects. If this is ever extended for other LED modules it probably will need refactoring on the API level. On a more specific level: The effects are only applicable to a single stripe at the moment. Adding support for dual mode and up to 8 stripes for the ESP32 needs a different approach. Probably an own effects class where you derive objects for each buffer/stripe from. What are your thoughts here? |
I share your thoughts, however I thought, if I don't try to bring this into the firmware somewhen, I will never do so - that is why I initiated the pull request. Right now, I don't think that the "old" PWM based strips will really need something like this, as they are just too limited. However, I also stumbled upon SK6812, which is similar to APA102, but not identical. Also, having the current buffer objects with RGB(W) values is suboptimal, as they do not allow lossless brightness adjustments. My final hope is to have a buffer object in the HSV value range and perform effects on this buffer, and then have different writers for each LED strip type, and individual strip connected to the chip. Unfortunately, I am no LUA module pro, and also miss the time to get all this done fast enough. Maybe there is someone who wants to join? I'd also love to look at the ESP32. I have one, but so far didn't manage to build the firmware. So, before spending too much time in trying to fix the individual comments, it maybe makes sense to get a common understanding of how and where we should go from here. Thanks! |
app/modules/ws2812.c
Outdated
} | ||
|
||
val >>= 8; |
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 that this was pulled out of the loop to enable smooth fading. Why move it back?
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. That was probably an accident, I did not intend to change this.
app/include/user_modules.h
Outdated
@@ -29,7 +29,7 @@ | |||
//#define LUA_USE_MODULES_BME680 | |||
//#define LUA_USE_MODULES_COAP | |||
//#define LUA_USE_MODULES_COLOR_UTILS | |||
#define LUA_USE_MODULES_CRON | |||
//define LUA_USE_MODULES_CRON |
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.
Don't fiddle with the default modules!
app/include/user_modules.h
Outdated
@@ -49,7 +49,7 @@ | |||
#define LUA_USE_MODULES_MQTT | |||
#define LUA_USE_MODULES_NET | |||
#define LUA_USE_MODULES_NODE | |||
//#define LUA_USE_MODULES_OW | |||
#define LUA_USE_MODULES_OW |
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.
dito
app/include/user_modules.h
Outdated
@@ -69,7 +69,7 @@ | |||
//#define LUA_USE_MODULES_SWITEC | |||
// #define LUA_USE_MODULES_TCS34725 | |||
//#define LUA_USE_MODULES_TM1829 | |||
//#define LUA_USE_MODULES_TLS | |||
#define LUA_USE_MODULES_TLS |
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.
dito
I copied the current DEV branch user_modules.h file and just added the two modules of this PR. This should be OK now hopefully. Never intended to change them. |
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 from my side and no technical concerns. I recommend to merge this if no further objections arise.
* ws2812 effects and color utils modules added * Added documentation for new modules to mkdocs.yml * changed mode option to string, documentation, default modules fixed * updated user_modules.h
* ws2812 effects and color utils modules added * Added documentation for new modules to mkdocs.yml * changed mode option to string, documentation, default modules fixed * updated user_modules.h
Contributes to idea in #1352.
dev
branch rather than formaster
.docs/en/*
.This PR adds two new modules: A color library, extracted to an own module because it is helpful for other RGB LEDs as well (e.g. PWM) and a ws2812 effects module.
The color utils provide conversion between RGB and HSV color spaces, and a convenience function to get color wheel values based on an angle.
The ws2812 effects module provides some nice effects for ws2812 LED strips. This is an initial set, and the module itself is probably not perfect, but it does some nice stuff which might be useful for others as well. The effects have been natively implemented because LUA implementations are much too slow. In order to test the module, it must be enabled in the user_modules configuration before building the firmware.