From 04a5e674438132e2190a7cd281df09a510dac8a8 Mon Sep 17 00:00:00 2001 From: funshine Date: Wed, 31 Dec 2014 14:26:51 +0800 Subject: [PATCH] add node.info() to get version, chipid, flash info --- app/include/user_config.h | 5 +++++ app/modules/node.c | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/app/include/user_config.h b/app/include/user_config.h index a9c75301..ddff4cc1 100644 --- a/app/include/user_config.h +++ b/app/include/user_config.h @@ -1,6 +1,11 @@ #ifndef __USER_CONFIG_H__ #define __USER_CONFIG_H__ +#define NODE_VERSION_MAJOR 0U +#define NODE_VERSION_MINOR 9U +#define NODE_VERSION_REVISION 4U +#define NODE_VERSION_INTERNAL 0U + #define NODE_VERSION "NodeMcu 0.9.4" #define BUILD_DATE "build 20141230" // #define FLASH_512K diff --git a/app/modules/node.c b/app/modules/node.c index 3c7a41b2..cc2470cc 100644 --- a/app/modules/node.c +++ b/app/modules/node.c @@ -32,6 +32,20 @@ static int ICACHE_FLASH_ATTR node_deepsleep( lua_State* L ) return 0; } +// Lua: info() +static int ICACHE_FLASH_ATTR node_info( lua_State* L ) +{ + lua_pushinteger(L, NODE_VERSION_MAJOR); + lua_pushinteger(L, NODE_VERSION_MINOR); + lua_pushinteger(L, NODE_VERSION_REVISION); + lua_pushinteger(L, system_get_chip_id()); // chip id + lua_pushinteger(L, spi_flash_get_id()); // flash id + lua_pushinteger(L, flash_get_size_byte() / 1024); // flash size in KB + lua_pushinteger(L, flash_get_mode()); + lua_pushinteger(L, flash_get_speed()); + return 8; +} + // Lua: chipid() static int ICACHE_FLASH_ATTR node_chipid( lua_State* L ) { @@ -264,6 +278,7 @@ const LUA_REG_TYPE node_map[] = { { LSTRKEY( "restart" ), LFUNCVAL( node_restart ) }, { LSTRKEY( "dsleep" ), LFUNCVAL( node_deepsleep ) }, + { LSTRKEY( "info" ), LFUNCVAL( node_info ) }, { LSTRKEY( "chipid" ), LFUNCVAL( node_chipid ) }, { LSTRKEY( "flashid" ), LFUNCVAL( node_flashid ) }, { LSTRKEY( "flashsize" ), LFUNCVAL( node_flashsize) },