- Sun Nov 27, 2016 8:52 am
#58752
I don't know where demo.c came from - I thought it was part of
nodemcu-master-1.5.4.1-20160802 from GitHub, but it's not there,
so where I got it from is a mystery. Anyway, I was using it as a
test module for experimentation while I fixed the OneWire read_bytes()
function, and that's done. I messed with the luaL_Buffer stuff for
a while and got no further; then, since the two buffers took up
1024 bytes each I removed them and rewrote the ow.c functions below:
Code: Select allstatic int ow_search( lua_State *L )
{
unsigned id = luaL_checkinteger( L, 1 );
MOD_CHECK_ID( ow, id );
uint8_t buff[16];
if (onewire_search(id, buff))
lua_pushlstring(L, buff, 8);
else
lua_pushnil(L);
return 1;
}
static int ow_read_bytes( lua_State *L )
{
unsigned id = luaL_checkinteger( L, 1 );
MOD_CHECK_ID( ow, id );
u16 size = ( u16 )luaL_checkinteger( L, 2 );
if ( size == 0 )
return 0;
uint8_t buff[16];
onewire_read_bytes(id, buff, size);
// NB. Lua makes an internal copy of the string.
lua_pushlstring(L, buff, size);
return 1;
}
The OneWire calls now work, and use a lot less memory; AFAIK patches to
NodeMCU are no longer accepted, but if anyone is interested in using
them here they are.
(And many, many thanks for all your work on the online build system.)
C W Rose