Browse Source

add: 添加pm.shutdown函数 https://gitee.com/openLuat/LuatOS/issues/I62IX7

Wendal Chen 3 years ago
parent
commit
cc60f72029
3 changed files with 42 additions and 1 deletions
  1. 2 0
      luat/include/luat_pm.h
  2. 39 0
      luat/modules/luat_lib_pm.c
  3. 1 1
      luat/modules/luat_lib_rtos.c

+ 2 - 0
luat/include/luat_pm.h

@@ -32,4 +32,6 @@ int luat_pm_dtimer_list(size_t* count, size_t* list);
 
 int luat_pm_dtimer_wakeup_id(int* id);
 
+int luat_pm_poweroff(void);
+
 #endif

+ 39 - 0
luat/modules/luat_lib_pm.c

@@ -13,6 +13,9 @@
 #include "luat_pm.h"
 #include "luat_msgbus.h"
 
+#define LUAT_LOG_TAG "pm"
+#include "luat_log.h"
+
 // static int lua_event_cb = 0;
 
 /**
@@ -206,6 +209,40 @@ static int l_pm_check(lua_State *L) {
 }
 
 
+#ifndef LUAT_COMPILER_NOWEAK
+LUAT_WEAK int luat_pm_poweroff(void) {
+    LLOGW("powerOff is not supported");
+    return -1;
+}
+#else
+extern int luat_pm_poweroff(void);
+#endif
+
+/**
+关机
+@api pm.shutdown()
+@return nil 无返回值
+@usage
+-- 当前仅EC618系列(Air780E/Air600E/Air700E/Air780EG支持)
+-- 需要2022-12-22之后编译的固件
+pm.shutdown()
+ */
+static int l_pm_power_off(lua_State *L) {
+    (void)L;
+    luat_pm_poweroff();
+    return 0;
+}
+
+/**
+重启
+@api pm.reboot()
+@return nil          无返回值
+-- 立即重启设备, 本函数的行为与rtos.reboot()完全一致,只是在pm库做个别名
+pm.reboot()
+ */
+int l_rtos_reboot(lua_State *L);
+int l_rtos_standby(lua_State *L);
+
 
 // static int luat_pm_msg_handler(lua_State *L, void* ptr) {
 //     rtos_msg_t* msg = (rtos_msg_t*)lua_topointer(L, -1);
@@ -246,6 +283,8 @@ static const rotable_Reg_t reg_pm[] =
     { "force",          ROREG_FUNC(l_pm_force)},
     { "check",          ROREG_FUNC(l_pm_check)},
     { "lastReson",      ROREG_FUNC(l_pm_last_reson)},
+    { "shutdown",       ROREG_FUNC(l_pm_power_off)},
+    { "reboot",         ROREG_FUNC(l_rtos_reboot)},
     //@const NONE number 不休眠模式
     { "NONE",           ROREG_INT(LUAT_PM_SLEEP_MODE_NONE)},
     //@const IDLE number IDLE模式

+ 1 - 1
luat/modules/luat_lib_rtos.c

@@ -173,7 +173,7 @@ static int l_rtos_timer_stop(lua_State *L) {
 -- 立即重启设备
 rtos.reboot()
 */
-static int l_rtos_reboot(lua_State *L) {
+int l_rtos_reboot(lua_State *L) {
     luat_os_reboot(luaL_optinteger(L, 1, 0));
     return 0;
 }