diff --git a/app/include/user_config.h b/app/include/user_config.h index 27efbc9a..be3332ef 100644 --- a/app/include/user_config.h +++ b/app/include/user_config.h @@ -1,8 +1,6 @@ #ifndef __USER_CONFIG_H__ #define __USER_CONFIG_H__ -// #define DEVKIT_VERSION_0_9 1 // define this only if you use NodeMCU devkit v0.9 - // #define FLASH_512K // #define FLASH_1M // #define FLASH_2M @@ -87,18 +85,6 @@ extern void luaL_assertfail(const char *file, int line, const char *message); #define LUA_PROCESS_LINE_SIG 2 #define LUA_OPTIMIZE_DEBUG 2 -#ifdef DEVKIT_VERSION_0_9 -#define KEYLED_INTERVAL 80 - -#define KEY_SHORT_MS 200 -#define KEY_LONG_MS 3000 -#define KEY_SHORT_COUNT (KEY_SHORT_MS / READLINE_INTERVAL) -#define KEY_LONG_COUNT (KEY_LONG_MS / READLINE_INTERVAL) - -#define LED_HIGH_COUNT_DEFAULT 10 -#define LED_LOW_COUNT_DEFAULT 0 -#endif - #define ENDUSER_SETUP_AP_SSID "SetupGadget" /* diff --git a/app/modules/node.c b/app/modules/node.c index 18a770e6..1d1d8f2f 100644 --- a/app/modules/node.c +++ b/app/modules/node.c @@ -146,160 +146,6 @@ static int node_heap( lua_State* L ) return 1; } -#ifdef DEVKIT_VERSION_0_9 -static int led_high_count = LED_HIGH_COUNT_DEFAULT; -static int led_low_count = LED_LOW_COUNT_DEFAULT; -static int led_count = 0; -static int key_press_count = 0; -static bool key_short_pressed = false; -static bool key_long_pressed = false; -static os_timer_t keyled_timer; -static int long_key_ref = LUA_NOREF; -static int short_key_ref = LUA_NOREF; - -static void default_long_press(void *arg) { - if (led_high_count == 12 && led_low_count == 12) { - led_low_count = led_high_count = 6; - } else { - led_low_count = led_high_count = 12; - } - // led_high_count = 1000 / READLINE_INTERVAL; - // led_low_count = 1000 / READLINE_INTERVAL; - // NODE_DBG("default_long_press is called. hc: %d, lc: %d\n", led_high_count, led_low_count); -} - -static void default_short_press(void *arg) { - system_restart(); -} - -static void key_long_press(void *arg) { - lua_State *L = lua_getstate(); - NODE_DBG("key_long_press is called.\n"); - if (long_key_ref == LUA_NOREF) { - default_long_press(arg); - return; - } - lua_rawgeti(L, LUA_REGISTRYINDEX, long_key_ref); - lua_call(L, 0, 0); -} - -static void key_short_press(void *arg) { - lua_State *L = lua_getstate(); - NODE_DBG("key_short_press is called.\n"); - if (short_key_ref == LUA_NOREF) { - default_short_press(arg); - return; - } - lua_rawgeti(L, LUA_REGISTRYINDEX, short_key_ref); - lua_call(L, 0, 0); -} - -static void update_key_led (void *p) -{ - (void)p; - uint8_t temp = 1, level = 1; - led_count++; - if(led_count>led_low_count+led_high_count){ - led_count = 0; // reset led_count, the level still high - } else if(led_count>led_low_count && led_count <=led_high_count+led_low_count){ - level = 1; // output high level - } else if(led_count<=led_low_count){ - level = 0; // output low level - } - temp = platform_key_led(level); - if(temp == 0){ // key is pressed - key_press_count++; - if(key_press_count>=KEY_LONG_COUNT){ - // key_long_press(NULL); - key_long_pressed = true; - key_short_pressed = false; - // key_press_count = 0; - } else if(key_press_count>=KEY_SHORT_COUNT){ // < KEY_LONG_COUNT - // key_short_press(NULL); - key_short_pressed = true; - } - }else{ // key is released - key_press_count = 0; - if(key_long_pressed){ - key_long_press(NULL); - key_long_pressed = false; - } - if(key_short_pressed){ - key_short_press(NULL); - key_short_pressed = false; - } - } -} - -static void prime_keyled_timer (void) -{ - os_timer_disarm (&keyled_timer); - os_timer_setfn (&keyled_timer, update_key_led, 0); - os_timer_arm (&keyled_timer, KEYLED_INTERVAL, 1); -} - -// Lua: led(low, high) -static int node_led( lua_State* L ) -{ - int low, high; - if ( lua_isnumber(L, 1) ) - { - low = lua_tointeger(L, 1); - if ( low < 0 ) { - return luaL_error( L, "wrong arg type" ); - } - } else { - low = LED_LOW_COUNT_DEFAULT; // default to LED_LOW_COUNT_DEFAULT - } - if ( lua_isnumber(L, 2) ) - { - high = lua_tointeger(L, 2); - if ( high < 0 ) { - return luaL_error( L, "wrong arg type" ); - } - } else { - high = LED_HIGH_COUNT_DEFAULT; // default to LED_HIGH_COUNT_DEFAULT - } - led_high_count = (uint32_t)high / READLINE_INTERVAL; - led_low_count = (uint32_t)low / READLINE_INTERVAL; - prime_keyled_timer(); - return 0; -} - -// Lua: key(type, function) -static int node_key( lua_State* L ) -{ - int *ref = NULL; - size_t sl; - - const char *str = luaL_checklstring( L, 1, &sl ); - if (str == NULL) - return luaL_error( L, "wrong arg type" ); - - if (sl == 5 && c_strcmp(str, "short") == 0) { - ref = &short_key_ref; - } else if (sl == 4 && c_strcmp(str, "long") == 0) { - ref = &long_key_ref; - } else { - ref = &short_key_ref; - } - // luaL_checkanyfunction(L, 2); - if (lua_type(L, 2) == LUA_TFUNCTION || lua_type(L, 2) == LUA_TLIGHTFUNCTION) { - lua_pushvalue(L, 2); // copy argument (func) to the top of stack - if (*ref != LUA_NOREF) - luaL_unref(L, LUA_REGISTRYINDEX, *ref); - *ref = luaL_ref(L, LUA_REGISTRYINDEX); - } else { // unref the key press function - if (*ref != LUA_NOREF) - luaL_unref(L, LUA_REGISTRYINDEX, *ref); - *ref = LUA_NOREF; - } - - prime_keyled_timer(); - return 0; -} -#endif - extern lua_Load gLoad; extern bool user_process_input(bool force); // Lua: input("string") @@ -643,10 +489,6 @@ static const LUA_REG_TYPE node_map[] = { LSTRKEY( "flashid" ), LFUNCVAL( node_flashid ) }, { LSTRKEY( "flashsize" ), LFUNCVAL( node_flashsize) }, { LSTRKEY( "heap" ), LFUNCVAL( node_heap ) }, -#ifdef DEVKIT_VERSION_0_9 - { LSTRKEY( "key" ), LFUNCVAL( node_key ) }, - { LSTRKEY( "led" ), LFUNCVAL( node_led ) }, -#endif { LSTRKEY( "input" ), LFUNCVAL( node_input ) }, { LSTRKEY( "output" ), LFUNCVAL( node_output ) }, // Moved to adc module, use adc.readvdd33() diff --git a/docs/en/modules/node.md b/docs/en/modules/node.md index 7989d708..ef033944 100644 --- a/docs/en/modules/node.md +++ b/docs/en/modules/node.md @@ -200,54 +200,6 @@ sk:on("receive", function(conn, payload) node.input(payload) end) #### See also [`node.output()`](#nodeoutput) -## node.key() --deprecated - -Defines action to take on button press (on the old devkit 0.9), button connected to GPIO 16. - -This function is only available if the firmware was compiled with DEVKIT_VERSION_0_9 defined. - -#### Syntax -`node.key(type, function())` - -#### Parameters - - `type`: type is either string "long" or "short". long: press the key for 3 seconds, short: press shortly(less than 3 seconds) - - `function`: user defined function which is called when key is pressed. If nil, remove the user defined function. Default function: long: change LED blinking rate, short: reset chip - -#### Returns -`nil` - -#### Example -```lua -node.key("long", function() print('hello world') end) -``` -#### See also -[`node.led()`](#nodeled-deprecated) - -## node.led() --deprecated - -Sets the on/off time for the LED (on the old devkit 0.9), with the LED connected to GPIO16, multiplexed with [`node.key()`](#nodekey-deprecated). - -This function is only available if the firmware was compiled with DEVKIT_VERSION_0_9 defined. - -#### Syntax -`node.led(low, high)` - -#### Parameters - - `low` LED off time, LED keeps on when low=0. Unit: milliseconds, time resolution: 80~100ms - - `high` LED on time. Unit: milliseconds, time resolution: 80~100ms - -#### Returns -`nil` - -#### Example -```lua --- turn led on forever. -node.led(0) -``` - -#### See also -[`node.key()`](#nodekey-deprecated) - ## node.output() Redirects the Lua interpreter output to a callback function. Optionally also prints it to the serial console.