Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
8866297c
Commit
8866297c
authored
Jul 20, 2016
by
Thomas Soëte
Committed by
Marcel Stör
Jul 20, 2016
Browse files
Remove buffer:write() as ws2812.write() handles buffers (#1408)
parent
854ad7c8
Changes
2
Show whitespace changes
Inline
Side-by-side
app/modules/ws2812.c
View file @
8866297c
...
...
@@ -396,17 +396,6 @@ static int ws2812_buffer_size(lua_State* L) {
return
1
;
}
static
int
ws2812_buffer_write
(
lua_State
*
L
)
{
ws2812_buffer
*
buffer
=
(
ws2812_buffer
*
)
lua_touserdata
(
L
,
1
);
luaL_argcheck
(
L
,
buffer
&&
buffer
->
canary
==
CANARY_VALUE
,
1
,
"ws2812.buffer expected"
);
// Send the buffer
ws2812_write_data
(
buffer
->
values
,
buffer
->
colorsPerLed
*
buffer
->
size
,
0
,
0
);
return
0
;
}
static
const
LUA_REG_TYPE
ws2812_buffer_map
[]
=
{
{
LSTRKEY
(
"fade"
),
LFUNCVAL
(
ws2812_buffer_fade
)},
...
...
@@ -415,7 +404,6 @@ static const LUA_REG_TYPE ws2812_buffer_map[] =
{
LSTRKEY
(
"set"
),
LFUNCVAL
(
ws2812_buffer_set
)},
{
LSTRKEY
(
"size"
),
LFUNCVAL
(
ws2812_buffer_size
)},
{
LSTRKEY
(
"shift"
),
LFUNCVAL
(
ws2812_buffer_shift
)},
{
LSTRKEY
(
"write"
),
LFUNCVAL
(
ws2812_buffer_write
)},
{
LSTRKEY
(
"__index"
),
LROVAL
(
ws2812_buffer_map
)},
{
LNILKEY
,
LNILVAL
}
};
...
...
docs/en/modules/ws2812.md
View file @
8866297c
...
...
@@ -77,11 +77,11 @@ For this purpose, the ws2812 library offers a read/write buffer.
Led chaser with a RGBW strip
```
lua
ws2812
.
init
()
local
i
,
b
=
0
,
ws2812
.
newBuffer
(
300
,
4
);
b
:
fill
(
0
,
0
,
0
,
0
);
tmr
.
alarm
(
0
,
50
,
1
,
function
()
local
i
,
b
uffer
=
0
,
ws2812
.
newBuffer
(
300
,
4
);
b
uffer
:
fill
(
0
,
0
,
0
,
0
);
tmr
.
alarm
(
0
,
50
,
1
,
function
()
i
=
i
+
1
b
:
fade
(
2
)
b
:
set
(
i
%
b
:
size
()
+
1
,
0
,
0
,
0
,
255
)
ws2812
.
write
(
b
)
b
uffer
:
fade
(
2
)
b
uffer
:
set
(
i
%
b
uffer
:
size
()
+
1
,
0
,
0
,
0
,
255
)
ws2812
.
write
(
b
uffer
)
end
)
```
...
...
@@ -112,8 +112,11 @@ Return the value at the given position
#### Example
```
lua
buffer
:
get
(
2
)
-- return the color of the second led
buffer
=
ws2812
.
newBuffer
(
32
,
4
)
print
(
buffer
:
get
(
1
))
0
0
0
0
```
## ws2812.buffer:set()
Set the value at the given position
...
...
@@ -122,21 +125,29 @@ Set the value at the given position
#### Parameters
-
`index`
position in the buffer (1 for the first led)
-
`color`
bytes of the color
-
`color`
payload of the color
Payload could be:
-
`number, number, ...`
you should pass as many arguments as
`bytesPerLed`
-
`table`
should contains
`bytesPerLed`
numbers
-
`string`
should contains
`bytesPerLed`
bytes
#### Returns
`nil`
#### Example
```
lua
buffer
=
ws2812
.
newBuffer
(
32
,
3
)
buffer
:
set
(
1
,
255
,
0
,
0
)
-- set the first led green for a RGB strip
```
```
lua
buffer
:
set
(
1
,
{
255
,
0
,
0
})
-- set the first led green for a RGB strip
buffer
=
ws2812
.
newBuffer
(
32
,
4
)
buffer
:
set
(
1
,
{
0
,
0
,
0
,
255
})
-- set the first led white for a RGBW strip
```
```
lua
buffer
=
ws2812
.
newBuffer
(
32
,
3
)
buffer
:
set
(
1
,
string.char
(
255
,
0
,
0
))
-- set the first led green for a RGB strip
```
...
...
@@ -160,7 +171,7 @@ The number of given bytes must match the number of bytesPerLed of the buffer
`buffer:fill(color)`
#### Parameters
-
`color`
bytes of the color
-
`color`
bytes of the color
, you should pass as many arguments as
`bytesPerLed`
#### Returns
`nil`
...
...
@@ -169,6 +180,7 @@ The number of given bytes must match the number of bytesPerLed of the buffer
```
lua
buffer
:
fill
(
0
,
0
,
0
)
-- fill the buffer with black for a RGB strip
```
## ws2812.buffer:fade()
Fade in or out. Defaults to out. Multiply or divide each byte of each led with/by the given value. Useful for a fading effect.
...
...
@@ -204,15 +216,3 @@ Shift the content of the buffer in positive or negative direction. This allows s
```
lua
buffer
:
shift
(
3
)
```
## ws2812.buffer:write()
Output the buffer to the led strip
#### Syntax
`buffer:write()`
#### Parameters
none
#### Returns
`nil`
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment