add: sleep and usleep in util module

Now using it in commands.lua
This commit is contained in:
Qingping Hou
2012-04-14 13:41:44 +08:00
parent db1b2cd01a
commit c71f5c6f6a
2 changed files with 17 additions and 1 deletions

View File

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

16
util.c
View File

@@ -17,6 +17,7 @@
*/
#include <sys/time.h>
#include <unistd.h>
#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}