From 89c17092e8358b70ece568aa023e3cc91072063a Mon Sep 17 00:00:00 2001 From: tob1az Date: Tue, 12 Mar 2019 08:05:43 +0200 Subject: [PATCH] [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. --- frontend/device/pocketbook/device.lua | 32 ++++++++++++++++++++------- frontend/ui/network/manager.lua | 2 +- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/frontend/device/pocketbook/device.lua b/frontend/device/pocketbook/device.lua index f75855c14..e02a1b163 100644 --- a/frontend/device/pocketbook/device.lua +++ b/frontend/device/pocketbook/device.lua @@ -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 diff --git a/frontend/ui/network/manager.lua b/frontend/ui/network/manager.lua index 01195631d..bd22626fc 100644 --- a/frontend/ui/network/manager.lua +++ b/frontend/ui/network/manager.lua @@ -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