diff --git a/commands.lua b/commands.lua index b818f258b..1dd6d6efb 100644 --- a/commands.lua +++ b/commands.lua @@ -174,7 +174,7 @@ function Commands:new(obj) obj:add(KEY_OUTOF_SCREEN_SAVER, nil, "Slider", "toggle screen saver", function() - os.execute("sleep 3") + util.sleep(3) --os.execute("killall -stop cvm") fb:setOrientation(Screen.kpv_rotation_mode) Screen:resotreFromSavedBB() diff --git a/util.c b/util.c index e8978f350..061847723 100644 --- a/util.c +++ b/util.c @@ -17,6 +17,7 @@ */ #include +#include #include "util.h" @@ -28,6 +29,19 @@ static int gettime(lua_State *L) { return 2; } +static int util_sleep(lua_State *L) { + unsigned int seconds = luaL_optint(L, 1, 0); + sleep(seconds); + return 0; +} + +static int util_usleep(lua_State *L) { + useconds_t useconds = luaL_optint(L, 1, 0); + usleep(useconds); + return 0; +} + +/* Turn UTF-8 char code to Unicode */ static int utf8charcode(lua_State *L) { size_t len; const char* utf8char = luaL_checklstring(L, 1, &len); @@ -57,6 +71,8 @@ static int isEmulated(lua_State *L) { static const struct luaL_Reg util_func[] = { {"gettime", gettime}, + {"sleep", util_sleep}, + {"usleep", util_usleep}, {"utf8charcode", utf8charcode}, {"isEmulated", isEmulated}, {NULL, NULL}