Handle cron tasks while in crust

mnc goal is to display when will occurs the next cron job.

We drop the "sxmo_screenlock.sh rtc" command and the
SXMO_RTCWAKEINTERVAL variable. We will now only use
"sxmo_screenlock.sh crust" which mean suspend until next cron job
(-2 seconds).

To replicate the old behavior of the blinking phone then returning to
suspension (if needed) we now use a new script.

By example:

*/15 * * * * DISPLAY=:0 sxmo_rtcwake.sh sleep 10

This will trigger a 10s sleep task every 15 minutes (the old default
rtcwake hook).

Signed-off-by: Stacy Harper <contact@stacyharper.net>
Signed-off-by: Maarten van Gompel <proycon@anaproy.nl>
master
Stacy Harper 3 years ago committed by Maarten van Gompel
parent 02a37c9dea
commit 0ed27f8538
  1. 4
      configs/appcfg/xinit_template
  2. 39
      configs/default_hooks/rtcwake
  3. 2
      scripts/core/sxmo_common.sh
  4. 12
      scripts/core/sxmo_inputhandler.sh
  5. 43
      scripts/core/sxmo_rtcwake.sh
  6. 61
      scripts/core/sxmo_screenlock.sh

@ -48,10 +48,6 @@ command -v firefox && export BROWSER=firefox
# Prepopulate Subreddits menu with custom subreddits
#export SXMO_SUBREDDITS="postmarketos pinephoneOfficial pinephone unixporn"
# Temporarily wake every 5 minutes during sleep
#(useful for getting notifications)
#export SXMO_RTCWAKEINTERVAL=300
# Change the default terminal command
# export TERMCMD="st -e"

@ -1,39 +0,0 @@
#!/usr/bin/env sh
. "$(which sxmo_common.sh)"
REDLED_PATH="/sys/class/leds/red:indicator/brightness"
BLUELED_PATH="/sys/class/leds/blue:indicator/brightness"
finish() {
kill $BLINKPID
echo 0 > "$REDLED_PATH"
echo 0 > "$BLUELED_PATH"
# Going back to crust
if [ "$(sxmo_screenlock.sh getCurState)" != "unlock" ]; then
sxmo_screenlock.sh rtc "$SXMO_RTCWAKEINTERVAL"
fi
exit 0
}
trap 'finish' TERM INT EXIT
blink() {
while [ "$(sxmo_screenlock.sh getCurState)" != "unlock" ]; do
echo 1 > "$REDLED_PATH"
echo 0 > "$BLUELED_PATH"
sleep 0.5
echo 0 > "$REDLED_PATH"
echo 1 > "$BLUELED_PATH"
sleep 0.5
done
}
blink &
BLINKPID=$!
# Replace this by wathever you want to do
sleep 10

@ -9,6 +9,8 @@
# we disable shellcheck SC2034 (variable not used)
# for all the variables we define here
# shellcheck disable=SC2034
export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-$HOME/.local/run}"
# shellcheck disable=SC2034
export NOTIFDIR="$XDG_DATA_HOME"/sxmo/notifications
# shellcheck disable=SC2034

@ -9,14 +9,6 @@ ACTION="$1"
# shellcheck source=scripts/core/sxmo_common.sh
. "$(dirname "$0")/sxmo_common.sh"
crust() {
if [ -n "$SXMO_RTCWAKEINTERVAL" ]; then
sxmo_screenlock.sh rtc "$SXMO_RTCWAKEINTERVAL"
else
sxmo_screenlock.sh crust
fi
}
lock_screen() {
if [ "$SXMO_LOCK_SCREEN_OFF" = "1" ]; then
sxmo_screenlock.sh off
@ -24,7 +16,7 @@ lock_screen() {
sxmo_screenlock.sh lock
fi
if [ "$SXMO_LOCK_SUSPEND" = "1" ]; then
crust
sxmo_screenlock.sh crust
fi
}
@ -46,7 +38,7 @@ typeenter() {
if [ "$(sxmo_screenlock.sh getCurState)" != "unlock" ]; then
case "$ACTION" in
"volup_three")
crust
sxmo_screenlock.sh crust
;;
"voldown_three")
if [ "$(sxmo_screenlock.sh getCurState)" = "lock" ]; then

@ -1,11 +1,40 @@
#!/usr/bin/env sh
# This script (and anything it calls) should return as quickly as possible
# as it blocks the system from suspending (and processing input) until done
# shellcheck disable=SC1090
. "$(which sxmo_common.sh)"
# If this script returns a non-zero exit code, the system will wake up
REDLED_PATH="/sys/class/leds/red:indicator/brightness"
BLUELED_PATH="/sys/class/leds/blue:indicator/brightness"
if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/rtcwake" ]; then
"$XDG_CONFIG_HOME/sxmo/hooks/rtcwake"
exit $?
fi
finish() {
kill $BLINKPID
sxmo_screenlock.sh updateLed
if grep -q rtc "$UNSUSPENDREASONFILE"; then
# Going back to crust
if [ "$(sxmo_screenlock.sh getCurState)" != "unlock" ]; then
sxmo_screenlock.sh crust
fi
fi
exit 0
}
trap 'finish' TERM INT EXIT
blink() {
while [ "$(sxmo_screenlock.sh getCurState)" != "unlock" ]; do
echo 1 > "$REDLED_PATH"
echo 0 > "$BLUELED_PATH"
sleep 0.25
echo 0 > "$REDLED_PATH"
echo 1 > "$BLUELED_PATH"
sleep 0.25
done
}
blink &
BLINKPID=$!
"$@"

@ -100,6 +100,7 @@ elif [ "$1" = "unlock" ] ; then
xset dpms force on
xinput enable "$TOUCH_POINTER_ID"
sxmo_lisgdstart.sh
echo 16000 > "$NETWORKRTCSCAN"
updateLed
exit 0
@ -120,41 +121,6 @@ elif [ "$1" = "off" ] ; then
exit 0
elif [ "$1" = "crust" ] ; then
getCurState > "$LASTSTATE"
if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/presuspend" ]; then
"$XDG_CONFIG_HOME/sxmo/hooks/presuspend"
fi
echo 1 > "$REDLED_PATH"
echo 0 > "$BLUELED_PATH"
xset dpms force off
# configure crust
# TODO: disable all wakeup sources other than button, rtc, and modem.
# TODO: make sure there is logic in whichWake and saveAllEventCounts functions
# Do I need to unbind? https://git.sr.ht/~mil/sxmo-utils/commit/bcf4f5c24968df0055d15a9fca649f67de9ced6a
echo "deep" > /sys/power/mem_sleep # deep sleep
echo "mem" > /sys/power/state
echo "crust" > "$LASTSTATE"
d=$(date)
echo "sxmo_screenlock: woke up from crust ($d)" >&2
updateLed
xset dpms force on
UNSUSPENDREASON=$(whichWake)
echo "$UNSUSPENDREASON" > "$UNSUSPENDREASONFILE"
if [ "$UNSUSPENDREASON" = "button" ] && [ -x "$XDG_CONFIG_HOME/sxmo/hooks/postwake" ]; then
"$XDG_CONFIG_HOME/sxmo/hooks/postwake"
fi
exit 0
elif [ "$1" = "rtc" ] ; then
getCurState > "$LASTSTATE"
# USER MUST USE sxmo_screenlock.sh rtc rather than using rtcwake directly.
# With this new version of lock, we dont check the exit code of the user hook. User must execute "sxmo_screenlock.sh rtc $TIME" at the end of their hook (depending on whether they want to re-rtc)
echo 1 > "$REDLED_PATH"
@ -167,20 +133,19 @@ elif [ "$1" = "rtc" ] ; then
fi
xset dpms force off
rtcwake -m mem -s "$2"
UNSUSPENDREASON=$(whichWake)
suspend_time="$(($(mnc)-10))"
if [ "$suspend_time" -gt 0 ]; then
rtcwake -m mem -s "$suspend_time"
UNSUSPENDREASON=$(whichWake)
else
UNSUSPENDREASON=rtc # we fake the crust for those seconds
fi
echo "$UNSUSPENDREASON" > "$UNSUSPENDREASONFILE"
echo "crust" > "$LASTSTATE"
updateLed
if [ "$UNSUSPENDREASON" = "rtc" ]; then
WAKEHOOK="$XDG_CONFIG_HOME/sxmo/hooks/rtcwake";
elif [ "$UNSUSPENDREASON" = "button" ]; then
WAKEHOOK="$XDG_CONFIG_HOME/sxmo/hooks/postwake";
fi
d=$(date)
echo "sxmo_screenlock: woke up from crust (reason=$UNSUSPENDREASON) ($d)" >&2
@ -188,16 +153,18 @@ elif [ "$1" = "rtc" ] ; then
xset dpms force on
fi
if [ -x "$WAKEHOOK" ]; then
if [ "$UNSUSPENDREASON" = "button" ] && [ -x "$XDG_CONFIG_HOME/sxmo/hooks/postwake" ]; then
echo 1200 > "$NETWORKRTCSCAN"
"$WAKEHOOK"
echo 16000 > "$NETWORKRTCSCAN"
"$XDG_CONFIG_HOME/sxmo/hooks/postwake"
fi
exit 0
elif [ "$1" = "getCurState" ] ; then
getCurState
exit 0
elif [ "$1" = "updateLed" ] ; then
updateLed
exit 0
fi
echo "usage: sxmo_screenlock.sh [lock|unlock|off|crust|rtc|getCurState]">&2
echo "usage: sxmo_screenlock.sh [lock|unlock|off|crust|rtc|getCurState|updateLed]">&2

Loading…
Cancel
Save