Files
Monitorink/kobo/monitorink.sh
jerem ca4febbc44 Refresh e-ink: multi-régions + full toutes les 2h (basé temps)
Le full refresh apparaissait trop souvent: getbbox() renvoyait un seul
rectangle englobant tous les pixels modifiés, donc météo (haut) + heure de
MaJ (ailleurs) qui changeaient au même cycle produisaient un rectangle
quasi plein écran -> ratio > partial_max_ratio -> full forcé.

- frame.py: détection des bandes horizontales modifiées disjointes
  (_changed_regions), refresh partiel serré par zone. Full basé sur le
  temps écoulé (last_full_at + time.monotonic) au lieu d'un compteur de
  cycles. État pngs/regions en liste, get_png(client, region).
- config.py: full_refresh_interval_minutes (MONITORINK_FULL_INTERVAL_MIN,
  défaut 120). Suppression de partial_max_ratio.
- app.py: /frame.meta renvoie un bloc multi-ligne "MODE SEQ N" + N régions
  "i x y w h"; /frame.png?region=i.
- monitorinkloop.sh: display_meta parse le bloc et fait N fbink partiels.
2026-06-16 14:06:49 +02:00

67 lines
3.1 KiB
Bash
Executable File

#!/bin/sh
# Monitorink — point d'entrée lancé par NickelMenu.
#
# Prend le contrôle complet de l'appareil en TUANT Nickel (sinon Nickel auto-suspend
# l'appareil et coupe le WiFi, en conflit avec notre boucle). On siphonne d'abord les
# variables d'environnement WiFi de Nickel (WIFI_MODULE/PLATFORM/INTERFACE) pour pouvoir
# gérer le WiFi nous-mêmes. À l'arrêt (entrée « Monitorink STOP »), on REBOOT pour
# restaurer Nickel et l'usage normal de la liseuse.
export LC_ALL="en_US.UTF-8"
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$PATH"
BASE="/mnt/onboard/.adds/Monitorink"
LOG="$BASE/monitorink.log"
cd "$BASE" || exit 1
# --- Configuration ---
export MONITORINK_URL="http://192.168.0.43:8899/image.png"
export MONITORINK_REFRESH=900 # PROD: refresh partiel 15 min (moins de réveils = batterie)
# Cadence du full refresh : côté SERVEUR via MONITORINK_FULL_INTERVAL_MIN (défaut 120 = 2 h),
# indépendante du cycle. Entre deux fulls, seuls les blocs modifiés sont rafraîchis (partiel).
echo "===== monitorink start $(date) =====" >> "$LOG"; sync
# --- Gouverneur CPU économe ---
CPUFREQ="/sys/devices/system/cpu/cpufreq/policy0"
[ -d "$CPUFREQ" ] || CPUFREQ="/sys/devices/system/cpu/cpu0/cpufreq"
if grep -q ondemand "$CPUFREQ/scaling_available_governors" 2>/dev/null; then
echo ondemand > "$CPUFREQ/scaling_governor" 2>/dev/null
fi
# --- Prendre le contrôle : siphonner l'env Nickel (WiFi) puis tuer Nickel ---
if pkill -0 nickel 2>/dev/null; then
NICKEL_PID="$(pidof -s nickel)"
if [ -n "$NICKEL_PID" ]; then
NENV=$(tr '\0' '\n' < "/proc/$NICKEL_PID/environ" 2>/dev/null \
| grep -E '^(WIFI_MODULE|INTERFACE|NICKEL_HOME|DBUS_SESSION_BUS_ADDRESS|LANG|PLATFORM|PRODUCT)=')
[ -n "$NENV" ] && export $NENV
fi
UDEV_PID="$(pidof -s udevd)"
if [ -n "$UDEV_PID" ]; then
[ -z "$PRODUCT" ] && { V=$(tr '\0' '\n' < "/proc/$UDEV_PID/environ" 2>/dev/null | grep -E '^PRODUCT='); [ -n "$V" ] && export $V; }
[ -z "$PLATFORM" ] && { V=$(tr '\0' '\n' < "/proc/$UDEV_PID/environ" 2>/dev/null | grep -E '^PLATFORM='); [ -n "$V" ] && export $V; }
fi
[ -z "$INTERFACE" ] && export INTERFACE="eth0"
echo "[monitorink] WIFI_MODULE=$WIFI_MODULE PLATFORM=$PLATFORM INTERFACE=$INTERFACE PRODUCT=$PRODUCT" >> "$LOG"; sync
sync
killall -q -TERM nickel hindenburg sickel fickel fontickel adobehost foxitpdf iink dhcpcd-dbus dhcpcd 2>/dev/null
t=0; while pkill -0 nickel 2>/dev/null; do [ "$t" -ge 16 ] && break; usleep 250000; t=$((t + 1)); done
rm -f /tmp/nickel-hardware-status
fi
[ -z "$INTERFACE" ] && export INTERFACE="eth0"
# Synchronise l'horloge RTC (sinon rtcwake calcule mal le réveil).
hwclock -w -u 2>/dev/null
# Watcher bouton power -> reboot logiciel (en arrière-plan, Nickel mort).
# Premier calage : préfixer par MONITORINK_PWR_DEBUG=1 pour logger device/format dans le log.
sh "$BASE/reboot_watcher.sh" &
# Boucle bloquante. À la sortie (STOP tue monitorinkloop.sh), on reboot pour restaurer Nickel.
sh "$BASE/monitorinkloop.sh" >> "$LOG" 2>&1
echo "===== monitorink stop $(date) — reboot =====" >> "$LOG"; sync
sleep 1
reboot