Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
310faf7f
Unverified
Commit
310faf7f
authored
Sep 07, 2019
by
Terry Ellison
Committed by
GitHub
Sep 07, 2019
Browse files
Merge pull request #2886 from nodemcu/dev
Next master drop
parents
68c425c0
a08e74d9
Changes
368
Show whitespace changes
Inline
Side-by-side
app/modules/somfy.c
View file @
310faf7f
...
@@ -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
)
{
LSTRKE
Y
(
"
UP
"
),
LNUMVAL
(
SOMFY_UP
)
},
LROT_NUMENTR
Y
(
UP
,
SOMFY_UP
)
{
LSTRKE
Y
(
"
DOWN
"
),
LNUMVAL
(
SOMFY_DOWN
)
},
LROT_NUMENTR
Y
(
DOWN
,
SOMFY_DOWN
)
{
LSTRKE
Y
(
"
PROG
"
),
LNUMVAL
(
SOMFY_PROG
)
},
LROT_NUMENTR
Y
(
PROG
,
SOMFY_PROG
)
{
LSTRKE
Y
(
"
STOP
"
),
LNUMVAL
(
SOMFY_STOP
)
},
LROT_NUMENTR
Y
(
STOP
,
SOMFY_STOP
)
{
LSTRKE
Y
(
"
sendcommand
"
),
LFUNCVAL
(
somfy_lua_sendcommand
)
},
LROT_FUNCENTR
Y
(
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
app/modules/spi.c
View file @
310faf7f
...
@@ -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
)
{
LSTRKE
Y
(
"
setup
"
),
LFUNCVAL
(
spi_setup
)
},
LROT_FUNCENTR
Y
(
setup
,
spi_setup
)
{
LSTRKE
Y
(
"
send
"
),
LFUNCVAL
(
spi_send_recv
)
},
LROT_FUNCENTR
Y
(
send
,
spi_send_recv
)
{
LSTRKE
Y
(
"
recv
"
),
LFUNCVAL
(
spi_recv
)
},
LROT_FUNCENTR
Y
(
recv
,
spi_recv
)
{
LSTRKE
Y
(
"
set_mosi
"
),
LFUNCVAL
(
spi_set_mosi
)
},
LROT_FUNCENTR
Y
(
set_mosi
,
spi_set_mosi
)
{
LSTRKE
Y
(
"
get_miso
"
),
LFUNCVAL
(
spi_get_miso
)
},
LROT_FUNCENTR
Y
(
get_miso
,
spi_get_miso
)
{
LSTRKE
Y
(
"
transaction
"
),
LFUNCVAL
(
spi_transaction
)
},
LROT_FUNCENTR
Y
(
transaction
,
spi_transaction
)
{
LSTRKE
Y
(
"
set_clock_div
"
),
LFUNCVAL
(
spi_set_clock_div
)
},
LROT_FUNCENTR
Y
(
set_clock_div
,
spi_set_clock_div
)
{
LSTRKE
Y
(
"
MASTER
"
),
LNUMVAL
(
PLATFORM_SPI_MASTER
)
},
LROT_NUMENTR
Y
(
MASTER
,
PLATFORM_SPI_MASTER
)
{
LSTRKE
Y
(
"
SLAVE
"
),
LNUMVAL
(
PLATFORM_SPI_SLAVE
)
},
LROT_NUMENTR
Y
(
SLAVE
,
PLATFORM_SPI_SLAVE
)
{
LSTRKE
Y
(
"
CPHA_LOW
"
),
LNUMVAL
(
PLATFORM_SPI_CPHA_LOW
)
},
LROT_NUMENTR
Y
(
CPHA_LOW
,
PLATFORM_SPI_CPHA_LOW
)
{
LSTRKE
Y
(
"
CPHA_HIGH
"
),
LNUMVAL
(
PLATFORM_SPI_CPHA_HIGH
)
},
LROT_NUMENTR
Y
(
CPHA_HIGH
,
PLATFORM_SPI_CPHA_HIGH
)
{
LSTRKE
Y
(
"
CPOL_LOW
"
),
LNUMVAL
(
PLATFORM_SPI_CPOL_LOW
)
},
LROT_NUMENTR
Y
(
CPOL_LOW
,
PLATFORM_SPI_CPOL_LOW
)
{
LSTRKE
Y
(
"
CPOL_HIGH
"
),
LNUMVAL
(
PLATFORM_SPI_CPOL_HIGH
)
},
LROT_NUMENTR
Y
(
CPOL_HIGH
,
PLATFORM_SPI_CPOL_HIGH
)
{
LSTRKE
Y
(
"
DATABITS_8
"
),
LNUMVAL
(
8
)
},
LROT_NUMENTR
Y
(
DATABITS_8
,
8
)
{
LSTRKE
Y
(
"
HALFDUPLEX
"
),
LNUMVAL
(
SPI_HALFDUPLEX
)
},
LROT_NUMENTR
Y
(
HALFDUPLEX
,
SPI_HALFDUPLEX
)
{
LSTRKE
Y
(
"
FULLDUPLEX
"
),
LNUMVAL
(
SPI_FULLDUPLEX
)
},
LROT_NUMENTR
Y
(
FULLDUPLEX
,
SPI_FULLDUPLEX
)
{
LNILKEY
,
LNILVAL
}
LROT_END
(
spi
,
NULL
,
0
)
};
NODEMCU_MODULE
(
SPI
,
"spi"
,
spi
_map
,
NULL
);
NODEMCU_MODULE
(
SPI
,
"spi"
,
spi
,
NULL
);
app/modules/sqlite3.c
View file @
310faf7f
...
@@ -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
app/modules/struct.c
View file @
310faf7f
...
@@ -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
);
...
...
app/modules/switec.c
View file @
310faf7f
...
@@ -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
)
{
LSTRKE
Y
(
"
setup
"
),
LFUNCVAL
(
lswitec_setup
)
},
LROT_FUNCENTR
Y
(
setup
,
lswitec_setup
)
{
LSTRKE
Y
(
"
close
"
),
LFUNCVAL
(
lswitec_close
)
},
LROT_FUNCENTR
Y
(
close
,
lswitec_close
)
{
LSTRKE
Y
(
"
reset
"
),
LFUNCVAL
(
lswitec_reset
)
},
LROT_FUNCENTR
Y
(
reset
,
lswitec_reset
)
{
LSTRKE
Y
(
"
moveto
"
),
LFUNCVAL
(
lswitec_moveto
)
},
LROT_FUNCENTR
Y
(
moveto
,
lswitec_moveto
)
{
LSTRKE
Y
(
"
getpos
"
),
LFUNCVAL
(
lswitec_getpos
)
},
LROT_FUNCENTR
Y
(
getpos
,
lswitec_getpos
)
#ifdef SQITEC_DEBUG
#ifdef SQITEC_DEBUG
{
LSTRKE
Y
(
"
dequeue
"
),
LFUNCVAL
(
lswitec_dequeue
)
},
LROT_FUNCENTR
Y
(
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
);
app/modules/tcs34725.c
View file @
310faf7f
...
@@ -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
app/modules/tls.c
View file @
310faf7f
...
@@ -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
_z
alloc
(
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
_z
alloc
(
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
)
{
LSTRKE
Y
(
"
connect
"
),
LFUNCVAL
(
tls_socket_connect
)
},
LROT_FUNCENTR
Y
(
connect
,
tls_socket_connect
)
{
LSTRKE
Y
(
"
close
"
),
LFUNCVAL
(
tls_socket_close
)
},
LROT_FUNCENTR
Y
(
close
,
tls_socket_close
)
{
LSTRKE
Y
(
"
on
"
),
LFUNCVAL
(
tls_socket_on
)
},
LROT_FUNCENTR
Y
(
on
,
tls_socket_on
)
{
LSTRKE
Y
(
"
send
"
),
LFUNCVAL
(
tls_socket_send
)
},
LROT_FUNCENTR
Y
(
send
,
tls_socket_send
)
{
LSTRKE
Y
(
"
hold
"
),
LFUNCVAL
(
tls_socket_hold
)
},
LROT_FUNCENTR
Y
(
hold
,
tls_socket_hold
)
{
LSTRKE
Y
(
"
unhold
"
),
LFUNCVAL
(
tls_socket_unhold
)
},
LROT_FUNCENTR
Y
(
unhold
,
tls_socket_unhold
)
{
LSTRKE
Y
(
"
getpeer
"
),
LFUNCVAL
(
tls_socket_getpeer
)
},
LROT_FUNCENTR
Y
(
getpeer
,
tls_socket_getpeer
)
{
LSTRKE
Y
(
"
__gc
"
),
LFUNCVAL
(
tls_socket_delete
)
},
LROT_FUNCENTR
Y
(
__gc
,
tls_socket_delete
)
{
LSTRKE
Y
(
"
__index
"
),
LROVAL
(
tls_socket
_map
)
},
LROT_TABENTR
Y
(
__index
,
tls_socket
)
{
LNILKEY
,
LNILVAL
}
LROT_END
(
tls_socket
,
tls_socket
,
0
)
};
const
LUA_REG_TYPE
tls_cert_map
[]
=
{
LROT_PUBLIC_BEGIN
(
tls_cert
)
{
LSTRKE
Y
(
"
verify
"
),
LFUNCVAL
(
tls_cert_verify
)
},
LROT_FUNCENTR
Y
(
verify
,
tls_cert_verify
)
{
LSTRKE
Y
(
"
auth
"
),
LFUNCVAL
(
tls_cert_auth
)
},
LROT_FUNCENTR
Y
(
auth
,
tls_cert_auth
)
{
LSTRKE
Y
(
"
__index
"
),
LROVAL
(
tls_cert_map
)
},
LROT_TABENTR
Y
(
__index
,
tls_cert
)
{
LNILKEY
,
LNILVAL
}
LROT_END
(
tls_cert
,
tls_cert
,
0
)
};
static
const
LUA_REG_TYPE
tls_map
[]
=
{
LROT_BEGIN
(
tls
)
{
LSTRKE
Y
(
"
createConnection
"
),
LFUNCVAL
(
tls_socket_create
)
},
LROT_FUNCENTR
Y
(
createConnection
,
tls_socket_create
)
#if defined(MBEDTLS_DEBUG_C)
#if defined(MBEDTLS_DEBUG_C)
{
LSTRKE
Y
(
"
setDebug
"
),
LFUNCVAL
(
tls_set_debug_threshold
)
},
LROT_FUNCENTR
Y
(
setDebug
,
tls_set_debug_threshold
)
#endif
#endif
{
LSTRKE
Y
(
"
cert
"
),
LROVAL
(
tls_cert_map
)
},
LROT_TABENTR
Y
(
cert
,
tls_cert
)
{
LSTRKE
Y
(
"
__metatable
"
),
LROVAL
(
tls_map
)
},
LROT_TABENTR
Y
(
__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
app/modules/tm1829.c
View file @
310faf7f
#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
);
app/modules/tmr.c
View file @
310faf7f
...
@@ -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
*
t
ime
r_t
;
typedef
timer_struct_t
*
t
m
r_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
){
t
ime
r_t
tmr
=
(
t
ime
r_t
)
arg
;
t
m
r_t
tmr
=
(
t
m
r_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
t
ime
r_t
tmr_get
(
lua_State
*
L
,
int
stack
)
{
static
t
m
r_t
tmr_get
(
lua_State
*
L
,
int
stack
)
{
t
ime
r_t
t
=
(
t
ime
r_t
)
luaL_checkudata
(
L
,
stack
,
"tmr.timer"
);
t
m
r_t
t
=
(
t
m
r_t
)
luaL_checkudata
(
L
,
stack
,
"tmr.timer"
);
if
(
t
==
NULL
)
if
(
t
==
NULL
)
return
(
t
ime
r_t
)
luaL_error
(
L
,
"timer object expected"
);
return
(
t
m
r_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
){
t
ime
r_t
tmr
=
tmr_get
(
L
,
1
);
t
m
r_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
){
t
ime
r_t
tmr
=
tmr_get
(
L
,
1
);
t
m
r_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
){
t
ime
r_t
tmr
=
tmr_get
(
L
,
1
);
t
m
r_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
){
t
ime
r_t
tmr
=
tmr_get
(
L
,
1
);
t
m
r_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
){
t
ime
r_t
tmr
=
tmr_get
(
L
,
1
);
t
m
r_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
){
t
ime
r_t
tmr
=
tmr_get
(
L
,
1
);
t
m
r_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
)
{
t
ime
r_t
ud
=
(
t
ime
r_t
)
lua_newuserdata
(
L
,
sizeof
(
timer_struct_t
));
t
m
r_t
ud
=
(
t
m
r_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
)
{
LSTRKE
Y
(
"
register
"
),
LFUNCVAL
(
tmr_register
)
},
LROT_FUNCENTR
Y
(
register
,
tmr_register
)
{
LSTRKE
Y
(
"
alarm
"
),
LFUNCVAL
(
tmr_alarm
)
},
LROT_FUNCENTR
Y
(
alarm
,
tmr_alarm
)
{
LSTRKE
Y
(
"
start
"
),
LFUNCVAL
(
tmr_start
)
},
LROT_FUNCENTR
Y
(
start
,
tmr_start
)
{
LSTRKE
Y
(
"
stop
"
),
LFUNCVAL
(
tmr_stop
)
},
LROT_FUNCENTR
Y
(
stop
,
tmr_stop
)
{
LSTRKE
Y
(
"
unregister
"
),
LFUNCVAL
(
tmr_unregister
)
},
LROT_FUNCENTR
Y
(
unregister
,
tmr_unregister
)
{
LSTRKE
Y
(
"
state
"
),
LFUNCVAL
(
tmr_state
)
},
LROT_FUNCENTR
Y
(
state
,
tmr_state
)
{
LSTRKE
Y
(
"
interval
"
),
LFUNCVAL
(
tmr_interval
)
},
LROT_FUNCENTR
Y
(
interval
,
tmr_interval
)
#ifdef TIMER_SUSPEND_ENABLE
#ifdef TIMER_SUSPEND_ENABLE
{
LSTRKE
Y
(
"
suspend
"
),
LFUNCVAL
(
tmr_suspend
)
},
LROT_FUNCENTR
Y
(
suspend
,
tmr_suspend
)
{
LSTRKE
Y
(
"
resume
"
),
LFUNCVAL
(
tmr_resume
)
},
LROT_FUNCENTR
Y
(
resume
,
tmr_resume
)
#endif
#endif
{
LSTRKE
Y
(
"
__gc
"
),
LFUNCVAL
(
tmr_unregister
)
},
LROT_FUNCENTR
Y
(
__gc
,
tmr_unregister
)
{
LSTRKE
Y
(
"
__index
"
),
LROVAL
(
tmr_dyn_map
)
},
LROT_TABENTR
Y
(
__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
)
{
LSTRKE
Y
(
"
delay
"
),
LFUNCVAL
(
tmr_delay
)
},
LROT_FUNCENTR
Y
(
delay
,
tmr_delay
)
{
LSTRKE
Y
(
"
now
"
),
LFUNCVAL
(
tmr_now
)
},
LROT_FUNCENTR
Y
(
now
,
tmr_now
)
{
LSTRKE
Y
(
"
wdclr
"
),
LFUNCVAL
(
tmr_wdclr
)
},
LROT_FUNCENTR
Y
(
wdclr
,
tmr_wdclr
)
{
LSTRKE
Y
(
"
softwd
"
),
LFUNCVAL
(
tmr_softwd
)
},
LROT_FUNCENTR
Y
(
softwd
,
tmr_softwd
)
{
LSTRKE
Y
(
"
time
"
),
LFUNCVAL
(
tmr_time
)
},
LROT_FUNCENTR
Y
(
time
,
tmr_time
)
#ifdef TIMER_SUSPEND_ENABLE
#ifdef TIMER_SUSPEND_ENABLE
{
LSTRKE
Y
(
"
suspend_all
"
),
LFUNCVAL
(
tmr_suspend_all
)
},
LROT_FUNCENTR
Y
(
suspend_all
,
tmr_suspend_all
)
{
LSTRKE
Y
(
"
resume_all
"
),
LFUNCVAL
(
tmr_resume_all
)
},
LROT_FUNCENTR
Y
(
resume_all
,
tmr_resume_all
)
#endif
#endif
{
LSTRKE
Y
(
"
create
"
),
LFUNCVAL
(
tmr_create
)
},
LROT_FUNCENTR
Y
(
create
,
tmr_create
)
{
LSTRKE
Y
(
"
ALARM_SINGLE
"
),
LNUMVAL
(
TIMER_MODE_SINGLE
)
},
LROT_NUMENTR
Y
(
ALARM_SINGLE
,
TIMER_MODE_SINGLE
)
{
LSTRKE
Y
(
"
ALARM_SEMI
"
),
LNUMVAL
(
TIMER_MODE_SEMI
)
},
LROT_NUMENTR
Y
(
ALARM_SEMI
,
TIMER_MODE_SEMI
)
{
LSTRKE
Y
(
"
ALARM_AUTO
"
),
LNUMVAL
(
TIMER_MODE_AUTO
)
},
LROT_NUMENTR
Y
(
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
);
app/modules/tsl2561.c
View file @
310faf7f
...
@@ -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
);
app/modules/u8g2.c
View file @
310faf7f
...
@@ -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
//
//
{
LSTRKE
Y
(
"
DRAW_UPPER_RIGHT
"
),
LNUMVAL
(
U8G2_DRAW_UPPER_RIGHT
)
},
LROT_NUMENTR
Y
(
DRAW_UPPER_RIGHT
,
U8G2_DRAW_UPPER_RIGHT
)
{
LSTRKE
Y
(
"
DRAW_UPPER_LEFT
"
),
LNUMVAL
(
U8G2_DRAW_UPPER_LEFT
)
},
LROT_NUMENTR
Y
(
DRAW_UPPER_LEFT
,
U8G2_DRAW_UPPER_LEFT
)
{
LSTRKE
Y
(
"
DRAW_LOWER_RIGHT
"
),
LNUMVAL
(
U8G2_DRAW_LOWER_RIGHT
)
},
LROT_NUMENTR
Y
(
DRAW_LOWER_RIGHT
,
U8G2_DRAW_LOWER_RIGHT
)
{
LSTRKE
Y
(
"
DRAW_LOWER_LEFT
"
),
LNUMVAL
(
U8G2_DRAW_LOWER_LEFT
)
},
LROT_NUMENTR
Y
(
DRAW_LOWER_LEFT
,
U8G2_DRAW_LOWER_LEFT
)
{
LSTRKE
Y
(
"
DRAW_ALL
"
),
LNUMVAL
(
U8G2_DRAW_ALL
)
},
LROT_NUMENTR
Y
(
DRAW_ALL
,
U8G2_DRAW_ALL
)
{
LSTRKE
Y
(
"
R0
"
),
LUDATA
(
(
void
*
)
U8G2_R0
)
},
LROT_LUDENTR
Y
(
R0
,
U8G2_R0
)
{
LSTRKE
Y
(
"
R1
"
),
LUDATA
(
(
void
*
)
U8G2_R1
)
},
LROT_LUDENTR
Y
(
R1
,
U8G2_R1
)
{
LSTRKE
Y
(
"
R2
"
),
LUDATA
(
(
void
*
)
U8G2_R2
)
},
LROT_LUDENTR
Y
(
R2
,
U8G2_R2
)
{
LSTRKE
Y
(
"
R3
"
),
LUDATA
(
(
void
*
)
U8G2_R3
)
},
LROT_LUDENTR
Y
(
R3
,
U8G2_R3
)
{
LSTRKE
Y
(
"
MIRROR
"
),
LUDATA
(
(
void
*
)
U8G2_MIRROR
)
},
LROT_LUDENTR
Y
(
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) */
app/modules/uart.c
View file @
310faf7f
...
@@ -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
)
{
LSTRKE
Y
(
"
setup
"
),
LFUNCVAL
(
l_uart_setup
)
},
LROT_FUNCENTR
Y
(
setup
,
l_uart_setup
)
{
LSTRKE
Y
(
"
getconfig
"
),
LFUNCVAL
(
l_uart_getconfig
)
},
LROT_FUNCENTR
Y
(
getconfig
,
l_uart_getconfig
)
{
LSTRKE
Y
(
"
write
"
),
LFUNCVAL
(
l_uart_write
)
},
LROT_FUNCENTR
Y
(
write
,
l_uart_write
)
{
LSTRKE
Y
(
"
on
"
),
LFUNCVAL
(
l_uart_on
)
},
LROT_FUNCENTR
Y
(
on
,
l_uart_on
)
{
LSTRKE
Y
(
"
alt
"
),
LFUNCVAL
(
l_uart_alt
)
},
LROT_FUNCENTR
Y
(
alt
,
l_uart_alt
)
{
LSTRKE
Y
(
"
STOPBITS_1
"
),
LNUMVAL
(
PLATFORM_UART_STOPBITS_1
)
},
LROT_NUMENTR
Y
(
STOPBITS_1
,
PLATFORM_UART_STOPBITS_1
)
{
LSTRKE
Y
(
"
STOPBITS_1_5
"
),
LNUMVAL
(
PLATFORM_UART_STOPBITS_1_5
)
},
LROT_NUMENTR
Y
(
STOPBITS_1_5
,
PLATFORM_UART_STOPBITS_1_5
)
{
LSTRKE
Y
(
"
STOPBITS_2
"
),
LNUMVAL
(
PLATFORM_UART_STOPBITS_2
)
},
LROT_NUMENTR
Y
(
STOPBITS_2
,
PLATFORM_UART_STOPBITS_2
)
{
LSTRKE
Y
(
"
PARITY_NONE
"
),
LNUMVAL
(
PLATFORM_UART_PARITY_NONE
)
},
LROT_NUMENTR
Y
(
PARITY_NONE
,
PLATFORM_UART_PARITY_NONE
)
{
LSTRKE
Y
(
"
PARITY_EVEN
"
),
LNUMVAL
(
PLATFORM_UART_PARITY_EVEN
)
},
LROT_NUMENTR
Y
(
PARITY_EVEN
,
PLATFORM_UART_PARITY_EVEN
)
{
LSTRKE
Y
(
"
PARITY_ODD
"
),
LNUMVAL
(
PLATFORM_UART_PARITY_ODD
)
},
LROT_NUMENTR
Y
(
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
);
app/modules/ucg.c
View file @
310faf7f
...
@@ -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
{
LSTRKE
Y
(
"
FONT_MODE_TRANSPARENT
"
),
LNUMVAL
(
UCG_FONT_MODE_TRANSPARENT
)
},
LROT_NUMENTR
Y
(
FONT_MODE_TRANSPARENT
,
UCG_FONT_MODE_TRANSPARENT
)
{
LSTRKE
Y
(
"
FONT_MODE_SOLID
"
),
LNUMVAL
(
UCG_FONT_MODE_SOLID
)
},
LROT_NUMENTR
Y
(
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 */
app/modules/websocket.c
View file @
310faf7f
...
@@ -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
);
app/modules/wifi.c
View file @
310faf7f
...
@@ -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
)
{
LSTRKE
Y
(
"
autoconnect
"
),
LFUNCVAL
(
wifi_station_setauto
)
},
LROT_FUNCENTR
Y
(
autoconnect
,
wifi_station_setauto
)
{
LSTRKE
Y
(
"
changeap
"
),
LFUNCVAL
(
wifi_station_change_ap
)
},
LROT_FUNCENTR
Y
(
changeap
,
wifi_station_change_ap
)
{
LSTRKE
Y
(
"
clearconfig
"
),
LFUNCVAL
(
wifi_station_clear_config
)
},
LROT_FUNCENTR
Y
(
clearconfig
,
wifi_station_clear_config
)
{
LSTRKE
Y
(
"
config
"
),
LFUNCVAL
(
wifi_station_config
)
},
LROT_FUNCENTR
Y
(
config
,
wifi_station_config
)
{
LSTRKE
Y
(
"
connect
"
),
LFUNCVAL
(
wifi_station_connect4lua
)
},
LROT_FUNCENTR
Y
(
connect
,
wifi_station_connect4lua
)
{
LSTRKE
Y
(
"
disconnect
"
),
LFUNCVAL
(
wifi_station_disconnect4lua
)
},
LROT_FUNCENTR
Y
(
disconnect
,
wifi_station_disconnect4lua
)
{
LSTRKE
Y
(
"
getap
"
),
LFUNCVAL
(
wifi_station_listap
)
},
LROT_FUNCENTR
Y
(
getap
,
wifi_station_listap
)
{
LSTRKE
Y
(
"
getapindex
"
),
LFUNCVAL
(
wifi_station_get_ap_index
)
},
LROT_FUNCENTR
Y
(
getapindex
,
wifi_station_get_ap_index
)
{
LSTRKE
Y
(
"
getapinfo
"
),
LFUNCVAL
(
wifi_station_get_ap_info4lua
)
},
LROT_FUNCENTR
Y
(
getapinfo
,
wifi_station_get_ap_info4lua
)
{
LSTRKE
Y
(
"
getbroadcast
"
),
LFUNCVAL
(
wifi_station_getbroadcast
)
},
LROT_FUNCENTR
Y
(
getbroadcast
,
wifi_station_getbroadcast
)
{
LSTRKE
Y
(
"
getconfig
"
),
LFUNCVAL
(
wifi_station_getconfig_current
)
},
LROT_FUNCENTR
Y
(
getconfig
,
wifi_station_getconfig_current
)
{
LSTRKE
Y
(
"
getdefaultconfig
"
),
LFUNCVAL
(
wifi_station_getconfig_default
)
},
LROT_FUNCENTR
Y
(
getdefaultconfig
,
wifi_station_getconfig_default
)
{
LSTRKE
Y
(
"
gethostname
"
),
LFUNCVAL
(
wifi_sta_gethostname
)
},
LROT_FUNCENTR
Y
(
gethostname
,
wifi_sta_gethostname
)
{
LSTRKE
Y
(
"
getip
"
),
LFUNCVAL
(
wifi_station_getip
)
},
LROT_FUNCENTR
Y
(
getip
,
wifi_station_getip
)
{
LSTRKE
Y
(
"
getmac
"
),
LFUNCVAL
(
wifi_station_getmac
)
},
LROT_FUNCENTR
Y
(
getmac
,
wifi_station_getmac
)
{
LSTRKE
Y
(
"
getrssi
"
),
LFUNCVAL
(
wifi_station_getrssi
)
},
LROT_FUNCENTR
Y
(
getrssi
,
wifi_station_getrssi
)
{
LSTRKE
Y
(
"
setaplimit
"
),
LFUNCVAL
(
wifi_station_ap_number_set4lua
)
},
LROT_FUNCENTR
Y
(
setaplimit
,
wifi_station_ap_number_set4lua
)
{
LSTRKE
Y
(
"
sethostname
"
),
LFUNCVAL
(
wifi_sta_sethostname_lua
)
},
LROT_FUNCENTR
Y
(
sethostname
,
wifi_sta_sethostname_lua
)
{
LSTRKE
Y
(
"
setip
"
),
LFUNCVAL
(
wifi_station_setip
)
},
LROT_FUNCENTR
Y
(
setip
,
wifi_station_setip
)
{
LSTRKE
Y
(
"
setmac
"
),
LFUNCVAL
(
wifi_station_setmac
)
},
LROT_FUNCENTR
Y
(
setmac
,
wifi_station_setmac
)
{
LSTRKE
Y
(
"
sleeptype
"
),
LFUNCVAL
(
wifi_station_sleeptype
)
},
LROT_FUNCENTR
Y
(
sleeptype
,
wifi_station_sleeptype
)
{
LSTRKE
Y
(
"
status
"
),
LFUNCVAL
(
wifi_station_status
)
},
LROT_FUNCENTR
Y
(
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
)
{
LSTRKE
Y
(
"
config
"
),
LFUNCVAL
(
wifi_ap_dhcp_config
)
},
LROT_FUNCENTR
Y
(
config
,
wifi_ap_dhcp_config
)
{
LSTRKE
Y
(
"
start
"
),
LFUNCVAL
(
wifi_ap_dhcp_start
)
},
LROT_FUNCENTR
Y
(
start
,
wifi_ap_dhcp_start
)
{
LSTRKE
Y
(
"
stop
"
),
LFUNCVAL
(
wifi_ap_dhcp_stop
)
},
LROT_FUNCENTR
Y
(
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
)
{
LSTRKE
Y
(
"
config
"
),
LFUNCVAL
(
wifi_ap_config
)
},
LROT_FUNCENTR
Y
(
config
,
wifi_ap_config
)
{
LSTRKE
Y
(
"
deauth
"
),
LFUNCVAL
(
wifi_ap_deauth
)
},
LROT_FUNCENTR
Y
(
deauth
,
wifi_ap_deauth
)
{
LSTRKE
Y
(
"
getip
"
),
LFUNCVAL
(
wifi_ap_getip
)
},
LROT_FUNCENTR
Y
(
getip
,
wifi_ap_getip
)
{
LSTRKE
Y
(
"
setip
"
),
LFUNCVAL
(
wifi_ap_setip
)
},
LROT_FUNCENTR
Y
(
setip
,
wifi_ap_setip
)
{
LSTRKE
Y
(
"
getbroadcast
"
),
LFUNCVAL
(
wifi_ap_getbroadcast
)
},
LROT_FUNCENTR
Y
(
getbroadcast
,
wifi_ap_getbroadcast
)
{
LSTRKE
Y
(
"
getmac
"
),
LFUNCVAL
(
wifi_ap_getmac
)
},
LROT_FUNCENTR
Y
(
getmac
,
wifi_ap_getmac
)
{
LSTRKE
Y
(
"
setmac
"
),
LFUNCVAL
(
wifi_ap_setmac
)
},
LROT_FUNCENTR
Y
(
setmac
,
wifi_ap_setmac
)
{
LSTRKE
Y
(
"
getclient
"
),
LFUNCVAL
(
wifi_ap_listclient
)
},
LROT_FUNCENTR
Y
(
getclient
,
wifi_ap_listclient
)
{
LSTRKE
Y
(
"
getconfig
"
),
LFUNCVAL
(
wifi_ap_getconfig_current
)
},
LROT_FUNCENTR
Y
(
getconfig
,
wifi_ap_getconfig_current
)
{
LSTRKE
Y
(
"
getdefaultconfig
"
),
LFUNCVAL
(
wifi_ap_getconfig_default
)
},
LROT_FUNCENTR
Y
(
getdefaultconfig
,
wifi_ap_getconfig_default
)
{
LSTRKE
Y
(
"
dhcp
"
),
LROVAL
(
wifi_ap_dhcp
_map
)
},
LROT_TABENTR
Y
(
dhcp
,
wifi_ap_dhcp
)
//
{
L
STRKE
Y(
"
__metatable
" ), LROVAL( wifi_ap_map ) },
//
L
ROT_TABENTR
Y( __metatable
, wifi_ap )
{
LNILKEY
,
LNILVAL
}
LROT_END
(
wifi_ap
,
wifi_ap
,
0
)
};
static
const
LUA_REG_TYPE
wifi_map
[]
=
{
LROT_BEGIN
(
wifi
)
{
LSTRKE
Y
(
"
setmode
"
),
LFUNCVAL
(
wifi_setmode
)
},
LROT_FUNCENTR
Y
(
setmode
,
wifi_setmode
)
{
LSTRKE
Y
(
"
getmode
"
),
LFUNCVAL
(
wifi_getmode
)
},
LROT_FUNCENTR
Y
(
getmode
,
wifi_getmode
)
{
LSTRKE
Y
(
"
getdefaultmode
"
),
LFUNCVAL
(
wifi_getdefaultmode
)
},
LROT_FUNCENTR
Y
(
getdefaultmode
,
wifi_getdefaultmode
)
{
LSTRKE
Y
(
"
getchannel
"
),
LFUNCVAL
(
wifi_getchannel
)
},
LROT_FUNCENTR
Y
(
getchannel
,
wifi_getchannel
)
{
LSTRKE
Y
(
"
getcountry
"
),
LFUNCVAL
(
wifi_getcountry
)
},
LROT_FUNCENTR
Y
(
getcountry
,
wifi_getcountry
)
{
LSTRKE
Y
(
"
setcountry
"
),
LFUNCVAL
(
wifi_setcountry
)
},
LROT_FUNCENTR
Y
(
setcountry
,
wifi_setcountry
)
{
LSTRKE
Y
(
"
setphymode
"
),
LFUNCVAL
(
wifi_setphymode
)
},
LROT_FUNCENTR
Y
(
setphymode
,
wifi_setphymode
)
{
LSTRKE
Y
(
"
getphymode
"
),
LFUNCVAL
(
wifi_getphymode
)
},
LROT_FUNCENTR
Y
(
getphymode
,
wifi_getphymode
)
{
LSTRKE
Y
(
"
setmaxtxpower
"
),
LFUNCVAL
(
wifi_setmaxtxpower
)
},
LROT_FUNCENTR
Y
(
setmaxtxpower
,
wifi_setmaxtxpower
)
{
LSTRKE
Y
(
"
suspend
"
),
LFUNCVAL
(
wifi_suspend
)
},
LROT_FUNCENTR
Y
(
suspend
,
wifi_suspend
)
{
LSTRKE
Y
(
"
resume
"
),
LFUNCVAL
(
wifi_resume
)
},
LROT_FUNCENTR
Y
(
resume
,
wifi_resume
)
{
LSTRKE
Y
(
"
nullmodesleep
"
),
LFUNCVAL
(
wifi_null_mode_auto_sleep
)
},
LROT_FUNCENTR
Y
(
nullmodesleep
,
wifi_null_mode_auto_sleep
)
#ifdef WIFI_SMART_ENABLE
#ifdef WIFI_SMART_ENABLE
{
LSTRKE
Y
(
"
startsmart
"
),
LFUNCVAL
(
wifi_start_smart
)
},
LROT_FUNCENTR
Y
(
startsmart
,
wifi_start_smart
)
{
LSTRKE
Y
(
"
stopsmart
"
),
LFUNCVAL
(
wifi_exit_smart
)
},
LROT_FUNCENTR
Y
(
stopsmart
,
wifi_exit_smart
)
#endif
#endif
{
LSTRKE
Y
(
"
sleeptype
"
),
LFUNCVAL
(
wifi_station_sleeptype
)
},
LROT_FUNCENTR
Y
(
sleeptype
,
wifi_station_sleeptype
)
{
LSTRKE
Y
(
"
sta
"
),
LROVAL
(
wifi_station
_map
)
},
LROT_TABENTR
Y
(
sta
,
wifi_station
)
{
LSTRKE
Y
(
"
ap
"
),
LROVAL
(
wifi_ap_map
)
},
LROT_TABENTR
Y
(
ap
,
wifi_ap
)
#if defined(WIFI_SDK_EVENT_MONITOR_ENABLE)
#if defined(WIFI_SDK_EVENT_MONITOR_ENABLE)
{
LSTRKE
Y
(
"
eventmon
"
),
LROVAL
(
wifi_event_monitor_map
)
},
//declared in wifi_eventmon.c
LROT_TABENTR
Y
(
eventmon
,
wifi_event_monitor
)
#endif
#endif
#if defined(LUA_USE_MODULES_WIFI_MONITOR)
#if defined(LUA_USE_MODULES_WIFI_MONITOR)
{
LSTRKE
Y
(
"
monitor
"
),
LROVAL
(
wifi_monitor_map
)
},
//declared in wifi_monitor.c
LROT_TABENTR
Y
(
monitor
,
wifi_monitor
)
#endif
#endif
{
LSTRKE
Y
(
"
NULLMODE
"
),
LNUMVAL
(
NULL_MODE
)
},
LROT_NUMENTR
Y
(
NULLMODE
,
NULL_MODE
)
{
LSTRKE
Y
(
"
STATION
"
),
LNUMVAL
(
STATION_MODE
)
},
LROT_NUMENTR
Y
(
STATION
,
STATION_MODE
)
{
LSTRKE
Y
(
"
SOFTAP
"
),
LNUMVAL
(
SOFTAP_MODE
)
},
LROT_NUMENTR
Y
(
SOFTAP
,
SOFTAP_MODE
)
{
LSTRKE
Y
(
"
STATIONAP
"
),
LNUMVAL
(
STATIONAP_MODE
)
},
LROT_NUMENTR
Y
(
STATIONAP
,
STATIONAP_MODE
)
{
LSTRKE
Y
(
"
PHYMODE_B
"
),
LNUMVAL
(
PHY_MODE_11B
)
},
LROT_NUMENTR
Y
(
PHYMODE_B
,
PHY_MODE_11B
)
{
LSTRKE
Y
(
"
PHYMODE_G
"
),
LNUMVAL
(
PHY_MODE_11G
)
},
LROT_NUMENTR
Y
(
PHYMODE_G
,
PHY_MODE_11G
)
{
LSTRKE
Y
(
"
PHYMODE_N
"
),
LNUMVAL
(
PHY_MODE_11N
)
},
LROT_NUMENTR
Y
(
PHYMODE_N
,
PHY_MODE_11N
)
{
LSTRKE
Y
(
"
NONE_SLEEP
"
),
LNUMVAL
(
NONE_SLEEP_T
)
},
LROT_NUMENTR
Y
(
NONE_SLEEP
,
NONE_SLEEP_T
)
{
LSTRKE
Y
(
"
LIGHT_SLEEP
"
),
LNUMVAL
(
LIGHT_SLEEP_T
)
},
LROT_NUMENTR
Y
(
LIGHT_SLEEP
,
LIGHT_SLEEP_T
)
{
LSTRKE
Y
(
"
MODEM_SLEEP
"
),
LNUMVAL
(
MODEM_SLEEP_T
)
},
LROT_NUMENTR
Y
(
MODEM_SLEEP
,
MODEM_SLEEP_T
)
{
LSTRKE
Y
(
"
OPEN
"
),
LNUMVAL
(
AUTH_OPEN
)
},
LROT_NUMENTR
Y
(
OPEN
,
AUTH_OPEN
)
//
{
L
STRKE
Y(
"
WEP
" ), LNUMVAL(
AUTH_WEP )
},
//
L
ROT_NUMENTR
Y( WEP
,
AUTH_WEP )
{
LSTRKE
Y
(
"
WPA_PSK
"
),
LNUMVAL
(
AUTH_WPA_PSK
)
},
LROT_NUMENTR
Y
(
WPA_PSK
,
AUTH_WPA_PSK
)
{
LSTRKE
Y
(
"
WPA2_PSK
"
),
LNUMVAL
(
AUTH_WPA2_PSK
)
},
LROT_NUMENTR
Y
(
WPA2_PSK
,
AUTH_WPA2_PSK
)
{
LSTRKE
Y
(
"
WPA_WPA2_PSK
"
),
LNUMVAL
(
AUTH_WPA_WPA2_PSK
)
},
LROT_NUMENTR
Y
(
WPA_WPA2_PSK
,
AUTH_WPA_WPA2_PSK
)
{
LSTRKE
Y
(
"
STA_IDLE
"
),
LNUMVAL
(
STATION_IDLE
)
},
LROT_NUMENTR
Y
(
STA_IDLE
,
STATION_IDLE
)
{
LSTRKE
Y
(
"
STA_CONNECTING
"
),
LNUMVAL
(
STATION_CONNECTING
)
},
LROT_NUMENTR
Y
(
STA_CONNECTING
,
STATION_CONNECTING
)
{
LSTRKE
Y
(
"
STA_WRONGPWD
"
),
LNUMVAL
(
STATION_WRONG_PASSWORD
)
},
LROT_NUMENTR
Y
(
STA_WRONGPWD
,
STATION_WRONG_PASSWORD
)
{
LSTRKE
Y
(
"
STA_APNOTFOUND
"
),
LNUMVAL
(
STATION_NO_AP_FOUND
)
},
LROT_NUMENTR
Y
(
STA_APNOTFOUND
,
STATION_NO_AP_FOUND
)
{
LSTRKE
Y
(
"
STA_FAIL
"
),
LNUMVAL
(
STATION_CONNECT_FAIL
)
},
LROT_NUMENTR
Y
(
STA_FAIL
,
STATION_CONNECT_FAIL
)
{
LSTRKE
Y
(
"
STA_GOTIP
"
),
LNUMVAL
(
STATION_GOT_IP
)
},
LROT_NUMENTR
Y
(
STA_GOTIP
,
STATION_GOT_IP
)
{
LSTRKE
Y
(
"
COUNTRY_AUTO
"
),
LNUMVAL
(
WIFI_COUNTRY_POLICY_AUTO
)
},
LROT_NUMENTR
Y
(
COUNTRY_AUTO
,
WIFI_COUNTRY_POLICY_AUTO
)
{
LSTRKE
Y
(
"
COUNTRY_MANUAL
"
),
LNUMVAL
(
WIFI_COUNTRY_POLICY_MANUAL
)
},
LROT_NUMENTR
Y
(
COUNTRY_MANUAL
,
WIFI_COUNTRY_POLICY_MANUAL
)
{
LSTRKE
Y
(
"
__metatable
"
),
LROVAL
(
wifi_map
)
},
LROT_TABENTR
Y
(
__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
);
app/modules/wifi_common.c
View file @
310faf7f
...
@@ -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
);
...
...
app/modules/wifi_common.h
View file @
310faf7f
...
@@ -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
...
...
app/modules/wifi_eventmon.c
View file @
310faf7f
...
@@ -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
(
4
WAY_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
{
LSTRKE
Y
(
"
reason
"
),
LROVAL
(
wifi_event_monitor_reason
_map
)
},
LROT_TABENTR
Y
(
reason
,
wifi_event_monitor_reason
)
#endif
#endif
{
LNILKEY
,
LNILVAL
}
LROT_END
(
wifi_event_monitor
,
NULL
,
0
)
};
void
wifi_eventmon_init
()
void
wifi_eventmon_init
()
{
{
...
...
app/modules/wifi_monitor.c
View file @
310faf7f
...
@@ -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
)
{
LSTRKE
Y
(
"
start
"
),
LFUNCVAL
(
wifi_monitor_start
)
},
LROT_FUNCENTR
Y
(
start
,
wifi_monitor_start
)
{
LSTRKE
Y
(
"
stop
"
),
LFUNCVAL
(
wifi_monitor_stop
)
},
LROT_FUNCENTR
Y
(
stop
,
wifi_monitor_stop
)
{
LSTRKE
Y
(
"
channel
"
),
LFUNCVAL
(
wifi_monitor_channel
)
},
LROT_FUNCENTR
Y
(
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
();
...
...
app/modules/wps.c
View file @
310faf7f
...
@@ -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
)
{
LSTRKE
Y
(
"
disable
"
),
LFUNCVAL
(
wps_disable
)
},
LROT_FUNCENTR
Y
(
disable
,
wps_disable
)
{
LSTRKE
Y
(
"
enable
"
),
LFUNCVAL
(
wps_enable
)
},
LROT_FUNCENTR
Y
(
enable
,
wps_enable
)
{
LSTRKE
Y
(
"
start
"
),
LFUNCVAL
(
wps_start
)
},
LROT_FUNCENTR
Y
(
start
,
wps_start
)
{
LSTRKE
Y
(
"
SUCCESS
"
),
LNUMVAL
(
WPS_CB_ST_SUCCESS
)
},
LROT_NUMENTR
Y
(
SUCCESS
,
WPS_CB_ST_SUCCESS
)
{
LSTRKE
Y
(
"
FAILED
"
),
LNUMVAL
(
WPS_CB_ST_FAILED
)
},
LROT_NUMENTR
Y
(
FAILED
,
WPS_CB_ST_FAILED
)
{
LSTRKE
Y
(
"
TIMEOUT
"
),
LNUMVAL
(
WPS_CB_ST_TIMEOUT
)
},
LROT_NUMENTR
Y
(
TIMEOUT
,
WPS_CB_ST_TIMEOUT
)
{
LSTRKE
Y
(
"
WEP
"
),
LNUMVAL
(
WPS_CB_ST_WEP
)
},
LROT_NUMENTR
Y
(
WEP
,
WPS_CB_ST_WEP
)
{
LSTRKE
Y
(
"
SCAN_ERR
"
),
LNUMVAL
(
4
)
},
// WPS_CB_ST_SCAN_ERR
LROT_NUMENTR
Y
(
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
);
Prev
1
…
8
9
10
11
12
13
14
15
16
…
19
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment