2
0
mirror of https://github.com/koreader/koreader synced 2024-10-31 21:20:20 +00:00
koreader/frontend/ui/networkmgr.lua

74 lines
2.1 KiB
Lua
Raw Normal View History

local ConfirmBox = require("ui/widget/confirmbox")
local UIManager = require("ui/uimanager")
local Device = require("ui/device")
local DEBUG = require("dbg")
local _ = require("gettext")
local NetworkMgr = {}
local function kindleEnableWifi(toggle)
local lipc = require("liblipclua")
local lipc_handle = nil
if lipc then
lipc_handle = lipc.init("com.github.koreader.networkmgr")
end
if lipc_handle then
lipc_handle:set_int_property("com.lab126.cmd", "wirelessEnable", toggle)
lipc_handle:close()
end
end
2014-08-18 22:48:06 +00:00
local function koboEnableWifi(toggle)
2014-08-20 07:47:10 +00:00
if toggle == 1 then
local path = "/etc/wpa_supplicant/wpa_supplicant.conf"
os.execute("insmod /drivers/ntx508/wifi/sdio_wifi_pwr.ko 2>/dev/null")
os.execute("insmod /drivers/ntx508/wifi/dhd.ko")
os.execute("ifconfig eth0 up")
os.execute("wlarm_le -i eth0 up")
os.execute("wpa_supplicant -s -i eth0 -c "..path.." -C /var/run/wpa_supplicant -B")
os.execute("udhcpc -S -i eth0 -s /etc/udhcpc.d/default.script -t15 -T10 -A3 -b -q >/dev/null 2>&1")
2014-08-18 22:48:06 +00:00
else
2014-08-20 07:47:10 +00:00
os.execute("killall udhcpc wpa_supplicant 2>/dev/null")
os.execute("wlarm_le -i eth0 down")
os.execute("ifconfig eth0 down")
os.execute("rmmod -r dhd")
os.execute("rmmod -r sdio_wifi_pwr")
2014-08-18 22:48:06 +00:00
end
end
function NetworkMgr:turnOnWifi()
if Device:isKindle() then
kindleEnableWifi(1)
elseif Device:isKobo() then
2014-08-18 22:48:06 +00:00
koboEnableWifi(1)
end
end
function NetworkMgr:turnOffWifi()
if Device:isKindle() then
kindleEnableWifi(0)
elseif Device:isKobo() then
2014-08-18 22:48:06 +00:00
koboEnableWifi(0)
end
end
function NetworkMgr:promptWifiOn()
UIManager:show(ConfirmBox:new{
text = _("Do you want to Turn on Wifi?"),
ok_callback = function()
self:turnOnWifi()
end,
})
end
function NetworkMgr:promptWifiOff()
UIManager:show(ConfirmBox:new{
text = _("Do you want to Turn off Wifi?"),
ok_callback = function()
self:turnOffWifi()
end,
})
end
return NetworkMgr