mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Add visual feedback to OTA updates on Kindle
Dry-coded
This commit is contained in:
2
Makefile
2
Makefile
@@ -101,6 +101,8 @@ kindleupdate: all
|
||||
ln -sf ../kindle/extensions $(INSTALL_DIR)/
|
||||
ln -sf ../kindle/launchpad $(INSTALL_DIR)/
|
||||
ln -sf ../../kindle/koreader.sh $(INSTALL_DIR)/koreader
|
||||
ln -sf ../../kindle/libkoreader.inc $(INSTALL_DIR)/koreader
|
||||
ln -sf ../../kindle/kotar_cpoint $(INSTALL_DIR)/koreader
|
||||
# create new package
|
||||
# Don't bundle launchpad on touch devices..
|
||||
ifeq ($(TARGET), kindle-legacy)
|
||||
|
||||
@@ -4,84 +4,17 @@
|
||||
#
|
||||
##
|
||||
|
||||
## A bit of helper functions...
|
||||
# Check which type of init system we're running on
|
||||
if [ -d /etc/upstart ] ; then
|
||||
INIT_TYPE="upstart"
|
||||
# We'll need that for logging
|
||||
[ -f /etc/upstart/functions ] && source /etc/upstart/functions
|
||||
# KOReader's working directory
|
||||
KOREADER_DIR="/mnt/us/koreader"
|
||||
|
||||
# Load our helper functions...
|
||||
if [ -f "${KOREADER_DIR}/libkoreader.inc" ] ; then
|
||||
source "${KOREADER_DIR}/libkoreader.inc"
|
||||
else
|
||||
INIT_TYPE="sysv"
|
||||
# We'll need that for logging
|
||||
[ -f /etc/rc.d/functions ] && source /etc/rc.d/functions
|
||||
echo "Can't source helper functions, aborting!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# We need to get the proper constants for our model...
|
||||
kmodel="$(cut -c3-4 /proc/usid)"
|
||||
case "${kmodel}" in
|
||||
"24" | "1B" | "1D" | "1F" | "1C" | "20" | "D4" | "5A" | "D5" | "D6" | "D7" | "D8" | "F2" | "17" )
|
||||
# PaperWhite...
|
||||
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.
|
||||
;;
|
||||
* )
|
||||
# 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
|
||||
# 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
|
||||
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...
|
||||
usleep 150000 # 150ms
|
||||
|
||||
# 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
|
||||
}
|
||||
|
||||
## Handle logging...
|
||||
logmsg()
|
||||
{
|
||||
|
||||
@@ -6,15 +6,15 @@ PROC_FIVEWAY="/proc/fiveway"
|
||||
[ -e $PROC_KEYPAD ] && echo unlock > $PROC_KEYPAD
|
||||
[ -e $PROC_FIVEWAY ] && echo unlock > $PROC_FIVEWAY
|
||||
|
||||
# Check which type of init system we're running on
|
||||
if [ -d /etc/upstart ] ; then
|
||||
INIT_TYPE="upstart"
|
||||
# We'll need that for logging
|
||||
[ -f /etc/upstart/functions ] && source /etc/upstart/functions
|
||||
# KOReader's working directory
|
||||
KOREADER_DIR="/mnt/us/koreader"
|
||||
|
||||
# Load our helper functions...
|
||||
if [ -f "${KOREADER_DIR}/libkoreader.inc" ] ; then
|
||||
source "${KOREADER_DIR}/libkoreader.inc"
|
||||
else
|
||||
INIT_TYPE="sysv"
|
||||
# We'll need that for logging
|
||||
[ -f /etc/rc.d/functions ] && source /etc/rc.d/functions
|
||||
echo "Can't source helper functions, aborting!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Handle logging...
|
||||
@@ -76,19 +76,33 @@ if [ "$(nice)" == "5" ] ; then
|
||||
renice -n -5 $$
|
||||
fi
|
||||
|
||||
# working directory of koreader
|
||||
KOREADER_DIR=/mnt/us/koreader
|
||||
|
||||
# update to new version from OTA directory
|
||||
NEWUPDATE=${KOREADER_DIR}/ota/koreader.updated.tar
|
||||
if [ -f $NEWUPDATE ]; then
|
||||
# TODO: any graphic indication for the updating progress?
|
||||
logmsg "Updating koreader . . ."
|
||||
cd /mnt/us && tar xf $NEWUPDATE && rm $NEWUPDATE
|
||||
fi
|
||||
|
||||
# we're always starting from our working directory
|
||||
cd $KOREADER_DIR
|
||||
cd "${KOREADER_DIR}"
|
||||
|
||||
# Handle pending OTA update
|
||||
NEWUPDATE="${KOREADER_DIR}/ota/koreader.updated.tar"
|
||||
if [ -f "${NEWUPDATE}" ] ; then
|
||||
logmsg "Updating koreader . . ."
|
||||
# Look for our own GNU tar build to do a fancy update tracking...
|
||||
GNUTAR_BIN="${KOREADER_DIR}/tar"
|
||||
if [ -x "${GNUTAR_BIN}" ] ; then
|
||||
# Let our checkpoint script handle the visual feedback...
|
||||
${GNUTAR_BIN} -C "/mnt/us" --checkpoint=200 --checkpoint-action=exec='./kotar_cpoint $TAR_CHECKPOINT' -xf "${NEWUPDATE}"
|
||||
else
|
||||
# Fall back to busybox tar
|
||||
eips_print_bottom_centered "Updating koreader . . ." 1
|
||||
tar -C "/mnt/us" -xf "${NEWUPDATE}"
|
||||
fi
|
||||
# Cleanup behind us...
|
||||
if [ $? -eq 0 ] ; then
|
||||
rm "${NEWUPDATE}"
|
||||
logmsg "Update sucessful :)"
|
||||
else
|
||||
# Huh ho...
|
||||
logmsg "Update failed :("
|
||||
eips_print_bottom_centered "Update failed :(" 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# export trained OCR data directory
|
||||
export TESSDATA_PREFIX="data"
|
||||
@@ -174,6 +188,7 @@ fi
|
||||
|
||||
# finally call reader
|
||||
logmsg "Starting KOReader . . ."
|
||||
eips_print_bottom_centered "Starting KOReader . . ." 1
|
||||
./reader.lua "$@" 2> crash.log
|
||||
|
||||
# clean up our own process tree in case the reader crashed (if needed, to avoid flooding KUAL's log)
|
||||
|
||||
28
kindle/kotar_cpoint
Executable file
28
kindle/kotar_cpoint
Executable file
@@ -0,0 +1,28 @@
|
||||
#!/bin/sh
|
||||
|
||||
# KOReader's working directory
|
||||
KOREADER_DIR="/mnt/us/koreader"
|
||||
|
||||
# Load our helper functions...
|
||||
if [ -f "${KOREADER_DIR}/libkoreader.inc" ] ; then
|
||||
source "${KOREADER_DIR}/libkoreader.inc"
|
||||
else
|
||||
echo "Can't source helper functions, aborting!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
## First arg is the chekpoint number, and we get one every 200 checkpoints.
|
||||
CHECKPOINT_NUM="${1}"
|
||||
CHECKPOINT_GRANULARITY="200"
|
||||
|
||||
# Use that to build a poor man's progress bar, with dots.
|
||||
PROGRESS_AMOUNT="$(( ${CHECKPOINT_NUM} / ${CHECKPOINT_GRANULARITY} ))"
|
||||
PROGRESS_STRING="Updating koreader "
|
||||
for foo in $( seq 1 ${PROGRESS_AMOUNT} ) ; do
|
||||
# Append a dot until we hit the needed amount
|
||||
PROGRESS_STRING="${PROGRESS_STRING}."
|
||||
done
|
||||
|
||||
# Print our status
|
||||
eips_print_bottom_centered "${PROGRESS_STRING}" 1
|
||||
79
kindle/libkoreader.inc
Normal file
79
kindle/libkoreader.inc
Normal file
@@ -0,0 +1,79 @@
|
||||
#!/bin/sh
|
||||
|
||||
## A bit of helper functions...
|
||||
# Check which type of init system we're running on
|
||||
if [ -d /etc/upstart ] ; then
|
||||
INIT_TYPE="upstart"
|
||||
# We'll need that for logging
|
||||
[ -f /etc/upstart/functions ] && source /etc/upstart/functions
|
||||
else
|
||||
INIT_TYPE="sysv"
|
||||
# We'll need that for logging
|
||||
[ -f /etc/rc.d/functions ] && source /etc/rc.d/functions
|
||||
fi
|
||||
|
||||
# We need to get the proper constants for our model...
|
||||
kmodel="$(cut -c3-4 /proc/usid)"
|
||||
case "${kmodel}" in
|
||||
"24" | "1B" | "1D" | "1F" | "1C" | "20" | "D4" | "5A" | "D5" | "D6" | "D7" | "D8" | "F2" | "17" )
|
||||
# PaperWhite...
|
||||
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.
|
||||
;;
|
||||
* )
|
||||
# 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
|
||||
# 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
|
||||
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...
|
||||
usleep 150000 # 150ms
|
||||
|
||||
# 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
|
||||
}
|
||||
Submodule koreader-base updated: 7bd19dfee7...66b1bcf4f8
Reference in New Issue
Block a user