mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
add: sleep and usleep in util module
Now using it in commands.lua
This commit is contained in:
@@ -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
16
util.c
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user