|
@@ -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()
|