Johny Mattsson 4e8ef87d03 Reworked module registration, removed modules.h
Module creation & registration now made a lot simpler. In essence,
each module file is now self-contained and only needs a

  NODEMCU_MODULE(MYNAME, "myname", myname_map, luaopen_myname);

line to both be automatically recognised by the Lua initialization
as well as honor the LUA_USE_MODULES_MYNAME #define.
2015-12-16 16:09:16 +11:00

35 lines
751 B
C

// Module for interfacing with adc
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "c_types.h"
#include "user_interface.h"
// Lua: read(id) , return system adc
static int adc_sample( lua_State* L )
{
unsigned id = luaL_checkinteger( L, 1 );
MOD_CHECK_ID( adc, id );
unsigned val = 0xFFFF & system_adc_read();
lua_pushinteger( L, val );
return 1;
}
// Lua: readvdd33()
static int adc_readvdd33( lua_State* L )
{
lua_pushinteger(L, system_get_vdd33 ());
return 1;
}
// Module function map
static const LUA_REG_TYPE adc_map[] = {
{ LSTRKEY( "read" ), LFUNCVAL( adc_sample ) },
{ LSTRKEY( "readvdd33" ), LFUNCVAL( adc_readvdd33) },
{ LNILKEY, LNILVAL }
};
NODEMCU_MODULE(ADC, "adc", adc_map, NULL);