gpio_pin_wakeup_enable(uint32 i, GPIO_INT_TYPE intr_state);
Posted: Sat Feb 21, 2015 5:34 am
Anyone has any success with it ? That comes with the 0.9.5 and lets you to wake the module via pin interrupt.
-->
Open Community Forum for ESP8266, Come share Arduino and IoT (Internet of Things)
https://www.esp8266.com/
gpio.mode(4, gpio.INPUT, gpio.PULLUP)
node.enablewakeup(4, "both")
node.dsleep(2000)
diff --git a/app/modules/node.c b/app/modules/node.c
index 90dd0d9..a0285ac 100644
--- a/app/modules/node.c
+++ b/app/modules/node.c
@@ -387,6 +387,47 @@ static int node_compile( lua_State* L )
return 0;
}
+/* testing for wakeup enable and disable */
+
+static int node_wakeup_enable( lua_State* L )
+{
+ s32 pin, mode;
+ size_t sl;
+ const char *str;
+
+ pin = luaL_checkinteger( L, 1 );
+ MOD_CHECK_ID( gpio, pin );
+ if(pin==0)
+ return luaL_error( L, "no interrupt for D0" );
+
+ str = luaL_checklstring( L, 2, &sl );
+ if (str == NULL)
+ return luaL_error( L, "wrong arg type" );
+
+ if(sl == 2 && c_strcmp(str, "up") == 0){
+ mode = GPIO_PIN_INTR_POSEDGE;
+ }else if(sl == 4 && c_strcmp(str, "down") == 0){
+ mode = GPIO_PIN_INTR_NEGEDGE;
+ }else if(sl == 4 && c_strcmp(str, "both") == 0){
+ mode = GPIO_PIN_INTR_ANYEGDE;
+ }else if(sl == 3 && c_strcmp(str, "low") == 0){
+ mode = GPIO_PIN_INTR_LOLEVEL;
+ }else if(sl == 4 && c_strcmp(str, "high") == 0){
+ mode = GPIO_PIN_INTR_HILEVEL;
+ }else{
+ return luaL_error( L, "wrong arg type" );
+ }
+
+ gpio_pin_wakeup_enable(pin, mode);
+ return 0;
+}
+
+static int node_wakeup_disable( lua_State* L )
+{
+ gpio_pin_wakeup_disable();
+ return 0;
+}
+
// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
@@ -407,6 +448,9 @@ const LUA_REG_TYPE node_map[] =
{ LSTRKEY( "output" ), LFUNCVAL( node_output ) },
{ LSTRKEY( "readvdd33" ), LFUNCVAL( node_readvdd33) },
{ LSTRKEY( "compile" ), LFUNCVAL( node_compile) },
+
+ { LSTRKEY( "enablewakeup"), LFUNCVAL( node_wakeup_enable ) },
+ { LSTRKEY( "disablewakeup"), LFUNCVAL( node_wakeup_disable ) },
// Combined to dsleep(us, option)
// { LSTRKEY( "dsleepsetoption" ), LFUNCVAL( node_deepsleep_setoption) },
#if LUA_OPTIMIZE_MEMORY > 0