-
Notifications
You must be signed in to change notification settings - Fork 0
/
libkohelper.sh
72 lines (63 loc) · 2.31 KB
/
libkohelper.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/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
# Adapted from libkh[5]
## Check if we have an FBInk binary available somewhere...
# Default to something that won't horribly blow up...
FBINK_BIN="true"
for my_dir in /var/tmp /mnt/us/koreader /mnt/us/libkh/bin /mnt/us/linkss/bin /mnt/us/linkfonts/bin /mnt/us/usbnet/bin; do
my_fbink="${my_dir}/fbink"
if [ -x "${my_fbink}" ]; then
FBINK_BIN="${my_fbink}"
# Got it!
break
fi
done
has_fbink() {
# Because the fallback is the "true" binary/shell built-in ;).
if [ "${FBINK_BIN}" != "true" ]; then
# Got it!
return 0
fi
# If we got this far, we don't have fbink installed
return 1
}
# NOTE: Yeah, the name becomes a bit of a lie now that we're (hopefully) exclusively using FBInk ;p.
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}"
# Unlike eips, we need at least a single space to even try to print something ;).
if [ "${kh_eips_string}" = "" ]; then
kh_eips_string=" "
fi
# 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 [ -z "${EIPS_NO_SLEEP}" ]; then
usleep 150000 # 150ms
fi
# NOTE: FBInk will handle the padding. FBInk's default font is square, not tall like eips,
# so we compensate by tweaking the baseline ;). This matches the baseline we use on Kobo, too.
if has_fbink; then
${FBINK_BIN} -qpm -y $((-4 - kh_eips_y_shift_up)) "${kh_eips_string}"
else
# Crappy fallback
eips 0 0 "${kh_eips_string}" >/dev/null
fi
}