From e2a0929c51fb3afe64097df2b676a5acce5e7967 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Sun, 1 Jul 2018 17:35:12 +0200 Subject: [PATCH] Better KOA2 support (#4037) * Better KOA2 support * Fix FL * Add physical pageturn keys * Add accelerometer support * Possibly better NaturalLight handling on the Clara * Fix WiFi module name used in some(?) Mk7 Kobos * A bunch of kodev fixes --- base | 2 +- frontend/device/kindle/device.lua | 52 ++++++++++++-- frontend/device/kobo/device.lua | 8 ++- frontend/document/credocument.lua | 2 +- kodev | 108 ++++++++++++++++-------------- platform/kobo/disable-wifi.sh | 2 +- platform/kobo/enable-wifi.sh | 2 +- platform/kobo/nickel.sh | 2 +- 8 files changed, 112 insertions(+), 66 deletions(-) diff --git a/base b/base index d7e8a782a..4f182587d 160000 --- a/base +++ b/base @@ -1 +1 @@ -Subproject commit d7e8a782ab0fa1e4b7ba0f7cc68aa0202ad7e290 +Subproject commit 4f182587da457b36449693e970d9e6c723656eb1 diff --git a/frontend/device/kindle/device.lua b/frontend/device/kindle/device.lua index 902551607..d2b6801b2 100644 --- a/frontend/device/kindle/device.lua +++ b/frontend/device/kindle/device.lua @@ -517,7 +517,7 @@ function KindleOasis:init() self.input.open("/dev/input/by-path/platform-gpiokey.0-event") -- get rotate dev by EV=d - local std_out = io.popen("cat /proc/bus/input/devices | grep -e 'Handlers\\|EV=' | grep -B1 'EV=d'| grep -o 'event[0-9]'", "r") + local std_out = io.popen("grep -e 'Handlers\\|EV=' /proc/bus/input/devices | grep -B1 'EV=d' | grep -o 'event[0-9]'", "r") if std_out then local rotation_dev = std_out:read() std_out:close() @@ -529,32 +529,70 @@ function KindleOasis:init() self.input.open("fake_events") end --- FIXME: Should be enough for the bare minimum to work, TBC. --- FIXME: Pageturn keys. And whatever else might be missing. function KindleOasis2:init() self.screen = require("ffi/framebuffer_mxcfb"):new{device = self, debug = logger.dbg} self.powerd = require("device/kindle/powerd"):new{ device = self, - fl_intensity_file = "/sys/class/backlight/max77696-bl/brightness", + fl_intensity_file = "/sys/class/backlight/max77796-bl/brightness", batt_capacity_file = "/sys/class/power_supply/max77796-battery/capacity", is_charging_file = "/sys/class/power_supply/max77796-charger/charging", } - --[[ self.input = require("device/input"):new{ device = self, + -- Top, Bottom (yes, it's the reverse than on non-Oasis devices) event_map = { [104] = "RPgFwd", [109] = "RPgBack", } } - --]] + + local haslipc, lipc = pcall(require, "liblipclua") + if haslipc and lipc then + local lipc_handle = lipc.init("com.github.koreader.screen") + if lipc_handle then + local orientation_code = lipc_handle:get_string_property( + "com.lab126.winmgr", "accelerometer") + local rotation_mode = 0 + if orientation_code then + if orientation_code == "U" then + rotation_mode = self.screen.ORIENTATION_PORTRAIT + elseif orientation_code == "R" then + rotation_mode = self.screen.ORIENTATION_LANDSCAPE + elseif orientation_code == "D" then + rotation_mode = self.screen.ORIENTATION_PORTRAIT_ROTATED + elseif orientation_code == "L" then + rotation_mode = self.screen.ORIENTATION_LANDSCAPE_ROTATED + end + end + + if rotation_mode > 0 then + self.screen.native_rotation_mode = rotation_mode + self.screen.cur_rotation_mode = rotation_mode + end + + lipc_handle:close() + end + end Kindle.init(self) + -- NOTE: Hopefully the KOA2 needs the exact same tweaks as the KOA... + self.input:registerEventAdjustHook(self.input.adjustKindleOasisOrientation) + self.input.open(self.touch_dev) - --self.input.open("/dev/input/by-path/platform-gpiokey.0-event") + self.input.open("/dev/input/by-path/platform-gpio-keys-event") + + -- Get accelerometer device by looking for EV=d + local std_out = io.popen("grep -e 'Handlers\\|EV=' /proc/bus/input/devices | grep -B1 'EV=d' | grep -o 'event[0-9]\\{1,2\\}'", "r") + if std_out then + local rotation_dev = std_out:read() + std_out:close() + if rotation_dev then + self.input.open("/dev/input/"..rotation_dev) + end + end self.input.open("fake_events") end diff --git a/frontend/device/kobo/device.lua b/frontend/device/kobo/device.lua index 6a8d87116..5779d21a9 100644 --- a/frontend/device/kobo/device.lua +++ b/frontend/device/kobo/device.lua @@ -179,14 +179,18 @@ local KoboPika = Kobo:new{ } -- Kobo Clara HD: --- FIXME: NaturalLight doesn't exactly work right. --- FIXME: Also, rebooting (?!!) might be FUBAR, too (KOReader crash, too). +-- FIXME: Check that NaturalLight behaves properly (c.f., #4015) local KoboNova = Kobo:new{ model = "Kobo_nova", hasFrontlight = yes, touch_snow_protocol = true, display_dpi = 300, hasNaturalLight = yes, + frontlight_settings = { + frontlight_white = "/sys/class/backlight/lm3630a_ledb", + frontlight_red = "/sys/class/backlight/lm3630a_leda", + frontlight_green = "/sys/class/backlight/lm3630a_led1b", + }, } function Kobo:init() diff --git a/frontend/document/credocument.lua b/frontend/document/credocument.lua index b58544ce1..35d24487f 100644 --- a/frontend/document/credocument.lua +++ b/frontend/document/credocument.lua @@ -81,7 +81,7 @@ function CreDocument:engineInit() if not _v:find("/urw/") then local ok, err = pcall(cre.registerFont, _v) if not ok then - logger.err("failed to register crengine font", err) + logger.err("failed to register crengine font:", err) end end end diff --git a/kodev b/kodev index d2335d44d..2551f581d 100755 --- a/kodev +++ b/kodev @@ -5,11 +5,11 @@ VERSION=$(git describe HEAD) VERSION=${VERSION}_$(git describe HEAD | xargs git show -s --format=format:"%cd" --date=short) # Default Android build to arm. -ANDROID_ARCH=${ANDROID_ARCH:-arm} -if [ -z "${ANDROID_FULL_ARCH+x}" ]; then - if [ "$ANDROID_ARCH" = arm ]; then +ANDROID_ARCH="${ANDROID_ARCH:-arm}" +if [ -z "${ANDROID_FULL_ARCH}" ]; then + if [ "${ANDROID_ARCH}" = "arm" ]; then ANDROID_FULL_ARCH_APK="${ANDROID_FULL_ARCH_APK:-arm-linux-androideabi}" - elif [ "$ANDROID_ARCH" = x86 ]; then + elif [ "${ANDROID_ARCH}" = "x86" ]; then ANDROID_FULL_ARCH_APK="${ANDROID_FULL_ARCH_APK:-i686-linux-android}" else ANDROID_FULL_ARCH_APK="${ANDROID_ARCH}" @@ -20,9 +20,9 @@ NDKABI=${NDKABI:-14} export NDKABI function assert_ret_zero() { - if [ "$1" -ne 0 ]; then - if [ ! -z "$2" ]; then - echo "$2" + if [ "${1}" -ne 0 ]; then + if [ ! -z "${2}" ]; then + echo "${2}" fi exit 1 fi @@ -94,7 +94,7 @@ EOL function setup_env() { SETUP_ENV_GREP_COMMAND="grep -v debug" - if [ -n "${KODEBUG+x}" ]; then + if [ -n "${KODEBUG}" ]; then SETUP_ENV_GREP_COMMAND="grep debug" # for android adb install KODEBUG_SUFFIX=-debug @@ -134,10 +134,10 @@ OPTIONS: TARGET: ${SUPPORTED_TARGETS}" - while [[ $1 == '-'* ]]; do - PARAM=$(echo "$1" | awk -F= '{print $1}') - VALUE=$(echo "$1" | awk -F= '{print $2}') - case $PARAM in + while [[ "${1}" == '-'* ]]; do + PARAM=$(echo "${1}" | awk -F= '{print $1}') + VALUE=$(echo "${1}" | awk -F= '{print $2}') + case "${PARAM}" in -v | --verbose) export VERBOSE=1 ;; @@ -163,7 +163,7 @@ ${SUPPORTED_TARGETS}" done check_submodules - case $1 in + case "${1}" in kindle) make TARGET=kindle assert_ret_zero $? @@ -181,8 +181,8 @@ ${SUPPORTED_TARGETS}" assert_ret_zero $? ;; android) - if [ -z "${NDK+x}" ]; then - if [ -n "${ANDROID_NDK+x}" ]; then + if [ -z "${NDK}" ]; then + if [ -n "${ANDROID_NDK}" ]; then # some distributions use `ANDROID_NDK` instead, fall back to it export NDK="${ANDROID_NDK}" else @@ -220,7 +220,7 @@ ${SUPPORTED_TARGETS}" assert_ret_zero $? ;; *) - if [ -z "${KODEBUG_NO_DEFAULT+x}" ]; then # no explicit --debug / --no-debug + if [ -z "${KODEBUG_NO_DEFAULT}" ]; then # no explicit --debug / --no-debug # builds a debug build by default, like kodev-run export KODEBUG=1 fi @@ -238,7 +238,7 @@ usage: clean TARGET: ${SUPPORTED_TARGETS}" - case $1 in + case "${1}" in -h | --help) echo "${CLEAN_HELP_MSG}" exit 0 @@ -297,10 +297,10 @@ ${SUPPORTED_RELEASE_TARGETS}" ignore_translation=0 - while [[ $1 == '-'* ]]; do - PARAM=$(echo "$1" | awk -F= '{print $1}') - VALUE=$(echo "$1" | awk -F= '{print $2}') - case $PARAM in + while [[ "${1}" == '-'* ]]; do + PARAM=$(echo "${1}" | awk -F= '{print $1}') + VALUE=$(echo "${1}" | awk -F= '{print $2}') + case "${PARAM}" in --debug) export KODEBUG=1 ;; @@ -335,7 +335,7 @@ ${SUPPORTED_RELEASE_TARGETS}" fi fi - case $1 in + case "${1}" in kindle) kodev-build kindle make TARGET=kindle update @@ -416,15 +416,15 @@ TARGET: screen_width=540 screen_height=720 export KODEBUG=1 - while [[ $1 == '-'* ]]; do - PARAM=$(echo "$1" | awk -F= '{print $1}') - VALUE=$(echo "$1" | awk -F= '{print $2}') - case $PARAM in + while [[ "${1}" == '-'* ]]; do + PARAM=$(echo "${1}" | awk -F= '{print $1}') + VALUE=$(echo "${1}" | awk -F= '{print $2}') + case "${PARAM}" in --disable-touch) export DISABLE_TOUCH=1 ;; --no-build) - no_build=true + no_build=1 ;; --no-debug) export KODEBUG= @@ -453,7 +453,7 @@ TARGET: fi ;; --graph) - graph_memory=true + graph_memory=1 ;; --valgrind) if [ ! -z "${VALUE}" ]; then @@ -485,7 +485,7 @@ TARGET: ;; -s | --simulate) device_model=${VALUE} - case ${device_model} in + case "${device_model}" in kindle3) screen_width=600 screen_height=800 @@ -518,10 +518,10 @@ TARGET: shift done - case $1 in + case "${1}" in android) command -v adb >/dev/null && { - if [ ! ${no_build} ]; then + if [ -z "${no_build}" ]; then echo "[*] Building KOReader for Android…" kodev-release --ignore-translation android assert_ret_zero $? @@ -541,9 +541,13 @@ TARGET: } || echo "Failed to find adb in PATH to interact with Android device." ;; *) - if [ ! ${no_build} ]; then + if [ -z "${no_build}" ]; then echo "[*] Building KOReader…" - kodev-build + if [ -z "${KODEBUG}" ]; then + kodev-build --no-debug + else + kodev-build + fi else setup_env fi @@ -553,7 +557,7 @@ TARGET: exit 1 fi - if [ ${graph_memory} ]; then + if [ -n "${graph_memory}" ]; then gnuplot_wrapper "--parent $$" "reader.lua" fi @@ -579,19 +583,19 @@ TARGET: args=${CURDIR}/test else args="$*" - [[ $args != /* ]] && args="${CURDIR}/${args}" + [[ "${args}" != /* ]] && args="${CURDIR}/${args}" fi KOREADER_COMMAND="$KOREADER_COMMAND ${args}" RETURN_VALUE=85 - while [ $RETURN_VALUE -eq 85 ]; do + while [ "${RETURN_VALUE}" -eq 85 ]; do EMULATE_READER_W=${screen_width} EMULATE_READER_H=${screen_height} EMULATE_READER_DPI=${screen_dpi} \ ${KOREADER_COMMAND} RETURN_VALUE=$? done } && popd || exit - if [ ${graph_memory} ]; then + if [ -n "${graph_memory}" ]; then capture_ctrl_c fi ;; @@ -608,12 +612,12 @@ OPTIONS: --tags=TAGS only run tests with given tags " - while [[ $1 == '-'* ]]; do - PARAM=$(echo "$1" | awk -F= '{print $1}') - VALUE=$(echo "$1" | awk -F= '{print $2}') - case $PARAM in + while [[ "${1}" == '-'* ]]; do + PARAM=$(echo "${1}" | awk -F= '{print $1}') + VALUE=$(echo "${1}" | awk -F= '{print $2}') + case "${PARAM}" in --graph) - graph_memory=true + graph_memory=1 ;; --tags) opts="--tags=${VALUE}" @@ -635,7 +639,7 @@ OPTIONS: echo "${TEST_HELP_MSG}" exit 1 } - [[ $1 != "front" && $1 != "base" ]] && { + [[ "${1}" != "front" && "${1}" != "base" ]] && { echo "Invalid test suite: $1!" echo "${TEST_HELP_MSG}" exit 1 @@ -649,7 +653,7 @@ OPTIONS: test_path="./spec/$1/unit" rm -rf "${test_path}"/data/*.sdr - if [ ! -z "$2" ]; then + if [ ! -z "${2}" ]; then test_path="${test_path}/$2" fi @@ -673,10 +677,10 @@ OPTIONS: " show_full=0 show_previous=0 - while [[ $1 == '-'* ]]; do - PARAM=$(echo "$1" | awk -F= '{print $1}') - VALUE=$(echo "$1" | awk -F= '{print $2}') - case $PARAM in + while [[ "${1}" == '-'* ]]; do + PARAM=$(echo "${1}" | awk -F= '{print $1}') + VALUE=$(echo "${1}" | awk -F= '{print $2}') + case "${PARAM}" in --full) show_full=1 ;; @@ -702,7 +706,7 @@ OPTIONS: pushd "${EMU_DIR}" && { target=front test_path="./spec/${target}/unit" - if [ ${show_previous} -eq 0 ]; then + if [ "${show_previous}" -eq 0 ]; then echo "Running tests in" ${test_path} busted --lua="./luajit" \ --sort-files \ @@ -714,7 +718,7 @@ OPTIONS: echo "Failed to run tests!" && exit 1 } fi - if [ ${show_full} -eq 1 ]; then + if [ "${show_full}" -eq 1 ]; then cat luacov.report.out else LUACOV_REPORT_SUMMARY=$(grep -nm1 -e '^Summary$' luacov.report.out | cut -d: -f1) @@ -738,7 +742,7 @@ TARGET: exit 1 } - case $1 in + case "${1}" in -h | --help) echo "${LOG_HELP_MSG}" exit 0 @@ -775,7 +779,7 @@ Supported commands: exit 1 } -case $1 in +case "${1}" in activate) echo "adding ${CURDIR} to \$PATH..." export PATH="${PATH}:${CURDIR}" diff --git a/platform/kobo/disable-wifi.sh b/platform/kobo/disable-wifi.sh index 96427e037..a8737f1cd 100755 --- a/platform/kobo/disable-wifi.sh +++ b/platform/kobo/disable-wifi.sh @@ -4,7 +4,7 @@ killall udhcpc default.script wpa_supplicant 2>/dev/null -[ "${WIFI_MODULE}" != "8189fs" ] && [ "${WIFI_MODULE}" != "8189es" ] && wlarm_le -i "${INTERFACE}" down +[ "${WIFI_MODULE}" != "8189fs" ] && [ "${WIFI_MODULE}" != "8192es" ] && wlarm_le -i "${INTERFACE}" down ifconfig "${INTERFACE}" down # Some sleep in between may avoid system getting hung diff --git a/platform/kobo/enable-wifi.sh b/platform/kobo/enable-wifi.sh index 0c13b1039..7390e5317 100755 --- a/platform/kobo/enable-wifi.sh +++ b/platform/kobo/enable-wifi.sh @@ -11,7 +11,7 @@ lsmod | grep -q "${WIFI_MODULE}" || insmod "${WIFI_MODULE_PATH}" sleep 1 ifconfig "${INTERFACE}" up -[ "$WIFI_MODULE" != "8189fs" ] && [ "${WIFI_MODULE}" != "8189es" ] && wlarm_le -i "${INTERFACE}" up +[ "$WIFI_MODULE" != "8189fs" ] && [ "${WIFI_MODULE}" != "8192es" ] && wlarm_le -i "${INTERFACE}" up pidof wpa_supplicant >/dev/null \ || env -u LD_LIBRARY_PATH \ diff --git a/platform/kobo/nickel.sh b/platform/kobo/nickel.sh index 73696cc7e..63e390f76 100755 --- a/platform/kobo/nickel.sh +++ b/platform/kobo/nickel.sh @@ -18,7 +18,7 @@ export LD_LIBRARY_PATH="/usr/local/Kobo" # NOTE: That check is possibly wrong on PLATFORM == freescale (because I don't know if the sdio_wifi_pwr module exists there), but we don't terribly care about that. if lsmod | grep -q sdio_wifi_pwr; then killall udhcpc default.script wpa_supplicant 2>/dev/null - [ "${WIFI_MODULE}" != "8189fs" ] && [ "${WIFI_MODULE}" != "8189es" ] && wlarm_le -i "${INTERFACE}" down + [ "${WIFI_MODULE}" != "8189fs" ] && [ "${WIFI_MODULE}" != "8192es" ] && wlarm_le -i "${INTERFACE}" down ifconfig "${INTERFACE}" down # NOTE: Kobo's busybox build is weird. rmmod appears to be modprobe in disguise, defaulting to the -r flag... # But since there's currently no modules.dep file being shipped, nor do they include the depmod applet,