Unverified Commit 310faf7f authored by Terry Ellison's avatar Terry Ellison Committed by GitHub
Browse files

Merge pull request #2886 from nodemcu/dev

Next master drop
parents 68c425c0 a08e74d9
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
//#define NODE_DEBUG //#define NODE_DEBUG
#include <stdint.h>
#include "os_type.h" #include "os_type.h"
#include "osapi.h" #include "osapi.h"
#include "sections.h" #include "sections.h"
...@@ -231,18 +232,18 @@ static int somfy_lua_sendcommand(lua_State* L) { // pin, remote, command, rollin ...@@ -231,18 +232,18 @@ static int somfy_lua_sendcommand(lua_State* L) { // pin, remote, command, rollin
return 0; return 0;
} }
static const LUA_REG_TYPE somfy_map[] = { LROT_BEGIN(somfy)
{ LSTRKEY( "UP" ), LNUMVAL( SOMFY_UP ) }, LROT_NUMENTRY( UP, SOMFY_UP )
{ LSTRKEY( "DOWN" ), LNUMVAL( SOMFY_DOWN ) }, LROT_NUMENTRY( DOWN, SOMFY_DOWN )
{ LSTRKEY( "PROG" ), LNUMVAL( SOMFY_PROG ) }, LROT_NUMENTRY( PROG, SOMFY_PROG )
{ LSTRKEY( "STOP" ), LNUMVAL( SOMFY_STOP ) }, LROT_NUMENTRY( STOP, SOMFY_STOP )
{ LSTRKEY( "sendcommand" ), LFUNCVAL(somfy_lua_sendcommand)}, LROT_FUNCENTRY( sendcommand, somfy_lua_sendcommand )
{ LNILKEY, LNILVAL} LROT_END( somfy, NULL, 0 )
};
int luaopen_somfy( lua_State *L ) { int luaopen_somfy( lua_State *L ) {
done_taskid = task_get_id((task_callback_t) somfy_transmissionDone); done_taskid = task_get_id((task_callback_t) somfy_transmissionDone);
return 0; return 0;
} }
NODEMCU_MODULE(SOMFY, "somfy", somfy_map, luaopen_somfy); NODEMCU_MODULE(SOMFY, "somfy", somfy, luaopen_somfy);
\ No newline at end of file
...@@ -319,24 +319,24 @@ static int spi_set_clock_div( lua_State *L ) ...@@ -319,24 +319,24 @@ static int spi_set_clock_div( lua_State *L )
// Module function map // Module function map
static const LUA_REG_TYPE spi_map[] = { LROT_BEGIN(spi)
{ LSTRKEY( "setup" ), LFUNCVAL( spi_setup ) }, LROT_FUNCENTRY( setup, spi_setup )
{ LSTRKEY( "send" ), LFUNCVAL( spi_send_recv ) }, LROT_FUNCENTRY( send, spi_send_recv )
{ LSTRKEY( "recv" ), LFUNCVAL( spi_recv ) }, LROT_FUNCENTRY( recv, spi_recv )
{ LSTRKEY( "set_mosi" ), LFUNCVAL( spi_set_mosi ) }, LROT_FUNCENTRY( set_mosi, spi_set_mosi )
{ LSTRKEY( "get_miso" ), LFUNCVAL( spi_get_miso ) }, LROT_FUNCENTRY( get_miso, spi_get_miso )
{ LSTRKEY( "transaction" ), LFUNCVAL( spi_transaction ) }, LROT_FUNCENTRY( transaction, spi_transaction )
{ LSTRKEY( "set_clock_div" ), LFUNCVAL( spi_set_clock_div ) }, LROT_FUNCENTRY( set_clock_div, spi_set_clock_div )
{ LSTRKEY( "MASTER" ), LNUMVAL( PLATFORM_SPI_MASTER ) }, LROT_NUMENTRY( MASTER, PLATFORM_SPI_MASTER )
{ LSTRKEY( "SLAVE" ), LNUMVAL( PLATFORM_SPI_SLAVE) }, LROT_NUMENTRY( SLAVE, PLATFORM_SPI_SLAVE )
{ LSTRKEY( "CPHA_LOW" ), LNUMVAL( PLATFORM_SPI_CPHA_LOW) }, LROT_NUMENTRY( CPHA_LOW, PLATFORM_SPI_CPHA_LOW )
{ LSTRKEY( "CPHA_HIGH" ), LNUMVAL( PLATFORM_SPI_CPHA_HIGH) }, LROT_NUMENTRY( CPHA_HIGH, PLATFORM_SPI_CPHA_HIGH )
{ LSTRKEY( "CPOL_LOW" ), LNUMVAL( PLATFORM_SPI_CPOL_LOW) }, LROT_NUMENTRY( CPOL_LOW, PLATFORM_SPI_CPOL_LOW )
{ LSTRKEY( "CPOL_HIGH" ), LNUMVAL( PLATFORM_SPI_CPOL_HIGH) }, LROT_NUMENTRY( CPOL_HIGH, PLATFORM_SPI_CPOL_HIGH )
{ LSTRKEY( "DATABITS_8" ), LNUMVAL( 8 ) }, LROT_NUMENTRY( DATABITS_8, 8 )
{ LSTRKEY( "HALFDUPLEX" ), LNUMVAL( SPI_HALFDUPLEX ) }, LROT_NUMENTRY( HALFDUPLEX, SPI_HALFDUPLEX )
{ LSTRKEY( "FULLDUPLEX" ), LNUMVAL( SPI_FULLDUPLEX ) }, LROT_NUMENTRY( FULLDUPLEX, SPI_FULLDUPLEX )
{ LNILKEY, LNILVAL } LROT_END( spi, NULL, 0 )
};
NODEMCU_MODULE(SPI, "spi", spi_map, NULL); NODEMCU_MODULE(SPI, "spi", spi, NULL);
...@@ -25,12 +25,13 @@ ...@@ -25,12 +25,13 @@
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE *
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
************************************************************************/ ************************************************************************/
#if 0
#define LSQLITE_VERSION "0.9.4" #define LSQLITE_VERSION "0.9.4"
#define LSQLITE_OMIT_UPDATE_HOOK 1 #define LSQLITE_OMIT_UPDATE_HOOK 1
#define SQLITE_OMIT_PROGRESS_CALLBACK 1 #define SQLITE_OMIT_PROGRESS_CALLBACK 1
#include <c_stdlib.h> #include <stdlib.h>
#include <c_string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#define LUA_LIB #define LUA_LIB
...@@ -58,7 +59,7 @@ ...@@ -58,7 +59,7 @@
#endif #endif
#endif #endif
#include "sqlite3.h" #include "sqlite3/sqlite3.h"
/* compile time features */ /* compile time features */
#if !defined(SQLITE_OMIT_PROGRESS_CALLBACK) #if !defined(SQLITE_OMIT_PROGRESS_CALLBACK)
...@@ -272,7 +273,7 @@ static int dbvm_tostring(lua_State *L) { ...@@ -272,7 +273,7 @@ static int dbvm_tostring(lua_State *L) {
if (svm->vm == NULL) if (svm->vm == NULL)
strcpy(buff, "closed"); strcpy(buff, "closed");
else else
c_sprintf(buff, "%p", svm); sprintf(buff, "%p", svm);
lua_pushfstring(L, "sqlite virtual machine (%s)", buff); lua_pushfstring(L, "sqlite virtual machine (%s)", buff);
return 1; return 1;
} }
...@@ -742,7 +743,7 @@ static int cleanupdb(lua_State *L, sdb *db) { ...@@ -742,7 +743,7 @@ static int cleanupdb(lua_State *L, sdb *db) {
luaL_unref(L, LUA_REGISTRYINDEX, func->fn_step); luaL_unref(L, LUA_REGISTRYINDEX, func->fn_step);
luaL_unref(L, LUA_REGISTRYINDEX, func->fn_finalize); luaL_unref(L, LUA_REGISTRYINDEX, func->fn_finalize);
luaL_unref(L, LUA_REGISTRYINDEX, func->udata); luaL_unref(L, LUA_REGISTRYINDEX, func->udata);
c_free(func); free(func);
func = func_next; func = func_next;
} }
db->func = NULL; db->func = NULL;
...@@ -799,7 +800,7 @@ static int lcontext_tostring(lua_State *L) { ...@@ -799,7 +800,7 @@ static int lcontext_tostring(lua_State *L) {
if (ctx->ctx == NULL) if (ctx->ctx == NULL)
strcpy(buff, "closed"); strcpy(buff, "closed");
else else
c_sprintf(buff, "%p", ctx->ctx); sprintf(buff, "%p", ctx->ctx);
lua_pushfstring(L, "sqlite function context (%s)", buff); lua_pushfstring(L, "sqlite function context (%s)", buff);
return 1; return 1;
} }
...@@ -1155,7 +1156,7 @@ static int db_register_function(lua_State *L, int aggregate) { ...@@ -1155,7 +1156,7 @@ static int db_register_function(lua_State *L, int aggregate) {
if (aggregate) luaL_checktype(L, 5, LUA_TFUNCTION); if (aggregate) luaL_checktype(L, 5, LUA_TFUNCTION);
/* maybe an alternative way to allocate memory should be used/avoided */ /* maybe an alternative way to allocate memory should be used/avoided */
func = (sdb_func*)c_malloc(sizeof(sdb_func)); func = (sdb_func*)malloc(sizeof(sdb_func));
if (func == NULL) { if (func == NULL) {
luaL_error(L, "out of memory"); luaL_error(L, "out of memory");
} }
...@@ -1193,7 +1194,7 @@ static int db_register_function(lua_State *L, int aggregate) { ...@@ -1193,7 +1194,7 @@ static int db_register_function(lua_State *L, int aggregate) {
} }
else { else {
/* free allocated memory */ /* free allocated memory */
c_free(func); free(func);
} }
lua_pushboolean(L, result == SQLITE_OK ? 1 : 0); lua_pushboolean(L, result == SQLITE_OK ? 1 : 0);
...@@ -1231,7 +1232,7 @@ static int collwrapper(scc *co,int l1,const void *p1, ...@@ -1231,7 +1232,7 @@ static int collwrapper(scc *co,int l1,const void *p1,
static void collfree(scc *co) { static void collfree(scc *co) {
if (co) { if (co) {
luaL_unref(co->L,LUA_REGISTRYINDEX,co->ref); luaL_unref(co->L,LUA_REGISTRYINDEX,co->ref);
c_free(co); free(co);
} }
} }
...@@ -1245,7 +1246,7 @@ static int db_create_collation(lua_State *L) { ...@@ -1245,7 +1246,7 @@ static int db_create_collation(lua_State *L) {
else if (!lua_isnil(L,3)) else if (!lua_isnil(L,3))
luaL_error(L,"create_collation: function or nil expected"); luaL_error(L,"create_collation: function or nil expected");
if (collfunc != NULL) { if (collfunc != NULL) {
co=(scc *)c_malloc(sizeof(scc)); /* userdata is a no-no as it co=(scc *)malloc(sizeof(scc)); /* userdata is a no-no as it
will be garbage-collected */ will be garbage-collected */
if (co) { if (co) {
co->L=L; co->L=L;
...@@ -2036,7 +2037,7 @@ static int db_tostring(lua_State *L) { ...@@ -2036,7 +2037,7 @@ static int db_tostring(lua_State *L) {
if (db->db == NULL) if (db->db == NULL)
strcpy(buff, "closed"); strcpy(buff, "closed");
else else
c_sprintf(buff, "%p", lua_touserdata(L, 1)); sprintf(buff, "%p", lua_touserdata(L, 1));
lua_pushfstring(L, "sqlite database (%s)", buff); lua_pushfstring(L, "sqlite database (%s)", buff);
return 1; return 1;
} }
...@@ -2429,3 +2430,4 @@ LUALIB_API int luaopen_lsqlite3(lua_State *L) { ...@@ -2429,3 +2430,4 @@ LUALIB_API int luaopen_lsqlite3(lua_State *L) {
} }
NODEMCU_MODULE(SQLITE3, "sqlite3", sqlitelib, luaopen_lsqlite3); NODEMCU_MODULE(SQLITE3, "sqlite3", sqlitelib, luaopen_lsqlite3);
#endif
...@@ -389,13 +389,12 @@ static int b_size (lua_State *L) { ...@@ -389,13 +389,12 @@ static int b_size (lua_State *L) {
/* }====================================================== */ /* }====================================================== */
LROT_BEGIN(thislib)
LROT_FUNCENTRY( pack, b_pack )
LROT_FUNCENTRY( unpack, b_unpack )
LROT_FUNCENTRY( size, b_size )
LROT_END( thislib, NULL, 0 )
static const LUA_REG_TYPE thislib[] = {
{LSTRKEY("pack"), LFUNCVAL(b_pack)},
{LSTRKEY("unpack"), LFUNCVAL(b_unpack)},
{LSTRKEY("size"), LFUNCVAL(b_size)},
{LNILKEY, LNILVAL}
};
NODEMCU_MODULE(STRUCT, "struct", thislib, NULL); NODEMCU_MODULE(STRUCT, "struct", thislib, NULL);
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include "module.h" #include "module.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "c_types.h" #include <stdint.h>
#include "task/task.h" #include "task/task.h"
#include "driver/switec.h" #include "driver/switec.h"
...@@ -196,17 +196,17 @@ static int switec_open(lua_State *L) ...@@ -196,17 +196,17 @@ static int switec_open(lua_State *L)
// Module function map // Module function map
static const LUA_REG_TYPE switec_map[] = { LROT_BEGIN(switec)
{ LSTRKEY( "setup" ), LFUNCVAL( lswitec_setup ) }, LROT_FUNCENTRY( setup, lswitec_setup )
{ LSTRKEY( "close" ), LFUNCVAL( lswitec_close ) }, LROT_FUNCENTRY( close, lswitec_close )
{ LSTRKEY( "reset" ), LFUNCVAL( lswitec_reset ) }, LROT_FUNCENTRY( reset, lswitec_reset )
{ LSTRKEY( "moveto" ), LFUNCVAL( lswitec_moveto) }, LROT_FUNCENTRY( moveto, lswitec_moveto )
{ LSTRKEY( "getpos" ), LFUNCVAL( lswitec_getpos) }, LROT_FUNCENTRY( getpos, lswitec_getpos )
#ifdef SQITEC_DEBUG #ifdef SQITEC_DEBUG
{ LSTRKEY( "dequeue" ), LFUNCVAL( lswitec_dequeue) }, LROT_FUNCENTRY( dequeue, lswitec_dequeue )
#endif #endif
{ LNILKEY, LNILVAL } LROT_END( switec, NULL, 0 )
};
NODEMCU_MODULE(SWITEC, "switec", switec_map, switec_open);
NODEMCU_MODULE(SWITEC, "switec", switec, switec_open);
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#include "module.h" #include "module.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "c_math.h" #include <math.h>
// #define TCS34725_ADDRESS (0x29<<1) // #define TCS34725_ADDRESS (0x29<<1)
#define TCS34725_ADDRESS (0x29) #define TCS34725_ADDRESS (0x29)
...@@ -342,14 +342,14 @@ uint8_t tcs34725GetRawData(lua_State* L) ...@@ -342,14 +342,14 @@ uint8_t tcs34725GetRawData(lua_State* L)
} }
static const LUA_REG_TYPE tcs34725_map[] = { LROT_BEGIN(tcs34725)
{ LSTRKEY( "setup" ), LFUNCVAL(tcs34725Setup)}, LROT_FUNCENTRY( setup, tcs34725Setup )
{ LSTRKEY( "enable" ), LFUNCVAL(tcs34725Enable)}, LROT_FUNCENTRY( enable, tcs34725Enable )
{ LSTRKEY( "disable" ), LFUNCVAL(tcs34725Disable)}, LROT_FUNCENTRY( disable, tcs34725Disable )
{ LSTRKEY( "raw" ), LFUNCVAL(tcs34725GetRawData)}, LROT_FUNCENTRY( raw, tcs34725GetRawData )
{ LSTRKEY( "setGain" ), LFUNCVAL(tcs34725LuaSetGain)}, LROT_FUNCENTRY( setGain, tcs34725LuaSetGain )
{ LSTRKEY( "setIntegrationTime" ), LFUNCVAL(tcs34725LuaSetIntegrationTime)}, LROT_FUNCENTRY( setIntegrationTime, tcs34725LuaSetIntegrationTime )
{ LNILKEY, LNILVAL} LROT_END( tcs34725, NULL, 0 )
};
NODEMCU_MODULE(TCS34725, "tcs34725", tcs34725_map, NULL);
\ No newline at end of file NODEMCU_MODULE(TCS34725, "tcs34725", tcs34725, NULL);
\ No newline at end of file
...@@ -8,10 +8,10 @@ ...@@ -8,10 +8,10 @@
#include "platform.h" #include "platform.h"
#include "lmem.h" #include "lmem.h"
#include "c_string.h" #include <string.h>
#include "c_stdlib.h" #include <stddef.h>
#include "c_types.h" #include <stdint.h>
#include "mem.h" #include "mem.h"
#include "lwip/ip_addr.h" #include "lwip/ip_addr.h"
#include "espconn.h" #include "espconn.h"
...@@ -31,7 +31,7 @@ __attribute__((section(".servercert.flash"))) unsigned char tls_server_cert_area ...@@ -31,7 +31,7 @@ __attribute__((section(".servercert.flash"))) unsigned char tls_server_cert_area
__attribute__((section(".clientcert.flash"))) unsigned char tls_client_cert_area[INTERNAL_FLASH_SECTOR_SIZE]; __attribute__((section(".clientcert.flash"))) unsigned char tls_client_cert_area[INTERNAL_FLASH_SECTOR_SIZE];
extern int tls_socket_create( lua_State *L ); extern int tls_socket_create( lua_State *L );
extern const LUA_REG_TYPE tls_cert_map[]; LROT_EXTERN(tls_cert);
typedef struct { typedef struct {
struct espconn *pesp_conn; struct espconn *pesp_conn;
...@@ -77,10 +77,10 @@ static void tls_socket_cleanup(tls_socket_ud *ud) { ...@@ -77,10 +77,10 @@ static void tls_socket_cleanup(tls_socket_ud *ud) {
if (ud->pesp_conn) { if (ud->pesp_conn) {
espconn_secure_disconnect(ud->pesp_conn); espconn_secure_disconnect(ud->pesp_conn);
if (ud->pesp_conn->proto.tcp) { if (ud->pesp_conn->proto.tcp) {
c_free(ud->pesp_conn->proto.tcp); free(ud->pesp_conn->proto.tcp);
ud->pesp_conn->proto.tcp = NULL; ud->pesp_conn->proto.tcp = NULL;
} }
c_free(ud->pesp_conn); free(ud->pesp_conn);
ud->pesp_conn = NULL; ud->pesp_conn = NULL;
} }
lua_State *L = lua_getstate(); lua_State *L = lua_getstate();
...@@ -167,7 +167,7 @@ static void tls_socket_dns_cb( const char* domain, const ip_addr_t *ip_addr, tls ...@@ -167,7 +167,7 @@ static void tls_socket_dns_cb( const char* domain, const ip_addr_t *ip_addr, tls
lua_pushnil(L); lua_pushnil(L);
} else { } else {
char tmp[20]; char tmp[20];
c_sprintf(tmp, IPSTR, IP2STR(&addr.addr)); sprintf(tmp, IPSTR, IP2STR(&addr.addr));
lua_pushstring(L, tmp); lua_pushstring(L, tmp);
} }
lua_call(L, 2, 0); lua_call(L, 2, 0);
...@@ -205,13 +205,13 @@ static int tls_socket_connect( lua_State *L ) { ...@@ -205,13 +205,13 @@ static int tls_socket_connect( lua_State *L ) {
if (domain == NULL) if (domain == NULL)
return luaL_error(L, "invalid domain"); return luaL_error(L, "invalid domain");
ud->pesp_conn = (struct espconn*)c_zalloc(sizeof(struct espconn)); ud->pesp_conn = (struct espconn*)calloc(1,sizeof(struct espconn));
if(!ud->pesp_conn) if(!ud->pesp_conn)
return luaL_error(L, "not enough memory"); return luaL_error(L, "not enough memory");
ud->pesp_conn->proto.udp = NULL; ud->pesp_conn->proto.udp = NULL;
ud->pesp_conn->proto.tcp = (esp_tcp *)c_zalloc(sizeof(esp_tcp)); ud->pesp_conn->proto.tcp = (esp_tcp *)calloc(1,sizeof(esp_tcp));
if(!ud->pesp_conn->proto.tcp){ if(!ud->pesp_conn->proto.tcp){
c_free(ud->pesp_conn); free(ud->pesp_conn);
ud->pesp_conn = NULL; ud->pesp_conn = NULL;
return luaL_error(L, "not enough memory"); return luaL_error(L, "not enough memory");
} }
...@@ -349,7 +349,7 @@ static int tls_socket_getpeer( lua_State *L ) { ...@@ -349,7 +349,7 @@ static int tls_socket_getpeer( lua_State *L ) {
if(ud->pesp_conn && ud->pesp_conn->proto.tcp->remote_port != 0){ if(ud->pesp_conn && ud->pesp_conn->proto.tcp->remote_port != 0){
char temp[20] = {0}; char temp[20] = {0};
c_sprintf(temp, IPSTR, IP2STR( &(ud->pesp_conn->proto.tcp->remote_ip) ) ); sprintf(temp, IPSTR, IP2STR( &(ud->pesp_conn->proto.tcp->remote_ip) ) );
lua_pushstring( L, temp ); lua_pushstring( L, temp );
lua_pushinteger( L, ud->pesp_conn->proto.tcp->remote_port ); lua_pushinteger( L, ud->pesp_conn->proto.tcp->remote_port );
} else { } else {
...@@ -382,10 +382,10 @@ static int tls_socket_delete( lua_State *L ) { ...@@ -382,10 +382,10 @@ static int tls_socket_delete( lua_State *L ) {
if (ud->pesp_conn) { if (ud->pesp_conn) {
espconn_secure_disconnect(ud->pesp_conn); espconn_secure_disconnect(ud->pesp_conn);
if (ud->pesp_conn->proto.tcp) { if (ud->pesp_conn->proto.tcp) {
c_free(ud->pesp_conn->proto.tcp); free(ud->pesp_conn->proto.tcp);
ud->pesp_conn->proto.tcp = NULL; ud->pesp_conn->proto.tcp = NULL;
} }
c_free(ud->pesp_conn); free(ud->pesp_conn);
ud->pesp_conn = NULL; ud->pesp_conn = NULL;
} }
...@@ -507,7 +507,7 @@ static const char *fill_page_with_pem(lua_State *L, const unsigned char *flash_m ...@@ -507,7 +507,7 @@ static const char *fill_page_with_pem(lua_State *L, const unsigned char *flash_m
memset(buffer, 0xff, buffer_limit - buffer); memset(buffer, 0xff, buffer_limit - buffer);
// Lets see if it matches what is already there.... // Lets see if it matches what is already there....
if (c_memcmp(buffer_base, flash_memory, INTERNAL_FLASH_SECTOR_SIZE) != 0) { if (memcmp(buffer_base, flash_memory, INTERNAL_FLASH_SECTOR_SIZE) != 0) {
// Starts being dangerous // Starts being dangerous
if (platform_flash_erase_sector(flash_offset / INTERNAL_FLASH_SECTOR_SIZE) != PLATFORM_OK) { if (platform_flash_erase_sector(flash_offset / INTERNAL_FLASH_SECTOR_SIZE) != PLATFORM_OK) {
luaM_free(L, buffer_base); luaM_free(L, buffer_base);
...@@ -613,40 +613,40 @@ static int tls_set_debug_threshold(lua_State *L) { ...@@ -613,40 +613,40 @@ static int tls_set_debug_threshold(lua_State *L) {
} }
#endif #endif
static const LUA_REG_TYPE tls_socket_map[] = { LROT_BEGIN(tls_socket)
{ LSTRKEY( "connect" ), LFUNCVAL( tls_socket_connect ) }, LROT_FUNCENTRY( connect, tls_socket_connect )
{ LSTRKEY( "close" ), LFUNCVAL( tls_socket_close ) }, LROT_FUNCENTRY( close, tls_socket_close )
{ LSTRKEY( "on" ), LFUNCVAL( tls_socket_on ) }, LROT_FUNCENTRY( on, tls_socket_on )
{ LSTRKEY( "send" ), LFUNCVAL( tls_socket_send ) }, LROT_FUNCENTRY( send, tls_socket_send )
{ LSTRKEY( "hold" ), LFUNCVAL( tls_socket_hold ) }, LROT_FUNCENTRY( hold, tls_socket_hold )
{ LSTRKEY( "unhold" ), LFUNCVAL( tls_socket_unhold ) }, LROT_FUNCENTRY( unhold, tls_socket_unhold )
{ LSTRKEY( "getpeer" ), LFUNCVAL( tls_socket_getpeer ) }, LROT_FUNCENTRY( getpeer, tls_socket_getpeer )
{ LSTRKEY( "__gc" ), LFUNCVAL( tls_socket_delete ) }, LROT_FUNCENTRY( __gc, tls_socket_delete )
{ LSTRKEY( "__index" ), LROVAL( tls_socket_map ) }, LROT_TABENTRY( __index, tls_socket )
{ LNILKEY, LNILVAL } LROT_END( tls_socket, tls_socket, 0 )
};
const LUA_REG_TYPE tls_cert_map[] = { LROT_PUBLIC_BEGIN(tls_cert)
{ LSTRKEY( "verify" ), LFUNCVAL( tls_cert_verify ) }, LROT_FUNCENTRY( verify, tls_cert_verify )
{ LSTRKEY( "auth" ), LFUNCVAL( tls_cert_auth ) }, LROT_FUNCENTRY( auth, tls_cert_auth )
{ LSTRKEY( "__index" ), LROVAL( tls_cert_map ) }, LROT_TABENTRY( __index, tls_cert )
{ LNILKEY, LNILVAL } LROT_END( tls_cert, tls_cert, 0 )
};
static const LUA_REG_TYPE tls_map[] = { LROT_BEGIN(tls)
{ LSTRKEY( "createConnection" ), LFUNCVAL( tls_socket_create ) }, LROT_FUNCENTRY( createConnection, tls_socket_create )
#if defined(MBEDTLS_DEBUG_C) #if defined(MBEDTLS_DEBUG_C)
{ LSTRKEY( "setDebug" ), LFUNCVAL( tls_set_debug_threshold ) }, LROT_FUNCENTRY( setDebug, tls_set_debug_threshold )
#endif #endif
{ LSTRKEY( "cert" ), LROVAL( tls_cert_map ) }, LROT_TABENTRY( cert, tls_cert )
{ LSTRKEY( "__metatable" ), LROVAL( tls_map ) }, LROT_TABENTRY( __metatable, tls )
{ LNILKEY, LNILVAL } LROT_END( tls, tls, 0 )
};
int luaopen_tls( lua_State *L ) { int luaopen_tls( lua_State *L ) {
luaL_rometatable(L, "tls.socket", (void *)tls_socket_map); // create metatable for net.server luaL_rometatable(L, "tls.socket", LROT_TABLEREF(tls_socket));
return 0; return 0;
} }
NODEMCU_MODULE(TLS, "tls", tls_map, luaopen_tls); NODEMCU_MODULE(TLS, "tls", tls, luaopen_tls);
#endif #endif
#include "module.h" #include "module.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "c_stdlib.h" #include <stdlib.h>
#include "c_string.h" #include <string.h>
#include "user_interface.h" #include "user_interface.h"
static inline uint32_t _getCycleCount(void) { static inline uint32_t _getCycleCount(void) {
...@@ -68,7 +68,7 @@ static int ICACHE_FLASH_ATTR tm1829_write(lua_State* L) ...@@ -68,7 +68,7 @@ static int ICACHE_FLASH_ATTR tm1829_write(lua_State* L)
const char *rgb = luaL_checklstring(L, 2, &length); const char *rgb = luaL_checklstring(L, 2, &length);
// dont modify lua-internal lstring - make a copy instead // dont modify lua-internal lstring - make a copy instead
char *buffer = (char *)c_malloc(length); char *buffer = (char *)malloc(length);
// Ignore incomplete Byte triples at the end of buffer // Ignore incomplete Byte triples at the end of buffer
length -= length % 3; length -= length % 3;
...@@ -95,20 +95,19 @@ static int ICACHE_FLASH_ATTR tm1829_write(lua_State* L) ...@@ -95,20 +95,19 @@ static int ICACHE_FLASH_ATTR tm1829_write(lua_State* L)
os_delay_us(500); // reset time os_delay_us(500); // reset time
c_free(buffer); free(buffer);
return 0; return 0;
} }
static const LUA_REG_TYPE tm1829_map[] = LROT_BEGIN(tm1829)
{ LROT_FUNCENTRY( write, tm1829_write )
{ LSTRKEY( "write" ), LFUNCVAL( tm1829_write) }, LROT_END( tm1829, NULL, 0 )
{ LNILKEY, LNILVAL }
};
int luaopen_tm1829(lua_State *L) { int luaopen_tm1829(lua_State *L) {
// TODO: Make sure that the GPIO system is initialized // TODO: Make sure that the GPIO system is initialized
return 0; return 0;
} }
NODEMCU_MODULE(TM1829, "tm1829", tm1829_map, luaopen_tm1829); NODEMCU_MODULE(TM1829, "tm1829", tm1829, luaopen_tm1829);
...@@ -51,7 +51,7 @@ tmr.softwd(int) ...@@ -51,7 +51,7 @@ tmr.softwd(int)
#include "module.h" #include "module.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "c_types.h" #include <stdint.h>
#include "user_interface.h" #include "user_interface.h"
#include "pm/swtimer.h" #include "pm/swtimer.h"
...@@ -78,7 +78,7 @@ typedef struct{ ...@@ -78,7 +78,7 @@ typedef struct{
uint32_t interval; uint32_t interval;
uint8_t mode; uint8_t mode;
}timer_struct_t; }timer_struct_t;
typedef timer_struct_t* timer_t; typedef timer_struct_t* tmr_t;
// The previous implementation extended the rtc counter to 64 bits, and then // The previous implementation extended the rtc counter to 64 bits, and then
// applied rtc2sec with the current calibration value to that 64 bit value. // applied rtc2sec with the current calibration value to that 64 bit value.
...@@ -97,7 +97,7 @@ static sint32_t soft_watchdog = -1; ...@@ -97,7 +97,7 @@ static sint32_t soft_watchdog = -1;
static os_timer_t rtc_timer; static os_timer_t rtc_timer;
static void alarm_timer_common(void* arg){ static void alarm_timer_common(void* arg){
timer_t tmr = (timer_t)arg; tmr_t tmr = (tmr_t)arg;
lua_State* L = lua_getstate(); lua_State* L = lua_getstate();
if(tmr->lua_ref == LUA_NOREF) if(tmr->lua_ref == LUA_NOREF)
return; return;
...@@ -142,16 +142,16 @@ static int tmr_now(lua_State* L){ ...@@ -142,16 +142,16 @@ static int tmr_now(lua_State* L){
return 1; return 1;
} }
static timer_t tmr_get( lua_State *L, int stack ) { static tmr_t tmr_get( lua_State *L, int stack ) {
timer_t t = (timer_t)luaL_checkudata(L, stack, "tmr.timer"); tmr_t t = (tmr_t)luaL_checkudata(L, stack, "tmr.timer");
if (t == NULL) if (t == NULL)
return (timer_t)luaL_error(L, "timer object expected"); return (tmr_t)luaL_error(L, "timer object expected");
return t; return t;
} }
// Lua: tmr.register( ref, interval, mode, function ) // Lua: tmr.register( ref, interval, mode, function )
static int tmr_register(lua_State* L){ static int tmr_register(lua_State* L){
timer_t tmr = tmr_get(L, 1); tmr_t tmr = tmr_get(L, 1);
uint32_t interval = luaL_checkinteger(L, 2); uint32_t interval = luaL_checkinteger(L, 2);
uint8_t mode = luaL_checkinteger(L, 3); uint8_t mode = luaL_checkinteger(L, 3);
...@@ -176,7 +176,7 @@ static int tmr_register(lua_State* L){ ...@@ -176,7 +176,7 @@ static int tmr_register(lua_State* L){
// Lua: tmr.start( id / ref ) // Lua: tmr.start( id / ref )
static int tmr_start(lua_State* L){ static int tmr_start(lua_State* L){
timer_t tmr = tmr_get(L, 1); tmr_t tmr = tmr_get(L, 1);
if (tmr->self_ref == LUA_NOREF) { if (tmr->self_ref == LUA_NOREF) {
lua_pushvalue(L, 1); lua_pushvalue(L, 1);
...@@ -202,7 +202,7 @@ static int tmr_alarm(lua_State* L){ ...@@ -202,7 +202,7 @@ static int tmr_alarm(lua_State* L){
// Lua: tmr.stop( id / ref ) // Lua: tmr.stop( id / ref )
static int tmr_stop(lua_State* L){ static int tmr_stop(lua_State* L){
timer_t tmr = tmr_get(L, 1); tmr_t tmr = tmr_get(L, 1);
if (tmr->self_ref != LUA_REFNIL) { if (tmr->self_ref != LUA_REFNIL) {
luaL_unref(L, LUA_REGISTRYINDEX, tmr->self_ref); luaL_unref(L, LUA_REGISTRYINDEX, tmr->self_ref);
...@@ -244,7 +244,7 @@ static int tmr_resume_all (lua_State *L){ ...@@ -244,7 +244,7 @@ static int tmr_resume_all (lua_State *L){
// Lua: tmr.unregister( id / ref ) // Lua: tmr.unregister( id / ref )
static int tmr_unregister(lua_State* L){ static int tmr_unregister(lua_State* L){
timer_t tmr = tmr_get(L, 1); tmr_t tmr = tmr_get(L, 1);
if (tmr->self_ref != LUA_REFNIL) { if (tmr->self_ref != LUA_REFNIL) {
luaL_unref(L, LUA_REGISTRYINDEX, tmr->self_ref); luaL_unref(L, LUA_REGISTRYINDEX, tmr->self_ref);
...@@ -262,7 +262,7 @@ static int tmr_unregister(lua_State* L){ ...@@ -262,7 +262,7 @@ static int tmr_unregister(lua_State* L){
// Lua: tmr.interval( id / ref, interval ) // Lua: tmr.interval( id / ref, interval )
static int tmr_interval(lua_State* L){ static int tmr_interval(lua_State* L){
timer_t tmr = tmr_get(L, 1); tmr_t tmr = tmr_get(L, 1);
uint32_t interval = luaL_checkinteger(L, 2); uint32_t interval = luaL_checkinteger(L, 2);
luaL_argcheck(L, (interval > 0 && interval <= MAX_TIMEOUT), 2, MAX_TIMEOUT_ERR_STR); luaL_argcheck(L, (interval > 0 && interval <= MAX_TIMEOUT), 2, MAX_TIMEOUT_ERR_STR);
...@@ -278,7 +278,7 @@ static int tmr_interval(lua_State* L){ ...@@ -278,7 +278,7 @@ static int tmr_interval(lua_State* L){
// Lua: tmr.state( id / ref ) // Lua: tmr.state( id / ref )
static int tmr_state(lua_State* L){ static int tmr_state(lua_State* L){
timer_t tmr = tmr_get(L, 1); tmr_t tmr = tmr_get(L, 1);
if(tmr->mode == TIMER_MODE_OFF){ if(tmr->mode == TIMER_MODE_OFF){
lua_pushnil(L); lua_pushnil(L);
...@@ -355,7 +355,7 @@ static int tmr_softwd( lua_State* L ){ ...@@ -355,7 +355,7 @@ static int tmr_softwd( lua_State* L ){
// Lua: tmr.create() // Lua: tmr.create()
static int tmr_create( lua_State *L ) { static int tmr_create( lua_State *L ) {
timer_t ud = (timer_t)lua_newuserdata(L, sizeof(timer_struct_t)); tmr_t ud = (tmr_t)lua_newuserdata(L, sizeof(timer_struct_t));
if (!ud) return luaL_error(L, "not enough memory"); if (!ud) return luaL_error(L, "not enough memory");
luaL_getmetatable(L, "tmr.timer"); luaL_getmetatable(L, "tmr.timer");
lua_setmetatable(L, -2); lua_setmetatable(L, -2);
...@@ -369,43 +369,43 @@ static int tmr_create( lua_State *L ) { ...@@ -369,43 +369,43 @@ static int tmr_create( lua_State *L ) {
// Module function map // Module function map
static const LUA_REG_TYPE tmr_dyn_map[] = { LROT_BEGIN(tmr_dyn)
{ LSTRKEY( "register" ), LFUNCVAL( tmr_register ) }, LROT_FUNCENTRY( register, tmr_register )
{ LSTRKEY( "alarm" ), LFUNCVAL( tmr_alarm ) }, LROT_FUNCENTRY( alarm, tmr_alarm )
{ LSTRKEY( "start" ), LFUNCVAL( tmr_start ) }, LROT_FUNCENTRY( start, tmr_start )
{ LSTRKEY( "stop" ), LFUNCVAL( tmr_stop ) }, LROT_FUNCENTRY( stop, tmr_stop )
{ LSTRKEY( "unregister" ), LFUNCVAL( tmr_unregister ) }, LROT_FUNCENTRY( unregister, tmr_unregister )
{ LSTRKEY( "state" ), LFUNCVAL( tmr_state ) }, LROT_FUNCENTRY( state, tmr_state )
{ LSTRKEY( "interval" ), LFUNCVAL( tmr_interval) }, LROT_FUNCENTRY( interval, tmr_interval )
#ifdef TIMER_SUSPEND_ENABLE #ifdef TIMER_SUSPEND_ENABLE
{ LSTRKEY( "suspend" ), LFUNCVAL( tmr_suspend ) }, LROT_FUNCENTRY( suspend, tmr_suspend )
{ LSTRKEY( "resume" ), LFUNCVAL( tmr_resume ) }, LROT_FUNCENTRY( resume, tmr_resume )
#endif #endif
{ LSTRKEY( "__gc" ), LFUNCVAL( tmr_unregister ) }, LROT_FUNCENTRY( __gc, tmr_unregister )
{ LSTRKEY( "__index" ), LROVAL( tmr_dyn_map ) }, LROT_TABENTRY( __index, tmr_dyn )
{ LNILKEY, LNILVAL } LROT_END( tmr_dyn, tmr_dyn, LROT_MASK_GC_INDEX )
};
static const LUA_REG_TYPE tmr_map[] = { LROT_BEGIN(tmr)
{ LSTRKEY( "delay" ), LFUNCVAL( tmr_delay ) }, LROT_FUNCENTRY( delay, tmr_delay )
{ LSTRKEY( "now" ), LFUNCVAL( tmr_now ) }, LROT_FUNCENTRY( now, tmr_now )
{ LSTRKEY( "wdclr" ), LFUNCVAL( tmr_wdclr ) }, LROT_FUNCENTRY( wdclr, tmr_wdclr )
{ LSTRKEY( "softwd" ), LFUNCVAL( tmr_softwd ) }, LROT_FUNCENTRY( softwd, tmr_softwd )
{ LSTRKEY( "time" ), LFUNCVAL( tmr_time ) }, LROT_FUNCENTRY( time, tmr_time )
#ifdef TIMER_SUSPEND_ENABLE #ifdef TIMER_SUSPEND_ENABLE
{ LSTRKEY( "suspend_all" ), LFUNCVAL( tmr_suspend_all ) }, LROT_FUNCENTRY( suspend_all, tmr_suspend_all )
{ LSTRKEY( "resume_all" ), LFUNCVAL( tmr_resume_all ) }, LROT_FUNCENTRY( resume_all, tmr_resume_all )
#endif #endif
{ LSTRKEY( "create" ), LFUNCVAL( tmr_create ) }, LROT_FUNCENTRY( create, tmr_create )
{ LSTRKEY( "ALARM_SINGLE" ), LNUMVAL( TIMER_MODE_SINGLE ) }, LROT_NUMENTRY( ALARM_SINGLE, TIMER_MODE_SINGLE )
{ LSTRKEY( "ALARM_SEMI" ), LNUMVAL( TIMER_MODE_SEMI ) }, LROT_NUMENTRY( ALARM_SEMI, TIMER_MODE_SEMI )
{ LSTRKEY( "ALARM_AUTO" ), LNUMVAL( TIMER_MODE_AUTO ) }, LROT_NUMENTRY( ALARM_AUTO, TIMER_MODE_AUTO )
{ LNILKEY, LNILVAL } LROT_END( tmr, NULL, 0 )
};
#include "pm/swtimer.h" #include "pm/swtimer.h"
int luaopen_tmr( lua_State *L ){ int luaopen_tmr( lua_State *L ){
luaL_rometatable(L, "tmr.timer", (void *)tmr_dyn_map); luaL_rometatable(L, "tmr.timer", LROT_TABLEREF(tmr_dyn));
last_rtc_time=system_get_rtc_time(); // Right now is time 0 last_rtc_time=system_get_rtc_time(); // Right now is time 0
last_rtc_time_us=0; last_rtc_time_us=0;
...@@ -425,4 +425,4 @@ int luaopen_tmr( lua_State *L ){ ...@@ -425,4 +425,4 @@ int luaopen_tmr( lua_State *L ){
return 0; return 0;
} }
NODEMCU_MODULE(TMR, "tmr", tmr_map, luaopen_tmr); NODEMCU_MODULE(TMR, "tmr", tmr, luaopen_tmr);
...@@ -101,27 +101,27 @@ static int ICACHE_FLASH_ATTR tsl2561_lua_getchannels(lua_State* L) { ...@@ -101,27 +101,27 @@ static int ICACHE_FLASH_ATTR tsl2561_lua_getchannels(lua_State* L) {
} }
// Module function map // Module function map
static const LUA_REG_TYPE tsl2561_map[] = { LROT_BEGIN(tsl2561)
{ LSTRKEY( "settiming" ), LFUNCVAL( tsl2561_lua_settiming)}, LROT_FUNCENTRY( settiming, tsl2561_lua_settiming )
{ LSTRKEY( "getlux" ), LFUNCVAL( tsl2561_lua_calclux )}, LROT_FUNCENTRY( getlux, tsl2561_lua_calclux )
{ LSTRKEY( "getrawchannels" ), LFUNCVAL( tsl2561_lua_getchannels )}, LROT_FUNCENTRY( getrawchannels, tsl2561_lua_getchannels )
{ LSTRKEY( "init" ), LFUNCVAL( tsl2561_init )}, LROT_FUNCENTRY( init, tsl2561_init )
{ LSTRKEY( "TSL2561_OK" ), LNUMVAL( TSL2561_ERROR_OK )}, LROT_NUMENTRY( TSL2561_OK, TSL2561_ERROR_OK )
{ LSTRKEY( "TSL2561_ERROR_I2CINIT" ), LNUMVAL( TSL2561_ERROR_I2CINIT )}, LROT_NUMENTRY( TSL2561_ERROR_I2CINIT, TSL2561_ERROR_I2CINIT )
{ LSTRKEY( "TSL2561_ERROR_I2CBUSY" ), LNUMVAL( TSL2561_ERROR_I2CBUSY )}, LROT_NUMENTRY( TSL2561_ERROR_I2CBUSY, TSL2561_ERROR_I2CBUSY )
{ LSTRKEY( "TSL2561_ERROR_NOINIT" ), LNUMVAL( TSL2561_ERROR_NOINIT )}, LROT_NUMENTRY( TSL2561_ERROR_NOINIT, TSL2561_ERROR_NOINIT )
{ LSTRKEY( "TSL2561_ERROR_LAST" ), LNUMVAL( TSL2561_ERROR_LAST )}, LROT_NUMENTRY( TSL2561_ERROR_LAST, TSL2561_ERROR_LAST )
{ LSTRKEY( "INTEGRATIONTIME_13MS" ), LNUMVAL( TSL2561_INTEGRATIONTIME_13MS )}, LROT_NUMENTRY( INTEGRATIONTIME_13MS, TSL2561_INTEGRATIONTIME_13MS )
{ LSTRKEY( "INTEGRATIONTIME_101MS" ), LNUMVAL( TSL2561_INTEGRATIONTIME_101MS )}, LROT_NUMENTRY( INTEGRATIONTIME_101MS, TSL2561_INTEGRATIONTIME_101MS )
{ LSTRKEY( "INTEGRATIONTIME_402MS" ), LNUMVAL( TSL2561_INTEGRATIONTIME_402MS )}, LROT_NUMENTRY( INTEGRATIONTIME_402MS, TSL2561_INTEGRATIONTIME_402MS )
{ LSTRKEY( "GAIN_1X" ), LNUMVAL( TSL2561_GAIN_1X )}, LROT_NUMENTRY( GAIN_1X, TSL2561_GAIN_1X )
{ LSTRKEY( "GAIN_16X" ), LNUMVAL( TSL2561_GAIN_16X )}, LROT_NUMENTRY( GAIN_16X, TSL2561_GAIN_16X )
{ LSTRKEY( "PACKAGE_CS" ), LNUMVAL( TSL2561_PACKAGE_CS )}, LROT_NUMENTRY( PACKAGE_CS, TSL2561_PACKAGE_CS )
{ LSTRKEY( "PACKAGE_T_FN_CL" ), LNUMVAL( TSL2561_PACKAGE_T_FN_CL )}, LROT_NUMENTRY( PACKAGE_T_FN_CL, TSL2561_PACKAGE_T_FN_CL )
{ LSTRKEY( "ADDRESS_GND" ), LNUMVAL( TSL2561_ADDRESS_GND )}, LROT_NUMENTRY( ADDRESS_GND, TSL2561_ADDRESS_GND )
{ LSTRKEY( "ADDRESS_FLOAT" ), LNUMVAL( TSL2561_ADDRESS_FLOAT )}, LROT_NUMENTRY( ADDRESS_FLOAT, TSL2561_ADDRESS_FLOAT )
{ LSTRKEY( "ADDRESS_VDD" ), LNUMVAL( TSL2561_ADDRESS_VDD )}, LROT_NUMENTRY( ADDRESS_VDD, TSL2561_ADDRESS_VDD )
{ LNILKEY, LNILVAL} LROT_END( tsl2561, NULL, 0 )
};
NODEMCU_MODULE(TSL2561, "tsl2561", tsl2561_map, NULL);
NODEMCU_MODULE(TSL2561, "tsl2561", tsl2561, NULL);
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "lauxlib.h" #include "lauxlib.h"
#define U8X8_USE_PINS #define U8X8_USE_PINS
#define U8X8_WITH_USER_PTR
#include "u8g2.h" #include "u8g2.h"
#include "u8x8_nodemcu_hal.h" #include "u8x8_nodemcu_hal.h"
...@@ -540,51 +541,76 @@ static int lu8g2_setPowerSave( lua_State *L ) ...@@ -540,51 +541,76 @@ static int lu8g2_setPowerSave( lua_State *L )
return 0; return 0;
} }
static int lu8g2_updateDisplay( lua_State *L )
{
GET_U8G2();
u8g2_UpdateDisplay( u8g2 );
return 0;
}
static int lu8g2_updateDisplayArea( lua_State *L )
{
GET_U8G2();
int stack = 1;
static const LUA_REG_TYPE lu8g2_display_map[] = { int x = luaL_checkint( L, ++stack );
{ LSTRKEY( "clearBuffer" ), LFUNCVAL( lu8g2_clearBuffer ) }, int y = luaL_checkint( L, ++stack );
{ LSTRKEY( "drawBox" ), LFUNCVAL( lu8g2_drawBox ) }, int w = luaL_checkint( L, ++stack );
{ LSTRKEY( "drawCircle" ), LFUNCVAL( lu8g2_drawCircle ) }, int h = luaL_checkint( L, ++stack );
{ LSTRKEY( "drawDisc" ), LFUNCVAL( lu8g2_drawDisc ) },
{ LSTRKEY( "drawEllipse" ), LFUNCVAL( lu8g2_drawEllipse ) }, u8g2_UpdateDisplayArea( u8g2, x, y, w, h );
{ LSTRKEY( "drawFilledEllipse" ), LFUNCVAL( lu8g2_drawFilledEllipse ) },
{ LSTRKEY( "drawFrame" ), LFUNCVAL( lu8g2_drawFrame ) }, return 0;
{ LSTRKEY( "drawGlyph" ), LFUNCVAL( lu8g2_drawGlyph ) }, }
{ LSTRKEY( "drawHLine" ), LFUNCVAL( lu8g2_drawHLine ) },
{ LSTRKEY( "drawLine" ), LFUNCVAL( lu8g2_drawLine ) },
{ LSTRKEY( "drawPixel" ), LFUNCVAL( lu8g2_drawPixel ) }, LROT_BEGIN(lu8g2_display)
{ LSTRKEY( "drawRBox" ), LFUNCVAL( lu8g2_drawRBox ) }, LROT_FUNCENTRY( clearBuffer, lu8g2_clearBuffer )
{ LSTRKEY( "drawRFrame" ), LFUNCVAL( lu8g2_drawRFrame ) }, LROT_FUNCENTRY( drawBox, lu8g2_drawBox )
{ LSTRKEY( "drawStr" ), LFUNCVAL( lu8g2_drawStr ) }, LROT_FUNCENTRY( drawCircle, lu8g2_drawCircle )
{ LSTRKEY( "drawTriangle" ), LFUNCVAL( lu8g2_drawTriangle ) }, LROT_FUNCENTRY( drawDisc, lu8g2_drawDisc )
{ LSTRKEY( "drawUTF8" ), LFUNCVAL( lu8g2_drawUTF8 ) }, LROT_FUNCENTRY( drawEllipse, lu8g2_drawEllipse )
{ LSTRKEY( "drawVLine" ), LFUNCVAL( lu8g2_drawVLine ) }, LROT_FUNCENTRY( drawFilledEllipse, lu8g2_drawFilledEllipse )
{ LSTRKEY( "drawXBM" ), LFUNCVAL( lu8g2_drawXBM ) }, LROT_FUNCENTRY( drawFrame, lu8g2_drawFrame )
{ LSTRKEY( "getAscent" ), LFUNCVAL( lu8g2_getAscent ) }, LROT_FUNCENTRY( drawGlyph, lu8g2_drawGlyph )
{ LSTRKEY( "getDescent" ), LFUNCVAL( lu8g2_getDescent ) }, LROT_FUNCENTRY( drawHLine, lu8g2_drawHLine )
{ LSTRKEY( "getStrWidth" ), LFUNCVAL( lu8g2_getStrWidth ) }, LROT_FUNCENTRY( drawLine, lu8g2_drawLine )
{ LSTRKEY( "getUTF8Width" ), LFUNCVAL( lu8g2_getUTF8Width ) }, LROT_FUNCENTRY( drawPixel, lu8g2_drawPixel )
{ LSTRKEY( "sendBuffer" ), LFUNCVAL( lu8g2_sendBuffer ) }, LROT_FUNCENTRY( drawRBox, lu8g2_drawRBox )
{ LSTRKEY( "setBitmapMode" ), LFUNCVAL( lu8g2_setBitmapMode ) }, LROT_FUNCENTRY( drawRFrame, lu8g2_drawRFrame )
{ LSTRKEY( "setContrast" ), LFUNCVAL( lu8g2_setContrast ) }, LROT_FUNCENTRY( drawStr, lu8g2_drawStr )
{ LSTRKEY( "setDisplayRotation" ), LFUNCVAL( lu8g2_setDisplayRotation ) }, LROT_FUNCENTRY( drawTriangle, lu8g2_drawTriangle )
{ LSTRKEY( "setDrawColor" ), LFUNCVAL( lu8g2_setDrawColor ) }, LROT_FUNCENTRY( drawUTF8, lu8g2_drawUTF8 )
{ LSTRKEY( "setFlipMode" ), LFUNCVAL( lu8g2_setFlipMode ) }, LROT_FUNCENTRY( drawVLine, lu8g2_drawVLine )
{ LSTRKEY( "setFont" ), LFUNCVAL( lu8g2_setFont ) }, LROT_FUNCENTRY( drawXBM, lu8g2_drawXBM )
{ LSTRKEY( "setFontDirection" ), LFUNCVAL( lu8g2_setFontDirection ) }, LROT_FUNCENTRY( getAscent, lu8g2_getAscent )
{ LSTRKEY( "setFontMode" ), LFUNCVAL( lu8g2_setFontMode ) }, LROT_FUNCENTRY( getDescent, lu8g2_getDescent )
{ LSTRKEY( "setFontPosBaseline" ), LFUNCVAL( lu8g2_setFontPosBaseline ) }, LROT_FUNCENTRY( getStrWidth, lu8g2_getStrWidth )
{ LSTRKEY( "setFontPosBottom" ), LFUNCVAL( lu8g2_setFontPosBottom ) }, LROT_FUNCENTRY( getUTF8Width, lu8g2_getUTF8Width )
{ LSTRKEY( "setFontPosTop" ), LFUNCVAL( lu8g2_setFontPosTop ) }, LROT_FUNCENTRY( sendBuffer, lu8g2_sendBuffer )
{ LSTRKEY( "setFontPosCenter" ), LFUNCVAL( lu8g2_setFontPosCenter ) }, LROT_FUNCENTRY( setBitmapMode, lu8g2_setBitmapMode )
{ LSTRKEY( "setFontRefHeightAll" ), LFUNCVAL( lu8g2_setFontRefHeightAll ) }, LROT_FUNCENTRY( setContrast, lu8g2_setContrast )
{ LSTRKEY( "setFontRefHeightExtendedText" ), LFUNCVAL( lu8g2_setFontRefHeightExtendedText ) }, LROT_FUNCENTRY( setDisplayRotation, lu8g2_setDisplayRotation )
{ LSTRKEY( "setFontRefHeightText" ), LFUNCVAL( lu8g2_setFontRefHeightText ) }, LROT_FUNCENTRY( setDrawColor, lu8g2_setDrawColor )
{ LSTRKEY( "setPowerSave" ), LFUNCVAL( lu8g2_setPowerSave ) }, LROT_FUNCENTRY( setFlipMode, lu8g2_setFlipMode )
//{ LSTRKEY( "__gc" ), LFUNCVAL( lu8g2_display_free ) }, LROT_FUNCENTRY( setFont, lu8g2_setFont )
{ LSTRKEY( "__index" ), LROVAL( lu8g2_display_map ) }, LROT_FUNCENTRY( setFontDirection, lu8g2_setFontDirection )
{LNILKEY, LNILVAL} LROT_FUNCENTRY( setFontMode, lu8g2_setFontMode )
}; LROT_FUNCENTRY( setFontPosBaseline, lu8g2_setFontPosBaseline )
LROT_FUNCENTRY( setFontPosBottom, lu8g2_setFontPosBottom )
LROT_FUNCENTRY( setFontPosTop, lu8g2_setFontPosTop )
LROT_FUNCENTRY( setFontPosCenter, lu8g2_setFontPosCenter )
LROT_FUNCENTRY( setFontRefHeightAll, lu8g2_setFontRefHeightAll )
LROT_FUNCENTRY( setFontRefHeightExtendedText, lu8g2_setFontRefHeightExtendedText )
LROT_FUNCENTRY( setFontRefHeightText, lu8g2_setFontRefHeightText )
LROT_FUNCENTRY( setPowerSave, lu8g2_setPowerSave )
LROT_FUNCENTRY( updateDispla, lu8g2_updateDisplay )
LROT_FUNCENTRY( updateDisplayArea, lu8g2_updateDisplayArea )
// LROT_FUNCENTRY( __gc, lu8g2_display_free )
LROT_TABENTRY( __index, lu8g2_display )
LROT_END( lu8g2_display, lu8g2_display, LROT_MASK_GC_INDEX )
uint8_t u8x8_d_overlay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr); uint8_t u8x8_d_overlay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
...@@ -622,11 +648,11 @@ static int ldisplay_i2c( lua_State *L, display_setup_fn_t setup_fn ) ...@@ -622,11 +648,11 @@ static int ldisplay_i2c( lua_State *L, display_setup_fn_t setup_fn )
u8g2_nodemcu_t *ext_u8g2 = &(ud->u8g2); u8g2_nodemcu_t *ext_u8g2 = &(ud->u8g2);
ud->font_ref = LUA_NOREF; ud->font_ref = LUA_NOREF;
ud->host_ref = LUA_NOREF; ud->host_ref = LUA_NOREF;
/* the i2c driver id is forwarded in the hal member */
ext_u8g2->hal = id >= 0 ? (void *)id : NULL;
u8g2_t *u8g2 = (u8g2_t *)ext_u8g2; u8g2_t *u8g2 = (u8g2_t *)ext_u8g2;
u8x8_t *u8x8 = (u8x8_t *)u8g2; u8x8_t *u8x8 = (u8x8_t *)u8g2;
/* the i2c driver id is forwarded in the user pointer */
u8x8->user_ptr = id >= 0 ? (void *)id : NULL;
setup_fn( u8g2, U8G2_R0, u8x8_byte_nodemcu_i2c, u8x8_gpio_and_delay_nodemcu ); setup_fn( u8g2, U8G2_R0, u8x8_byte_nodemcu_i2c, u8x8_gpio_and_delay_nodemcu );
...@@ -715,11 +741,11 @@ static int ldisplay_spi( lua_State *L, display_setup_fn_t setup_fn ) ...@@ -715,11 +741,11 @@ static int ldisplay_spi( lua_State *L, display_setup_fn_t setup_fn )
u8g2_nodemcu_t *ext_u8g2 = &(ud->u8g2); u8g2_nodemcu_t *ext_u8g2 = &(ud->u8g2);
ud->font_ref = LUA_NOREF; ud->font_ref = LUA_NOREF;
ud->host_ref = host_ref; ud->host_ref = host_ref;
/* the spi host id is forwarded in the hal member */
ext_u8g2->hal = host ? (void *)(host->host) : NULL;
u8g2_t *u8g2 = (u8g2_t *)ext_u8g2; u8g2_t *u8g2 = (u8g2_t *)ext_u8g2;
u8x8_t *u8x8 = (u8x8_t *)u8g2; u8x8_t *u8x8 = (u8x8_t *)u8g2;
/* the spi host id is forwarded in the user pointer */
u8x8->user_ptr = host ? (void *)(host->host) : NULL;
setup_fn( u8g2, U8G2_R0, u8x8_byte_nodemcu_spi, u8x8_gpio_and_delay_nodemcu ); setup_fn( u8g2, U8G2_R0, u8x8_byte_nodemcu_spi, u8x8_gpio_and_delay_nodemcu );
...@@ -781,36 +807,33 @@ U8G2_DISPLAY_TABLE_SPI ...@@ -781,36 +807,33 @@ U8G2_DISPLAY_TABLE_SPI
#undef U8G2_FONT_TABLE_ENTRY #undef U8G2_FONT_TABLE_ENTRY
#undef U8G2_DISPLAY_TABLE_ENTRY #undef U8G2_DISPLAY_TABLE_ENTRY
#define U8G2_DISPLAY_TABLE_ENTRY(function, binding) \ #define U8G2_DISPLAY_TABLE_ENTRY(function, binding) LROT_FUNCENTRY(binding,l ## binding)
{ LSTRKEY( #binding ), LFUNCVAL( l ## binding ) }, LROT_BEGIN(lu8g2)
static const LUA_REG_TYPE lu8g2_map[] = {
U8G2_DISPLAY_TABLE_I2C U8G2_DISPLAY_TABLE_I2C
U8G2_DISPLAY_TABLE_SPI U8G2_DISPLAY_TABLE_SPI
// //
// Register fonts // Register fonts
#define U8G2_FONT_TABLE_ENTRY(font) \ #define U8G2_FONT_TABLE_ENTRY(font) LROT_LUDENTRY(font, u8g2_ ## font)
{ LSTRKEY( #font ), LUDATA( (void *)(u8g2_ ## font) ) },
U8G2_FONT_TABLE U8G2_FONT_TABLE
// //
{ LSTRKEY( "DRAW_UPPER_RIGHT" ), LNUMVAL( U8G2_DRAW_UPPER_RIGHT ) }, LROT_NUMENTRY( DRAW_UPPER_RIGHT, U8G2_DRAW_UPPER_RIGHT )
{ LSTRKEY( "DRAW_UPPER_LEFT" ), LNUMVAL( U8G2_DRAW_UPPER_LEFT ) }, LROT_NUMENTRY( DRAW_UPPER_LEFT, U8G2_DRAW_UPPER_LEFT )
{ LSTRKEY( "DRAW_LOWER_RIGHT" ), LNUMVAL( U8G2_DRAW_LOWER_RIGHT ) }, LROT_NUMENTRY( DRAW_LOWER_RIGHT, U8G2_DRAW_LOWER_RIGHT )
{ LSTRKEY( "DRAW_LOWER_LEFT" ), LNUMVAL( U8G2_DRAW_LOWER_LEFT ) }, LROT_NUMENTRY( DRAW_LOWER_LEFT, U8G2_DRAW_LOWER_LEFT )
{ LSTRKEY( "DRAW_ALL" ), LNUMVAL( U8G2_DRAW_ALL ) }, LROT_NUMENTRY( DRAW_ALL, U8G2_DRAW_ALL )
{ LSTRKEY( "R0" ), LUDATA( (void *)U8G2_R0 ) }, LROT_LUDENTRY( R0, U8G2_R0 )
{ LSTRKEY( "R1" ), LUDATA( (void *)U8G2_R1 ) }, LROT_LUDENTRY( R1, U8G2_R1 )
{ LSTRKEY( "R2" ), LUDATA( (void *)U8G2_R2 ) }, LROT_LUDENTRY( R2, U8G2_R2 )
{ LSTRKEY( "R3" ), LUDATA( (void *)U8G2_R3 ) }, LROT_LUDENTRY( R3, U8G2_R3 )
{ LSTRKEY( "MIRROR" ), LUDATA( (void *)U8G2_MIRROR ) }, LROT_LUDENTRY( MIRROR, U8G2_MIRROR )
{LNILKEY, LNILVAL} LROT_END( lu8g2, NULL, 0 )
};
int luaopen_u8g2( lua_State *L ) { int luaopen_u8g2( lua_State *L ) {
luaL_rometatable(L, "u8g2.display", (void *)lu8g2_display_map); luaL_rometatable(L, "u8g2.display", LROT_TABLEREF(lu8g2_display));
return 0; return 0;
} }
NODEMCU_MODULE(U8G2, "u8g2", lu8g2_map, luaopen_u8g2); NODEMCU_MODULE(U8G2, "u8g2", lu8g2, luaopen_u8g2);
#endif /* defined(LUA_USE_MODULES_U8G2) || defined(ESP_PLATFORM) */ #endif /* defined(LUA_USE_MODULES_U8G2) || defined(ESP_PLATFORM) */
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "c_types.h" #include <stdint.h>
#include "c_string.h" #include <string.h>
#include "rom.h" #include "rom.h"
static int uart_receive_rf = LUA_NOREF; static int uart_receive_rf = LUA_NOREF;
...@@ -67,7 +67,7 @@ static int l_uart_on( lua_State* L ) ...@@ -67,7 +67,7 @@ static int l_uart_on( lua_State* L )
} else { } else {
lua_pushnil(L); lua_pushnil(L);
} }
if(sl == 4 && c_strcmp(method, "data") == 0){ if(sl == 4 && strcmp(method, "data") == 0){
run_input = true; run_input = true;
if(uart_receive_rf != LUA_NOREF){ if(uart_receive_rf != LUA_NOREF){
luaL_unref(L, LUA_REGISTRYINDEX, uart_receive_rf); luaL_unref(L, LUA_REGISTRYINDEX, uart_receive_rf);
...@@ -174,19 +174,19 @@ static int l_uart_write( lua_State* L ) ...@@ -174,19 +174,19 @@ static int l_uart_write( lua_State* L )
} }
// Module function map // Module function map
static const LUA_REG_TYPE uart_map[] = { LROT_BEGIN(uart)
{ LSTRKEY( "setup" ), LFUNCVAL( l_uart_setup ) }, LROT_FUNCENTRY( setup, l_uart_setup )
{ LSTRKEY( "getconfig" ), LFUNCVAL( l_uart_getconfig ) }, LROT_FUNCENTRY( getconfig, l_uart_getconfig )
{ LSTRKEY( "write" ), LFUNCVAL( l_uart_write ) }, LROT_FUNCENTRY( write, l_uart_write )
{ LSTRKEY( "on" ), LFUNCVAL( l_uart_on ) }, LROT_FUNCENTRY( on, l_uart_on )
{ LSTRKEY( "alt" ), LFUNCVAL( l_uart_alt ) }, LROT_FUNCENTRY( alt, l_uart_alt )
{ LSTRKEY( "STOPBITS_1" ), LNUMVAL( PLATFORM_UART_STOPBITS_1 ) }, LROT_NUMENTRY( STOPBITS_1, PLATFORM_UART_STOPBITS_1 )
{ LSTRKEY( "STOPBITS_1_5" ), LNUMVAL( PLATFORM_UART_STOPBITS_1_5 ) }, LROT_NUMENTRY( STOPBITS_1_5, PLATFORM_UART_STOPBITS_1_5 )
{ LSTRKEY( "STOPBITS_2" ), LNUMVAL( PLATFORM_UART_STOPBITS_2 ) }, LROT_NUMENTRY( STOPBITS_2, PLATFORM_UART_STOPBITS_2 )
{ LSTRKEY( "PARITY_NONE" ), LNUMVAL( PLATFORM_UART_PARITY_NONE ) }, LROT_NUMENTRY( PARITY_NONE, PLATFORM_UART_PARITY_NONE )
{ LSTRKEY( "PARITY_EVEN" ), LNUMVAL( PLATFORM_UART_PARITY_EVEN ) }, LROT_NUMENTRY( PARITY_EVEN, PLATFORM_UART_PARITY_EVEN )
{ LSTRKEY( "PARITY_ODD" ), LNUMVAL( PLATFORM_UART_PARITY_ODD ) }, LROT_NUMENTRY( PARITY_ODD, PLATFORM_UART_PARITY_ODD )
{ LNILKEY, LNILVAL } LROT_END( uart, NULL, 0 )
};
NODEMCU_MODULE(UART, "uart", uart_map, NULL); NODEMCU_MODULE(UART, "uart", uart, NULL);
...@@ -690,89 +690,87 @@ UCG_DISPLAY_TABLE ...@@ -690,89 +690,87 @@ UCG_DISPLAY_TABLE
// Module function map // Module function map
static const LUA_REG_TYPE lucg_display_map[] = LROT_BEGIN(lucg_display)
{ LROT_FUNCENTRY( begin, lucg_begin )
{ LSTRKEY( "begin" ), LFUNCVAL( lucg_begin ) }, LROT_FUNCENTRY( clearScreen, lucg_clearScreen )
{ LSTRKEY( "clearScreen" ), LFUNCVAL( lucg_clearScreen ) }, LROT_FUNCENTRY( draw90Line, lucg_draw90Line )
{ LSTRKEY( "draw90Line" ), LFUNCVAL( lucg_draw90Line ) }, LROT_FUNCENTRY( drawBox, lucg_drawBox )
{ LSTRKEY( "drawBox" ), LFUNCVAL( lucg_drawBox ) }, LROT_FUNCENTRY( drawCircle, lucg_drawCircle )
{ LSTRKEY( "drawCircle" ), LFUNCVAL( lucg_drawCircle ) }, LROT_FUNCENTRY( drawDisc, lucg_drawDisc )
{ LSTRKEY( "drawDisc" ), LFUNCVAL( lucg_drawDisc ) }, LROT_FUNCENTRY( drawFrame, lucg_drawFrame )
{ LSTRKEY( "drawFrame" ), LFUNCVAL( lucg_drawFrame ) }, LROT_FUNCENTRY( drawGlyph, lucg_drawGlyph )
{ LSTRKEY( "drawGlyph" ), LFUNCVAL( lucg_drawGlyph ) }, LROT_FUNCENTRY( drawGradientBox, lucg_drawGradientBox )
{ LSTRKEY( "drawGradientBox" ), LFUNCVAL( lucg_drawGradientBox ) }, LROT_FUNCENTRY( drawGradientLine, lucg_drawGradientLine )
{ LSTRKEY( "drawGradientLine" ), LFUNCVAL( lucg_drawGradientLine ) }, LROT_FUNCENTRY( drawHLine, lucg_drawHLine )
{ LSTRKEY( "drawHLine" ), LFUNCVAL( lucg_drawHLine ) }, LROT_FUNCENTRY( drawLine, lucg_drawLine )
{ LSTRKEY( "drawLine" ), LFUNCVAL( lucg_drawLine ) }, LROT_FUNCENTRY( drawPixel, lucg_drawPixel )
{ LSTRKEY( "drawPixel" ), LFUNCVAL( lucg_drawPixel ) }, LROT_FUNCENTRY( drawRBox, lucg_drawRBox )
{ LSTRKEY( "drawRBox" ), LFUNCVAL( lucg_drawRBox ) }, LROT_FUNCENTRY( drawRFrame, lucg_drawRFrame )
{ LSTRKEY( "drawRFrame" ), LFUNCVAL( lucg_drawRFrame ) }, LROT_FUNCENTRY( drawString, lucg_drawString )
{ LSTRKEY( "drawString" ), LFUNCVAL( lucg_drawString ) }, LROT_FUNCENTRY( drawTetragon, lucg_drawTetragon )
{ LSTRKEY( "drawTetragon" ), LFUNCVAL( lucg_drawTetragon ) }, LROT_FUNCENTRY( drawTriangle, lucg_drawTriangle )
{ LSTRKEY( "drawTriangle" ), LFUNCVAL( lucg_drawTriangle ) }, LROT_FUNCENTRY( drawVLine, lucg_drawVLine )
{ LSTRKEY( "drawVLine" ), LFUNCVAL( lucg_drawVLine ) }, LROT_FUNCENTRY( getFontAscent, lucg_getFontAscent )
{ LSTRKEY( "getFontAscent" ), LFUNCVAL( lucg_getFontAscent ) }, LROT_FUNCENTRY( getFontDescent, lucg_getFontDescent )
{ LSTRKEY( "getFontDescent" ), LFUNCVAL( lucg_getFontDescent ) }, LROT_FUNCENTRY( getHeight, lucg_getHeight )
{ LSTRKEY( "getHeight" ), LFUNCVAL( lucg_getHeight ) }, LROT_FUNCENTRY( getStrWidth, lucg_getStrWidth )
{ LSTRKEY( "getStrWidth" ), LFUNCVAL( lucg_getStrWidth ) }, LROT_FUNCENTRY( getWidth, lucg_getWidth )
{ LSTRKEY( "getWidth" ), LFUNCVAL( lucg_getWidth ) }, LROT_FUNCENTRY( print, lucg_print )
{ LSTRKEY( "print" ), LFUNCVAL( lucg_print ) }, LROT_FUNCENTRY( setClipRange, lucg_setClipRange )
{ LSTRKEY( "setClipRange" ), LFUNCVAL( lucg_setClipRange ) }, LROT_FUNCENTRY( setColor, lucg_setColor )
{ LSTRKEY( "setColor" ), LFUNCVAL( lucg_setColor ) }, LROT_FUNCENTRY( setFont, lucg_setFont )
{ LSTRKEY( "setFont" ), LFUNCVAL( lucg_setFont ) }, LROT_FUNCENTRY( setFontMode, lucg_setFontMode )
{ LSTRKEY( "setFontMode" ), LFUNCVAL( lucg_setFontMode ) }, LROT_FUNCENTRY( setFontPosBaseline, lucg_setFontPosBaseline )
{ LSTRKEY( "setFontPosBaseline" ), LFUNCVAL( lucg_setFontPosBaseline ) }, LROT_FUNCENTRY( setFontPosBottom, lucg_setFontPosBottom )
{ LSTRKEY( "setFontPosBottom" ), LFUNCVAL( lucg_setFontPosBottom ) }, LROT_FUNCENTRY( setFontPosCenter, lucg_setFontPosCenter )
{ LSTRKEY( "setFontPosCenter" ), LFUNCVAL( lucg_setFontPosCenter ) }, LROT_FUNCENTRY( setFontPosTop, lucg_setFontPosTop )
{ LSTRKEY( "setFontPosTop" ), LFUNCVAL( lucg_setFontPosTop ) }, LROT_FUNCENTRY( setMaxClipRange, lucg_setMaxClipRange )
{ LSTRKEY( "setMaxClipRange" ), LFUNCVAL( lucg_setMaxClipRange ) }, LROT_FUNCENTRY( setPrintDir, lucg_setPrintDir )
{ LSTRKEY( "setPrintDir" ), LFUNCVAL( lucg_setPrintDir ) }, LROT_FUNCENTRY( setPrintPos, lucg_setPrintPos )
{ LSTRKEY( "setPrintPos" ), LFUNCVAL( lucg_setPrintPos ) }, LROT_FUNCENTRY( setRotate90, lucg_setRotate90 )
{ LSTRKEY( "setRotate90" ), LFUNCVAL( lucg_setRotate90 ) }, LROT_FUNCENTRY( setRotate180, lucg_setRotate180 )
{ LSTRKEY( "setRotate180" ), LFUNCVAL( lucg_setRotate180 ) }, LROT_FUNCENTRY( setRotate270, lucg_setRotate270 )
{ LSTRKEY( "setRotate270" ), LFUNCVAL( lucg_setRotate270 ) }, LROT_FUNCENTRY( setScale2x2, lucg_setScale2x2 )
{ LSTRKEY( "setScale2x2" ), LFUNCVAL( lucg_setScale2x2 ) }, LROT_FUNCENTRY( undoClipRange, lucg_setMaxClipRange )
{ LSTRKEY( "undoClipRange" ), LFUNCVAL( lucg_setMaxClipRange ) }, LROT_FUNCENTRY( undoRotate, lucg_undoRotate )
{ LSTRKEY( "undoRotate" ), LFUNCVAL( lucg_undoRotate ) }, LROT_FUNCENTRY( undoScale, lucg_undoScale )
{ LSTRKEY( "undoScale" ), LFUNCVAL( lucg_undoScale ) },
LROT_FUNCENTRY( __gc, lucg_close_display )
{ LSTRKEY( "__gc" ), LFUNCVAL( lucg_close_display ) }, LROT_TABENTRY( __index, lucg_display )
{ LSTRKEY( "__index" ), LROVAL ( lucg_display_map ) }, LROT_END( lucg_display, lucg_display, 0 )
{ LNILKEY, LNILVAL }
};
LROT_BEGIN(lucg)
static const LUA_REG_TYPE lucg_map[] =
{
#undef UCG_DISPLAY_TABLE_ENTRY #undef UCG_DISPLAY_TABLE_ENTRY
#define UCG_DISPLAY_TABLE_ENTRY(binding, device, extension) { LSTRKEY( #binding ), LFUNCVAL ( l ## binding ) }, #define UCG_DISPLAY_TABLE_ENTRY(binding, device, extension) LROT_FUNCENTRY(binding,l ## binding)
UCG_DISPLAY_TABLE UCG_DISPLAY_TABLE
// Register fonts // Register fonts
#undef UCG_FONT_TABLE_ENTRY #undef UCG_FONT_TABLE_ENTRY
#define UCG_FONT_TABLE_ENTRY(font) { LSTRKEY( #font ), LUDATA( (void *)(ucg_ ## font) ) }, #define UCG_FONT_TABLE_ENTRY(font) LROT_LUDENTRY(font, ucg_ ## font )
UCG_FONT_TABLE UCG_FONT_TABLE
// Font modes // Font modes
{ LSTRKEY( "FONT_MODE_TRANSPARENT" ), LNUMVAL( UCG_FONT_MODE_TRANSPARENT ) }, LROT_NUMENTRY( FONT_MODE_TRANSPARENT, UCG_FONT_MODE_TRANSPARENT )
{ LSTRKEY( "FONT_MODE_SOLID" ), LNUMVAL( UCG_FONT_MODE_SOLID ) }, LROT_NUMENTRY( FONT_MODE_SOLID, UCG_FONT_MODE_SOLID )
// Options for circle/ disc drawing // Options for circle/ disc drawing
{ LSTRKEY( "DRAW_UPPER_RIGHT" ), LNUMVAL( UCG_DRAW_UPPER_RIGHT ) }, LROT_NUMENTRY( DRAW_UPPER_RIGHT, UCG_DRAW_UPPER_RIGHT )
{ LSTRKEY( "DRAW_UPPER_LEFT" ), LNUMVAL( UCG_DRAW_UPPER_LEFT ) }, LROT_NUMENTRY( DRAW_UPPER_LEFT, UCG_DRAW_UPPER_LEFT )
{ LSTRKEY( "DRAW_LOWER_RIGHT" ), LNUMVAL( UCG_DRAW_LOWER_RIGHT ) }, LROT_NUMENTRY( DRAW_LOWER_RIGHT, UCG_DRAW_LOWER_RIGHT )
{ LSTRKEY( "DRAW_LOWER_LEFT" ), LNUMVAL( UCG_DRAW_LOWER_LEFT ) }, LROT_NUMENTRY( DRAW_LOWER_LEFT, UCG_DRAW_LOWER_LEFT )
{ LSTRKEY( "DRAW_ALL" ), LNUMVAL( UCG_DRAW_ALL ) }, LROT_NUMENTRY( DRAW_ALL, UCG_DRAW_ALL )
LROT_TABENTRY( __metatable, lucg )
LROT_END( lucg, lucg, 0 )
{ LSTRKEY( "__metatable" ), LROVAL( lucg_map ) },
{ LNILKEY, LNILVAL }
};
int luaopen_ucg( lua_State *L ) int luaopen_ucg( lua_State *L )
{ {
luaL_rometatable(L, "ucg.display", (void *)lucg_display_map); // create metatable luaL_rometatable(L, "ucg.display", LROT_TABLEREF(lucg_display));
return 0; return 0;
} }
NODEMCU_MODULE(UCG, "ucg", lucg_map, luaopen_ucg); NODEMCU_MODULE(UCG, "ucg", lucg, luaopen_ucg);
#endif /* LUA_USE_MODULES_UCG */ #endif /* LUA_USE_MODULES_UCG */
...@@ -13,11 +13,11 @@ ...@@ -13,11 +13,11 @@
#include "platform.h" #include "platform.h"
#include "module.h" #include "module.h"
#include "c_types.h" #include <stdint.h>
#include "c_string.h" #include <string.h>
#include "c_stdlib.h" #include <stddef.h>
#include "websocketclient.h" #include "websocket/websocketclient.h"
#define METATABLE_WSCLIENT "websocket.client" #define METATABLE_WSCLIENT "websocket.client"
...@@ -191,14 +191,14 @@ static int websocketclient_connect(lua_State *L) { ...@@ -191,14 +191,14 @@ static int websocketclient_connect(lua_State *L) {
static header_t *realloc_headers(header_t *headers, int new_size) { static header_t *realloc_headers(header_t *headers, int new_size) {
if(headers) { if(headers) {
for(header_t *header = headers; header->key; header++) { for(header_t *header = headers; header->key; header++) {
c_free(header->value); free(header->value);
c_free(header->key); free(header->key);
} }
c_free(headers); free(headers);
} }
if(!new_size) if(!new_size)
return NULL; return NULL;
return (header_t *)c_malloc(sizeof(header_t) * (new_size + 1)); return (header_t *)malloc(sizeof(header_t) * (new_size + 1));
} }
static int websocketclient_config(lua_State *L) { static int websocketclient_config(lua_State *L) {
...@@ -225,8 +225,8 @@ static int websocketclient_config(lua_State *L) { ...@@ -225,8 +225,8 @@ static int websocketclient_config(lua_State *L) {
lua_pushnil(L); lua_pushnil(L);
while(lua_next(L, -2)) { while(lua_next(L, -2)) {
header->key = c_strdup(lua_tostring(L, -2)); header->key = strdup(lua_tostring(L, -2));
header->value = c_strdup(lua_tostring(L, -1)); header->value = strdup(lua_tostring(L, -1));
header++; header++;
lua_pop(L, 1); lua_pop(L, 1);
} }
...@@ -307,28 +307,26 @@ static int websocketclient_gc(lua_State *L) { ...@@ -307,28 +307,26 @@ static int websocketclient_gc(lua_State *L) {
return 0; return 0;
} }
static const LUA_REG_TYPE websocket_map[] = LROT_BEGIN(websocket)
{ LROT_FUNCENTRY( createClient, websocket_createClient )
{ LSTRKEY("createClient"), LFUNCVAL(websocket_createClient) }, LROT_END( websocket, NULL, 0 )
{ LNILKEY, LNILVAL }
};
LROT_BEGIN(websocketclient)
static const LUA_REG_TYPE websocketclient_map[] = LROT_FUNCENTRY( on, websocketclient_on )
{ LROT_FUNCENTRY( config, websocketclient_config )
{ LSTRKEY("on"), LFUNCVAL(websocketclient_on) }, LROT_FUNCENTRY( connect, websocketclient_connect )
{ LSTRKEY("config"), LFUNCVAL(websocketclient_config) }, LROT_FUNCENTRY( send, websocketclient_send )
{ LSTRKEY("connect"), LFUNCVAL(websocketclient_connect) }, LROT_FUNCENTRY( close, websocketclient_close )
{ LSTRKEY("send"), LFUNCVAL(websocketclient_send) }, LROT_FUNCENTRY( __gc, websocketclient_gc )
{ LSTRKEY("close"), LFUNCVAL(websocketclient_close) }, LROT_TABENTRY( __index, websocketclient )
{ LSTRKEY("__gc" ), LFUNCVAL(websocketclient_gc) }, LROT_END( websocketclient, websocketclient, LROT_MASK_GC_INDEX )
{ LSTRKEY("__index"), LROVAL(websocketclient_map) },
{ LNILKEY, LNILVAL }
};
int loadWebsocketModule(lua_State *L) { int loadWebsocketModule(lua_State *L) {
luaL_rometatable(L, METATABLE_WSCLIENT, (void *) websocketclient_map); luaL_rometatable(L, METATABLE_WSCLIENT, LROT_TABLEREF( websocketclient));
return 0; return 0;
} }
NODEMCU_MODULE(WEBSOCKET, "websocket", websocket_map, loadWebsocketModule); NODEMCU_MODULE(WEBSOCKET, "websocket", websocket, loadWebsocketModule);
...@@ -6,18 +6,18 @@ ...@@ -6,18 +6,18 @@
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "c_string.h" #include <string.h>
#include "c_stdlib.h" #include <stddef.h>
#include "ctype.h" #include "ctype.h"
#include "c_types.h" #include <stdint.h>
#include "user_interface.h" #include "user_interface.h"
#include "wifi_common.h" #include "wifi_common.h"
#ifdef WIFI_SMART_ENABLE #ifdef WIFI_SMART_ENABLE
#include "smart.h" #include "smart/smart.h"
#include "smartconfig.h" #include "smart/smartconfig.h"
static int wifi_smart_succeed = LUA_NOREF; static int wifi_smart_succeed = LUA_NOREF;
#endif #endif
...@@ -95,18 +95,18 @@ static void wifi_scan_done(void *arg, STATUS status) ...@@ -95,18 +95,18 @@ static void wifi_scan_done(void *arg, STATUS status)
while (bss_link != NULL) while (bss_link != NULL)
{ {
c_memset(ssid, 0, 33); memset(ssid, 0, 33);
if (c_strlen(bss_link->ssid) <= 32) if (strlen(bss_link->ssid) <= 32)
{ {
c_memcpy(ssid, bss_link->ssid, c_strlen(bss_link->ssid)); memcpy(ssid, bss_link->ssid, strlen(bss_link->ssid));
} }
else else
{ {
c_memcpy(ssid, bss_link->ssid, 32); memcpy(ssid, bss_link->ssid, 32);
} }
if(getap_output_format==1) //use new format(BSSID : SSID, RSSI, Authmode, Channel) if(getap_output_format==1) //use new format(BSSID : SSID, RSSI, Authmode, Channel)
{ {
c_sprintf(temp,MACSTR, MAC2STR(bss_link->bssid)); sprintf(temp,MACSTR, MAC2STR(bss_link->bssid));
wifi_add_sprintf_field(L, temp, "%s,%d,%d,%d", wifi_add_sprintf_field(L, temp, "%s,%d,%d,%d",
ssid, bss_link->rssi, bss_link->authmode, bss_link->channel); ssid, bss_link->rssi, bss_link->authmode, bss_link->channel);
NODE_DBG(MACSTR" : %s\n",MAC2STR(bss_link->bssid) , temp);//00 00 00 00 00 00 NODE_DBG(MACSTR" : %s\n",MAC2STR(bss_link->bssid) , temp);//00 00 00 00 00 00
...@@ -260,7 +260,7 @@ static int wifi_setcountry( lua_State* L ){ ...@@ -260,7 +260,7 @@ static int wifi_setcountry( lua_State* L ){
if( lua_isstring(L, -1) ){ if( lua_isstring(L, -1) ){
const char *country_code = luaL_checklstring( L, -1, &len ); const char *country_code = luaL_checklstring( L, -1, &len );
luaL_argcheck(L, (len==2 && isalpha(country_code[0]) && isalpha(country_code[1])), 1, "country: country code must be 2 chars"); luaL_argcheck(L, (len==2 && isalpha(country_code[0]) && isalpha(country_code[1])), 1, "country: country code must be 2 chars");
c_memcpy(cfg.cc, country_code, len); memcpy(cfg.cc, country_code, len);
if(cfg.cc[0] >= 0x61) cfg.cc[0]=cfg.cc[0]-32; //if lowercase change to uppercase if(cfg.cc[0] >= 0x61) cfg.cc[0]=cfg.cc[0]-32; //if lowercase change to uppercase
if(cfg.cc[1] >= 0x61) cfg.cc[1]=cfg.cc[1]-32; //if lowercase change to uppercase if(cfg.cc[1] >= 0x61) cfg.cc[1]=cfg.cc[1]-32; //if lowercase change to uppercase
} }
...@@ -552,7 +552,7 @@ static int wifi_getmac( lua_State* L, uint8_t mode ) ...@@ -552,7 +552,7 @@ static int wifi_getmac( lua_State* L, uint8_t mode )
char temp[64]; char temp[64];
uint8_t mac[6]; uint8_t mac[6];
wifi_get_macaddr(mode, mac); wifi_get_macaddr(mode, mac);
c_sprintf(temp, MACSTR, MAC2STR(mac)); sprintf(temp, MACSTR, MAC2STR(mac));
lua_pushstring( L, temp ); lua_pushstring( L, temp );
return 1; return 1;
} }
...@@ -581,11 +581,11 @@ static int wifi_getip( lua_State* L, uint8_t mode ) ...@@ -581,11 +581,11 @@ static int wifi_getip( lua_State* L, uint8_t mode )
} }
else else
{ {
c_sprintf(temp, "%d.%d.%d.%d", IP2STR(&pTempIp.ip) ); sprintf(temp, "%d.%d.%d.%d", IP2STR(&pTempIp.ip) );
lua_pushstring( L, temp ); lua_pushstring( L, temp );
c_sprintf(temp, "%d.%d.%d.%d", IP2STR(&pTempIp.netmask) ); sprintf(temp, "%d.%d.%d.%d", IP2STR(&pTempIp.netmask) );
lua_pushstring( L, temp ); lua_pushstring( L, temp );
c_sprintf(temp, "%d.%d.%d.%d", IP2STR(&pTempIp.gw) ); sprintf(temp, "%d.%d.%d.%d", IP2STR(&pTempIp.gw) );
lua_pushstring( L, temp ); lua_pushstring( L, temp );
return 3; return 3;
} }
...@@ -609,7 +609,7 @@ static int wifi_getbroadcast( lua_State* L, uint8_t mode ) ...@@ -609,7 +609,7 @@ static int wifi_getbroadcast( lua_State* L, uint8_t mode )
uint32 broadcast_address32 = ~pTempIp.netmask.addr | subnet_mask32; uint32 broadcast_address32 = ~pTempIp.netmask.addr | subnet_mask32;
broadcast_address.addr = broadcast_address32; broadcast_address.addr = broadcast_address32;
c_sprintf(temp, "%d.%d.%d.%d", IP2STR(&broadcast_address) ); sprintf(temp, "%d.%d.%d.%d", IP2STR(&broadcast_address) );
lua_pushstring( L, temp ); lua_pushstring( L, temp );
return 1; return 1;
...@@ -688,7 +688,7 @@ static int wifi_station_get_ap_info4lua( lua_State* L ) ...@@ -688,7 +688,7 @@ static int wifi_station_get_ap_info4lua( lua_State* L )
lua_pushstring(L, temp); lua_pushstring(L, temp);
lua_setfield(L, -2, "ssid"); lua_setfield(L, -2, "ssid");
#if defined(WIFI_DEBUG) #if defined(WIFI_DEBUG)
c_sprintf(debug_temp, " %-6d %-32s ", i, temp); sprintf(debug_temp, " %-6d %-32s ", i, temp);
#endif #endif
memset(temp, 0, sizeof(temp)); memset(temp, 0, sizeof(temp));
...@@ -699,13 +699,13 @@ static int wifi_station_get_ap_info4lua( lua_State* L ) ...@@ -699,13 +699,13 @@ static int wifi_station_get_ap_info4lua( lua_State* L )
lua_setfield(L, -2, "pwd"); lua_setfield(L, -2, "pwd");
} }
#if defined(WIFI_DEBUG) #if defined(WIFI_DEBUG)
c_sprintf(debug_temp + strlen(debug_temp), "%-64s ", temp); sprintf(debug_temp + strlen(debug_temp), "%-64s ", temp);
#endif #endif
memset(temp, 0, sizeof(temp)); memset(temp, 0, sizeof(temp));
if (config[i].bssid_set) if (config[i].bssid_set)
{ {
c_sprintf(temp, MACSTR, MAC2STR(config[i].bssid)); sprintf(temp, MACSTR, MAC2STR(config[i].bssid));
lua_pushstring(L, temp); lua_pushstring(L, temp);
lua_setfield(L, -2, "bssid"); lua_setfield(L, -2, "bssid");
} }
...@@ -812,7 +812,7 @@ static int wifi_station_getconfig( lua_State* L, bool get_flash_cfg) ...@@ -812,7 +812,7 @@ static int wifi_station_getconfig( lua_State* L, bool get_flash_cfg)
lua_setfield(L, -2, "bssid_set"); lua_setfield(L, -2, "bssid_set");
memset(temp, 0, sizeof(temp)); memset(temp, 0, sizeof(temp));
c_sprintf(temp, MACSTR, MAC2STR(sta_conf.bssid)); sprintf(temp, MACSTR, MAC2STR(sta_conf.bssid));
lua_pushstring( L, temp); lua_pushstring( L, temp);
lua_setfield(L, -2, "bssid"); lua_setfield(L, -2, "bssid");
...@@ -827,7 +827,7 @@ static int wifi_station_getconfig( lua_State* L, bool get_flash_cfg) ...@@ -827,7 +827,7 @@ static int wifi_station_getconfig( lua_State* L, bool get_flash_cfg)
memcpy(temp, sta_conf.password, sizeof(sta_conf.password)); memcpy(temp, sta_conf.password, sizeof(sta_conf.password));
lua_pushstring(L, temp); lua_pushstring(L, temp);
lua_pushinteger( L, sta_conf.bssid_set); lua_pushinteger( L, sta_conf.bssid_set);
c_sprintf(temp, MACSTR, MAC2STR(sta_conf.bssid)); sprintf(temp, MACSTR, MAC2STR(sta_conf.bssid));
lua_pushstring( L, temp); lua_pushstring( L, temp);
return 4; return 4;
} }
...@@ -1180,8 +1180,8 @@ static int wifi_station_listap( lua_State* L ) ...@@ -1180,8 +1180,8 @@ static int wifi_station_listap( lua_State* L )
const char *ssidstr = luaL_checklstring( L, -1, &len ); const char *ssidstr = luaL_checklstring( L, -1, &len );
if(len>32) if(len>32)
return luaL_error( L, "ssid:<32" ); return luaL_error( L, "ssid:<32" );
c_memset(ssid, 0, 32); memset(ssid, 0, 32);
c_memcpy(ssid, ssidstr, len); memcpy(ssid, ssidstr, len);
scan_cfg.ssid=ssid; scan_cfg.ssid=ssid;
NODE_DBG(scan_cfg.ssid); NODE_DBG(scan_cfg.ssid);
NODE_DBG("\n"); NODE_DBG("\n");
...@@ -1199,7 +1199,7 @@ static int wifi_station_listap( lua_State* L ) ...@@ -1199,7 +1199,7 @@ static int wifi_station_listap( lua_State* L )
{ {
const char *macaddr = luaL_checklstring( L, -1, &len ); const char *macaddr = luaL_checklstring( L, -1, &len );
luaL_argcheck(L, len==17, 1, INVALID_MAC_STR); luaL_argcheck(L, len==17, 1, INVALID_MAC_STR);
c_memset(bssid, 0, 6); memset(bssid, 0, 6);
ets_str2macaddr(bssid, macaddr); ets_str2macaddr(bssid, macaddr);
scan_cfg.bssid=bssid; scan_cfg.bssid=bssid;
NODE_DBG(MACSTR, MAC2STR(scan_cfg.bssid)); NODE_DBG(MACSTR, MAC2STR(scan_cfg.bssid));
...@@ -1401,7 +1401,7 @@ static int wifi_ap_deauth( lua_State* L ) ...@@ -1401,7 +1401,7 @@ static int wifi_ap_deauth( lua_State* L )
} }
else else
{ {
c_memset(&mac, 0xFF, sizeof(mac)); memset(&mac, 0xFF, sizeof(mac));
} }
lua_pushboolean(L,wifi_softap_deauth(mac)); lua_pushboolean(L,wifi_softap_deauth(mac));
return 1; return 1;
...@@ -1799,7 +1799,7 @@ static int wifi_ap_listclient( lua_State* L ) ...@@ -1799,7 +1799,7 @@ static int wifi_ap_listclient( lua_State* L )
struct station_info * next_station; struct station_info * next_station;
while (station != NULL) while (station != NULL)
{ {
c_sprintf(temp, MACSTR, MAC2STR(station->bssid)); sprintf(temp, MACSTR, MAC2STR(station->bssid));
wifi_add_sprintf_field(L, temp, IPSTR, IP2STR(&station->ip)); wifi_add_sprintf_field(L, temp, IPSTR, IP2STR(&station->ip));
station = STAILQ_NEXT(station, next); station = STAILQ_NEXT(station, next);
} }
...@@ -1833,9 +1833,9 @@ static int wifi_ap_dhcp_config( lua_State* L ) ...@@ -1833,9 +1833,9 @@ static int wifi_ap_dhcp_config( lua_State* L )
ip4_addr4(&lease.end_ip) += config.max_connection - 1; ip4_addr4(&lease.end_ip) += config.max_connection - 1;
char temp[64]; char temp[64];
c_sprintf(temp, IPSTR, IP2STR(&lease.start_ip)); sprintf(temp, IPSTR, IP2STR(&lease.start_ip));
lua_pushstring(L, temp); lua_pushstring(L, temp);
c_sprintf(temp, IPSTR, IP2STR(&lease.end_ip)); sprintf(temp, IPSTR, IP2STR(&lease.end_ip));
lua_pushstring(L, temp); lua_pushstring(L, temp);
// note: DHCP max range = 101 from start_ip to end_ip // note: DHCP max range = 101 from start_ip to end_ip
...@@ -1864,114 +1864,114 @@ static int wifi_ap_dhcp_stop( lua_State* L ) ...@@ -1864,114 +1864,114 @@ static int wifi_ap_dhcp_stop( lua_State* L )
// Module function map // Module function map
static const LUA_REG_TYPE wifi_station_map[] = { LROT_BEGIN(wifi_station)
{ LSTRKEY( "autoconnect" ), LFUNCVAL( wifi_station_setauto ) }, LROT_FUNCENTRY( autoconnect, wifi_station_setauto )
{ LSTRKEY( "changeap" ), LFUNCVAL( wifi_station_change_ap ) }, LROT_FUNCENTRY( changeap, wifi_station_change_ap )
{ LSTRKEY( "clearconfig"), LFUNCVAL( wifi_station_clear_config ) }, LROT_FUNCENTRY( clearconfig, wifi_station_clear_config )
{ LSTRKEY( "config" ), LFUNCVAL( wifi_station_config ) }, LROT_FUNCENTRY( config, wifi_station_config )
{ LSTRKEY( "connect" ), LFUNCVAL( wifi_station_connect4lua ) }, LROT_FUNCENTRY( connect, wifi_station_connect4lua )
{ LSTRKEY( "disconnect" ), LFUNCVAL( wifi_station_disconnect4lua ) }, LROT_FUNCENTRY( disconnect, wifi_station_disconnect4lua )
{ LSTRKEY( "getap" ), LFUNCVAL( wifi_station_listap ) }, LROT_FUNCENTRY( getap, wifi_station_listap )
{ LSTRKEY( "getapindex" ), LFUNCVAL( wifi_station_get_ap_index ) }, LROT_FUNCENTRY( getapindex, wifi_station_get_ap_index )
{ LSTRKEY( "getapinfo" ), LFUNCVAL( wifi_station_get_ap_info4lua ) }, LROT_FUNCENTRY( getapinfo, wifi_station_get_ap_info4lua )
{ LSTRKEY( "getbroadcast" ), LFUNCVAL( wifi_station_getbroadcast) }, LROT_FUNCENTRY( getbroadcast, wifi_station_getbroadcast )
{ LSTRKEY( "getconfig" ), LFUNCVAL( wifi_station_getconfig_current ) }, LROT_FUNCENTRY( getconfig, wifi_station_getconfig_current )
{ LSTRKEY( "getdefaultconfig" ), LFUNCVAL( wifi_station_getconfig_default ) }, LROT_FUNCENTRY( getdefaultconfig, wifi_station_getconfig_default )
{ LSTRKEY( "gethostname" ), LFUNCVAL( wifi_sta_gethostname ) }, LROT_FUNCENTRY( gethostname, wifi_sta_gethostname )
{ LSTRKEY( "getip" ), LFUNCVAL( wifi_station_getip ) }, LROT_FUNCENTRY( getip, wifi_station_getip )
{ LSTRKEY( "getmac" ), LFUNCVAL( wifi_station_getmac ) }, LROT_FUNCENTRY( getmac, wifi_station_getmac )
{ LSTRKEY( "getrssi" ), LFUNCVAL( wifi_station_getrssi ) }, LROT_FUNCENTRY( getrssi, wifi_station_getrssi )
{ LSTRKEY( "setaplimit" ), LFUNCVAL( wifi_station_ap_number_set4lua ) }, LROT_FUNCENTRY( setaplimit, wifi_station_ap_number_set4lua )
{ LSTRKEY( "sethostname" ), LFUNCVAL( wifi_sta_sethostname_lua ) }, LROT_FUNCENTRY( sethostname, wifi_sta_sethostname_lua )
{ LSTRKEY( "setip" ), LFUNCVAL( wifi_station_setip ) }, LROT_FUNCENTRY( setip, wifi_station_setip )
{ LSTRKEY( "setmac" ), LFUNCVAL( wifi_station_setmac ) }, LROT_FUNCENTRY( setmac, wifi_station_setmac )
{ LSTRKEY( "sleeptype" ), LFUNCVAL( wifi_station_sleeptype ) }, LROT_FUNCENTRY( sleeptype, wifi_station_sleeptype )
{ LSTRKEY( "status" ), LFUNCVAL( wifi_station_status ) }, LROT_FUNCENTRY( status, wifi_station_status )
{ LNILKEY, LNILVAL } LROT_END( wifi_station, wifi_station, 0 )
};
static const LUA_REG_TYPE wifi_ap_dhcp_map[] = { LROT_BEGIN(wifi_ap_dhcp)
{ LSTRKEY( "config" ), LFUNCVAL( wifi_ap_dhcp_config ) }, LROT_FUNCENTRY( config, wifi_ap_dhcp_config )
{ LSTRKEY( "start" ), LFUNCVAL( wifi_ap_dhcp_start ) }, LROT_FUNCENTRY( start, wifi_ap_dhcp_start )
{ LSTRKEY( "stop" ), LFUNCVAL( wifi_ap_dhcp_stop ) }, LROT_FUNCENTRY( stop, wifi_ap_dhcp_stop )
{ LNILKEY, LNILVAL } LROT_END( wifi_ap_dhcp, wifi_ap_dhcp, 0 )
};
static const LUA_REG_TYPE wifi_ap_map[] = { LROT_BEGIN(wifi_ap)
{ LSTRKEY( "config" ), LFUNCVAL( wifi_ap_config ) }, LROT_FUNCENTRY( config, wifi_ap_config )
{ LSTRKEY( "deauth" ), LFUNCVAL( wifi_ap_deauth ) }, LROT_FUNCENTRY( deauth, wifi_ap_deauth )
{ LSTRKEY( "getip" ), LFUNCVAL( wifi_ap_getip ) }, LROT_FUNCENTRY( getip, wifi_ap_getip )
{ LSTRKEY( "setip" ), LFUNCVAL( wifi_ap_setip ) }, LROT_FUNCENTRY( setip, wifi_ap_setip )
{ LSTRKEY( "getbroadcast" ), LFUNCVAL( wifi_ap_getbroadcast) }, LROT_FUNCENTRY( getbroadcast, wifi_ap_getbroadcast )
{ LSTRKEY( "getmac" ), LFUNCVAL( wifi_ap_getmac ) }, LROT_FUNCENTRY( getmac, wifi_ap_getmac )
{ LSTRKEY( "setmac" ), LFUNCVAL( wifi_ap_setmac ) }, LROT_FUNCENTRY( setmac, wifi_ap_setmac )
{ LSTRKEY( "getclient" ), LFUNCVAL( wifi_ap_listclient ) }, LROT_FUNCENTRY( getclient, wifi_ap_listclient )
{ LSTRKEY( "getconfig" ), LFUNCVAL( wifi_ap_getconfig_current ) }, LROT_FUNCENTRY( getconfig, wifi_ap_getconfig_current )
{ LSTRKEY( "getdefaultconfig" ), LFUNCVAL( wifi_ap_getconfig_default ) }, LROT_FUNCENTRY( getdefaultconfig, wifi_ap_getconfig_default )
{ LSTRKEY( "dhcp" ), LROVAL( wifi_ap_dhcp_map ) }, LROT_TABENTRY( dhcp, wifi_ap_dhcp )
//{ LSTRKEY( "__metatable" ), LROVAL( wifi_ap_map ) }, // LROT_TABENTRY( __metatable, wifi_ap )
{ LNILKEY, LNILVAL } LROT_END( wifi_ap, wifi_ap, 0 )
};
static const LUA_REG_TYPE wifi_map[] = { LROT_BEGIN(wifi)
{ LSTRKEY( "setmode" ), LFUNCVAL( wifi_setmode ) }, LROT_FUNCENTRY( setmode, wifi_setmode )
{ LSTRKEY( "getmode" ), LFUNCVAL( wifi_getmode ) }, LROT_FUNCENTRY( getmode, wifi_getmode )
{ LSTRKEY( "getdefaultmode" ), LFUNCVAL( wifi_getdefaultmode ) }, LROT_FUNCENTRY( getdefaultmode, wifi_getdefaultmode )
{ LSTRKEY( "getchannel" ), LFUNCVAL( wifi_getchannel ) }, LROT_FUNCENTRY( getchannel, wifi_getchannel )
{ LSTRKEY( "getcountry" ), LFUNCVAL( wifi_getcountry ) }, LROT_FUNCENTRY( getcountry, wifi_getcountry )
{ LSTRKEY( "setcountry" ), LFUNCVAL( wifi_setcountry ) }, LROT_FUNCENTRY( setcountry, wifi_setcountry )
{ LSTRKEY( "setphymode" ), LFUNCVAL( wifi_setphymode ) }, LROT_FUNCENTRY( setphymode, wifi_setphymode )
{ LSTRKEY( "getphymode" ), LFUNCVAL( wifi_getphymode ) }, LROT_FUNCENTRY( getphymode, wifi_getphymode )
{ LSTRKEY( "setmaxtxpower" ), LFUNCVAL( wifi_setmaxtxpower ) }, LROT_FUNCENTRY( setmaxtxpower, wifi_setmaxtxpower )
{ LSTRKEY( "suspend" ), LFUNCVAL( wifi_suspend ) }, LROT_FUNCENTRY( suspend, wifi_suspend )
{ LSTRKEY( "resume" ), LFUNCVAL( wifi_resume ) }, LROT_FUNCENTRY( resume, wifi_resume )
{ LSTRKEY( "nullmodesleep" ), LFUNCVAL( wifi_null_mode_auto_sleep ) }, LROT_FUNCENTRY( nullmodesleep, wifi_null_mode_auto_sleep )
#ifdef WIFI_SMART_ENABLE #ifdef WIFI_SMART_ENABLE
{ LSTRKEY( "startsmart" ), LFUNCVAL( wifi_start_smart ) }, LROT_FUNCENTRY( startsmart, wifi_start_smart )
{ LSTRKEY( "stopsmart" ), LFUNCVAL( wifi_exit_smart ) }, LROT_FUNCENTRY( stopsmart, wifi_exit_smart )
#endif #endif
{ LSTRKEY( "sleeptype" ), LFUNCVAL( wifi_station_sleeptype ) }, LROT_FUNCENTRY( sleeptype, wifi_station_sleeptype )
{ LSTRKEY( "sta" ), LROVAL( wifi_station_map ) }, LROT_TABENTRY( sta, wifi_station )
{ LSTRKEY( "ap" ), LROVAL( wifi_ap_map ) }, LROT_TABENTRY( ap, wifi_ap )
#if defined(WIFI_SDK_EVENT_MONITOR_ENABLE) #if defined(WIFI_SDK_EVENT_MONITOR_ENABLE)
{ LSTRKEY( "eventmon" ), LROVAL( wifi_event_monitor_map ) }, //declared in wifi_eventmon.c LROT_TABENTRY( eventmon, wifi_event_monitor )
#endif #endif
#if defined(LUA_USE_MODULES_WIFI_MONITOR) #if defined(LUA_USE_MODULES_WIFI_MONITOR)
{ LSTRKEY( "monitor" ), LROVAL( wifi_monitor_map ) }, //declared in wifi_monitor.c LROT_TABENTRY( monitor, wifi_monitor )
#endif #endif
{ LSTRKEY( "NULLMODE" ), LNUMVAL( NULL_MODE ) }, LROT_NUMENTRY( NULLMODE, NULL_MODE )
{ LSTRKEY( "STATION" ), LNUMVAL( STATION_MODE ) }, LROT_NUMENTRY( STATION, STATION_MODE )
{ LSTRKEY( "SOFTAP" ), LNUMVAL( SOFTAP_MODE ) }, LROT_NUMENTRY( SOFTAP, SOFTAP_MODE )
{ LSTRKEY( "STATIONAP" ), LNUMVAL( STATIONAP_MODE ) }, LROT_NUMENTRY( STATIONAP, STATIONAP_MODE )
{ LSTRKEY( "PHYMODE_B" ), LNUMVAL( PHY_MODE_11B ) }, LROT_NUMENTRY( PHYMODE_B, PHY_MODE_11B )
{ LSTRKEY( "PHYMODE_G" ), LNUMVAL( PHY_MODE_11G ) }, LROT_NUMENTRY( PHYMODE_G, PHY_MODE_11G )
{ LSTRKEY( "PHYMODE_N" ), LNUMVAL( PHY_MODE_11N ) }, LROT_NUMENTRY( PHYMODE_N, PHY_MODE_11N )
{ LSTRKEY( "NONE_SLEEP" ), LNUMVAL( NONE_SLEEP_T ) }, LROT_NUMENTRY( NONE_SLEEP, NONE_SLEEP_T )
{ LSTRKEY( "LIGHT_SLEEP" ), LNUMVAL( LIGHT_SLEEP_T ) }, LROT_NUMENTRY( LIGHT_SLEEP, LIGHT_SLEEP_T )
{ LSTRKEY( "MODEM_SLEEP" ), LNUMVAL( MODEM_SLEEP_T ) }, LROT_NUMENTRY( MODEM_SLEEP, MODEM_SLEEP_T )
{ LSTRKEY( "OPEN" ), LNUMVAL( AUTH_OPEN ) }, LROT_NUMENTRY( OPEN, AUTH_OPEN )
//{ LSTRKEY( "WEP" ), LNUMVAL( AUTH_WEP ) }, // LROT_NUMENTRY( WEP, AUTH_WEP )
{ LSTRKEY( "WPA_PSK" ), LNUMVAL( AUTH_WPA_PSK ) }, LROT_NUMENTRY( WPA_PSK, AUTH_WPA_PSK )
{ LSTRKEY( "WPA2_PSK" ), LNUMVAL( AUTH_WPA2_PSK ) }, LROT_NUMENTRY( WPA2_PSK, AUTH_WPA2_PSK )
{ LSTRKEY( "WPA_WPA2_PSK" ), LNUMVAL( AUTH_WPA_WPA2_PSK ) }, LROT_NUMENTRY( WPA_WPA2_PSK, AUTH_WPA_WPA2_PSK )
{ LSTRKEY( "STA_IDLE" ), LNUMVAL( STATION_IDLE ) }, LROT_NUMENTRY( STA_IDLE, STATION_IDLE )
{ LSTRKEY( "STA_CONNECTING" ), LNUMVAL( STATION_CONNECTING ) }, LROT_NUMENTRY( STA_CONNECTING, STATION_CONNECTING )
{ LSTRKEY( "STA_WRONGPWD" ), LNUMVAL( STATION_WRONG_PASSWORD ) }, LROT_NUMENTRY( STA_WRONGPWD, STATION_WRONG_PASSWORD )
{ LSTRKEY( "STA_APNOTFOUND" ), LNUMVAL( STATION_NO_AP_FOUND ) }, LROT_NUMENTRY( STA_APNOTFOUND, STATION_NO_AP_FOUND )
{ LSTRKEY( "STA_FAIL" ), LNUMVAL( STATION_CONNECT_FAIL ) }, LROT_NUMENTRY( STA_FAIL, STATION_CONNECT_FAIL )
{ LSTRKEY( "STA_GOTIP" ), LNUMVAL( STATION_GOT_IP ) }, LROT_NUMENTRY( STA_GOTIP, STATION_GOT_IP )
{ LSTRKEY( "COUNTRY_AUTO" ), LNUMVAL( WIFI_COUNTRY_POLICY_AUTO ) }, LROT_NUMENTRY( COUNTRY_AUTO, WIFI_COUNTRY_POLICY_AUTO )
{ LSTRKEY( "COUNTRY_MANUAL" ), LNUMVAL( WIFI_COUNTRY_POLICY_MANUAL ) }, LROT_NUMENTRY( COUNTRY_MANUAL, WIFI_COUNTRY_POLICY_MANUAL )
{ LSTRKEY( "__metatable" ), LROVAL( wifi_map ) }, LROT_TABENTRY( __metatable, wifi )
{ LNILKEY, LNILVAL } LROT_END( wifi, wifi, 0 )
};
// Used by user_rf_pre_init(user_main.c) // Used by user_rf_pre_init(user_main.c)
void wifi_change_default_host_name(void) void wifi_change_default_host_name(void)
...@@ -1983,20 +1983,20 @@ void wifi_change_default_host_name(void) ...@@ -1983,20 +1983,20 @@ void wifi_change_default_host_name(void)
wifi_get_macaddr(STATION_IF, mac); wifi_get_macaddr(STATION_IF, mac);
#ifndef WIFI_STA_HOSTNAME #ifndef WIFI_STA_HOSTNAME
c_sprintf(temp, "NODE-%X%X%X", (mac)[3], (mac)[4], (mac)[5]); sprintf(temp, "NODE-%X%X%X", (mac)[3], (mac)[4], (mac)[5]);
#elif defined(WIFI_STA_HOSTNAME) && !defined(WIFI_STA_HOSTNAME_APPEND_MAC) #elif defined(WIFI_STA_HOSTNAME) && !defined(WIFI_STA_HOSTNAME_APPEND_MAC)
if(wifi_sta_checkhostname(WIFI_STA_HOSTNAME, strlen(WIFI_STA_HOSTNAME))){ if(wifi_sta_checkhostname(WIFI_STA_HOSTNAME, strlen(WIFI_STA_HOSTNAME))){
c_sprintf(temp, "%s", WIFI_STA_HOSTNAME); sprintf(temp, "%s", WIFI_STA_HOSTNAME);
} }
else{ else{
c_sprintf(temp, "NODE-%X%X%X", (mac)[3], (mac)[4], (mac)[5]); sprintf(temp, "NODE-%X%X%X", (mac)[3], (mac)[4], (mac)[5]);
} }
#elif defined(WIFI_STA_HOSTNAME) && defined(WIFI_STA_HOSTNAME_APPEND_MAC) #elif defined(WIFI_STA_HOSTNAME) && defined(WIFI_STA_HOSTNAME_APPEND_MAC)
if(strlen(WIFI_STA_HOSTNAME) <= 26 && wifi_sta_checkhostname(WIFI_STA_HOSTNAME, strlen(WIFI_STA_HOSTNAME))){ if(strlen(WIFI_STA_HOSTNAME) <= 26 && wifi_sta_checkhostname(WIFI_STA_HOSTNAME, strlen(WIFI_STA_HOSTNAME))){
c_sprintf(temp, "%s%X%X%X", WIFI_STA_HOSTNAME, (mac)[3], (mac)[4], (mac)[5]); sprintf(temp, "%s%X%X%X", WIFI_STA_HOSTNAME, (mac)[3], (mac)[4], (mac)[5]);
} }
else{ else{
c_sprintf(temp, "NODE-%X%X%X", (mac)[3], (mac)[4], (mac)[5]); sprintf(temp, "NODE-%X%X%X", (mac)[3], (mac)[4], (mac)[5]);
} }
#endif #endif
...@@ -2024,4 +2024,4 @@ int luaopen_wifi( lua_State *L ) ...@@ -2024,4 +2024,4 @@ int luaopen_wifi( lua_State *L )
return 0; return 0;
} }
NODEMCU_MODULE(WIFI, "wifi", wifi_map, luaopen_wifi); NODEMCU_MODULE(WIFI, "wifi", wifi, luaopen_wifi);
...@@ -10,7 +10,7 @@ void wifi_add_sprintf_field(lua_State* L, char* name, char* string, ...) ...@@ -10,7 +10,7 @@ void wifi_add_sprintf_field(lua_State* L, char* name, char* string, ...)
char buffer[256]; char buffer[256];
va_list arglist; va_list arglist;
va_start( arglist, string ); va_start( arglist, string );
c_vsprintf( buffer, string, arglist ); vsprintf( buffer, string, arglist );
va_end( arglist ); va_end( arglist );
lua_pushstring(L, buffer); lua_pushstring(L, buffer);
lua_setfield(L, -2, name); lua_setfield(L, -2, name);
......
...@@ -5,12 +5,11 @@ ...@@ -5,12 +5,11 @@
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "c_string.h" #include <string.h>
#include "c_stdlib.h" #include <stdlib.h>
#include "c_types.h" #include <stdio.h>
#include "user_interface.h" #include "user_interface.h"
#include "user_config.h" #include "user_config.h"
#include "c_stdio.h"
#include "task/task.h" #include "task/task.h"
//#define WIFI_DEBUG //#define WIFI_DEBUG
...@@ -37,16 +36,16 @@ static inline void unregister_lua_cb(lua_State* L, int* cb_ref){ ...@@ -37,16 +36,16 @@ static inline void unregister_lua_cb(lua_State* L, int* cb_ref){
void wifi_change_default_host_name(void); void wifi_change_default_host_name(void);
#if defined(WIFI_DEBUG) || defined(NODE_DEBUG) #if defined(WIFI_DEBUG) || defined(NODE_DEBUG)
#define WIFI_DBG(...) c_printf(__VA_ARGS__) #define WIFI_DBG(...) printf(__VA_ARGS__)
#else #else
#define WIFI_DBG(...) //c_printf(__VA_ARGS__) #define WIFI_DBG(...) //printf(__VA_ARGS__)
#endif #endif
#if defined(EVENT_DEBUG) || defined(NODE_DEBUG) #if defined(EVENT_DEBUG) || defined(NODE_DEBUG)
#define EVENT_DBG(fmt, ...) c_printf("\n EVENT_DBG(%s): "fmt"\n", __FUNCTION__, ##__VA_ARGS__) #define EVENT_DBG(fmt, ...) printf("\n EVENT_DBG(%s): "fmt"\n", __FUNCTION__, ##__VA_ARGS__)
#else #else
#define EVENT_DBG(...) //c_printf(__VA_ARGS__) #define EVENT_DBG(...) //printf(__VA_ARGS__)
#endif #endif
enum wifi_suspension_state{ enum wifi_suspension_state{
...@@ -58,13 +57,13 @@ enum wifi_suspension_state{ ...@@ -58,13 +57,13 @@ enum wifi_suspension_state{
#ifdef WIFI_SDK_EVENT_MONITOR_ENABLE #ifdef WIFI_SDK_EVENT_MONITOR_ENABLE
extern const LUA_REG_TYPE wifi_event_monitor_map[]; LROT_EXTERN(wifi_event_monitor);
void wifi_eventmon_init(); void wifi_eventmon_init();
int wifi_event_monitor_register(lua_State* L); int wifi_event_monitor_register(lua_State* L);
#endif #endif
#ifdef LUA_USE_MODULES_WIFI_MONITOR #ifdef LUA_USE_MODULES_WIFI_MONITOR
extern const LUA_REG_TYPE wifi_monitor_map[]; LROT_EXTERN(wifi_monitor);
int wifi_monitor_init(lua_State *L); int wifi_monitor_init(lua_State *L);
#endif #endif
......
...@@ -4,12 +4,12 @@ ...@@ -4,12 +4,12 @@
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "c_string.h" #include <string.h>
#include "c_stdlib.h" #include <stddef.h>
#include "c_types.h" #include <stdint.h>
#include "user_interface.h" #include "user_interface.h"
#include "smart.h" #include "smart/smart.h"
#include "smartconfig.h" #include "smartconfig.h"
#include "user_config.h" #include "user_config.h"
...@@ -82,7 +82,7 @@ static void wifi_event_monitor_handle_event_cb(System_Event_t *evt) ...@@ -82,7 +82,7 @@ static void wifi_event_monitor_handle_event_cb(System_Event_t *evt)
lua_rawgeti(L, LUA_REGISTRYINDEX, event_queue_ref); lua_rawgeti(L, LUA_REGISTRYINDEX, event_queue_ref);
System_Event_t* evt_tmp = lua_newuserdata(L, sizeof(System_Event_t)); System_Event_t* evt_tmp = lua_newuserdata(L, sizeof(System_Event_t));
c_memcpy(evt_tmp, evt, sizeof(System_Event_t)); //copy event data to new struct memcpy(evt_tmp, evt, sizeof(System_Event_t)); //copy event data to new struct
sint32_t evt_ud_ref = luaL_ref(L, LUA_REGISTRYINDEX); sint32_t evt_ud_ref = luaL_ref(L, LUA_REGISTRYINDEX);
size_t queue_len = lua_objlen(L, -1); size_t queue_len = lua_objlen(L, -1);
...@@ -247,59 +247,57 @@ static void wifi_event_monitor_process_event_queue(task_param_t param, uint8 pri ...@@ -247,59 +247,57 @@ static void wifi_event_monitor_process_event_queue(task_param_t param, uint8 pri
} }
#ifdef WIFI_EVENT_MONITOR_DISCONNECT_REASON_LIST_ENABLE #ifdef WIFI_EVENT_MONITOR_DISCONNECT_REASON_LIST_ENABLE
static const LUA_REG_TYPE wifi_event_monitor_reason_map[] = LROT_BEGIN(wifi_event_monitor_reason)
{ LROT_NUMENTRY( UNSPECIFIED, REASON_UNSPECIFIED )
{ LSTRKEY( "UNSPECIFIED" ), LNUMVAL( REASON_UNSPECIFIED ) }, LROT_NUMENTRY( AUTH_EXPIRE, REASON_AUTH_EXPIRE )
{ LSTRKEY( "AUTH_EXPIRE" ), LNUMVAL( REASON_AUTH_EXPIRE ) }, LROT_NUMENTRY( AUTH_LEAVE, REASON_AUTH_LEAVE )
{ LSTRKEY( "AUTH_LEAVE" ), LNUMVAL( REASON_AUTH_LEAVE ) }, LROT_NUMENTRY( ASSOC_EXPIRE, REASON_ASSOC_EXPIRE )
{ LSTRKEY( "ASSOC_EXPIRE" ), LNUMVAL( REASON_ASSOC_EXPIRE ) }, LROT_NUMENTRY( ASSOC_TOOMANY, REASON_ASSOC_TOOMANY )
{ LSTRKEY( "ASSOC_TOOMANY" ), LNUMVAL( REASON_ASSOC_TOOMANY ) }, LROT_NUMENTRY( NOT_AUTHED, REASON_NOT_AUTHED )
{ LSTRKEY( "NOT_AUTHED" ), LNUMVAL( REASON_NOT_AUTHED ) }, LROT_NUMENTRY( NOT_ASSOCED, REASON_NOT_ASSOCED )
{ LSTRKEY( "NOT_ASSOCED" ), LNUMVAL( REASON_NOT_ASSOCED ) }, LROT_NUMENTRY( ASSOC_LEAVE, REASON_ASSOC_LEAVE )
{ LSTRKEY( "ASSOC_LEAVE" ), LNUMVAL( REASON_ASSOC_LEAVE ) }, LROT_NUMENTRY( ASSOC_NOT_AUTHED, REASON_ASSOC_NOT_AUTHED )
{ LSTRKEY( "ASSOC_NOT_AUTHED" ), LNUMVAL( REASON_ASSOC_NOT_AUTHED ) }, LROT_NUMENTRY( DISASSOC_PWRCAP_BAD, REASON_DISASSOC_PWRCAP_BAD )
{ LSTRKEY( "DISASSOC_PWRCAP_BAD" ), LNUMVAL( REASON_DISASSOC_PWRCAP_BAD ) }, LROT_NUMENTRY( DISASSOC_SUPCHAN_BAD, REASON_DISASSOC_SUPCHAN_BAD )
{ LSTRKEY( "DISASSOC_SUPCHAN_BAD" ), LNUMVAL( REASON_DISASSOC_SUPCHAN_BAD ) }, LROT_NUMENTRY( IE_INVALID, REASON_IE_INVALID )
{ LSTRKEY( "IE_INVALID" ), LNUMVAL( REASON_IE_INVALID ) }, LROT_NUMENTRY( MIC_FAILURE, REASON_MIC_FAILURE )
{ LSTRKEY( "MIC_FAILURE" ), LNUMVAL( REASON_MIC_FAILURE ) }, LROT_NUMENTRY( 4WAY_HANDSHAKE_TIMEOUT, REASON_4WAY_HANDSHAKE_TIMEOUT )
{ LSTRKEY( "4WAY_HANDSHAKE_TIMEOUT" ), LNUMVAL( REASON_4WAY_HANDSHAKE_TIMEOUT ) }, LROT_NUMENTRY( GROUP_KEY_UPDATE_TIMEOUT, REASON_GROUP_KEY_UPDATE_TIMEOUT )
{ LSTRKEY( "GROUP_KEY_UPDATE_TIMEOUT" ), LNUMVAL( REASON_GROUP_KEY_UPDATE_TIMEOUT ) }, LROT_NUMENTRY( IE_IN_4WAY_DIFFERS, REASON_IE_IN_4WAY_DIFFERS )
{ LSTRKEY( "IE_IN_4WAY_DIFFERS" ), LNUMVAL( REASON_IE_IN_4WAY_DIFFERS ) }, LROT_NUMENTRY( GROUP_CIPHER_INVALID, REASON_GROUP_CIPHER_INVALID )
{ LSTRKEY( "GROUP_CIPHER_INVALID" ), LNUMVAL( REASON_GROUP_CIPHER_INVALID ) }, LROT_NUMENTRY( PAIRWISE_CIPHER_INVALID, REASON_PAIRWISE_CIPHER_INVALID )
{ LSTRKEY( "PAIRWISE_CIPHER_INVALID" ), LNUMVAL( REASON_PAIRWISE_CIPHER_INVALID ) }, LROT_NUMENTRY( AKMP_INVALID, REASON_AKMP_INVALID )
{ LSTRKEY( "AKMP_INVALID" ), LNUMVAL( REASON_AKMP_INVALID ) }, LROT_NUMENTRY( UNSUPP_RSN_IE_VERSION, REASON_UNSUPP_RSN_IE_VERSION )
{ LSTRKEY( "UNSUPP_RSN_IE_VERSION" ), LNUMVAL( REASON_UNSUPP_RSN_IE_VERSION ) }, LROT_NUMENTRY( INVALID_RSN_IE_CAP, REASON_INVALID_RSN_IE_CAP )
{ LSTRKEY( "INVALID_RSN_IE_CAP" ), LNUMVAL( REASON_INVALID_RSN_IE_CAP ) }, LROT_NUMENTRY( 802_1X_AUTH_FAILED, REASON_802_1X_AUTH_FAILED )
{ LSTRKEY( "802_1X_AUTH_FAILED" ), LNUMVAL( REASON_802_1X_AUTH_FAILED ) }, LROT_NUMENTRY( CIPHER_SUITE_REJECTED, REASON_CIPHER_SUITE_REJECTED )
{ LSTRKEY( "CIPHER_SUITE_REJECTED" ), LNUMVAL( REASON_CIPHER_SUITE_REJECTED ) }, LROT_NUMENTRY( BEACON_TIMEOUT, REASON_BEACON_TIMEOUT )
{ LSTRKEY( "BEACON_TIMEOUT" ), LNUMVAL( REASON_BEACON_TIMEOUT ) }, LROT_NUMENTRY( NO_AP_FOUND, REASON_NO_AP_FOUND )
{ LSTRKEY( "NO_AP_FOUND" ), LNUMVAL( REASON_NO_AP_FOUND ) }, LROT_NUMENTRY( AUTH_FAIL, REASON_AUTH_FAIL )
{ LSTRKEY( "AUTH_FAIL" ), LNUMVAL( REASON_AUTH_FAIL ) }, LROT_NUMENTRY( ASSOC_FAIL, REASON_ASSOC_FAIL )
{ LSTRKEY( "ASSOC_FAIL" ), LNUMVAL( REASON_ASSOC_FAIL ) }, LROT_NUMENTRY( HANDSHAKE_TIMEOUT, REASON_HANDSHAKE_TIMEOUT )
{ LSTRKEY( "HANDSHAKE_TIMEOUT" ), LNUMVAL( REASON_HANDSHAKE_TIMEOUT ) }, LROT_END( wifi_event_monitor_reason, NULL, 0 )
{ LNILKEY, LNILVAL }
};
#endif #endif
const LUA_REG_TYPE wifi_event_monitor_map[] = LROT_PUBLIC_BEGIN(wifi_event_monitor)
{ LROT_FUNCENTRY( register, wifi_event_monitor_register )
{ LSTRKEY( "register" ), LFUNCVAL( wifi_event_monitor_register ) }, LROT_FUNCENTRY( unregister, wifi_event_monitor_register )
{ LSTRKEY( "unregister" ), LFUNCVAL( wifi_event_monitor_register ) }, LROT_NUMENTRY( STA_CONNECTED, EVENT_STAMODE_CONNECTED )
{ LSTRKEY( "STA_CONNECTED" ), LNUMVAL( EVENT_STAMODE_CONNECTED ) }, LROT_NUMENTRY( STA_DISCONNECTED, EVENT_STAMODE_DISCONNECTED )
{ LSTRKEY( "STA_DISCONNECTED" ), LNUMVAL( EVENT_STAMODE_DISCONNECTED ) }, LROT_NUMENTRY( STA_AUTHMODE_CHANGE, EVENT_STAMODE_AUTHMODE_CHANGE )
{ LSTRKEY( "STA_AUTHMODE_CHANGE" ), LNUMVAL( EVENT_STAMODE_AUTHMODE_CHANGE ) }, LROT_NUMENTRY( STA_GOT_IP, EVENT_STAMODE_GOT_IP )
{ LSTRKEY( "STA_GOT_IP" ), LNUMVAL( EVENT_STAMODE_GOT_IP ) }, LROT_NUMENTRY( STA_DHCP_TIMEOUT, EVENT_STAMODE_DHCP_TIMEOUT )
{ LSTRKEY( "STA_DHCP_TIMEOUT" ), LNUMVAL( EVENT_STAMODE_DHCP_TIMEOUT ) }, LROT_NUMENTRY( AP_STACONNECTED, EVENT_SOFTAPMODE_STACONNECTED )
{ LSTRKEY( "AP_STACONNECTED" ), LNUMVAL( EVENT_SOFTAPMODE_STACONNECTED ) }, LROT_NUMENTRY( AP_STADISCONNECTED, EVENT_SOFTAPMODE_STADISCONNECTED )
{ LSTRKEY( "AP_STADISCONNECTED" ), LNUMVAL( EVENT_SOFTAPMODE_STADISCONNECTED ) }, LROT_NUMENTRY( AP_PROBEREQRECVED, EVENT_SOFTAPMODE_PROBEREQRECVED )
{ LSTRKEY( "AP_PROBEREQRECVED" ), LNUMVAL( EVENT_SOFTAPMODE_PROBEREQRECVED ) }, LROT_NUMENTRY( WIFI_MODE_CHANGED, EVENT_OPMODE_CHANGED )
{ LSTRKEY( "WIFI_MODE_CHANGED" ), LNUMVAL( EVENT_OPMODE_CHANGED ) }, LROT_NUMENTRY( EVENT_MAX, EVENT_MAX )
{ LSTRKEY( "EVENT_MAX" ), LNUMVAL( EVENT_MAX ) },
#ifdef WIFI_EVENT_MONITOR_DISCONNECT_REASON_LIST_ENABLE #ifdef WIFI_EVENT_MONITOR_DISCONNECT_REASON_LIST_ENABLE
{ LSTRKEY( "reason" ), LROVAL( wifi_event_monitor_reason_map ) }, LROT_TABENTRY( reason, wifi_event_monitor_reason )
#endif #endif
{ LNILKEY, LNILVAL } LROT_END( wifi_event_monitor, NULL, 0 )
};
void wifi_eventmon_init() void wifi_eventmon_init()
{ {
......
...@@ -5,11 +5,11 @@ ...@@ -5,11 +5,11 @@
#include "lapi.h" #include "lapi.h"
#include "platform.h" #include "platform.h"
#include "c_string.h" #include <string.h>
#include "c_stdlib.h" #include <stddef.h>
#include "ctype.h" #include "ctype.h"
#include "c_types.h" #include <stdint.h>
#include "user_interface.h" #include "user_interface.h"
#include "wifi_common.h" #include "wifi_common.h"
#include "sys/network_80211.h" #include "sys/network_80211.h"
...@@ -276,7 +276,7 @@ typedef struct { ...@@ -276,7 +276,7 @@ typedef struct {
uint8 buf[]; uint8 buf[];
} packet_t; } packet_t;
static const LUA_REG_TYPE packet_function_map[]; LROT_TABLE(packet_function)
static void wifi_rx_cb(uint8 *buf, uint16 len) { static void wifi_rx_cb(uint8 *buf, uint16 len) {
if (len != sizeof(struct sniffer_buf2)) { if (len != sizeof(struct sniffer_buf2)) {
...@@ -294,12 +294,12 @@ static void wifi_rx_cb(uint8 *buf, uint16 len) { ...@@ -294,12 +294,12 @@ static void wifi_rx_cb(uint8 *buf, uint16 len) {
return; return;
} }
packet_t *packet = (packet_t *) c_malloc(len + sizeof(packet_t)); packet_t *packet = (packet_t *) malloc(len + sizeof(packet_t));
if (packet) { if (packet) {
packet->len = len; packet->len = len;
memcpy(packet->buf, buf, len); memcpy(packet->buf, buf, len);
if (!task_post_medium(tasknumber, (ETSParam) packet)) { if (!task_post_medium(tasknumber, (ETSParam) packet)) {
c_free(packet); free(packet);
} }
} }
} }
...@@ -320,11 +320,11 @@ static void monitor_task(os_param_t param, uint8_t prio) ...@@ -320,11 +320,11 @@ static void monitor_task(os_param_t param, uint8_t prio)
luaL_getmetatable(L, "wifi.packet"); luaL_getmetatable(L, "wifi.packet");
lua_setmetatable(L, -2); lua_setmetatable(L, -2);
c_free(input); free(input);
lua_call(L, 1, 0); lua_call(L, 1, 0);
} else { } else {
c_free(input); free(input);
} }
} }
...@@ -570,7 +570,7 @@ static int packet_map_lookup(lua_State *L) { ...@@ -570,7 +570,7 @@ static int packet_map_lookup(lua_State *L) {
} }
// Now search the packet function map // Now search the packet function map
lua_pushrotable(L, (void *)packet_function_map); lua_pushrotable(L, LROT_TABLEREF(packet_function));
lua_getfield(L, -1, field); lua_getfield(L, -1, field);
if (!lua_isnil(L, -1)) { if (!lua_isnil(L, -1)) {
return 1; return 1;
...@@ -757,32 +757,32 @@ static int wifi_monitor_stop(lua_State *L) { ...@@ -757,32 +757,32 @@ static int wifi_monitor_stop(lua_State *L) {
return 0; return 0;
} }
static const LUA_REG_TYPE packet_function_map[] = { LROT_BEGIN(packet_function)
{ LSTRKEY( "radio_byte" ), LFUNCVAL( packet_radio_byte ) }, LROT_FUNCENTRY( radio_byte, packet_radio_byte )
{ LSTRKEY( "frame_byte" ), LFUNCVAL( packet_frame_byte ) }, LROT_FUNCENTRY( frame_byte, packet_frame_byte )
{ LSTRKEY( "radio_sub" ), LFUNCVAL( packet_radio_sub ) }, LROT_FUNCENTRY( radio_sub, packet_radio_sub )
{ LSTRKEY( "frame_sub" ), LFUNCVAL( packet_frame_sub ) }, LROT_FUNCENTRY( frame_sub, packet_frame_sub )
{ LSTRKEY( "radio_subhex" ), LFUNCVAL( packet_radio_subhex ) }, LROT_FUNCENTRY( radio_subhex, packet_radio_subhex )
{ LSTRKEY( "frame_subhex" ), LFUNCVAL( packet_frame_subhex ) }, LROT_FUNCENTRY( frame_subhex, packet_frame_subhex )
{ LNILKEY, LNILVAL } LROT_END( packet_function, packet_function, LROT_MASK_INDEX )
};
LROT_BEGIN(packet)
LROT_FUNCENTRY( __index, packet_map_lookup )
LROT_END( packet, packet, LROT_MASK_INDEX )
static const LUA_REG_TYPE packet_map[] = {
{ LSTRKEY( "__index" ), LFUNCVAL( packet_map_lookup ) },
{ LNILKEY, LNILVAL }
};
// Module function map // Module function map
const LUA_REG_TYPE wifi_monitor_map[] = { LROT_PUBLIC_BEGIN(wifi_monitor)
{ LSTRKEY( "start" ), LFUNCVAL( wifi_monitor_start ) }, LROT_FUNCENTRY( start, wifi_monitor_start )
{ LSTRKEY( "stop" ), LFUNCVAL( wifi_monitor_stop ) }, LROT_FUNCENTRY( stop, wifi_monitor_stop )
{ LSTRKEY( "channel" ), LFUNCVAL( wifi_monitor_channel ) }, LROT_FUNCENTRY( channel, wifi_monitor_channel )
{ LNILKEY, LNILVAL } LROT_END( wifi_monitor, NULL, 0 )
};
int wifi_monitor_init(lua_State *L) int wifi_monitor_init(lua_State *L)
{ {
luaL_rometatable(L, "wifi.packet", (void *)packet_map); luaL_rometatable(L, "wifi.packet", LROT_TABLEREF(packet));
tasknumber = task_get_id(monitor_task); tasknumber = task_get_id(monitor_task);
eventmon_setup(); eventmon_setup();
......
...@@ -52,22 +52,22 @@ static int ICACHE_FLASH_ATTR wps_start(lua_State* L) ...@@ -52,22 +52,22 @@ static int ICACHE_FLASH_ATTR wps_start(lua_State* L)
} }
// Module function map // Module function map
const LUA_REG_TYPE wps_map[] = { LROT_BEGIN(wps)
{ LSTRKEY( "disable" ), LFUNCVAL( wps_disable ) }, LROT_FUNCENTRY( disable, wps_disable )
{ LSTRKEY( "enable" ), LFUNCVAL( wps_enable ) }, LROT_FUNCENTRY( enable, wps_enable )
{ LSTRKEY( "start" ), LFUNCVAL( wps_start ) }, LROT_FUNCENTRY( start, wps_start )
{ LSTRKEY( "SUCCESS" ), LNUMVAL( WPS_CB_ST_SUCCESS ) }, LROT_NUMENTRY( SUCCESS, WPS_CB_ST_SUCCESS )
{ LSTRKEY( "FAILED" ), LNUMVAL( WPS_CB_ST_FAILED ) }, LROT_NUMENTRY( FAILED, WPS_CB_ST_FAILED )
{ LSTRKEY( "TIMEOUT" ), LNUMVAL( WPS_CB_ST_TIMEOUT ) }, LROT_NUMENTRY( TIMEOUT, WPS_CB_ST_TIMEOUT )
{ LSTRKEY( "WEP" ), LNUMVAL( WPS_CB_ST_WEP ) }, LROT_NUMENTRY( WEP, WPS_CB_ST_WEP )
{ LSTRKEY( "SCAN_ERR" ), LNUMVAL( 4 ) }, // WPS_CB_ST_SCAN_ERR LROT_NUMENTRY( SCAN_ERR, 4 )
{ LNILKEY, LNILVAL } LROT_END( wps, NULL, 0 )
};
int luaopen_wps( lua_State *L ) int luaopen_wps( lua_State *L )
{ {
return 0; return 0;
} }
NODEMCU_MODULE(WPS, "wps", wps_map, luaopen_wps); NODEMCU_MODULE(WPS, "wps", wps, luaopen_wps);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment