示例#1
0
文件: ftp.c 项目: maplefish/MICO
      lua_pushinteger(L, -12);
    }
  }
  else {
    ftp_log("[FTP usr] Login first\r\n" );
    lua_pushinteger(L, -11);
  }
  return 1;
}


#define MIN_OPT_LEVEL   2
#include "lrodefs.h"
const LUA_REG_TYPE ftp_map[] =
{
  {LSTRKEY("new"), LFUNCVAL(lftp_new)},
  {LSTRKEY("start"), LFUNCVAL(lftp_start)},
  {LSTRKEY("stop"), LFUNCVAL(lftp_stop)},
  {LSTRKEY("on"), LFUNCVAL(lftp_on)},
  {LSTRKEY("chdir"), LFUNCVAL(lftp_chdir)},
  {LSTRKEY("recv"), LFUNCVAL(lftp_recv)},
  {LSTRKEY("send"), LFUNCVAL(lftp_send)},
  {LSTRKEY("sendstring"), LFUNCVAL(lftp_sendstring)},
  {LSTRKEY("list"), LFUNCVAL(lftp_list)},
  {LSTRKEY("debug"), LFUNCVAL(lftp_debug)},
#if LUA_OPTIMIZE_MEMORY > 0
#endif        
  {LNILKEY, LNILVAL}
};

LUALIB_API int luaopen_ftp(lua_State *L)
示例#2
0
文件: rtc.c 项目: SmartArduino/MICO-1
   time.month = luaL_checkinteger( L, 6 );
   time.year = luaL_checkinteger( L, 7 );

   if( MicoRtcSetTime(&time) == kNoErr ){
    lua_pushstring(L,"OK");
   }else {
     lua_pushstring(L, "RTC function unsupported"); 
   }  
  return 1;
}

#define MIN_OPT_LEVEL       2
#include "lrodefs.h"
const LUA_REG_TYPE rtc_map[] =
{
  { LSTRKEY( "getasc" ), LFUNCVAL( rtc_getasc )},
  { LSTRKEY( "set" ), LFUNCVAL( rtc_set )},
  { LSTRKEY( "get" ), LFUNCVAL( rtc_get )},
  { LSTRKEY( "getalarm" ), LFUNCVAL( rtc_getalarm )},
  { LSTRKEY( "standby" ), LFUNCVAL( rtc_standby )},
  { LSTRKEY( "standbyUntil" ), LFUNCVAL( rtc_standbyUntil )},
#if LUA_OPTIMIZE_MEMORY > 0
#endif      
  {LNILKEY, LNILVAL}
};

LUALIB_API int luaopen_rtc(lua_State *L)
{
#if LUA_OPTIMIZE_MEMORY > 0
    return 0;
#else    
示例#3
0
  int n = aux_getn(L, 1);
  luaL_checkstack(L, 40, "");  /* assume array is smaller than 2^40 */
  if (!lua_isnoneornil(L, 2))  /* is there a 2nd argument? */
    luaL_checktype(L, 2, LUA_TFUNCTION);
  lua_settop(L, 2);  /* make sure there is two arguments */
  auxsort(L, 1, n);
  return 0;
}

/* }====================================================== */


#define MIN_OPT_LEVEL 1
#include "lrodefs.h"
const LUA_REG_TYPE tab_funcs[] = {
  {LSTRKEY("concat"), LFUNCVAL(tconcat)},
  {LSTRKEY("foreach"), LFUNCVAL(foreach)},
  {LSTRKEY("foreachi"), LFUNCVAL(foreachi)},
  {LSTRKEY("getn"), LFUNCVAL(getn)},
  {LSTRKEY("maxn"), LFUNCVAL(maxn)},
  {LSTRKEY("insert"), LFUNCVAL(tinsert)},
  {LSTRKEY("remove"), LFUNCVAL(tremove)},
  {LSTRKEY("setn"), LFUNCVAL(setn)},
  {LSTRKEY("sort"), LFUNCVAL(sort)},
  {LNILKEY, LNILVAL}
};

LUALIB_API int ICACHE_FLASH_ATTR luaopen_table (lua_State *L) {
  LREGISTER(L, LUA_TABLIBNAME, tab_funcs);
}
示例#4
0
// Lua: clock = getclock( id )
static int pwm_getclock( lua_State *L )
{
	unsigned id;
	u32 clk;

	id = luaL_checkinteger( L, 1 );
	MOD_CHECK_ID( pwm, id );
	clk = platform_pwm_get_clock( id );
	lua_pushinteger( L, clk );
	return 1;
}

// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE pwm_map[] = {
	{ LSTRKEY( "setup" ), LFUNCVAL( pwm_setup ) },
	{ LSTRKEY( "start" ), LFUNCVAL( pwm_start ) },
	{ LSTRKEY( "stop" ), LFUNCVAL( pwm_stop ) },
	{ LSTRKEY( "setclock" ), LFUNCVAL( pwm_setclock ) },
	{ LSTRKEY( "getclock" ), LFUNCVAL( pwm_getclock ) },
	{ LNILKEY, LNILVAL }
};

LUALIB_API int luaopen_pwm( lua_State *L )
{
	LREGISTER( L, AUXLIB_PWM, pwm_map );
}
示例#5
0
  return 0;
}

// expose an array to lua, by storing it in a userdata with the array metatable
static int expose_array(lua_State* L, char *array, unsigned short len) {
  char** parray = lua_newuserdata(L, len);
  *parray = array;
  luaL_getmetatable(L, "net.array");
  lua_setmetatable(L, -2);
  return 1;
}
#endif

// Module function map
static const LUA_REG_TYPE net_server_map[] = {
  { LSTRKEY( "listen" ),  LFUNCVAL( net_server_listen ) },
  { LSTRKEY( "close" ),   LFUNCVAL( net_server_close ) },
  { LSTRKEY( "on" ),      LFUNCVAL( net_udpserver_on ) },
  { LSTRKEY( "send" ),    LFUNCVAL( net_udpserver_send ) },
//{ LSTRKEY( "delete" ),  LFUNCVAL( net_server_delete ) },
  { LSTRKEY( "__gc" ),    LFUNCVAL( net_server_delete ) },
  { LSTRKEY( "__index" ), LROVAL( net_server_map ) },
  { LNILKEY, LNILVAL }
};

static const LUA_REG_TYPE net_socket_map[] = {
  { LSTRKEY( "connect" ), LFUNCVAL( net_socket_connect ) },
  { LSTRKEY( "close" ),   LFUNCVAL( net_socket_close ) },
  { LSTRKEY( "on" ),      LFUNCVAL( net_socket_on ) },
  { LSTRKEY( "send" ),    LFUNCVAL( net_socket_send ) },
  { LSTRKEY( "hold" ),    LFUNCVAL( net_socket_hold ) },
示例#6
0
// Allows you to turn on the native Espressif SDK printing
static int node_osprint( lua_State* L )
{
  if (lua_toboolean(L, 1)) {
    system_set_os_print(1);
  } else {
    system_set_os_print(0);
  }

  return 0;  
}

// Module function map

static const LUA_REG_TYPE node_egc_map[] = {
  { LSTRKEY( "setmode" ),           LFUNCVAL( node_egc_setmode ) },
  { LSTRKEY( "NOT_ACTIVE" ),        LNUMVAL( EGC_NOT_ACTIVE ) },
  { LSTRKEY( "ON_ALLOC_FAILURE" ),  LNUMVAL( EGC_ON_ALLOC_FAILURE ) },
  { LSTRKEY( "ON_MEM_LIMIT" ),      LNUMVAL( EGC_ON_MEM_LIMIT ) },
  { LSTRKEY( "ALWAYS" ),            LNUMVAL( EGC_ALWAYS ) },
  { LNILKEY, LNILVAL }
};
static const LUA_REG_TYPE node_task_map[] = {
  { LSTRKEY( "post" ),            LFUNCVAL( node_task_post ) },
  { LSTRKEY( "LOW_PRIORITY" ),    LNUMVAL( TASK_PRIORITY_LOW ) },
  { LSTRKEY( "MEDIUM_PRIORITY" ), LNUMVAL( TASK_PRIORITY_MEDIUM ) },
  { LSTRKEY( "HIGH_PRIORITY" ),   LNUMVAL( TASK_PRIORITY_HIGH ) },
  { LNILKEY, LNILVAL }
};

static const LUA_REG_TYPE node_map[] =
示例#7
0
文件: wifi.c 项目: Zhang-Jia/WiFiMCU
      else
        micoWlanDisablePowerSave();
   }
   else
     {
       luaL_error( L, "boolean arg needed" );
     }
   
  return 0;
}

#define MIN_OPT_LEVEL       2
#include "lrodefs.h"
static const LUA_REG_TYPE wifi_station_map[] =
{
  { LSTRKEY( "getip" ), LFUNCVAL ( lwifi_station_getip ) },
  { LSTRKEY( "getipadv" ), LFUNCVAL ( lwifi_station_getipadv ) },
  { LSTRKEY( "getlink" ), LFUNCVAL ( lwifi_station_getlink ) },
  { LSTRKEY( "stop" ), LFUNCVAL ( lwifi_station_stop ) },
#if LUA_OPTIMIZE_MEMORY > 0
#endif        
  { LNILKEY, LNILVAL }
};

static const LUA_REG_TYPE wifi_ap_map[] =
{
  { LSTRKEY( "getip" ), LFUNCVAL ( lwifi_ap_getip ) },
  { LSTRKEY( "getipadv" ), LFUNCVAL ( lwifi_ap_getipadv ) },
  { LSTRKEY( "stop" ), LFUNCVAL ( lwifi_ap_stop ) },
#if LUA_OPTIMIZE_MEMORY > 0
#endif        
示例#8
0
        lua_setmetatable(L, -2);                                        \
                                                                        \
        return 1;                                                       \
    }
//
// Unroll the display table and insert binding functions.
UCG_DISPLAY_TABLE
//
// ***************************************************************************



// Module function map
static const LUA_REG_TYPE lucg_display_map[] =
{
    { LSTRKEY( "begin" ),              LFUNCVAL( lucg_begin ) },
    { LSTRKEY( "clearScreen" ),        LFUNCVAL( lucg_clearScreen ) },
    { LSTRKEY( "draw90Line" ),         LFUNCVAL( lucg_draw90Line ) },
    { LSTRKEY( "drawBox" ),            LFUNCVAL( lucg_drawBox ) },
    { LSTRKEY( "drawCircle" ),         LFUNCVAL( lucg_drawCircle ) },
    { LSTRKEY( "drawDisc" ),           LFUNCVAL( lucg_drawDisc ) },
    { LSTRKEY( "drawFrame" ),          LFUNCVAL( lucg_drawFrame ) },
    { LSTRKEY( "drawGlyph" ),          LFUNCVAL( lucg_drawGlyph ) },
    { LSTRKEY( "drawGradientBox" ),    LFUNCVAL( lucg_drawGradientBox ) },
    { LSTRKEY( "drawGradientLine" ),   LFUNCVAL( lucg_drawGradientLine ) },
    { LSTRKEY( "drawHLine" ),          LFUNCVAL( lucg_drawHLine ) },
    { LSTRKEY( "drawLine" ),           LFUNCVAL( lucg_drawLine ) },
    { LSTRKEY( "drawPixel" ),          LFUNCVAL( lucg_drawPixel ) },
    { LSTRKEY( "drawRBox" ),           LFUNCVAL( lucg_drawRBox ) },
    { LSTRKEY( "drawRFrame" ),         LFUNCVAL( lucg_drawRFrame ) },
    { LSTRKEY( "drawString" ),         LFUNCVAL( lucg_drawString ) },
示例#9
0
  int status;
  if (lua_isboolean(L, 1))
    status = (lua_toboolean(L, 1) ? EXIT_SUCCESS : EXIT_FAILURE);
  else
    status = (int)luaL_optinteger(L, 1, EXIT_SUCCESS);
  if (lua_toboolean(L, 2))
    lua_close(L);
  if (L) exit(status);  /* 'if' to avoid warnings for unreachable 'return' */
  return 0;
}

#include "modules.h"

static const LUA_REG_TYPE syslib[] = 
{
  { LSTRKEY( "date" ),       LFUNCVAL( os_date ) },
  { LSTRKEY( "difftime" ),   LFUNCVAL( os_difftime ) },
  { LSTRKEY( "clock" ),      LFUNCVAL( os_clock ) },
  { LSTRKEY( "remove" ),     LFUNCVAL( os_remove ) },
  { LSTRKEY( "rename" ),     LFUNCVAL( os_rename ) },
  { LSTRKEY( "time" ),       LFUNCVAL( os_time ) },
  { LSTRKEY( "tmpname" ),    LFUNCVAL( os_tmpname ) },
  { LSTRKEY( "exit" ),       LFUNCVAL( os_exit ) },
  { LSTRKEY( "execute" ),    LFUNCVAL( os_execute ) },
  { LSTRKEY( "setlocale" ),  LFUNCVAL( os_setlocale ) },
  { LSTRKEY( "getenv" ),  	 LFUNCVAL( os_getenv ) },

  { LSTRKEY( "clear" ),      LFUNCVAL( os_clear ) },
  { LSTRKEY( "cpu" ),        LFUNCVAL( os_cpu ) },
  { LSTRKEY( "sleep" ),      LFUNCVAL( os_sleep ) },
  { LSTRKEY( "version" ),    LFUNCVAL( os_version ) },
示例#10
0
static int i2c_setup( lua_State* L )
{
  return 0;
}

static int i2c_read( lua_State* L )
{
  return 0;
}


#define MIN_OPT_LEVEL   2
#include "lrodefs.h"
const LUA_REG_TYPE i2c_map[] =
{
  { LSTRKEY( "setup" ), LFUNCVAL( i2c_setup )},
  { LSTRKEY( "read" ), LFUNCVAL( i2c_read )},
  {LNILKEY, LNILVAL}
};

/*
 * Open library
 */
LUALIB_API int luaopen_i2c(lua_State *L)
{

#if LUA_OPTIMIZE_MEMORY > 0
  return 0;
#else // #if LUA_OPTIMIZE_MEMORY > 0
  luaL_register( L, EXLIB_I2C, i2c_map );
  // Add constants
示例#11
0
    data = data<<1;
    if (platform_gpio_read(data_pin)==1) {
      data = i==0 ? -1 : data|1; //signextend the first bit
    }
  }
  //add 25th clock pulse to prevent protocol error (probably not needed
  // since we'll go to sleep immediately after and reset on wakeup.)
  platform_gpio_write(clk_pin,1);
  platform_gpio_write(clk_pin,0);
  //sleep
  platform_gpio_write(clk_pin,1);
  lua_pushinteger( L, data );
  return 1;
}

#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE hx711_map[] =
{
  { LSTRKEY( "init" ), LFUNCVAL( hx711_init )},
  { LSTRKEY( "read" ), LFUNCVAL( hx711_read )},
  { LNILKEY, LNILVAL}
};

LUALIB_API int luaopen_hx711(lua_State *L) {
  // TODO: the below todo was inherited from the ws2812 code but is still valid.
  // TODO: Make sure that the GPIO system is initialized
  LREGISTER(L, "hx711", hx711_map);
  return 1;
}
示例#12
0
      // platform_gpio_write(pin, level);
      DIRECT_WRITE(pin, level);
      //interrupts();
      delayMicroseconds(delay_table[j]);
      level=!level;
    }
    repeat--;
  } while (repeat>0); 

  return 0;  
}
#undef DELAY_TABLE_MAX_LEN

// Module function map
const LUA_REG_TYPE gpio_map[] = {
  { LSTRKEY( "mode" ),   LFUNCVAL( lgpio_mode ) },
  { LSTRKEY( "read" ),   LFUNCVAL( lgpio_read ) },
  { LSTRKEY( "write" ),  LFUNCVAL( lgpio_write ) },
  { LSTRKEY( "serout" ), LFUNCVAL( lgpio_serout ) },
#ifdef GPIO_INTERRUPT_ENABLE
  { LSTRKEY( "remove" ),   LFUNCVAL( lgpio_remove_isr ) },
  { LSTRKEY( "uninstall" ),   LFUNCVAL( lgpio_uninstall ) },
  { LSTRKEY( "INT" ),    LNUMVAL( PLATFORM_INTERRUPT ) },
#endif
  { LSTRKEY( "OUTPUT" ), LNUMVAL( OUTPUT ) },
  { LSTRKEY( "INPUT" ),  LNUMVAL( INPUT ) },
  { LSTRKEY( "INOUT" ),  LNUMVAL( INOUT ) },
  { LSTRKEY( "HIGH" ),   LNUMVAL( HIGH ) },
  { LSTRKEY( "LOW" ),    LNUMVAL( LOW ) },
  { LSTRKEY( "FLOAT" ),  LNUMVAL( FLOAT ) },
  { LSTRKEY( "PULLUP" ), LNUMVAL( PULLUP ) },
示例#13
0
  uint32_t nbr_frames = buf_len / 4;

  if (nbr_frames > 100000) {
    return luaL_error(L, "The supplied buffer is too long, and might cause the callback watchdog to bark.");
  }

  // Initialize the output pins
  platform_gpio_mode(data_pin, PLATFORM_GPIO_OUTPUT, PLATFORM_GPIO_FLOAT);
  GPIO_OUTPUT_SET(alt_data_pin, PLATFORM_GPIO_HIGH); // Set pin high
  platform_gpio_mode(clock_pin, PLATFORM_GPIO_OUTPUT, PLATFORM_GPIO_FLOAT);
  GPIO_OUTPUT_SET(alt_clock_pin, PLATFORM_GPIO_LOW); // Set pin low

  // Send the buffers
  apa102_send_buffer(alt_data_pin, alt_clock_pin, (uint32_t *) buf, (uint32_t) nbr_frames);
  return 0;
}


const LUA_REG_TYPE apa102_map[] =
{
  { LSTRKEY( "write" ), LFUNCVAL( apa102_write )},
  { LNILKEY, LNILVAL}
};

LUALIB_API int luaopen_apa102(lua_State *L) {
  LREGISTER(L, "apa102", apa102_map);
  return 0;
}

NODEMCU_MODULE(APA102, "apa102", apa102_map, luaopen_apa102);
示例#14
0
		c_memset(saida,0,15);
		c_sprintf(saida,"%.01f",ALT);
		lua_pushstring(L, saida);
		c_memset(saida,0,15);
		c_sprintf(saida,"%.01f",DOP);
		lua_pushstring(L, saida);
		return 4;  // 4 é o número de valores a serem retornados
	}
return 0;
}



// Module function map
static const LUA_REG_TYPE gprs_map[] = {
  { LSTRKEY( "isReady" )	,LFUNCVAL( gprs_isReady ) },
  { LSTRKEY( "timestamp" )	,LFUNCVAL( gprs_getTimeStamp ) },
  { LSTRKEY( "readtimestamp" ),LFUNCVAL( gprs_readTimeStamp ) },
  { LSTRKEY( "start" )		,LFUNCVAL( gprs_start ) },
  { LSTRKEY( "send" )		,LFUNCVAL( gprs_send ) },
  { LSTRKEY( "poweroff" )	,LFUNCVAL( gprs_poweroff ) },
  { LSTRKEY( "getimei" )	,LFUNCVAL( gprs_getimei ) },
  { LSTRKEY( "clear" )		,LFUNCVAL( gprs_clear ) },
  { LSTRKEY( "flush" )		,LFUNCVAL( gprs_flush ) },
  { LSTRKEY( "flushbuffer" ),LFUNCVAL( gprs_flushbuffer ) },
  { LSTRKEY( "register" )	,LFUNCVAL( gprs_register ) },
  { LSTRKEY( "rssi" )		,LFUNCVAL( gprs_rssi ) },
  { LSTRKEY( "test" )		,LFUNCVAL( gprs_test ) },
  { LSTRKEY( "switchgps" )	,LFUNCVAL( gprs_switchgps ) },
  { LSTRKEY( "getlocation" ),LFUNCVAL( gprs_getlocation ) },
  { LNILKEY, LNILVAL }
示例#15
0
#endif


static int math_randomseed (lua_State *L) {
  srand(luaL_checkint(L, 1));
  return 0;
}



#undef MIN_OPT_LEVEL
#define MIN_OPT_LEVEL 1
#include "lrodefs.h"
const LUA_REG_TYPE math_map[] = {
#ifdef LUA_NUMBER_INTEGRAL
  {LSTRKEY("abs"),   LFUNCVAL(math_abs)},
  {LSTRKEY("ceil"),  LFUNCVAL(math_identity)},
  {LSTRKEY("floor"), LFUNCVAL(math_identity)},
  {LSTRKEY("max"),   LFUNCVAL(math_max)},
  {LSTRKEY("min"),   LFUNCVAL(math_min)},
  {LSTRKEY("pow"),   LFUNCVAL(math_pow)},
  {LSTRKEY("random"),     LFUNCVAL(math_random)},
  {LSTRKEY("randomseed"), LFUNCVAL(math_randomseed)},
  {LSTRKEY("sqrt"),  LFUNCVAL(math_sqrt)},
#if LUA_OPTIMIZE_MEMORY > 0
  {LSTRKEY("huge"),  LNUMVAL(LONG_MAX)},
#endif
#else
  {LSTRKEY("abs"),   LFUNCVAL(math_abs)},
  // {LSTRKEY("acos"),  LFUNCVAL(math_acos)},
  // {LSTRKEY("asin"),  LFUNCVAL(math_asin)},
示例#16
0
  return pushresult(L, fs_flush(getiofile(L, IO_OUTPUT)) == 0, NULL);
}


static int f_flush (lua_State *L) {
  return pushresult(L, fs_flush(tofile(L)) == 0, NULL);
}

#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
#if LUA_OPTIMIZE_MEMORY == 2
const LUA_REG_TYPE iolib_funcs[] = {
#else
const LUA_REG_TYPE iolib[] = {
#endif
  {LSTRKEY("close"), LFUNCVAL(io_close)},
  {LSTRKEY("flush"), LFUNCVAL(io_flush)},
  {LSTRKEY("input"), LFUNCVAL(io_input)},
  {LSTRKEY("lines"), LFUNCVAL(io_lines)},
  {LSTRKEY("open"), LFUNCVAL(io_open)},
  {LSTRKEY("output"), LFUNCVAL(io_output)},
  // {LSTRKEY("popen"), LFUNCVAL(io_popen)},
  {LSTRKEY("read"), LFUNCVAL(io_read)},
  // {LSTRKEY("tmpfile"), LFUNCVAL(io_tmpfile)},
  {LSTRKEY("type"), LFUNCVAL(io_type)},
  {LSTRKEY("write"), LFUNCVAL(io_write)},
  {LNILKEY, LNILVAL}
};

#if LUA_OPTIMIZE_MEMORY == 2
static int luaL_index(lua_State *L)
示例#17
0
			default: {  /* also treat cases `pnLlh' */
				return luaL_error(L, "invalid option " LUA_QL("%%%c") " to "
				                  LUA_QL("format"), *(strfrmt - 1));
			}
			}
			luaL_addlstring(&b, buff, strlen(buff));
		}
	}
	luaL_pushresult(&b);
	return 1;
}

#define MIN_OPT_LEVEL 1
#include "lrodefs.h"
const LUA_REG_TYPE strlib[] = {
	{LSTRKEY("byte"), LFUNCVAL(str_byte)},
	{LSTRKEY("char"), LFUNCVAL(str_char)},
	{LSTRKEY("dump"), LFUNCVAL(str_dump)},
	{LSTRKEY("find"), LFUNCVAL(str_find)},
	{LSTRKEY("format"), LFUNCVAL(str_format)},
#if LUA_OPTIMIZE_MEMORY > 0 && defined(LUA_COMPAT_GFIND)
	{LSTRKEY("gfind"), LFUNCVAL(gmatch)},
#else
	{LSTRKEY("gfind"), LFUNCVAL(gfind_nodef)},
#endif
	{LSTRKEY("gmatch"), LFUNCVAL(gmatch)},
	{LSTRKEY("gsub"), LFUNCVAL(str_gsub)},
	{LSTRKEY("len"), LFUNCVAL(str_len)},
	{LSTRKEY("lower"), LFUNCVAL(str_lower)},
	{LSTRKEY("match"), LFUNCVAL(str_match)},
	{LSTRKEY("rep"), LFUNCVAL(str_rep)},
示例#18
0
文件: mqtt.c 项目: pvvx/EspLua
  NODE_DBG("mqtt_socket_lwt: topic: %s, message: %s, qos: %d, retain: %d\n",
      mud->connect_info.will_topic,
      mud->connect_info.will_message,
      mud->connect_info.will_qos,
      mud->connect_info.will_retain);
  NODE_DBG("leave mqtt_socket_lwt.\n");
  return 0;
}

// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"

static const LUA_REG_TYPE mqtt_socket_map[] =
{
  { LSTRKEY( "connect" ), LFUNCVAL ( mqtt_socket_connect ) },
  { LSTRKEY( "close" ), LFUNCVAL ( mqtt_socket_close ) },
  { LSTRKEY( "publish" ), LFUNCVAL ( mqtt_socket_publish ) },
  { LSTRKEY( "subscribe" ), LFUNCVAL ( mqtt_socket_subscribe ) },
  { LSTRKEY( "lwt" ), LFUNCVAL ( mqtt_socket_lwt ) },
  { LSTRKEY( "on" ), LFUNCVAL ( mqtt_socket_on ) },
  { LSTRKEY( "__gc" ), LFUNCVAL ( mqtt_delete ) },
#if LUA_OPTIMIZE_MEMORY > 0
  { LSTRKEY( "__index" ), LROVAL ( mqtt_socket_map ) },
#endif
  { LNILKEY, LNILVAL }
};

const LUA_REG_TYPE mqtt_map[] = 
{
  { LSTRKEY( "Client" ), LFUNCVAL ( mqtt_socket_client ) },
示例#19
0
    return ret;
}

// Lua: mcu.trig( pin, trig, cb )
static int mcu_in_trig( lua_State* L )
{
    return 0;
}
// Module function map
#define MIN_OPT_LEVEL 2

#include "lrodefs.h"

const LUA_REG_TYPE mcu_map[] =
{
    { LSTRKEY( "write" ), LFUNCVAL( mcu_out_write ) },
    { LSTRKEY( "off" ), LFUNCVAL( mcu_out_off ) },
    { LSTRKEY( "on" ), LFUNCVAL( mcu_out_on ) },
    { LSTRKEY( "read" ), LFUNCVAL( mcu_in_read ) },
    { LSTRKEY( "trig" ), LFUNCVAL( mcu_in_trig ) },
    { LSTRKEY( "PUMP_IN"), LNUMVAL( OUT_PUMP_IN ) },
    { LSTRKEY( "PUMP_OUT"), LNUMVAL( OUT_PUMP_OUT ) },
    { LSTRKEY( "PUMP1"), LNUMVAL( OUT_PUMP1 ) },
    { LSTRKEY( "PUMP2"), LNUMVAL( OUT_PUMP2 ) },
    { LSTRKEY( "PUMP3"), LNUMVAL( OUT_PUMP3 ) },
    { LSTRKEY( "HEATER"), LNUMVAL( OUT_HEATER ) },
    { LSTRKEY( "FAN"), LNUMVAL( OUT_FAN ) },
    { LSTRKEY( "SPRAY"), LNUMVAL( OUT_SPRAY ) },
    { LSTRKEY( "LCD"), LNUMVAL( OUT_LCD ) },
    { LSTRKEY( "PUMP"), LNUMVAL( OUT_PUMP ) },
    { LSTRKEY( "LED"), LNUMVAL( OUT_LED ) },
示例#20
0
  if (result==LUA_ERR_CC_INTOVERFLOW){
    return luaL_error(L, "value too big or small for target integer type");
  }
  if (result==LUA_ERR_CC_NOTINTEGER){
    return luaL_error(L, "target lua_Number is integral but fractional value found");
  }

  return 0;
}

// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE node_map[] = 
{
  { LSTRKEY( "restart" ), LFUNCVAL( node_restart ) },
  { LSTRKEY( "dsleep" ), LFUNCVAL( node_deepsleep ) },
  { LSTRKEY( "info" ), LFUNCVAL( node_info ) },
  { LSTRKEY( "chipid" ), LFUNCVAL( node_chipid ) },
  { LSTRKEY( "flashid" ), LFUNCVAL( node_flashid ) },
  { LSTRKEY( "flashsize" ), LFUNCVAL( node_flashsize) },
  { LSTRKEY( "heap" ), LFUNCVAL( node_heap ) },
#ifdef DEVKIT_VERSION_0_9
  { LSTRKEY( "key" ), LFUNCVAL( node_key ) },
  { LSTRKEY( "led" ), LFUNCVAL( node_led ) },
#endif
  { LSTRKEY( "input" ), LFUNCVAL( node_input ) },
  { LSTRKEY( "output" ), LFUNCVAL( node_output ) },
  { LSTRKEY( "readvdd33" ), LFUNCVAL( node_readvdd33) },
  { LSTRKEY( "compile" ), LFUNCVAL( node_compile) },
// Combined to dsleep(us, option)  
示例#21
0
  luaL_buffinit( L, &b );
  for( i = 0; i < size; i ++ )
    if( ( data = platform_i2c_recv_byte( id, i < size - 1 ) ) == -1 )
      break;
    else
      luaL_addchar( &b, ( char )data );
  luaL_pushresult( &b );
  return 1;
}

// Module function map
#define MIN_OPT_LEVEL   2
#include "lrodefs.h"
const LUA_REG_TYPE i2c_map[] = 
{
  { LSTRKEY( "setup" ),  LFUNCVAL( i2c_setup ) },
  { LSTRKEY( "start" ), LFUNCVAL( i2c_start ) },
  { LSTRKEY( "stop" ), LFUNCVAL( i2c_stop ) },
  { LSTRKEY( "address" ), LFUNCVAL( i2c_address ) },
  { LSTRKEY( "write" ), LFUNCVAL( i2c_write ) },
  { LSTRKEY( "read" ), LFUNCVAL( i2c_read ) },
#if LUA_OPTIMIZE_MEMORY > 0
  { LSTRKEY( "FAST" ), LNUMVAL( PLATFORM_I2C_SPEED_FAST ) },
  { LSTRKEY( "SLOW" ), LNUMVAL( PLATFORM_I2C_SPEED_SLOW ) },
  { LSTRKEY( "TRANSMITTER" ), LNUMVAL( PLATFORM_I2C_DIRECTION_TRANSMITTER ) },
  { LSTRKEY( "RECEIVER" ), LNUMVAL( PLATFORM_I2C_DIRECTION_RECEIVER ) },
#endif
  { LNILKEY, LNILVAL }
};

LUALIB_API int luaopen_i2c( lua_State *L )
示例#22
0
int gsm_on_new_message(lua_State *L)
{
    int ref;
    lua_pushvalue(L, 1);
    g_gsm_new_message_cb_ref = luaL_ref(L, LUA_REGISTRYINDEX);

    lua_pushnumber(L, vm_gsm_sms_set_interrupt_event_handler(VM_GSM_SMS_EVENT_ID_SMS_NEW_MESSAGE, _gsm_on_new_message, NULL));

    return 1;
}

#undef MIN_OPT_LEVEL
#define MIN_OPT_LEVEL 0
#include "lrodefs.h"

const LUA_REG_TYPE gsm_map[] = {{LSTRKEY("call"), LFUNCVAL(gsm_call)},
                                {LSTRKEY("answer"), LFUNCVAL(gsm_anwser)},
                                {LSTRKEY("hang"), LFUNCVAL(gsm_hang)},
                                {LSTRKEY("on_incoming_call"), LFUNCVAL(gsm_on_incoming_call)},
                                {LSTRKEY("text"), LFUNCVAL(gsm_text)},
                                {LSTRKEY("on_new_message"), LFUNCVAL(gsm_on_new_message)},
                                {LNILKEY, LNILVAL}};

LUALIB_API int luaopen_gsm(lua_State *L) {
  vm_gsm_tel_call_reg_listener(call_listener_func);

  luaL_register(L, "gsm", gsm_map);
  return 1;
}
示例#23
0
	timer_t ud = (timer_t)lua_newuserdata(L, sizeof(timer_struct_t));
	if (!ud) return luaL_error(L, "not enough memory");
	luaL_getmetatable(L, "tmr.timer");
	lua_setmetatable(L, -2);
	ud->lua_ref = LUA_NOREF;
	ud->self_ref = LUA_NOREF;
	ud->mode = TIMER_MODE_OFF;
	os_timer_disarm(&ud->os);
	return 1;
}


// Module function map

static const LUA_REG_TYPE tmr_dyn_map[] = {
	{ LSTRKEY( "register" ),    LFUNCVAL( tmr_register ) },
	{ LSTRKEY( "alarm" ),       LFUNCVAL( tmr_alarm ) },
	{ LSTRKEY( "start" ),       LFUNCVAL( tmr_start ) },
	{ LSTRKEY( "stop" ),        LFUNCVAL( tmr_stop ) },
	{ LSTRKEY( "unregister" ),  LFUNCVAL( tmr_unregister ) },
	{ LSTRKEY( "state" ),       LFUNCVAL( tmr_state ) },
	{ LSTRKEY( "interval" ),    LFUNCVAL( tmr_interval) },
#ifdef TIMER_SUSPEND_ENABLE
	{ LSTRKEY( "suspend" ),      LFUNCVAL( tmr_suspend ) },
  { LSTRKEY( "resume" ),       LFUNCVAL( tmr_resume ) },
#endif
	{ LSTRKEY( "__gc" ),        LFUNCVAL( tmr_unregister ) },
	{ LSTRKEY( "__index" ),     LROVAL( tmr_dyn_map ) },
	{ LNILKEY, LNILVAL }
};
示例#24
0
}

#endif


static int math_randomseed (lua_State *L)
{
	srand(luaL_checkint(L, 1));
	return 0;
}

#define MIN_OPT_LEVEL 1
#include "lrodefs.h"
const LUA_REG_TYPE math_map[] = {
#ifdef LUA_NUMBER_INTEGRAL
	{LSTRKEY("abs"),   LFUNCVAL(math_abs)},
	{LSTRKEY("ceil"),  LFUNCVAL(math_identity)},
	{LSTRKEY("floor"), LFUNCVAL(math_identity)},
	{LSTRKEY("max"),   LFUNCVAL(math_max)},
	{LSTRKEY("min"),   LFUNCVAL(math_min)},
	{LSTRKEY("pow"),   LFUNCVAL(math_pow)},
	{LSTRKEY("random"),     LFUNCVAL(math_random)},
	{LSTRKEY("randomseed"), LFUNCVAL(math_randomseed)},
	{LSTRKEY("sqrt"),  LFUNCVAL(math_sqrt)},
#if LUA_OPTIMIZE_MEMORY > 0
	{LSTRKEY("huge"),  LNUMVAL(LONG_MAX)},
#endif
#else
	{LSTRKEY("abs"),   LFUNCVAL(math_abs)},
	{LSTRKEY("acos"),  LFUNCVAL(math_acos)},
	{LSTRKEY("asin"),  LFUNCVAL(math_asin)},
示例#25
0
文件: tmr.c 项目: rongfengyu/WiFiMCU
    mico_stop_timer(&_timer[id]);
    mico_deinit_timer( &_timer[id] );
    mico_init_timer(&_timer[id], interval, _tmr_handler, (void*)id);
    mico_start_timer(&_timer[id]);    
  }
  else
    return luaL_error( L, "callback function needed" );
  
  return 0;
}

#define MIN_OPT_LEVEL       2
#include "lrodefs.h"
const LUA_REG_TYPE tmr_map[] =
{
  { LSTRKEY( "tick" ), LFUNCVAL( ltmr_tick ) },
  { LSTRKEY( "delay" ), LFUNCVAL( ltmr_delay ) },
  { LSTRKEY( "start" ), LFUNCVAL( ltmr_start ) },
  { LSTRKEY( "stop" ), LFUNCVAL( ltmr_stop ) },
  { LSTRKEY( "wdclr" ), LFUNCVAL( ltmr_wdclr) },
  {LNILKEY, LNILVAL}
};

LUALIB_API int luaopen_tmr(lua_State *L)
{
  for(int i=0;i<NUM_TMR;i++){
    tmr_cb_ref[i] = LUA_NOREF;
  }
#if LUA_OPTIMIZE_MEMORY > 0
    return 0;
#else
示例#26
0
// Lua: cpuname = cpu()
static int pd_cpu( lua_State* L )
{
  lua_pushstring( L, MACRO_NAME( XMC4500 ) );
  return 1;
}

// Lua: boardname = board()
static int pd_board( lua_State* L )
{
  lua_pushstring( L, MACRO_NAME( HEXAGON_KIT ) );
  return 1;
}

// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE pd_map[] = 
{
  { LSTRKEY( "platform" ), LFUNCVAL( pd_platform ) }, 
  { LSTRKEY( "cpu" ), LFUNCVAL( pd_cpu ) },
  { LSTRKEY( "board" ), LFUNCVAL( pd_board ) },
  { LNILKEY, LNILVAL }
};

LUALIB_API int luaopen_pd( lua_State* L )
{
  LREGISTER( L, AUXLIB_PD, pd_map );
}
示例#27
0
		d1=0;
		os_delay_us(d);
		platform_gpio_write(servo_pin[i], 0);
		tt[i]-=system_get_time();
	}
	if(servo_stats){
		lua_newtable(L); 
		for(i=servo_min;i<MAX_NUM_SERVOS;i++){
			lua_pushinteger( L, servo_pin[i] );
			lua_pushinteger( L, tt[i] );
			lua_settable(L, -3);
		}
		return 1;
	} else return 0;
}

//*******************

// Module function map
static const LUA_REG_TYPE servo_map[] = {
  { LSTRKEY( "pulse" ), LFUNCVAL( lservo_pulse ) },
  { LSTRKEY( "set" ), LFUNCVAL( lservo_set ) },
  { LSTRKEY( "get" ), LFUNCVAL( lservo_get ) },
  { LSTRKEY( "init" ), LFUNCVAL( lservo_init ) },
  { LSTRKEY( "config" ), LFUNCVAL( lservo_config ) },
  { LNILKEY, LNILVAL }
};


NODEMCU_MODULE(SERVO, "servo", servo_map, lservo_init);
示例#28
0
  if( res == -1 )
    lua_pushstring( L, "" );
  else
  {
    cres = ( char )res;
    lua_pushlstring( L, &cres, 1 );
  }
  return 1;  
}

// Module function map
#define MIN_OPT_LEVEL   2
#include "lrodefs.h"
const LUA_REG_TYPE uart_map[] = 
{
  { LSTRKEY( "setup" ),  LFUNCVAL( uart_setup ) },
  { LSTRKEY( "write" ), LFUNCVAL( uart_write ) },
  { LSTRKEY( "read" ), LFUNCVAL( uart_read ) },
  { LSTRKEY( "getchar" ), LFUNCVAL( uart_getchar ) },
#if LUA_OPTIMIZE_MEMORY > 0
  { LSTRKEY( "PAR_EVEN" ), LNUMVAL( PLATFORM_UART_PARITY_EVEN ) },
  { LSTRKEY( "PAR_ODD" ), LNUMVAL( PLATFORM_UART_PARITY_ODD ) },
  { LSTRKEY( "PAR_NONE" ), LNUMVAL( PLATFORM_UART_PARITY_NONE ) },
  { LSTRKEY( "STOP_1" ), LNUMVAL( PLATFORM_UART_STOPBITS_1 ) },
  { LSTRKEY( "STOP_1_5" ), LNUMVAL( PLATFORM_UART_STOPBITS_1_5 ) },
  { LSTRKEY( "STOP_2" ), LNUMVAL( PLATFORM_UART_STOPBITS_2 ) },
  { LSTRKEY( "NO_TIMEOUT" ), LNUMVAL( 0 ) },
  { LSTRKEY( "INF_TIMEOUT" ), LNUMVAL( PLATFORM_UART_INFINITE_TIMEOUT ) },
#endif
  { LNILKEY, LNILVAL }
};
示例#29
0
			lua_pushinteger( L, adc_get_processed_sample( id ) );
		else
			lua_pushnil( L ); // nil-out values where we don't have enough samples

		lua_rawseti( L, 2, i );
	}

	return 0;
}
#endif

// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE adc_map[] = {
	{ LSTRKEY( "sample" ), LFUNCVAL( adc_sample ) },
	{ LSTRKEY( "maxval" ), LFUNCVAL( adc_maxval ) },
	{ LSTRKEY( "setclock" ), LFUNCVAL( adc_setclock ) },
	{ LSTRKEY( "isdone" ), LFUNCVAL( adc_isdone ) },
	{ LSTRKEY( "setblocking" ), LFUNCVAL( adc_setblocking ) },
	{ LSTRKEY( "setsmoothing" ), LFUNCVAL( adc_setsmoothing ) },
	{ LSTRKEY( "getsample" ), LFUNCVAL( adc_getsample ) },
#if defined( BUF_ENABLE_ADC )
	{ LSTRKEY( "getsamples" ), LFUNCVAL( adc_getsamples ) },
	{ LSTRKEY( "insertsamples" ), LFUNCVAL( adc_insertsamples ) },
#endif
	{ LNILKEY, LNILVAL }
};

LUALIB_API int luaopen_adc( lua_State *L )
{
示例#30
0
    {
      luaL_checktype( L, s, LUA_TSTRING );
      buf = lua_tolstring( L, s, &len );
      for( i = 0; i < len; i ++ )
        platform_uart_send( id, buf[ i ] );
    }
  }
  return 0;
}

// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE uart_map[] = 
{
  { LSTRKEY( "setup" ),  LFUNCVAL( uart_setup ) },
  { LSTRKEY( "write" ), LFUNCVAL( uart_write ) },
  { LSTRKEY( "on" ), LFUNCVAL( uart_on ) },
  { LSTRKEY( "alt" ), LFUNCVAL( uart_alt ) },

#if LUA_OPTIMIZE_MEMORY > 0

#endif
  { LNILKEY, LNILVAL }
};

LUALIB_API int luaopen_uart( lua_State *L )
{
#if LUA_OPTIMIZE_MEMORY > 0
  return 0;
#else // #if LUA_OPTIMIZE_MEMORY > 0