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
ff85cf43
Commit
ff85cf43
authored
Apr 05, 2015
by
Wolfram Ladurner
Browse files
fixes issue #321 "ws2812.writergb scrambles buffer" reported by makefu.
Don't modify Lua-internal lstring - use a copy instead.
parent
bcbde08b
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/modules/ws2812.c
View file @
ff85cf43
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
#include "platform.h"
#include "platform.h"
#include "auxmods.h"
#include "auxmods.h"
#include "lrotable.h"
#include "lrotable.h"
#include "c_stdlib.h"
#include "c_string.h"
/**
/**
* All this code is mostly from http://www.esp8266.com/viewtopic.php?f=21&t=1143&sid=a620a377672cfe9f666d672398415fcb
* All this code is mostly from http://www.esp8266.com/viewtopic.php?f=21&t=1143&sid=a620a377672cfe9f666d672398415fcb
* from user Markus Gritsch.
* from user Markus Gritsch.
...
@@ -35,7 +37,10 @@ static int ICACHE_FLASH_ATTR ws2812_writergb(lua_State* L)
...
@@ -35,7 +37,10 @@ static int ICACHE_FLASH_ATTR ws2812_writergb(lua_State* L)
{
{
const
uint8_t
pin
=
luaL_checkinteger
(
L
,
1
);
const
uint8_t
pin
=
luaL_checkinteger
(
L
,
1
);
size_t
length
;
size_t
length
;
char
*
buffer
=
(
char
*
)
luaL_checklstring
(
L
,
2
,
&
length
);
// Cast away the constness.
const
char
*
rgb
=
luaL_checklstring
(
L
,
2
,
&
length
);
// dont modify lua-internal lstring - make a copy instead
char
*
buffer
=
(
char
*
)
c_malloc
(
length
);
c_memcpy
(
buffer
,
rgb
,
length
);
// Initialize the output pin:
// Initialize the output pin:
platform_gpio_mode
(
pin
,
PLATFORM_GPIO_OUTPUT
,
PLATFORM_GPIO_FLOAT
);
platform_gpio_mode
(
pin
,
PLATFORM_GPIO_OUTPUT
,
PLATFORM_GPIO_FLOAT
);
...
@@ -59,17 +64,17 @@ static int ICACHE_FLASH_ATTR ws2812_writergb(lua_State* L)
...
@@ -59,17 +64,17 @@ static int ICACHE_FLASH_ATTR ws2812_writergb(lua_State* L)
// Send the buffer:
// Send the buffer:
os_intr_lock
();
os_intr_lock
();
const
char
*
const
end
=
buffer
+
length
;
for
(
i
=
0
;
i
<
length
;
i
++
)
{
while
(
buffer
!=
end
)
{
uint8_t
mask
=
0x80
;
uint8_t
mask
=
0x80
;
while
(
mask
)
{
while
(
mask
)
{
(
*
buffer
&
mask
)
?
send_ws_1
(
pin_num
[
pin
])
:
send_ws_0
(
pin_num
[
pin
]);
(
buffer
[
i
]
&
mask
)
?
send_ws_1
(
pin_num
[
pin
])
:
send_ws_0
(
pin_num
[
pin
]);
mask
>>=
1
;
mask
>>=
1
;
}
}
++
buffer
;
}
}
os_intr_unlock
();
os_intr_unlock
();
c_free
(
buffer
);
return
0
;
return
0
;
}
}
...
...
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