[feat] PocketBook: implement Wi-Fi connection toggling (#4775)

Partially resolves #4747. Will enable switching Wi-Fi on/off in the menu and getting the network status. However, a new Wi-Fi session lasts ~100 seconds and then terminates automatically, apparently, to save the energy. I believe it can be prolonged by some networking activity. Also it is not shut down if the auto suspension is disabled.
pull/4777/head
tob1az 5 years ago committed by Frans de Jonge
parent 644e0d6440
commit 89c17092e8

@ -36,26 +36,30 @@ local KEY_PREV2 = 0x1c
local KEY_NEXT2 = 0x1d
local KEY_COVEROPEN = 0x02
local KEY_COVERCLOSE = 0x03
local CONNECTING = 1
local CONNECTED = 2
local NET_OK = 0
-- luacheck: pop
ffi.cdef[[
char *GetSoftwareVersion(void);
char *GetDeviceModel(void);
int GetNetState(void);
int NetConnect(const char *name);
int NetDisconnect();
]]
local function yes() return true end
local function no() return false end
local function pocketbookEnableWifi(toggle)
os.execute("/ebrmain/bin/netagent " .. (toggle == 1 and "connect" or "disconnect"))
end
local PocketBook = Generic:new{
model = "PocketBook",
isPocketBook = yes,
isInBackGround = false,
hasOTAUpdates = yes,
hasWifiToggle = no,
hasWifiToggle = yes,
}
function PocketBook:init()
@ -139,12 +143,24 @@ function PocketBook:setDateTime(year, month, day, hour, min, sec)
end
function PocketBook:initNetworkManager(NetworkMgr)
NetworkMgr.turnOnWifi = function()
pocketbookEnableWifi(1)
function NetworkMgr:turnOnWifi(complete_callback)
if inkview.NetConnect(nil) ~= NET_OK then
logger.info('NetConnect failed')
end
if complete_callback then
complete_callback()
end
end
function NetworkMgr:turnOffWifi(complete_callback)
inkview.NetDisconnect()
if complete_callback then
complete_callback()
end
end
NetworkMgr.turnOffWifi = function()
pocketbookEnableWifi(0)
function NetworkMgr:isWifiOn()
return inkview.GetNetState() == CONNECTED
end
end

@ -98,7 +98,7 @@ function NetworkMgr:beforeWifiAction(callback)
end
function NetworkMgr:isConnected()
if Device:isAndroid() or Device:isCervantes() then
if Device:isAndroid() or Device:isCervantes() or Device:isPocketBook() then
return self:isWifiOn()
else
-- `-c1` try only once; `-w2` wait 2 seconds

Loading…
Cancel
Save