update at 2026-03-15 15:58:14
This commit is contained in:
@@ -3,14 +3,19 @@ DEBUG=${DEBUG:-false}
|
||||
[ "$DEBUG" = true ] && set -x
|
||||
|
||||
DIR="$(dirname "$0")"
|
||||
DASH_PNG="$DIR/dash.png"
|
||||
BACKGROUND_PNG="$DIR/kindlebg.png"
|
||||
FETCH_DASHBOARD_CMD="$DIR/local/fetch-dashboard.sh"
|
||||
LOW_BATTERY_CMD="$DIR/local/low-battery.sh"
|
||||
CLOCK_RENDER_CMD="$DIR/local/render-clock.sh"
|
||||
STATE_DIR="$DIR/local/state"
|
||||
BACKGROUND_TIMESTAMP_FILE="$STATE_DIR/background-updated-at"
|
||||
|
||||
REFRESH_SCHEDULE=${REFRESH_SCHEDULE:-"2,32 8-17 * * MON-FRI"}
|
||||
FULL_DISPLAY_REFRESH_RATE=${FULL_DISPLAY_REFRESH_RATE:-0}
|
||||
SLEEP_SCREEN_INTERVAL=${SLEEP_SCREEN_INTERVAL:-3600}
|
||||
DISABLE_SYSTEM_SUSPEND=${DISABLE_SYSTEM_SUSPEND:-false}
|
||||
BACKGROUND_REFRESH_INTERVAL_MINUTES=${BACKGROUND_REFRESH_INTERVAL_MINUTES:-120}
|
||||
CLOCK_FULL_REFRESH_INTERVAL_MINUTES=${CLOCK_FULL_REFRESH_INTERVAL_MINUTES:-15}
|
||||
RTC=/sys/devices/platform/mxc_rtc.0/wakeup_enable
|
||||
|
||||
LOW_BATTERY_REPORTING=${LOW_BATTERY_REPORTING:-false}
|
||||
@@ -27,6 +32,7 @@ init() {
|
||||
fi
|
||||
|
||||
echo "Starting dashboard with $REFRESH_SCHEDULE refresh..."
|
||||
mkdir -p "$STATE_DIR"
|
||||
|
||||
if [ "$DISABLE_SYSTEM_SUSPEND" = true ]; then
|
||||
echo "System suspend disabled, using normal sleep between refreshes."
|
||||
@@ -50,27 +56,72 @@ prepare_sleep() {
|
||||
num_refresh=$FULL_DISPLAY_REFRESH_RATE
|
||||
}
|
||||
|
||||
refresh_dashboard() {
|
||||
echo "Refreshing dashboard"
|
||||
now_epoch() {
|
||||
date '+%s'
|
||||
}
|
||||
|
||||
background_refresh_due() {
|
||||
if [ ! -f "$BACKGROUND_PNG" ] || [ ! -f "$BACKGROUND_TIMESTAMP_FILE" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
current_epoch=$(now_epoch)
|
||||
last_background_epoch=$(cat "$BACKGROUND_TIMESTAMP_FILE")
|
||||
refresh_interval_seconds=$((BACKGROUND_REFRESH_INTERVAL_MINUTES * 60))
|
||||
|
||||
[ $((current_epoch - last_background_epoch)) -ge "$refresh_interval_seconds" ]
|
||||
}
|
||||
|
||||
store_background_timestamp() {
|
||||
now_epoch >"$BACKGROUND_TIMESTAMP_FILE"
|
||||
}
|
||||
|
||||
fetch_background() {
|
||||
echo "Refreshing background"
|
||||
"$DIR/wait-for-wifi.sh" "$WIFI_TEST_IP"
|
||||
|
||||
"$FETCH_DASHBOARD_CMD" "$DASH_PNG"
|
||||
"$FETCH_DASHBOARD_CMD" "$BACKGROUND_PNG"
|
||||
fetch_status=$?
|
||||
|
||||
if [ "$fetch_status" -ne 0 ]; then
|
||||
echo "Not updating screen, fetch-dashboard returned $fetch_status"
|
||||
echo "Background fetch failed with $fetch_status"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ "$num_refresh" -eq "$FULL_DISPLAY_REFRESH_RATE" ]; then
|
||||
num_refresh=0
|
||||
store_background_timestamp
|
||||
return 0
|
||||
}
|
||||
|
||||
# trigger a full refresh once in every 4 refreshes, to keep the screen clean
|
||||
echo "Full screen refresh"
|
||||
/usr/sbin/eips -f -g "$DASH_PNG"
|
||||
clock_force_full_refresh() {
|
||||
eval "$("$DIR/local/clock-index.sh")"
|
||||
[ $((minute % CLOCK_FULL_REFRESH_INTERVAL_MINUTES)) -eq 0 ]
|
||||
}
|
||||
|
||||
refresh_dashboard() {
|
||||
background_refreshed=false
|
||||
|
||||
if background_refresh_due; then
|
||||
if fetch_background; then
|
||||
background_refreshed=true
|
||||
echo "Full screen refresh"
|
||||
/usr/sbin/eips -f -g "$BACKGROUND_PNG"
|
||||
elif [ ! -f "$BACKGROUND_PNG" ]; then
|
||||
echo "No cached background available."
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$background_refreshed" = false ] && [ ! -f "$BACKGROUND_PNG" ]; then
|
||||
echo "No cached background available."
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ "$background_refreshed" = true ] || clock_force_full_refresh; then
|
||||
echo "Clock patch full refresh"
|
||||
"$CLOCK_RENDER_CMD" true
|
||||
else
|
||||
echo "Partial screen refresh"
|
||||
/usr/sbin/eips -g "$DASH_PNG"
|
||||
echo "Clock patch partial refresh"
|
||||
"$CLOCK_RENDER_CMD" false
|
||||
fi
|
||||
|
||||
num_refresh=$((num_refresh + 1))
|
||||
|
||||
24
dash/src/local/clock-index.sh
Normal file
24
dash/src/local/clock-index.sh
Normal file
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env sh
|
||||
set -eu
|
||||
|
||||
to_decimal() {
|
||||
printf '%s' "$1" | awk '{
|
||||
sub(/^0+/, "", $0)
|
||||
if ($0 == "") {
|
||||
$0 = 0
|
||||
}
|
||||
print $0
|
||||
}'
|
||||
}
|
||||
|
||||
hour_value=${1:-$(date '+%H')}
|
||||
minute_value=${2:-$(date '+%M')}
|
||||
|
||||
hour_decimal=$(to_decimal "$hour_value")
|
||||
minute_decimal=$(to_decimal "$minute_value")
|
||||
hour_index=$(( (hour_decimal % 12) * 60 + minute_decimal ))
|
||||
|
||||
printf 'hour=%s\n' "$hour_decimal"
|
||||
printf 'minute=%s\n' "$minute_decimal"
|
||||
printf 'hour_index=%03d\n' "$hour_index"
|
||||
printf 'minute_index=%02d\n' "$minute_decimal"
|
||||
@@ -5,6 +5,13 @@ export WIFI_TEST_IP=${WIFI_TEST_IP:-1.1.1.1}
|
||||
# 测试配置:全天每分钟刷新一次,便于验证图片拉取与屏幕刷新是否正常。
|
||||
export REFRESH_SCHEDULE=${REFRESH_SCHEDULE:-"* * * * *"}
|
||||
export TIMEZONE=${TIMEZONE:-"Asia/Shanghai"}
|
||||
export BACKGROUND_URL=${BACKGROUND_URL:-"https://shell.biboer.cn:20001/kindlebg.png"}
|
||||
export BACKGROUND_REFRESH_INTERVAL_MINUTES=${BACKGROUND_REFRESH_INTERVAL_MINUTES:-120}
|
||||
export CLOCK_REGION_X=${CLOCK_REGION_X:-262}
|
||||
export CLOCK_REGION_Y=${CLOCK_REGION_Y:-55}
|
||||
export CLOCK_REGION_WIDTH=${CLOCK_REGION_WIDTH:-220}
|
||||
export CLOCK_REGION_HEIGHT=${CLOCK_REGION_HEIGHT:-220}
|
||||
export CLOCK_FULL_REFRESH_INTERVAL_MINUTES=${CLOCK_FULL_REFRESH_INTERVAL_MINUTES:-15}
|
||||
|
||||
# By default, partial screen updates are used to update the screen,
|
||||
# to prevent the screen from flashing. After a few partial updates,
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
#!/usr/bin/env sh
|
||||
# Fetch a new dashboard image, make sure to output it to "$1".
|
||||
# For example:
|
||||
"$(dirname "$0")/../xh" -d -q -o "$1" get https://raw.githubusercontent.com/pascalw/kindle-dash/master/example/example.png
|
||||
set -eu
|
||||
|
||||
# 拉取低频背景图,调用方负责传入输出路径。
|
||||
output_path=${1:?"missing output path"}
|
||||
background_url=${BACKGROUND_URL:-"https://shell.biboer.cn:20001/kindlebg.png"}
|
||||
|
||||
"$(dirname "$0")/../xh" -d -q -o "$output_path" get "$background_url"
|
||||
|
||||
32
dash/src/local/render-clock.sh
Normal file
32
dash/src/local/render-clock.sh
Normal file
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env sh
|
||||
set -eu
|
||||
|
||||
DIR="$(CDPATH= cd -- "$(dirname "$0")" && pwd)"
|
||||
clock_face_path=${CLOCK_FACE_PATH:-"$DIR/../assets/clock-face.png"}
|
||||
hour_assets_dir=${CLOCK_HOUR_ASSETS_DIR:-"$DIR/../assets/hour-hand"}
|
||||
minute_assets_dir=${CLOCK_MINUTE_ASSETS_DIR:-"$DIR/../assets/minute-hand"}
|
||||
clock_region_x=${CLOCK_REGION_X:-313}
|
||||
clock_region_y=${CLOCK_REGION_Y:-0}
|
||||
force_full_refresh=${1:-false}
|
||||
|
||||
eval "$("$DIR/clock-index.sh")"
|
||||
|
||||
hour_patch="$hour_assets_dir/$hour_index.png"
|
||||
minute_patch="$minute_assets_dir/$minute_index.png"
|
||||
|
||||
if [ ! -f "$clock_face_path" ] || [ ! -f "$hour_patch" ] || [ ! -f "$minute_patch" ]; then
|
||||
echo "Clock assets missing."
|
||||
echo "Face: $clock_face_path"
|
||||
echo "Hour: $hour_patch"
|
||||
echo "Minute: $minute_patch"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$force_full_refresh" = true ]; then
|
||||
/usr/sbin/eips -f -g "$clock_face_path" -x "$clock_region_x" -y "$clock_region_y"
|
||||
else
|
||||
/usr/sbin/eips -g "$clock_face_path" -x "$clock_region_x" -y "$clock_region_y"
|
||||
fi
|
||||
|
||||
/usr/sbin/eips -g "$hour_patch" -x "$clock_region_x" -y "$clock_region_y"
|
||||
/usr/sbin/eips -g "$minute_patch" -x "$clock_region_x" -y "$clock_region_y"
|
||||
Reference in New Issue
Block a user