From 4a89c93290e9fc0c532cd0b1b1db9082f310c2c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Fern=C3=A1ndez?= <975883+pazos@users.noreply.github.com> Date: Tue, 2 Feb 2021 03:19:37 +0100 Subject: [PATCH] Remarkable1 wifi (#7216) * add wifi support to Rm1 * remarkable: common suspend for all models --- frontend/device/remarkable/device.lua | 54 +++++++++++++-------------- platform/remarkable/disable-wifi.sh | 20 ++++------ platform/remarkable/enable-wifi.sh | 21 +++++------ 3 files changed, 45 insertions(+), 50 deletions(-) diff --git a/frontend/device/remarkable/device.lua b/frontend/device/remarkable/device.lua index 9abd6db63..b2ae96d3b 100644 --- a/frontend/device/remarkable/device.lua +++ b/frontend/device/remarkable/device.lua @@ -5,6 +5,17 @@ local logger = require("logger") local function yes() return true end local function no() return false end +-- returns isRm2, device_model +local function getModel() + local f = io.open("/sys/devices/soc0/machine") + if not f then + error("missing sysfs entry for a remarkable") + end + local model = f:read("*line") + f:close() + return model == "reMarkable 2.0", model +end + local EV_ABS = 3 local ABS_X = 00 local ABS_Y = 01 @@ -17,9 +28,11 @@ local wacom_width = 15725 -- unscaled_size_check: ignore local wacom_height = 20967 -- unscaled_size_check: ignore local wacom_scale_x = screen_width / wacom_width local wacom_scale_y = screen_height / wacom_height +local isRm2, rm_model = getModel() local Remarkable = Generic:new{ isRemarkable = yes, + model = rm_model, hasKeys = yes, needsScreenRefreshAfterResume = no, hasOTAUpdates = yes, @@ -34,7 +47,6 @@ local Remarkable = Generic:new{ } local Remarkable1 = Remarkable:new{ - model = "reMarkable", mt_width = 767, -- unscaled_size_check: ignore mt_height = 1023, -- unscaled_size_check: ignore input_wacom = "/dev/input/event0", @@ -59,7 +71,6 @@ function Remarkable1:adjustTouchEvent(ev, by) end local Remarkable2 = Remarkable:new{ - model = "reMarkable 2", mt_width = 1403, -- unscaled_size_check: ignore mt_height = 1871, -- unscaled_size_check: ignore input_wacom = "/dev/input/event1", @@ -167,26 +178,22 @@ function Remarkable:setDateTime(year, month, day, hour, min, sec) return os.execute(command) == 0 end -function Remarkable1:suspend() - os.execute("systemctl suspend") +function Remarkable:resume() end -function Remarkable2:suspend() - -- Need to remove brcmfmac kernel module before suspend. Otherwise the module crashes on wakeup +function Remarkable:suspend() os.execute("./disable-wifi.sh") - os.execute("systemctl suspend") - -- While device is suspended, when the user presses the power button and wakes up the device, - -- a "Power" event is NOT sent. - -- So we schedule a manual `UIManager:resume` call just far enough in the future that it won't - -- trigger before the `systemctl suspend` command finishes suspending the device - local UIManager = require("ui/uimanager") - UIManager:scheduleIn(0.5, function() - UIManager:resume() - end) -end - -function Remarkable:resume() + if isRm2 then + -- While device is suspended, when the user presses the power button and wakes up the device, + -- a "Power" event is NOT sent. + -- So we schedule a manual `UIManager:resume` call just far enough in the future that it won't + -- trigger before the `systemctl suspend` command finishes suspending the device + local UIManager = require("ui/uimanager") + UIManager:scheduleIn(0.5, function() + UIManager:resume() + end) + end end function Remarkable:powerOff() @@ -199,19 +206,12 @@ function Remarkable:reboot() os.execute("systemctl reboot") end -local f = io.open("/sys/devices/soc0/machine") -if not f then error("missing sysfs entry for a remarkable") end +logger.info(string.format("Starting %s", rm_model)) -local deviceType = f:read("*line") -f:close() - -logger.info("deviceType: ", deviceType) - -if deviceType == "reMarkable 2.0" then +if isRm2 then if not os.getenv("RM2FB_SHIM") then error("reMarkable2 requires RM2FB to work (https://github.com/ddvk/remarkable2-framebuffer)") end - return Remarkable2 else return Remarkable1 diff --git a/platform/remarkable/disable-wifi.sh b/platform/remarkable/disable-wifi.sh index 099f85c11..0b40e6d4e 100755 --- a/platform/remarkable/disable-wifi.sh +++ b/platform/remarkable/disable-wifi.sh @@ -2,17 +2,13 @@ # disable wifi and remove modules -read -r MACHINE_TYPE <"/sys/devices/soc0/machine" +# clean stop (if it's running) of main wpa_supplicant service, used by xochitl +systemctl stop wpa_supplicant +# clean stop of non-service wpa_supplicant, if running +wpa_cli terminate 2>/dev/null -if [ "reMarkable 2.0" = "${MACHINE_TYPE}" ]; then - # clean stop (if it's running) of main wpa_supplicant service, used by xochitl - systemctl stop wpa_supplicant - # clean stop of non-service wpa_supplicant, if running - wpa_cli terminate 2>/dev/null +# power down wifi interface +ifconfig wlan0 down 2>/dev/null - # power down wifi interface - ifconfig wlan0 down 2>/dev/null - - # remove module: IMPORTANT to do this before device suspends - modprobe -r brcmfmac 2>/dev/null -fi +# remove module +modprobe -r brcmfmac 2>/dev/null diff --git a/platform/remarkable/enable-wifi.sh b/platform/remarkable/enable-wifi.sh index 9968188e5..bf77f5a99 100755 --- a/platform/remarkable/enable-wifi.sh +++ b/platform/remarkable/enable-wifi.sh @@ -1,20 +1,19 @@ #!/bin/sh read -r MACHINE_TYPE <"/sys/devices/soc0/machine" - if [ "reMarkable 2.0" = "${MACHINE_TYPE}" ]; then - if lsmod | grep -q brcmfmac; then - ifconfig wlan0 up - else + if ! lsmod | grep -q brcmfmac; then modprobe brcmfmac fi +fi - # clean stop (if it's running) of main wpa_supplicant service, used by xochitl - systemctl stop wpa_supplicant - # clean stop of non-service wpa_supplicant, if running - wpa_cli terminate 2>/dev/null +# clean stop (if it's running) of main wpa_supplicant service, used by xochitl +systemctl stop wpa_supplicant - sleep 1 +# clean stop of non-service wpa_supplicant, if running +wpa_cli terminate 2>/dev/null - wpa_supplicant -i wlan0 -C /var/run/wpa_supplicant -B 2>/dev/null -fi +sleep 1 + +ifconfig wlan0 up +wpa_supplicant -i wlan0 -C /var/run/wpa_supplicant -B 2>/dev/null