2
0
mirror of https://github.com/koreader/koreader synced 2024-11-16 06:12:56 +00:00
koreader/platform/kindle/libkohelper.sh
NiLuJe 68c1246575
A round of Kindle fixes (#3955)
* Refresh Kindle model ID routines

* Pickup current OTA packages

We stopped shipping files w/ the full .tar.gz extension a looooong time
ago.

* And actually generally handle current packages properly

* Kindle screensaver handling experiment

WIP, because there's a fair bit of insanity left in there.
Namely, USBMS is anathema. We simply shouldn't do that, at all,
but the system allows us to do it and basically shoot ourselves in the
head one way or another.

* Don't try to handle the insanity that would be USBMS on Kindles

* Yay, one less thing to worry about :).

* Okay, that should be much saner...

Since the whole deal w/ letting the WM handle stuff was for SO, restrict
that to SO devices.
The other concern was USBMS, but we can't support it.

* Reword that

* And move that comment inside the branch, like its counterpart
2018-05-16 17:26:27 -04:00

139 lines
5.1 KiB
Bash

#!/bin/sh
## A bit of helper functions...
# Check which type of init system we're running on
if [ -d /etc/upstart ]; then
export INIT_TYPE="upstart"
# We'll need that for logging
# shellcheck disable=SC1091
[ -f /etc/upstart/functions ] && . /etc/upstart/functions
else
export INIT_TYPE="sysv"
# We'll need that for logging
# shellcheck disable=SC1091
[ -f /etc/rc.d/functions ] && . /etc/rc.d/functions
fi
# We need to get the proper constants for our model...
kmodel="$(cut -c3-4 /proc/usid)"
case "${kmodel}" in
"13" | "54" | "2A" | "4F" | "52" | "53")
# Voyage
SCREEN_X_RES=1088 # NOTE: Yes, 1088, not 1072 or 1080...
SCREEN_Y_RES=1448
EIPS_X_RES=16
EIPS_Y_RES=24 # Manually mesured, should be accurate.
;;
"24" | "1B" | "1D" | "1F" | "1C" | "20" | "D4" | "5A" | "D5" | "D6" | "D7" | "D8" | "F2" | "17" | "60" | "F4" | "F9" | "62" | "61" | "5F")
# PaperWhite & PaperWhite 2
SCREEN_X_RES=768 # NOTE: Yes, 768, not 758...
SCREEN_Y_RES=1024
EIPS_X_RES=16
EIPS_Y_RES=24 # Manually mesured, should be accurate.
;;
"C6" | "DD")
# KT2
SCREEN_X_RES=608
SCREEN_Y_RES=800
EIPS_X_RES=16
EIPS_Y_RES=24
;;
"0F" | "11" | "10" | "12")
# Touch
SCREEN_X_RES=600 # _v_width @ upstart/functions
SCREEN_Y_RES=800 # _v_height @ upstart/functions
EIPS_X_RES=12 # from f_puts @ upstart/functions
EIPS_Y_RES=20 # from f_puts @ upstart/functions
;;
*)
# Handle legacy devices...
if [ -f "/etc/rc.d/functions" ] && grep "EIPS" "/etc/rc.d/functions" >/dev/null 2>&1; then
# Already done...
#. /etc/rc.d/functions
echo "foo" >/dev/null
else
# Try the new device ID scheme...
kmodel="$(cut -c4-6 /proc/usid)"
case "${kmodel}" in
"0G1" | "0G2" | "0G4" | "0G5" | "0G6" | "0G7" | "0KB" | "0KC" | "0KD" | "0KE" | "0KF" | "0KG" | "0LK" | "0LL")
# PW3
SCREEN_X_RES=1088
SCREEN_Y_RES=1448
EIPS_X_RES=16
EIPS_Y_RES=24
;;
"0GC" | "0GD" | "0GR" | "0GS" | "0GT" | "0GU")
# Oasis
SCREEN_X_RES=1088
SCREEN_Y_RES=1448
EIPS_X_RES=16
EIPS_Y_RES=24
;;
"0LM" | "0LN" | "0LP" | "0LQ" | "0P1" | "0P2" | "0P6" | "0P7" | "0P8" | "0S1" | "0S2" | "0S3" | "0S4" | "0S7" | "0SA")
# Oasis 2
SCREEN_X_RES=1280 # NOTE: Yep, line_length/xres_virtual, not xres (1264)
SCREEN_Y_RES=1680
EIPS_X_RES=16 # TBD 19?
EIPS_Y_RES=24 # TBD 28? 25?!
;;
"0DU" | "0K9" | "0KA")
# KT3
SCREEN_X_RES=608
SCREEN_Y_RES=800
EIPS_X_RES=16
EIPS_Y_RES=24
;;
*)
# Fallback... We shouldn't ever hit that.
SCREEN_X_RES=600
SCREEN_Y_RES=800
EIPS_X_RES=12
EIPS_Y_RES=20
;;
esac
fi
;;
esac
# And now we can do the maths ;)
EIPS_MAXCHARS="$((SCREEN_X_RES / EIPS_X_RES))"
EIPS_MAXLINES="$((SCREEN_Y_RES / EIPS_Y_RES))"
# Adapted from libkh[5]
eips_print_bottom_centered() {
# We need at least two args
if [ $# -lt 2 ]; then
echo "not enough arguments passed to eips_print_bottom ($# while we need at least 2)"
return
fi
kh_eips_string="${1}"
kh_eips_y_shift_up="${2}"
# Get the real string length now
kh_eips_strlen="${#kh_eips_string}"
# Add the right amount of left & right padding, since we're centered, and eips doesn't trigger a full refresh,
# so we'll have to padd our string with blank spaces to make sure two consecutive messages don't run into each other
kh_padlen="$(((EIPS_MAXCHARS - kh_eips_strlen) / 2))"
# Left padding...
while [ ${#kh_eips_string} -lt $((kh_eips_strlen + kh_padlen)) ]; do
kh_eips_string=" ${kh_eips_string}"
done
# Right padding (crop to the edge of the screen)
while [ ${#kh_eips_string} -lt ${EIPS_MAXCHARS} ]; do
kh_eips_string="${kh_eips_string} "
done
# Sleep a tiny bit to workaround the logic in the 'new' (K4+) eInk controllers that tries to bundle updates,
# otherwise it may drop part of our messages because of other screen updates from KUAL...
# Unless we really don't want to sleep, for special cases...
if [ ! -n "${EIPS_NO_SLEEP}" ]; then
usleep 150000 # 150ms
fi
# And finally, show our formatted message centered on the bottom of the screen (NOTE: Redirect to /dev/null to kill unavailable character & pixel not in range warning messages)
eips 0 $((EIPS_MAXLINES - 2 - kh_eips_y_shift_up)) "${kh_eips_string}" >/dev/null
}