Browse Source

:sparkles: 适配 EC718P POWERKEY

Mizore 1 year ago
parent
commit
d6f27b4dd1
1 changed files with 31 additions and 25 deletions
  1. 31 25
      script/main.lua

+ 31 - 25
script/main.lua

@@ -26,31 +26,37 @@ mobile.setAuto(1000 * 10, nil, nil, true, 1000 * 60)
 -- mobile.ipv6(true)
 
 -- POWERKEY
-local button_last_press_time, button_last_release_time = 0, 0
-gpio.setup(35, function()
-    local current_time = mcu.ticks()
-    -- 按下
-    if gpio.get(35) == 0 then
-        button_last_press_time = current_time -- 记录最后一次按下时间
-        return
-    end
-    -- 释放
-    if button_last_press_time == 0 then -- 开机前已经按下, 开机后释放
-        return
-    end
-    if current_time - button_last_release_time < 250 then -- 防止连按
-        return
-    end
-    local duration = current_time - button_last_press_time -- 按键持续时间
-    button_last_release_time = current_time -- 记录最后一次释放时间
-    if duration > 2000 then
-        log.debug("EVENT.POWERKEY_LONG_PRESS", duration)
-        sys.publish("POWERKEY_LONG_PRESS", duration)
-    elseif duration > 50 then
-        log.debug("EVENT.POWERKEY_SHORT_PRESS", duration)
-        sys.publish("POWERKEY_SHORT_PRESS", duration)
-    end
-end, gpio.PULLUP)
+local rtos_bsp = rtos.bsp()
+local pin_table = { ["EC618"] = 35, ["EC718P"] = 46 }
+local powerkey_pin = pin_table[rtos_bsp]
+
+if powerkey_pin then
+    local button_last_press_time, button_last_release_time = 0, 0
+    gpio.setup(powerkey_pin, function()
+        local current_time = mcu.ticks()
+        -- 按下
+        if gpio.get(powerkey_pin) == 0 then
+            button_last_press_time = current_time -- 记录最后一次按下时间
+            return
+        end
+        -- 释放
+        if button_last_press_time == 0 then -- 开机前已经按下, 开机后释放
+            return
+        end
+        if current_time - button_last_release_time < 250 then -- 防止连按
+            return
+        end
+        local duration = current_time - button_last_press_time -- 按键持续时间
+        button_last_release_time = current_time -- 记录最后一次释放时间
+        if duration > 2000 then
+            log.debug("EVENT.POWERKEY_LONG_PRESS", duration)
+            sys.publish("POWERKEY_LONG_PRESS", duration)
+        elseif duration > 50 then
+            log.debug("EVENT.POWERKEY_SHORT_PRESS", duration)
+            sys.publish("POWERKEY_SHORT_PRESS", duration)
+        end
+    end, gpio.PULLUP)
+end
 
 -- 加载模块
 config = require "config"