Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround to support new kobo firmwares (+4.0) without needing KSM8 #2731

Merged
merged 2 commits into from
Apr 7, 2017

Conversation

pazos
Copy link
Member

@pazos pazos commented Apr 6, 2017

Waiting for #2502. Until now only KSM8 supports new firmware and this is because it uses its own version of koreader.sh.

This forces depth to 16bpp before running koreader. It was suggested by baskerville on #2542
It also handles weird rotations that I've found on a Kobo Aura HD. AFAIK the same rotation bug happens on Kobo Aura H20 too.
Useful to run koreader from shell, fmon, kfmon...

@houqp houqp merged commit 3a75b6d into koreader:master Apr 7, 2017
@houqp
Copy link
Member

houqp commented Apr 7, 2017

@pazos could you also help do a quick check on #2712 when you have time?

# to run koreader in 16bpp. Useful since FW 4.0
FB_BPP=$(cat /sys/class/graphics/fb0/bits_per_pixel)
[ "$FB_BPP" -gt 16 ] && /usr/sbin/fbset -depth 16
# fix rotation issues on Kobo Aura HD (dragon) and Kobo Aura H2O (dahlia)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From KSM this actually "cause". There was some stuff about this on c2bd85b#commitcomment-12846700

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work? (It does with KSM.)

case "$PRODUCT" in "dragon" | "dahlia" )
	cur_rotate="$(cat "/sys/class/graphics/fb0/rotate")"
	echo "${cur_rotate}" > "/sys/class/graphics/fb0/rotate"
	cat "/sys/class/graphics/fb0/rotate" > "/sys/class/graphics/fb0/rotate"
	;;
esac

@pazos
Copy link
Member Author

pazos commented Apr 8, 2017

@Frenzie: that was needed on my aura HD. After killing nickel rotation is 3. Koreader needs the same rotation to work. If the line is removed then rotation is 1 and the screen is flipped. I didn't think about the rationale of this, but in my end seems to works reliable. I didn't found that bug on KA1 but it should be safe to do on all kobo devices.

@Frenzie
Copy link
Member

Frenzie commented Apr 8, 2017

Okay, so just this without the check?

cur_rotate="$(cat "/sys/class/graphics/fb0/rotate")"
echo "${cur_rotate}" > "/sys/class/graphics/fb0/rotate"
cat "/sys/class/graphics/fb0/rotate" > "/sys/class/graphics/fb0/rotate"

@pazos
Copy link
Member Author

pazos commented Apr 8, 2017

Yes, it works nice. But again: the last line alone does the job for all my devices (mini, aura hd and ka1)

@Frenzie
Copy link
Member

Frenzie commented Apr 8, 2017

Actually this is still not good. This causes random rotations all around. It was working fine the way it was. :-( @NiLuJe Help? :-P

As indicated in the forum this is what happens on H2O:

[root@(none) ~]# cat "/sys/class/graphics/fb0/rotate"
2
[root@(none) ~]# cat "/sys/class/graphics/fb0/rotate" > "/sys/class/graphics/fb0
/rotate"
[root@(none) ~]# cat "/sys/class/graphics/fb0/rotate"
0
[root@(none) ~]# cat "/sys/class/graphics/fb0/rotate" > "/sys/class/graphics/fb0
/rotate"
[root@(none) ~]# cat "/sys/class/graphics/fb0/rotate"
2

I'll have to do some more testing here about when the values are what.

Edit: okay, I think I tracked down the problem.

[root@(none) ~]# cat "/sys/class/graphics/fb0/rotate"
2
[root@(none) ~]# /usr/sbin/fbset -depth 16
[root@(none) ~]# cat "/sys/class/graphics/fb0/rotate"
0

Edit: correction, KSM already sets it to 16-bit of course. But where does the extra rotation come from…

@pazos
Copy link
Member Author

pazos commented Apr 8, 2017

this is why we change rotation after changing fb depth.

@Frenzie: could you look at fbset -geometry before and after the fb depth change?: 1440x1080 vs 1080x1440.

Sorry but my devices are out of home (except the KA1), I'm talking from memory :/

@Frenzie
Copy link
Member

Frenzie commented Apr 8, 2017

@pazos Yes, but the fb depth doesn't change anyway because KSM already sets it to 16 bit, so that's actually unrelated. (And even if it did I set the cur_rotate before the fbset.)

Anyway, I've got a much simpler fix:

# workaround 32-bit without KSM
if [ -z ${ksmroot+x} ]; then
# TODO: add support for 32bit framebuffer in koreader. This is a workaround
# to run koreader in 16bpp. Useful since FW 4.0
CUR_ROTATE="$(cat "/sys/class/graphics/fb0/rotate")"
FB_BPP=$(cat /sys/class/graphics/fb0/bits_per_pixel)
[ "$FB_BPP" -gt 16 ] && /usr/sbin/fbset -depth 16
# fix rotation issues on Kobo Aura HD (dragon) and Kobo Aura H2O (dahlia)
echo "${CUR_ROTATE}" > "/sys/class/graphics/fb0/rotate"
# shellcheck disable=SC2094
cat "/sys/class/graphics/fb0/rotate" > "/sys/class/graphics/fb0/rotate"
fi

./reader.lua "${args}" >> crash.log 2>&1
RESULT=$?

# workaround 32-bit without KSM
if [ -z ${ksmroot+x} ]; then
# back to default depth in framebuffer.
[ "$FB_BPP" -gt 16 ] && /usr/sbin/fbset -depth "$FB_BPP"
fi

@pazos
Copy link
Member Author

pazos commented Apr 8, 2017

@Frenzie: I don't understand your logic here.

KSM doesn't use our koreader.sh script at all. So checking for KSM within the script isn't needed. KSM also handles the rotation bug in its code.

@Frenzie
Copy link
Member

Frenzie commented Apr 8, 2017

Sorry, I should've been clearer.

Your script turns KOReader upside down. My proposed fix works fine but "causes random rotations all around" in KSM, after exiting KOReader. Avoiding the non-KSM codepath also avoids all issues.

@pazos
Copy link
Member Author

pazos commented Apr 8, 2017

Ahhh, ok.

I'm using fmon to launch koreader. After leaving koreader.sh nickel.sh was called. This file (nickel.sh) is used by koreader with fmon or kfmon, but AFAIK Tshering forked all those files and bundle them in KSM8.

Take a look on https://github.com/koreader/koreader/blob/master/platform/kobo/nickel.sh#L5 and https://github.com/koreader/koreader/blob/master/platform/kobo/nickel.sh#L89. This works for me and nickel is running fine.

@pazos
Copy link
Member Author

pazos commented Apr 8, 2017

Your script turns KOReader upside down. My proposed fix works fine but "causes random rotations all around" in KSM, after exiting KOReader.

In which devices?. Did you mean with or without the product check?

@pazos
Copy link
Member Author

pazos commented Apr 8, 2017

Relevant files for KSM8 are in adds/kbmenu/onstart.

There are: start_koreader.sh / start_nickel.sh / start_nickel_fromloop.sh / nickelkoreaderloop.sh ...

If you look at the code you'll find how the author is handling this

@Frenzie
Copy link
Member

Frenzie commented Apr 8, 2017

What you linked (which I'm not sure why considering I already linked to it =P) is pretty much all H2O-related afaik: https://www.mobileread.com/forums/showthread.php?p=3028142#post3028142

On other devices it should be innocent repetition.

CUR_ROTATE="$(cat "/sys/class/graphics/fb0/rotate")"
# this suffices on normal devices, but H2O is stupid and sets the opposite
echo "${CUR_ROTATE}" > "/sys/class/graphics/fb0/rotate"
# this therefore turns it around on H2O (and other potential idiots) and just innocently repeats on sane devices
cat "/sys/class/graphics/fb0/rotate" > "/sys/class/graphics/fb0/rotate"

@Frenzie
Copy link
Member

Frenzie commented Apr 8, 2017

If you look at the code you'll find how the author is handling this

It's handled in a way that causes KOReader to turn upside down after exiting Nickel. (I'm sure you can draw the relevant conclusions from the fact that I never noticed.) But what's your objection to #2731 (comment) precisely?

Frenzie added a commit to Frenzie/koreader that referenced this pull request Apr 8, 2017
@pazos
Copy link
Member Author

pazos commented Apr 8, 2017

But what's your objection to #2731 (comment) precisely?

I thought that the if statement if [ -z ${ksmroot+x} ]; wasn't neccesary because KSM uses its own scripts to launch koreader and our main script isn't called from KSM. I may be wrong and how KSM launches koreader is different than I thought.

Sorry for the discussion overflow :P

Frenzie added a commit to Frenzie/koreader that referenced this pull request Apr 8, 2017
Frenzie added a commit to Frenzie/koreader that referenced this pull request Apr 8, 2017
@Frenzie
Copy link
Member

Frenzie commented Apr 8, 2017

That was true a few years ago. It's a more of a symbiosis now, with amusing workarounds on both sides. For example, I had to add this line after $from_nickel was renamed to $FROM_NICKEL and weird things happened.

# Do not delete this line because KSM detects newer versions of KOReader by the presence of the phrase 'from_nickel'.

Frenzie added a commit that referenced this pull request Apr 9, 2017
* Add ShellCheck and shfmt shell code quality analysis

* kobo/koreader.sh: remove useless $PREFIX

* kobo/koreader.sh: fix rotation issue caused by #2731

* Travis: speed up (caching Luarocks should shave a minute off install process)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants