mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Kindle: toggle cover events
Allow disabling the hall efect sensor via the sysfs knob, so the kindle system wont sleep & wake the device for those of use that stay in koreader, are caseless and have get spurious wakeups
This commit is contained in:
@@ -5,9 +5,13 @@ This module contains miscellaneous helper functions for the KOReader frontend.
|
||||
local BaseUtil = require("ffi/util")
|
||||
local Utf8Proc = require("ffi/utf8proc")
|
||||
local lfs = require("libs/libkoreader-lfs")
|
||||
local logger = require("logger")
|
||||
local _ = require("gettext")
|
||||
local C_ = _.pgettext
|
||||
local T = BaseUtil.template
|
||||
local ffi = require("ffi")
|
||||
local C = ffi.C
|
||||
require("ffi/posix_h")
|
||||
|
||||
local lshift = bit.lshift
|
||||
local rshift = bit.rshift
|
||||
@@ -829,6 +833,26 @@ function util.removeFile(file)
|
||||
end
|
||||
end
|
||||
|
||||
function util.writeToSysfs(val, file)
|
||||
-- NOTE: We do things by hand via ffi, because io.write uses fwrite,
|
||||
-- which isn't a great fit for procfs/sysfs (e.g., we lose failure cases like EBUSY,
|
||||
-- as it only reports failures to write to the *stream*, not to the disk/file!).
|
||||
local fd = C.open(file, bit.bor(C.O_WRONLY, C.O_CLOEXEC)) -- procfs/sysfs, we shouldn't need O_TRUNC
|
||||
if fd == -1 then
|
||||
logger.err("Cannot open file `" .. file .. "`:", ffi.string(C.strerror(ffi.errno())))
|
||||
return
|
||||
end
|
||||
val = tostring(val)
|
||||
local bytes = #val
|
||||
local nw = C.write(fd, val, bytes)
|
||||
if nw == -1 then
|
||||
logger.err("Cannot write `" .. val .. "` to file `" .. file .. "`:", ffi.string(C.strerror(ffi.errno())))
|
||||
end
|
||||
C.close(fd)
|
||||
-- NOTE: Allows the caller to possibly handle short writes (not that these should ever happen here).
|
||||
return nw == bytes
|
||||
end
|
||||
|
||||
-- Gets total, used and available bytes for the mountpoint that holds a given directory.
|
||||
-- @string path of the directory
|
||||
-- @treturn table with total, used and available bytes
|
||||
|
||||
Reference in New Issue
Block a user