As the title says... Chat on...

User avatar
By cwr
#58623 I've been looking at the demo.c code in NodeMCU, which seems to declare a
function demo_identity() returning 1. However, compiling the result and
running print(demo.identity()) at the NodeMCU prompt gives:
lightfunction: 40268fc8

As far as I can tell the demo_identity function _is_ a lightfunction, but
how do I get a value out of it?

Thanks - Will
User avatar
By marcelstoer
#58626
cwr wrote:I've been looking at the demo.c code in NodeMCU


Which file is that?

Code: Select all~/Data/NodeMCU/nodemcu-firmware (dev) > find . -name demo.c

Finds nothing and neither does

Code: Select all~/Data/NodeMCU/nodemcu-firmware (dev) > grep -r demo_identity *
User avatar
By cwr
#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
User avatar
By marcelstoer
#58760
cwr wrote:AFAIK patches to NodeMCU are no longer accepted


Far from it! Where did you get that from? Just follow the guidelines at https://github.com/nodemcu/nodemcu-firm ... IBUTING.md and we're happy to accept your contributions.