From 6c8bbfd4707ab1b7bdca60115203a3e2d914ff2d Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Mon, 29 Feb 2016 20:12:50 +0100 Subject: [PATCH 01/19] Unbreak Kobo frontlight -> off when suspending. If no-one touches anything, flState stays false... And anyway, we should unconditionally disable the fl on sleep. --- frontend/device/kobo/powerd.lua | 15 +++--- platform/kobo/nickel_suspend_strace.txt | 64 +++++++++++++++++++++++++ platform/kobo/suspend.sh | 2 +- 3 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 platform/kobo/nickel_suspend_strace.txt diff --git a/frontend/device/kobo/powerd.lua b/frontend/device/kobo/powerd.lua index 19376d3ca..dadefbcd9 100644 --- a/frontend/device/kobo/powerd.lua +++ b/frontend/device/kobo/powerd.lua @@ -62,19 +62,20 @@ end -- Turn off front light before suspend. function KoboPowerD:beforeSuspend() - if self.flState then - assert(self.fl ~= nil) + if self.fl ~= nil then + self.flState = true self.fl:setBrightness(0) end end -- Restore front light state after resume. function KoboPowerD:afterResume() - if KOBO_LIGHT_ON_START and tonumber(KOBO_LIGHT_ON_START) > -1 then - self:setIntensity(math.min(KOBO_LIGHT_ON_START, 100)) - elseif self.flState then - assert(self.fl ~= nil) - self.fl:setBrightness(self.flIntensity) + if self.fl ~= nil then + if KOBO_LIGHT_ON_START and tonumber(KOBO_LIGHT_ON_START) > -1 then + self:setIntensity(math.min(KOBO_LIGHT_ON_START, 100)) + elseif self.flState then + self.fl:setBrightness(self.flIntensity) + end end end diff --git a/platform/kobo/nickel_suspend_strace.txt b/platform/kobo/nickel_suspend_strace.txt new file mode 100644 index 000000000..28546a406 --- /dev/null +++ b/platform/kobo/nickel_suspend_strace.txt @@ -0,0 +1,64 @@ +## On the other hand, nickel doesn't seem to fare any better... it spends its time doing this over and over: +# strace -fitv -P /sys/power/state -P /sys/power/state-extended -P /sys/power/wakeup_count -p $(pidof nickel) + +strace: Process 4474 attached +strace: Process 4475 attached +[pid 4475] 19:38:43 [????????] +++ exited with 0 +++ +[pid 4474] 19:38:43 [2ab4c276] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=4475, si_uid=0, si_status=0, si_utime=1, si_stime=0} --- +[pid 4474] 19:38:43 [????????] +++ exited with 0 +++ +[pid 3681] 19:38:43 [2f0d8386] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=4474, si_uid=0, si_status=0, si_utime=0, si_stime=2} --- +[pid 3681] 19:38:46 [2f0d8386] open("/sys/power/wakeup_count", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 24 +[pid 3681] 19:38:46 [2f0d8386] fcntl64(24, F_SETFD, FD_CLOEXEC) = 0 +[pid 3681] 19:38:46 [2f232276] fstat64(24, {st_dev=makedev(0, 14), st_ino=36, st_mode=S_IFREG|0644, st_nlink=1, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=0, st_size=4096, st_atime=2016/02/29-18:18:37.514794262, st_mtime=2016/02/29-19:08:22.880008624, st_ctime=2016/02/29-19:08:22.880008624}) = 0 +[pid 3681] 19:38:46 [2f232276] fstat64(24, {st_dev=makedev(0, 14), st_ino=36, st_mode=S_IFREG|0644, st_nlink=1, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=0, st_size=4096, st_atime=2016/02/29-18:18:37.514794262, st_mtime=2016/02/29-19:08:22.880008624, st_ctime=2016/02/29-19:08:22.880008624}) = 0 +[pid 3681] 19:38:46 [2f232276] fstat64(24, {st_dev=makedev(0, 14), st_ino=36, st_mode=S_IFREG|0644, st_nlink=1, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=0, st_size=4096, st_atime=2016/02/29-18:18:37.514794262, st_mtime=2016/02/29-19:08:22.880008624, st_ctime=2016/02/29-19:08:22.880008624}) = 0 +[pid 3681] 19:38:46 [2f0d63a4] read(24, "3183\n", 16384) = 5 +[pid 3681] 19:38:46 [2f0d63a4] read(24, "", 16379) = 0 +[pid 3681] 19:38:46 [2f0d63a4] read(24, "", 4091) = 0 +[pid 3681] 19:38:46 [2f0d6454] close(24) = 0 +[pid 3681] 19:38:46 [2f0d8386] open("/sys/power/state-extended", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE|O_CLOEXEC, 0666) = 26 +[pid 3681] 19:38:46 [2f0d8386] fcntl64(26, F_SETFD, FD_CLOEXEC) = 0 +[pid 3681] 19:38:46 [2f232276] fstat64(26, {st_dev=makedev(0, 14), st_ino=38, st_mode=S_IFREG|0644, st_nlink=1, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=0, st_size=4096, st_atime=2016/02/29-18:18:37.514794262, st_mtime=2016/02/29-19:38:46.129858648, st_ctime=2016/02/29-19:38:46.129858648}) = 0 +[pid 3681] 19:38:46 [2f0d62f4] write(26, "1", 1) = 1 +[pid 3681] 19:38:46 [2f0d6454] close(26) = 0 +[pid 3681] 19:38:46 [2f0d8386] open("/sys/power/state", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE|O_CLOEXEC, 0666) = 26 +[pid 3681] 19:38:46 [2f0d8386] fcntl64(26, F_SETFD, FD_CLOEXEC) = 0 +[pid 3681] 19:38:46 [2f232276] fstat64(26, {st_dev=makedev(0, 14), st_ino=33, st_mode=S_IFREG|0644, st_nlink=1, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=0, st_size=4096, st_atime=2016/02/29-18:18:37.514794262, st_mtime=2016/02/29-19:38:46.129858648, st_ctime=2016/02/29-19:38:46.129858648}) = 0 +[pid 3681] 19:38:46 [2f0d62f4] write(26, "mem", 3) = -1 EBUSY (Device or resource busy) +[pid 3681] 19:38:46 [2f0d6454] close(26) = 0 +[pid 3681] 19:38:46 [2f0d8386] open("/sys/power/state-extended", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE|O_CLOEXEC, 0666) = 26 +[pid 3681] 19:38:46 [2f0d8386] fcntl64(26, F_SETFD, FD_CLOEXEC) = 0 +[pid 3681] 19:38:46 [2f232276] fstat64(26, {st_dev=makedev(0, 14), st_ino=38, st_mode=S_IFREG|0644, st_nlink=1, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=0, st_size=4096, st_atime=2016/02/29-18:18:37.514794262, st_mtime=2016/02/29-19:38:46.449974712, st_ctime=2016/02/29-19:38:46.449974712}) = 0 +[pid 3681] 19:38:46 [2f0d62f4] write(26, "0", 1) = 1 +[pid 3681] 19:38:46 [2f0d6454] close(26) = 0 +strace: Process 4478 attached +strace: Process 4479 attached +[pid 4479] 19:38:47 [????????] +++ exited with 0 +++ +[pid 4478] 19:38:47 [2ab4c276] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=4479, si_uid=0, si_status=0, si_utime=1, si_stime=0} --- +[pid 4478] 19:38:47 [????????] +++ exited with 0 +++ +[pid 3681] 19:38:47 [2f0d8386] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=4478, si_uid=0, si_status=0, si_utime=1, si_stime=0} --- +[pid 3681] 19:38:50 [2f0d8386] open("/sys/power/wakeup_count", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 24 +[pid 3681] 19:38:50 [2f0d8386] fcntl64(24, F_SETFD, FD_CLOEXEC) = 0 +[pid 3681] 19:38:50 [2f232276] fstat64(24, {st_dev=makedev(0, 14), st_ino=36, st_mode=S_IFREG|0644, st_nlink=1, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=0, st_size=4096, st_atime=2016/02/29-18:18:37.514794262, st_mtime=2016/02/29-19:08:22.880008624, st_ctime=2016/02/29-19:08:22.880008624}) = 0 +[pid 3681] 19:38:50 [2f232276] fstat64(24, {st_dev=makedev(0, 14), st_ino=36, st_mode=S_IFREG|0644, st_nlink=1, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=0, st_size=4096, st_atime=2016/02/29-18:18:37.514794262, st_mtime=2016/02/29-19:08:22.880008624, st_ctime=2016/02/29-19:08:22.880008624}) = 0 +[pid 3681] 19:38:50 [2f232276] fstat64(24, {st_dev=makedev(0, 14), st_ino=36, st_mode=S_IFREG|0644, st_nlink=1, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=0, st_size=4096, st_atime=2016/02/29-18:18:37.514794262, st_mtime=2016/02/29-19:08:22.880008624, st_ctime=2016/02/29-19:08:22.880008624}) = 0 +[pid 3681] 19:38:50 [2f0d63a4] read(24, "3185\n", 16384) = 5 +[pid 3681] 19:38:50 [2f0d63a4] read(24, "", 16379) = 0 +[pid 3681] 19:38:50 [2f0d63a4] read(24, "", 4091) = 0 +[pid 3681] 19:38:50 [2f0d6454] close(24) = 0 +[pid 3681] 19:38:50 [2f0d8386] open("/sys/power/state-extended", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE|O_CLOEXEC, 0666) = 26 +[pid 3681] 19:38:50 [2f0d8386] fcntl64(26, F_SETFD, FD_CLOEXEC) = 0 +[pid 3681] 19:38:50 [2f232276] fstat64(26, {st_dev=makedev(0, 14), st_ino=38, st_mode=S_IFREG|0644, st_nlink=1, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=0, st_size=4096, st_atime=2016/02/29-18:18:37.514794262, st_mtime=2016/02/29-19:38:50.129984109, st_ctime=2016/02/29-19:38:50.129984109}) = 0 +[pid 3681] 19:38:50 [2f0d62f4] write(26, "1", 1) = 1 +[pid 3681] 19:38:50 [2f0d6454] close(26) = 0 +[pid 3681] 19:38:50 [2f0d8386] open("/sys/power/state", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE|O_CLOEXEC, 0666) = 26 +[pid 3681] 19:38:50 [2f0d8386] fcntl64(26, F_SETFD, FD_CLOEXEC) = 0 +[pid 3681] 19:38:50 [2f232276] fstat64(26, {st_dev=makedev(0, 14), st_ino=33, st_mode=S_IFREG|0644, st_nlink=1, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=0, st_size=4096, st_atime=2016/02/29-18:18:37.514794262, st_mtime=2016/02/29-19:38:50.129984109, st_ctime=2016/02/29-19:38:50.129984109}) = 0 +[pid 3681] 19:38:50 [2f0d62f4] write(26, "mem", 3) = -1 EBUSY (Device or resource busy) +[pid 3681] 19:38:50 [2f0d6454] close(26) = 0 +[pid 3681] 19:38:50 [2f0d8386] open("/sys/power/state-extended", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE|O_CLOEXEC, 0666) = 26 +[pid 3681] 19:38:50 [2f0d8386] fcntl64(26, F_SETFD, FD_CLOEXEC) = 0 +[pid 3681] 19:38:50 [2f232276] fstat64(26, {st_dev=makedev(0, 14), st_ino=38, st_mode=S_IFREG|0644, st_nlink=1, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=0, st_size=4096, st_atime=2016/02/29-18:18:37.514794262, st_mtime=2016/02/29-19:38:50.440016287, st_ctime=2016/02/29-19:38:50.440016287}) = 0 +[pid 3681] 19:38:50 [2f0d62f4] write(26, "0", 1) = 1 +[pid 3681] 19:38:50 [2f0d6454] close(26) = 0 + diff --git a/platform/kobo/suspend.sh b/platform/kobo/suspend.sh index f4d605adc..df97e1da0 100755 --- a/platform/kobo/suspend.sh +++ b/platform/kobo/suspend.sh @@ -13,4 +13,4 @@ fi sync echo 1 > /sys/power/state-extended sleep 2 # Because reasons? -echo mem > /sys/power/state +echo mem > /sys/power/state # This will return -EBUSY, for some reason... From fe13af9d7ef0ac38f9023c89f9b4c34af1f64bf5 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Mon, 29 Feb 2016 21:21:38 +0100 Subject: [PATCH 02/19] More Kobo suspend tweaks... Basically more loging to debug suspend issues... AFAICT, having anything plugged in over USB will screw things up, for instance. --- platform/kobo/suspend.sh | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/platform/kobo/suspend.sh b/platform/kobo/suspend.sh index df97e1da0..602449732 100755 --- a/platform/kobo/suspend.sh +++ b/platform/kobo/suspend.sh @@ -1,16 +1,32 @@ #!/bin/sh export PATH="${PATH}:/sbin:/usr/sbin" +echo "[$(date +'%x @ %X')] Kobo Suspend: BEGIN!" # Disable wifi if lsmod | grep -q sdio_wifi_pwr ; then wlarm_le -i eth0 down ifconfig eth0 down rmmod -r dhd rmmod -r sdio_wifi_pwr + echo "[$(date +'%x @ %X')] Kobo Suspend: Killed WiFi" fi # Go to sleep -sync +current_wakeup_count="$(cat /sys/power/wakeup_count)" +echo "[$(date +'%x @ %X')] Kobo Suspend: Current WakeUp count: ${current_wakeup_count}" echo 1 > /sys/power/state-extended -sleep 2 # Because reasons? -echo mem > /sys/power/state # This will return -EBUSY, for some reason... +echo "[$(date +'%x @ %X')] Kobo Suspend: Asked for a Sleep mode suspend" +sleep 2 +echo "[$(date +'%x @ %X')] Kobo Suspend: Waited for 2s because of reasons..." +sync +echo "[$(date +'%x @ %X')] Kobo Suspend: Synced FS" +echo ${current_wakeup_count} > /sys/power/wakeup_count +echo "[$(date +'%x @ %X')] Kobo Suspend: Wrote WakeUp count: ${current_wakeup_count} ($?)" +echo mem > /sys/power/state +echo "[$(date +'%x @ %X')] Kobo Suspend: Asked to suspend to RAM... ZzZ ZzZ ZzZ? ($?)" + +## And nickel apparently loops like a crazy person if the write to /sys/power/state returns EBUSY... +#echo 0 > /sys/power/state-extended +#echo "Kobo Suspend: Asked to wakeup" + +echo "[$(date +'%x @ %X')] Kobo Suspend: END! (WakeUp count: $(cat /sys/power/wakeup_count))" From 06e1bd4ed27348776c551c623a1339b9f9c6c718 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Tue, 1 Mar 2016 01:12:54 +0100 Subject: [PATCH 03/19] Slightly more accurate comments re: Kobo suspend --- platform/kobo/nickel_suspend_strace.txt | 29 ++++++++++++++++++++++++- platform/kobo/suspend.sh | 10 +++++---- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/platform/kobo/nickel_suspend_strace.txt b/platform/kobo/nickel_suspend_strace.txt index 28546a406..184bdf695 100644 --- a/platform/kobo/nickel_suspend_strace.txt +++ b/platform/kobo/nickel_suspend_strace.txt @@ -1,4 +1,4 @@ -## On the other hand, nickel doesn't seem to fare any better... it spends its time doing this over and over: +## On the other hand, nickel doesn't seem to fare any better... when the suspend to ram fails, it spends its time doing this over and over: # strace -fitv -P /sys/power/state -P /sys/power/state-extended -P /sys/power/wakeup_count -p $(pidof nickel) strace: Process 4474 attached @@ -62,3 +62,30 @@ strace: Process 4479 attached [pid 3681] 19:38:50 [2f0d62f4] write(26, "0", 1) = 1 [pid 3681] 19:38:50 [2f0d6454] close(26) = 0 + +## Compared to a successful suspend/wakeup cycle: +522 00:59:53 [2f0d8386] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=1291, si_uid=0, si_status=0, si_utime=0, si_stime=1} --- +522 00:59:54 [2f0d8386] open("/sys/power/wakeup_count", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 21 +522 00:59:54 [2f0d8386] fcntl64(21, F_SETFD, FD_CLOEXEC) = 0 +522 00:59:54 [2f232276] fstat64(21, {st_dev=makedev(0, 14), st_ino=36, st_mode=S_IFREG|0644, st_nlink=1, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=0, st_size=4096, st_atime=2016/03/01-00:52:55.478751029, st_mtime=2016/03/01-00:52:55.478751029, st_ctime=2016/03/01-00:52:55.478751029}) = 0 +522 00:59:54 [2f232276] fstat64(21, {st_dev=makedev(0, 14), st_ino=36, st_mode=S_IFREG|0644, st_nlink=1, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=0, st_size=4096, st_atime=2016/03/01-00:52:55.478751029, st_mtime=2016/03/01-00:52:55.478751029, st_ctime=2016/03/01-00:52:55.478751029}) = 0 +522 00:59:54 [2f232276] fstat64(21, {st_dev=makedev(0, 14), st_ino=36, st_mode=S_IFREG|0644, st_nlink=1, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=0, st_size=4096, st_atime=2016/03/01-00:52:55.478751029, st_mtime=2016/03/01-00:52:55.478751029, st_ctime=2016/03/01-00:52:55.478751029}) = 0 +522 00:59:54 [2f0d63a4] read(21, "93\n", 16384) = 3 +522 00:59:54 [2f0d63a4] read(21, "", 16381) = 0 +522 00:59:54 [2f0d63a4] read(21, "", 4093) = 0 +522 00:59:54 [2f0d6454] close(21) = 0 +522 00:59:54 [2f0d8386] open("/sys/power/state-extended", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE|O_CLOEXEC, 0666) = 24 +522 00:59:54 [2f0d8386] fcntl64(24, F_SETFD, FD_CLOEXEC) = 0 +522 00:59:54 [2f232276] fstat64(24, {st_dev=makedev(0, 14), st_ino=38, st_mode=S_IFREG|0644, st_nlink=1, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=0, st_size=4096, st_atime=2016/03/01-00:59:54.358750902, st_mtime=2016/03/01-00:59:54.358750902, st_ctime=2016/03/01-00:59:54.358750902}) = 0 +522 00:59:54 [2f0d62f4] write(24, "1", 1) = 1 +522 00:59:54 [2f0d6454] close(24) = 0 +522 00:59:54 [2f0d8386] open("/sys/power/state", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE|O_CLOEXEC, 0666) = 24 +522 00:59:54 [2f0d8386] fcntl64(24, F_SETFD, FD_CLOEXEC) = 0 +522 00:59:54 [2f232276] fstat64(24, {st_dev=makedev(0, 14), st_ino=33, st_mode=S_IFREG|0644, st_nlink=1, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=0, st_size=4096, st_atime=2016/03/01-00:59:54.358750902, st_mtime=2016/03/01-00:59:54.358750902, st_ctime=2016/03/01-00:59:54.358750902}) = 0 +522 00:59:54 [2f0d62f4] write(24, "mem", 3) = 3 +522 01:00:27 [2f0d6454] close(24) = 0 +522 01:00:27 [2f0d8386] open("/sys/power/state-extended", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE|O_CLOEXEC, 0666) = 24 +522 01:00:27 [2f0d8386] fcntl64(24, F_SETFD, FD_CLOEXEC) = 0 +522 01:00:27 [2f232276] fstat64(24, {st_dev=makedev(0, 14), st_ino=38, st_mode=S_IFREG|0644, st_nlink=1, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=0, st_size=4096, st_atime=2016/03/01-00:59:54.358750902, st_mtime=2016/03/01-01:00:27.398750985, st_ctime=2016/03/01-01:00:27.398750985}) = 0 +522 01:00:27 [2f0d62f4] write(24, "0", 1) = 1 +522 01:00:27 [2f0d6454] close(24) = 0 diff --git a/platform/kobo/suspend.sh b/platform/kobo/suspend.sh index 602449732..818a217c1 100755 --- a/platform/kobo/suspend.sh +++ b/platform/kobo/suspend.sh @@ -24,9 +24,11 @@ echo ${current_wakeup_count} > /sys/power/wakeup_count echo "[$(date +'%x @ %X')] Kobo Suspend: Wrote WakeUp count: ${current_wakeup_count} ($?)" echo mem > /sys/power/state echo "[$(date +'%x @ %X')] Kobo Suspend: Asked to suspend to RAM... ZzZ ZzZ ZzZ? ($?)" - -## And nickel apparently loops like a crazy person if the write to /sys/power/state returns EBUSY... -#echo 0 > /sys/power/state-extended -#echo "Kobo Suspend: Asked to wakeup" +## NOTE: Ideally, we'd need a way to warn the user that suspending gloriously failed at this point... +## We can safely assume that just from a non-zero return code, without looking at the detailed stderr message +## (most of the failures we'll see are -EBUSY anyway) +## For reference, when that happens to nickel, it appears to keep retrying to wakeup & sleep ad nauseam, +## which is where the non-sensical 1 -> mem -> 0 loop idea comes from... +## cf. nickel_suspend_strace.txt for more details. echo "[$(date +'%x @ %X')] Kobo Suspend: END! (WakeUp count: $(cat /sys/power/wakeup_count))" From 150aac1630c942a8b555db79d1eea8a8847f63c8 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Tue, 1 Mar 2016 02:23:50 +0100 Subject: [PATCH 04/19] More comment tweaks re: Kobo suspend --- platform/kobo/suspend.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/platform/kobo/suspend.sh b/platform/kobo/suspend.sh index 818a217c1..5f275a4f3 100755 --- a/platform/kobo/suspend.sh +++ b/platform/kobo/suspend.sh @@ -15,7 +15,9 @@ fi current_wakeup_count="$(cat /sys/power/wakeup_count)" echo "[$(date +'%x @ %X')] Kobo Suspend: Current WakeUp count: ${current_wakeup_count}" echo 1 > /sys/power/state-extended -echo "[$(date +'%x @ %X')] Kobo Suspend: Asked for a Sleep mode suspend" +# NOTE: Sets gSleep_Mode_Suspend to 1. Used as a flag throughout the kernel to suspend/resume various subsystems +# cf. kernel/power/main.c @ L#207 +echo "[$(date +'%x @ %X')] Kobo Suspend: Asked the kernel to put subsystems to sleep" sleep 2 echo "[$(date +'%x @ %X')] Kobo Suspend: Waited for 2s because of reasons..." sync From ea382aea86f12eb4b825ecc125edaf5a91748bfd Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Tue, 1 Mar 2016 19:43:56 +0100 Subject: [PATCH 05/19] Tweak the sd is ro check a bit Inspired from MRPI, but without a strict check of the device name, because I'm not sure it'll be the same across the whole range of Kobos... --- platform/kobo/koreader.sh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/platform/kobo/koreader.sh b/platform/kobo/koreader.sh index 0a55964c1..56abf1a5b 100755 --- a/platform/kobo/koreader.sh +++ b/platform/kobo/koreader.sh @@ -80,11 +80,9 @@ if [ ! -n "${PLATFORM}" ] ; then fi # end of value check of PLATFORM -grep ' /mnt/sd ' /proc/mounts | grep 'ro' -# Remount SD to RW if it's RO -if [ $? -eq 0 ] -then - mount -o remount,rw /mnt/sd +# Remount the SD card RW if it's inserted and currently RO +if awk '$4~/(^|,)ro($|,)/' /proc/mounts | grep ' /mnt/sd ' ; then + mount -o remount,rw /mnt/sd fi ./reader.lua "${args}" 2> crash.log From 85737e2b9d458a345ab4b71cd579dd003f59d745 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Tue, 1 Mar 2016 19:56:42 +0100 Subject: [PATCH 06/19] Forcibly re-activate IR grid on resume... re #1862 --- frontend/device/kobo/device.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/frontend/device/kobo/device.lua b/frontend/device/kobo/device.lua index 7a1ec8571..c4dd67d22 100644 --- a/frontend/device/kobo/device.lua +++ b/frontend/device/kobo/device.lua @@ -143,6 +143,12 @@ end function Kobo:resume() os.execute("echo 0 > /sys/power/state-extended") + -- cf. #1862, I can reliably break IR touch input on resume... + local f = io.open("/sys/devices/virtual/input/input1/neocmd", "r") + if f ~= nil then + io.close(f) + os.execute("echo 'a' > /sys/devices/virtual/input/input1/neocmd") + end end -------------- device probe ------------ From 770625d756868c713c897575da6750726761315b Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Tue, 1 Mar 2016 20:01:10 +0100 Subject: [PATCH 07/19] Tweak the 'IR down on resume' workaround... Only apply it when started from nickel, because I'm guessing we'd have seen a number of reports of this if it happened more widely... --- frontend/device/kobo/device.lua | 10 ++++++---- platform/kobo/koreader.sh | 8 ++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/frontend/device/kobo/device.lua b/frontend/device/kobo/device.lua index c4dd67d22..0007509dc 100644 --- a/frontend/device/kobo/device.lua +++ b/frontend/device/kobo/device.lua @@ -144,10 +144,12 @@ end function Kobo:resume() os.execute("echo 0 > /sys/power/state-extended") -- cf. #1862, I can reliably break IR touch input on resume... - local f = io.open("/sys/devices/virtual/input/input1/neocmd", "r") - if f ~= nil then - io.close(f) - os.execute("echo 'a' > /sys/devices/virtual/input/input1/neocmd") + if os.getenv("FROM_NICKEL") == "true" then + local f = io.open("/sys/devices/virtual/input/input1/neocmd", "r") + if f ~= nil then + io.close(f) + os.execute("echo 'a' > /sys/devices/virtual/input/input1/neocmd") + end end end diff --git a/platform/kobo/koreader.sh b/platform/kobo/koreader.sh index 56abf1a5b..c9ba7c21d 100755 --- a/platform/kobo/koreader.sh +++ b/platform/kobo/koreader.sh @@ -29,12 +29,12 @@ export EXT_FONT_DIR="/mnt/onboard/fonts" # fast and dirty way of check if we are called from nickel # through fmon, or from another launcher (KSM or advboot) -from_nickel="false" +export FROM_NICKEL="false" if pkill -0 nickel ; then - from_nickel="true" + FROM_NICKEL="true" fi -if [ "${from_nickel}" == "true" ] ; then +if [ "${FROM_NICKEL}" == "true" ] ; then # Siphon a few things from nickel's env... eval "$(xargs -n 1 -0 < /proc/$(pidof nickel)/environ | grep -e DBUS_SESSION_BUS_ADDRESS -e WIFI_MODULE -e PLATFORM -e WIFI_MODULE_PATH -e INTERFACE -e PRODUCT 2>/dev/null)" export DBUS_SESSION_BUS_ADDRESS WIFI_MODULE PLATFORM WIFI_MODULE_PATH INTERFACE PRODUCT @@ -87,7 +87,7 @@ fi ./reader.lua "${args}" 2> crash.log -if [ "${from_nickel}" == "true" ] ; then +if [ "${FROM_NICKEL}" == "true" ] ; then # start kobo software because it was running before koreader ./nickel.sh & else From f213fb64051db442ea74bb54a39726cd8f2d8820 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Tue, 1 Mar 2016 20:11:05 +0100 Subject: [PATCH 08/19] Bypass flState on suspend/wakeup We pretty much always want to turn it off on suspend, and turn it on to some measure on wakeup. That, and nickel's FrontLightState is completely nonsensical on my device anyway... --- frontend/device/kobo/powerd.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frontend/device/kobo/powerd.lua b/frontend/device/kobo/powerd.lua index dadefbcd9..59908d79f 100644 --- a/frontend/device/kobo/powerd.lua +++ b/frontend/device/kobo/powerd.lua @@ -63,7 +63,6 @@ end -- Turn off front light before suspend. function KoboPowerD:beforeSuspend() if self.fl ~= nil then - self.flState = true self.fl:setBrightness(0) end end @@ -73,7 +72,7 @@ function KoboPowerD:afterResume() if self.fl ~= nil then if KOBO_LIGHT_ON_START and tonumber(KOBO_LIGHT_ON_START) > -1 then self:setIntensity(math.min(KOBO_LIGHT_ON_START, 100)) - elseif self.flState then + else self.fl:setBrightness(self.flIntensity) end end From 32874b18c5c0575b0dff3c7c7f05ccccc8685aff Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Tue, 1 Mar 2016 21:04:22 -0800 Subject: [PATCH 09/19] kodev: fix clean command for android --- kodev | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kodev b/kodev index 45fc377b2..cbdc21a35 100755 --- a/kodev +++ b/kodev @@ -130,7 +130,7 @@ ${SUPPORTED_TARGETS}" ;; android) make TARGET=android clean - rm *.apk + rm -f *.apk ;; pocketbook) make TARGET=pocketbook clean From 9afae91b1306baadeef992ee6352c3b279182c59 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Tue, 1 Mar 2016 22:06:21 -0800 Subject: [PATCH 10/19] chore: rename frontlight related variables to keep style consistent flIntensity -> fl_intensity flState -> is_fl_on fallback_FrontLightLevel -> fallback_fl_level --- .../apps/reader/modules/readerfrontlight.lua | 12 +++++----- frontend/device/generic/powerd.lua | 4 ++-- frontend/device/kindle/powerd.lua | 12 +++++----- frontend/device/kobo/nickel_conf.lua | 6 ++--- frontend/device/kobo/powerd.lua | 22 +++++++++---------- reader.lua | 2 +- 6 files changed, 29 insertions(+), 29 deletions(-) diff --git a/frontend/apps/reader/modules/readerfrontlight.lua b/frontend/apps/reader/modules/readerfrontlight.lua index ee5ee71e2..e6c7623c2 100644 --- a/frontend/apps/reader/modules/readerfrontlight.lua +++ b/frontend/apps/reader/modules/readerfrontlight.lua @@ -40,17 +40,17 @@ end function ReaderFrontLight:onAdjust(arg, ges) local powerd = Device:getPowerDevice() - if powerd.flIntensity ~= nil then - DEBUG("frontlight intensity", powerd.flIntensity) + if powerd.fl_intensity ~= nil then + DEBUG("frontlight intensity", powerd.fl_intensity) local step = math.ceil(#self.steps * ges.distance / self.gestureScale) DEBUG("step = ", step) local delta_int = self.steps[step] or self.steps[#self.steps] DEBUG("delta_int = ", delta_int) local new_intensity if ges.direction == "north" then - new_intensity = powerd.flIntensity + delta_int + new_intensity = powerd.fl_intensity + delta_int elseif ges.direction == "south" then - new_intensity = powerd.flIntensity - delta_int + new_intensity = powerd.fl_intensity - delta_int end if new_intensity ~= nil then powerd:setIntensity(new_intensity) @@ -61,9 +61,9 @@ end function ReaderFrontLight:onShowIntensity() local powerd = Device:getPowerDevice() - if powerd.flIntensity ~= nil then + if powerd.fl_intensity ~= nil then UIManager:show(Notification:new{ - text = T( _("Frontlight intensity is set to %1."), powerd.flIntensity), + text = T( _("Frontlight intensity is set to %1."), powerd.fl_intensity), timeout = 1.0, }) end diff --git a/frontend/device/generic/powerd.lua b/frontend/device/generic/powerd.lua index 9fb44ea76..dad7a9788 100644 --- a/frontend/device/generic/powerd.lua +++ b/frontend/device/generic/powerd.lua @@ -1,7 +1,7 @@ local BasePowerD = { fl_min = 0, -- min frontlight intensity fl_max = 10, -- max frontlight intensity - flIntensity = nil, -- frontlight intensity + fl_intensity = nil, -- frontlight intensity battCapacity = nil, -- battery capacity device = nil, -- device object @@ -57,7 +57,7 @@ function BasePowerD:normalizeIntensity(intensity) end function BasePowerD:setIntensity(intensity) - self.flIntensity = self:normalizeIntensity(intensity) + self.fl_intensity = self:normalizeIntensity(intensity) self:setIntensityHW() end diff --git a/frontend/device/kindle/powerd.lua b/frontend/device/kindle/powerd.lua index 6d025d5bb..de1e80213 100644 --- a/frontend/device/kindle/powerd.lua +++ b/frontend/device/kindle/powerd.lua @@ -4,7 +4,7 @@ local BasePowerD = require("device/generic/powerd") local KindlePowerD = BasePowerD:new{ fl_min = 0, fl_max = 24, - flIntensity = nil, + fl_intensity = nil, battCapacity = nil, is_charging = nil, lipc_handle = nil, @@ -17,9 +17,9 @@ function KindlePowerD:init() end if self.device.hasFrontlight() then if self.lipc_handle ~= nil then - self.flIntensity = self.lipc_handle:get_int_property("com.lab126.powerd", "flIntensity") + self.fl_intensity = self.lipc_handle:get_int_property("com.lab126.powerd", "flIntensity") else - self.flIntensity = self:read_int_file(self.fl_intensity_file) + self.fl_intensity = self:read_int_file(self.fl_intensity_file) end end end @@ -27,7 +27,7 @@ end function KindlePowerD:toggleFrontlight() local sysint = self:read_int_file(self.fl_intensity_file) if sysint == 0 then - self:setIntensity(self.flIntensity) + self:setIntensity(self.fl_intensity) else os.execute("echo -n 0 > " .. self.fl_intensity_file) end @@ -35,9 +35,9 @@ end function KindlePowerD:setIntensityHW() if self.lipc_handle ~= nil then - self.lipc_handle:set_int_property("com.lab126.powerd", "flIntensity", self.flIntensity) + self.lipc_handle:set_int_property("com.lab126.powerd", "flIntensity", self.fl_intensity) else - os.execute("echo -n ".. self.flIntensity .." > " .. self.fl_intensity_file) + os.execute("echo -n ".. self.fl_intensity .." > " .. self.fl_intensity_file) end end diff --git a/frontend/device/kobo/nickel_conf.lua b/frontend/device/kobo/nickel_conf.lua index 9248f994d..f0e39ca9d 100644 --- a/frontend/device/kobo/nickel_conf.lua +++ b/frontend/device/kobo/nickel_conf.lua @@ -57,9 +57,9 @@ function NickelConf.frontLightLevel.get() if new_intensity then return powerd:normalizeIntensity(new_intensity) else - local fallback_FrontLightLevel = powerd.flIntensity or 1 - assert(NickelConf.frontLightLevel.set(fallback_FrontLightLevel)) - return fallback_FrontLightLevel + local fallback_fl_level = powerd.fl_intensity or 1 + assert(NickelConf.frontLightLevel.set(fallback_fl_level)) + return fallback_fl_level end end diff --git a/frontend/device/kobo/powerd.lua b/frontend/device/kobo/powerd.lua index 59908d79f..7b218e934 100644 --- a/frontend/device/kobo/powerd.lua +++ b/frontend/device/kobo/powerd.lua @@ -8,11 +8,11 @@ local KoboPowerD = BasePowerD:new{ -- Do not actively set front light to 0, it may confuse users -- pressing -- hardware button won't take any effect. fl_min = 1, fl_max = 100, - flIntensity = 20, + fl_intensity = 20, restore_settings = true, fl = nil, - - flState = false, + -- this attribute should be synced with nickel's FrontLightState config + is_fl_on = false, batt_capacity_file = batt_state_folder .. "capacity", is_charging_file = batt_state_folder .. "status", battCapacity = nil, @@ -29,23 +29,23 @@ end function KoboPowerD:toggleFrontlight() if self.fl ~= nil then - if self.flState then + if self.is_fl_on then self.fl:setBrightness(0) else - self.fl:setBrightness(self.flIntensity) + self.fl:setBrightness(self.fl_intensity) end - self.flState = not self.flState + self.is_fl_on = not self.is_fl_on if KOBO_SYNC_BRIGHTNESS_WITH_NICKEL then - NickelConf.frontLightState.set(self.flState) + NickelConf.frontLightState.set(self.is_fl_on) end end end function KoboPowerD:setIntensityHW() if self.fl ~= nil then - self.fl:setBrightness(self.flIntensity) + self.fl:setBrightness(self.fl_intensity) if KOBO_SYNC_BRIGHTNESS_WITH_NICKEL then - NickelConf.frontLightLevel.set(self.flIntensity) + NickelConf.frontLightLevel.set(self.fl_intensity) end end end @@ -72,8 +72,8 @@ function KoboPowerD:afterResume() if self.fl ~= nil then if KOBO_LIGHT_ON_START and tonumber(KOBO_LIGHT_ON_START) > -1 then self:setIntensity(math.min(KOBO_LIGHT_ON_START, 100)) - else - self.fl:setBrightness(self.flIntensity) + elseif self.is_fl_on then + self.fl:setBrightness(self.fl_intensity) end end end diff --git a/reader.lua b/reader.lua index c014e02b6..ed201012b 100755 --- a/reader.lua +++ b/reader.lua @@ -121,7 +121,7 @@ if Device:isKobo() then local powerd = Device:getPowerDevice() if powerd and powerd.restore_settings then local intensity = G_reader_settings:readSetting("frontlight_intensity") - powerd.flIntensity = intensity or powerd.flIntensity + powerd.fl_intensity = intensity or powerd.fl_intensity local state = G_reader_settings:readSetting("frontlight_state") if state then -- Default state is off From cf3b97537b58cf296eefe8a9178737807a122b79 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Tue, 1 Mar 2016 22:30:29 -0800 Subject: [PATCH 11/19] kobo: build fl_state based on fl_intensity if model does not support toggle --- frontend/device/kobo/nickel_conf.lua | 8 ++------ frontend/ui/uimanager.lua | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/frontend/device/kobo/nickel_conf.lua b/frontend/device/kobo/nickel_conf.lua index f0e39ca9d..57aca7ac1 100644 --- a/frontend/device/kobo/nickel_conf.lua +++ b/frontend/device/kobo/nickel_conf.lua @@ -68,12 +68,8 @@ function NickelConf.frontLightState.get() if new_state then new_state = (new_state == "true") or false end - - if new_state == nil then - assert(NickelConf.frontLightState.set(false)) - return false - end - + -- for devices that do not have toggle button, the entry will be missing + -- and we return nil in this case. return new_state end diff --git a/frontend/ui/uimanager.lua b/frontend/ui/uimanager.lua index 7576d5c87..7d57e0f2c 100644 --- a/frontend/ui/uimanager.lua +++ b/frontend/ui/uimanager.lua @@ -74,12 +74,21 @@ function UIManager:init() local NickelConf = require("device/kobo/nickel_conf") new_intensity = NickelConf.frontLightLevel.get() new_state = NickelConf.frontLightState:get() + if new_state == nil then + -- this device does not support frontlight toggle, + -- we set the state based on frontlight intensity. + if new_intensity > 0 then + new_state = true + else + new_state = false + end + end end + -- Since this kobo-specific, we save all values in settings here + -- and let the code (reader.lua) pick it up later during bootstrap. if new_intensity then - -- Since this kobo-specific, we save here and let the code pick - -- it up later from the reader settings. - G_reader_settings:saveSetting( - "frontlight_intensity", new_intensity) + G_reader_settings:saveSetting("frontlight_intensity", + new_intensity) end G_reader_settings:saveSetting("frontlight_state", new_state) end From 08b08d69f7fd753f6820dfde2285dc1adead4ba0 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Tue, 1 Mar 2016 22:42:50 -0800 Subject: [PATCH 12/19] kobo: always set light intensity to 0 if state is nil or false --- reader.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/reader.lua b/reader.lua index ed201012b..fd53d181c 100755 --- a/reader.lua +++ b/reader.lua @@ -124,8 +124,15 @@ if Device:isKobo() then powerd.fl_intensity = intensity or powerd.fl_intensity local state = G_reader_settings:readSetting("frontlight_state") if state then - -- Default state is off + -- default state is off, turn it on powerd:toggleFrontlight() + else + -- the light can still be turned on manually outside of koreader + -- or nickel. so we always set the intensity to 0 here to keep it + -- in sync with the default state + -- NOTE: we cant use setIntensity method here because for kobo the + -- min intensity is 1 :( + powerd.fl:setBrightness(0) end end if Device:getCodeName() == "trilogy" then From 8b7658b8cd9a9754ba66d959274190daddebb25f Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Tue, 1 Mar 2016 22:59:48 -0800 Subject: [PATCH 13/19] kobo: always keep intensity value and is_fl_on in sync --- frontend/device/generic/powerd.lua | 9 +++++---- frontend/device/kobo/powerd.lua | 30 +++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/frontend/device/generic/powerd.lua b/frontend/device/generic/powerd.lua index dad7a9788..c0dae784e 100644 --- a/frontend/device/generic/powerd.lua +++ b/frontend/device/generic/powerd.lua @@ -1,9 +1,9 @@ local BasePowerD = { - fl_min = 0, -- min frontlight intensity - fl_max = 10, -- max frontlight intensity - fl_intensity = nil, -- frontlight intensity + fl_min = 0, -- min frontlight intensity + fl_max = 10, -- max frontlight intensity + fl_intensity = nil, -- frontlight intensity battCapacity = nil, -- battery capacity - device = nil, -- device object + device = nil, -- device object capacity_pulled_count = 0, capacity_cached_count = 10, @@ -57,6 +57,7 @@ function BasePowerD:normalizeIntensity(intensity) end function BasePowerD:setIntensity(intensity) + if intensity == self.fl_intensity then return end self.fl_intensity = self:normalizeIntensity(intensity) self:setIntensityHW() end diff --git a/frontend/device/kobo/powerd.lua b/frontend/device/kobo/powerd.lua index 7b218e934..6aec18b53 100644 --- a/frontend/device/kobo/powerd.lua +++ b/frontend/device/kobo/powerd.lua @@ -11,8 +11,12 @@ local KoboPowerD = BasePowerD:new{ fl_intensity = 20, restore_settings = true, fl = nil, - -- this attribute should be synced with nickel's FrontLightState config + + -- We will set this value for all kobo models. but it will only be synced + -- with nickel's FrontLightState config if the current model has a + -- frontlight toggle button. is_fl_on = false, + batt_capacity_file = batt_state_folder .. "capacity", is_charging_file = batt_state_folder .. "status", battCapacity = nil, @@ -23,7 +27,14 @@ function KoboPowerD:init() if self.device.hasFrontlight() then local kobolight = require("ffi/kobolight") local ok, light = pcall(kobolight.open) - if ok then self.fl = light end + if ok then + self.fl = light + if NickelConf.frontLightState.get() ~= nil then + self.has_fl_toggle_btn = true + else + self.has_fl_toggle_btn = false + end + end end end @@ -35,7 +46,7 @@ function KoboPowerD:toggleFrontlight() self.fl:setBrightness(self.fl_intensity) end self.is_fl_on = not self.is_fl_on - if KOBO_SYNC_BRIGHTNESS_WITH_NICKEL then + if self.has_fl_toggle_btn and KOBO_SYNC_BRIGHTNESS_WITH_NICKEL then NickelConf.frontLightState.set(self.is_fl_on) end end @@ -47,6 +58,19 @@ function KoboPowerD:setIntensityHW() if KOBO_SYNC_BRIGHTNESS_WITH_NICKEL then NickelConf.frontLightLevel.set(self.fl_intensity) end + -- also keep self.is_fl_on in sync with intensity if needed + local is_fl_on + if self.fl_intensity > 0 then + is_fl_on = true + else + is_fl_on = false + end + if self.is_fl_on ~= is_fl_on then + self.is_fl_on = is_fl_on + if self.has_fl_toggle_btn and KOBO_SYNC_BRIGHTNESS_WITH_NICKEL then + NickelConf.frontLightState.set(self.is_fl_on) + end + end end end From 8190093f839a471522beec34b5b611be1a502341 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Tue, 1 Mar 2016 23:09:14 -0800 Subject: [PATCH 14/19] kobo: don't create FrontLightState config if it didn't exist to begin with --- frontend/apps/reader/modules/readerfrontlight.lua | 2 +- frontend/device/kobo/nickel_conf.lua | 8 +++++--- spec/unit/nickel_conf_spec.lua | 10 +++------- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/frontend/apps/reader/modules/readerfrontlight.lua b/frontend/apps/reader/modules/readerfrontlight.lua index e6c7623c2..d19d1c153 100644 --- a/frontend/apps/reader/modules/readerfrontlight.lua +++ b/frontend/apps/reader/modules/readerfrontlight.lua @@ -63,7 +63,7 @@ function ReaderFrontLight:onShowIntensity() local powerd = Device:getPowerDevice() if powerd.fl_intensity ~= nil then UIManager:show(Notification:new{ - text = T( _("Frontlight intensity is set to %1."), powerd.fl_intensity), + text = T(_("Frontlight intensity is set to %1."), powerd.fl_intensity), timeout = 1.0, }) end diff --git a/frontend/device/kobo/nickel_conf.lua b/frontend/device/kobo/nickel_conf.lua index 57aca7ac1..2cfcceb05 100644 --- a/frontend/device/kobo/nickel_conf.lua +++ b/frontend/device/kobo/nickel_conf.lua @@ -73,7 +73,7 @@ function NickelConf.frontLightState.get() return new_state end -function NickelConf._write_kobo_conf(re_Match, key, value) +function NickelConf._write_kobo_conf(re_Match, key, value, dont_create) local kobo_conf = io.open(kobo_conf_path, "r") local lines = {} local found = false @@ -108,7 +108,7 @@ function NickelConf._write_kobo_conf(re_Match, key, value) kobo_conf:close() end - if not found then + if not found and dont_create ~= true then if not correct_section then lines[#lines + 1] = "[PowerOptions]" end @@ -140,7 +140,9 @@ function NickelConf.frontLightState.set(new_state) "Wrong front light state value type (expect boolean)!") return NickelConf._write_kobo_conf(re_FrontLightState, front_light_state_str, - new_state) + new_state, + -- do not create this entry is missing + true) end return NickelConf diff --git a/spec/unit/nickel_conf_spec.lua b/spec/unit/nickel_conf_spec.lua index 44beba96b..3e9f648f4 100644 --- a/spec/unit/nickel_conf_spec.lua +++ b/spec/unit/nickel_conf_spec.lua @@ -59,7 +59,7 @@ bar=baz NickelConf._set_kobo_conf_path(fn) assert.Equals(NickelConf.frontLightLevel.get(), 20) - assert.Equals(NickelConf.frontLightState.get(), false) + assert.Equals(NickelConf.frontLightState.get(), nil) os.remove(fn) end) @@ -83,7 +83,6 @@ FrontLightLevel=6 FrontLightLevel=6 [PowerOptions] FrontLightLevel=100 -FrontLightState=true ]]) fd:close() os.remove(fn) @@ -99,7 +98,6 @@ FrontLightState=true assert.Equals(fd:read("*a"), [[ [PowerOptions] FrontLightLevel=20 -FrontLightState=false ]]) fd:close() os.remove(fn) @@ -153,14 +151,13 @@ bar=baz NickelConf.frontLightState.set(true) fd = io.open(fn, "r") - assert.Equals(fd:read("*a"), [[ + assert.Equals([[ [PowerOptions] foo=bar FrontLightLevel=1 -FrontLightState=true [OtherThing] bar=baz -]]) +]], fd:read("*a")) fd:close() os.remove(fn) end) @@ -178,7 +175,6 @@ bar=baz assert.Equals([[ [PowerOptions] FrontLightLevel=15 -FrontLightState=false ]], fd:read("*a")) fd:close() From 399d676cf060f6457aeee02fe387e99f9bea6384 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Wed, 2 Mar 2016 00:05:56 -0800 Subject: [PATCH 15/19] kobo: rename frontlight_state config to is_frontlight_on --- frontend/ui/uimanager.lua | 18 +++++++++--------- reader.lua | 8 ++++---- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/frontend/ui/uimanager.lua b/frontend/ui/uimanager.lua index 7d57e0f2c..1aa449729 100644 --- a/frontend/ui/uimanager.lua +++ b/frontend/ui/uimanager.lua @@ -64,23 +64,23 @@ function UIManager:init() local kobo_light_on_start = tonumber(KOBO_LIGHT_ON_START) if kobo_light_on_start then local new_intensity - local new_state + local is_fl_on if kobo_light_on_start > 0 then new_intensity = math.min(kobo_light_on_start, 100) - new_state = true + is_fl_on = true elseif kobo_light_on_start == 0 then - new_state = false + is_fl_on = false elseif kobo_light_on_start == -2 then local NickelConf = require("device/kobo/nickel_conf") new_intensity = NickelConf.frontLightLevel.get() - new_state = NickelConf.frontLightState:get() - if new_state == nil then + is_fl_on = NickelConf.frontLightState:get() + if is_fl_on == nil then -- this device does not support frontlight toggle, - -- we set the state based on frontlight intensity. + -- we set the value based on frontlight intensity. if new_intensity > 0 then - new_state = true + is_fl_on = true else - new_state = false + is_fl_on = false end end end @@ -90,7 +90,7 @@ function UIManager:init() G_reader_settings:saveSetting("frontlight_intensity", new_intensity) end - G_reader_settings:saveSetting("frontlight_state", new_state) + G_reader_settings:saveSetting("is_frontlight_on", is_fl_on) end elseif Device:isKindle() then self.event_handlers["IntoSS"] = function() diff --git a/reader.lua b/reader.lua index fd53d181c..df564aacc 100755 --- a/reader.lua +++ b/reader.lua @@ -122,14 +122,14 @@ if Device:isKobo() then if powerd and powerd.restore_settings then local intensity = G_reader_settings:readSetting("frontlight_intensity") powerd.fl_intensity = intensity or powerd.fl_intensity - local state = G_reader_settings:readSetting("frontlight_state") - if state then - -- default state is off, turn it on + local is_fl_on = G_reader_settings:readSetting("is_frontlight_on") + if is_fl_on then + -- default is_fl_on is false, turn it on powerd:toggleFrontlight() else -- the light can still be turned on manually outside of koreader -- or nickel. so we always set the intensity to 0 here to keep it - -- in sync with the default state + -- in sync with powerd.is_fl_on (false by default) -- NOTE: we cant use setIntensity method here because for kobo the -- min intensity is 1 :( powerd.fl:setBrightness(0) From 4751aba46ca226ce7faecfc174ba6b3e8297fddb Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Wed, 2 Mar 2016 00:11:09 -0800 Subject: [PATCH 16/19] kobo: rewording, turns out has_toggle_btn != has_state_cfg :( --- frontend/device/kobo/powerd.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/frontend/device/kobo/powerd.lua b/frontend/device/kobo/powerd.lua index 6aec18b53..1a2f311b2 100644 --- a/frontend/device/kobo/powerd.lua +++ b/frontend/device/kobo/powerd.lua @@ -13,8 +13,8 @@ local KoboPowerD = BasePowerD:new{ fl = nil, -- We will set this value for all kobo models. but it will only be synced - -- with nickel's FrontLightState config if the current model has a - -- frontlight toggle button. + -- with nickel's FrontLightState config if the current nickel firmware + -- supports this config. is_fl_on = false, batt_capacity_file = batt_state_folder .. "capacity", @@ -30,9 +30,9 @@ function KoboPowerD:init() if ok then self.fl = light if NickelConf.frontLightState.get() ~= nil then - self.has_fl_toggle_btn = true + self.has_fl_state_cfg = true else - self.has_fl_toggle_btn = false + self.has_fl_state_cfg = false end end end @@ -46,7 +46,7 @@ function KoboPowerD:toggleFrontlight() self.fl:setBrightness(self.fl_intensity) end self.is_fl_on = not self.is_fl_on - if self.has_fl_toggle_btn and KOBO_SYNC_BRIGHTNESS_WITH_NICKEL then + if self.has_fl_state_cfg and KOBO_SYNC_BRIGHTNESS_WITH_NICKEL then NickelConf.frontLightState.set(self.is_fl_on) end end @@ -67,7 +67,7 @@ function KoboPowerD:setIntensityHW() end if self.is_fl_on ~= is_fl_on then self.is_fl_on = is_fl_on - if self.has_fl_toggle_btn and KOBO_SYNC_BRIGHTNESS_WITH_NICKEL then + if self.has_fl_state_cfg and KOBO_SYNC_BRIGHTNESS_WITH_NICKEL then NickelConf.frontLightState.set(self.is_fl_on) end end From 45bb1ef79e4af3d05fbed420275dc9d98d83224c Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Wed, 2 Mar 2016 18:26:13 +0100 Subject: [PATCH 17/19] Bump base --- base | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base b/base index a3deaf03a..84d7b7a06 160000 --- a/base +++ b/base @@ -1 +1 @@ -Subproject commit a3deaf03addb8703fae618eca8b1aab12fe1579f +Subproject commit 84d7b7a064a6c70a069366b3eb3eb5d9cf4721b9 From a82fe3ac44e19af673900cd1c5041576213df139 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Wed, 2 Mar 2016 19:08:07 +0100 Subject: [PATCH 18/19] is_fl_on -> is_frontlight_on outside of powerd Matches the reader setting we're reading/writing at that point, and avoids confusion related to scoping because it doesn't necessarily match powerd.is_fl_on at that point. Well, at least I had to wrap my mind around it ^^ --- frontend/ui/uimanager.lua | 16 ++++++++-------- reader.lua | 7 ++++--- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/frontend/ui/uimanager.lua b/frontend/ui/uimanager.lua index 1aa449729..1e145ddd6 100644 --- a/frontend/ui/uimanager.lua +++ b/frontend/ui/uimanager.lua @@ -64,23 +64,23 @@ function UIManager:init() local kobo_light_on_start = tonumber(KOBO_LIGHT_ON_START) if kobo_light_on_start then local new_intensity - local is_fl_on + local is_frontlight_on if kobo_light_on_start > 0 then new_intensity = math.min(kobo_light_on_start, 100) - is_fl_on = true + is_frontlight_on = true elseif kobo_light_on_start == 0 then - is_fl_on = false + is_frontlight_on = false elseif kobo_light_on_start == -2 then local NickelConf = require("device/kobo/nickel_conf") new_intensity = NickelConf.frontLightLevel.get() - is_fl_on = NickelConf.frontLightState:get() - if is_fl_on == nil then + is_frontlight_on = NickelConf.frontLightState:get() + if is_frontlight_on == nil then -- this device does not support frontlight toggle, -- we set the value based on frontlight intensity. if new_intensity > 0 then - is_fl_on = true + is_frontlight_on = true else - is_fl_on = false + is_frontlight_on = false end end end @@ -90,7 +90,7 @@ function UIManager:init() G_reader_settings:saveSetting("frontlight_intensity", new_intensity) end - G_reader_settings:saveSetting("is_frontlight_on", is_fl_on) + G_reader_settings:saveSetting("is_frontlight_on", is_frontlight_on) end elseif Device:isKindle() then self.event_handlers["IntoSS"] = function() diff --git a/reader.lua b/reader.lua index df564aacc..ea258569d 100755 --- a/reader.lua +++ b/reader.lua @@ -120,11 +120,12 @@ end if Device:isKobo() then local powerd = Device:getPowerDevice() if powerd and powerd.restore_settings then + -- UIManager:init() should have sanely set up the frontlight_stuff by this point local intensity = G_reader_settings:readSetting("frontlight_intensity") powerd.fl_intensity = intensity or powerd.fl_intensity - local is_fl_on = G_reader_settings:readSetting("is_frontlight_on") - if is_fl_on then - -- default is_fl_on is false, turn it on + local is_frontlight_on = G_reader_settings:readSetting("is_frontlight_on") + if is_frontlight_on then + -- default powerd.is_fl_on is false, turn it on powerd:toggleFrontlight() else -- the light can still be turned on manually outside of koreader From e60de3044ce31be0e076717193c21b60a1544e1c Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Wed, 2 Mar 2016 19:16:02 +0100 Subject: [PATCH 19/19] Keep intensity in sync at the config level too Make sure frontlight_intensity in reader.lua settings matches what we write into Nikcel's config --- frontend/device/kobo/nickel_conf.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frontend/device/kobo/nickel_conf.lua b/frontend/device/kobo/nickel_conf.lua index 2cfcceb05..bfdb23334 100644 --- a/frontend/device/kobo/nickel_conf.lua +++ b/frontend/device/kobo/nickel_conf.lua @@ -130,6 +130,9 @@ end function NickelConf.frontLightLevel.set(new_intensity) assert(new_intensity >= 0 and new_intensity <= 100, "Wrong brightness value given!") + -- Make sure we're in sync with KOReader on the config level, too + G_reader_settings:saveSetting("frontlight_intensity", + new_intensity) return NickelConf._write_kobo_conf(re_FrontLightLevel, front_light_level_str, new_intensity)