mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-07-04 15:23:03 +02:00
- Drop overrideredirect on the dismiss UI: on X11 it bypassed the WM and silently killed keyboard focus on the Entry, so the user could not type the dismiss code. -fullscreen + -topmost still cover the whole screen. - Add _max_sink_volume() / _restore_sink_volume(): unmute the default PulseAudio/PipeWire sink and raise it to 100% at alarm start, restore the original volume + mute state on dismiss. This is the biggest audio lever — pcspkr is hardware-fixed and was already maxed. - pcspkr: 3 back-to-back 1.5s beeps per cycle (was 1x 0.8s) at near-S16 max amplitude. - Fans script: control every NCT pwm[1-9] channel, persist per-channel pre-alarm state to /run/wake-alarm-fans.state so restore needs no args. - Tests: 100% branch coverage on python_pkg/wake_alarm/ (140 passed).
64 lines
2.0 KiB
Bash
Executable File
64 lines
2.0 KiB
Bash
Executable File
#!/bin/bash
|
|
# Control ALL NCT pwm fan channels for the wake alarm.
|
|
#
|
|
# Usage:
|
|
# wake-alarm-fans.sh max — ramp every pwm[1-9] channel to 100%
|
|
# wake-alarm-fans.sh restore — restore the state captured by the last `max`
|
|
#
|
|
# Must be run as root (installed in /etc/sudoers.d/wake-alarm via install.sh).
|
|
# Safe: fans are designed to run at max speed indefinitely.
|
|
#
|
|
# State is stored at $STATE_FILE so `restore` doesn't need any arguments.
|
|
|
|
set -euo pipefail
|
|
|
|
STATE_FILE="/run/wake-alarm-fans.state"
|
|
|
|
# Locate the hwmon directory for any NCT Super I/O fan controller.
|
|
HWMON=""
|
|
for name_file in /sys/class/hwmon/hwmon*/name; do
|
|
[[ -f "$name_file" ]] || continue
|
|
chip=$(cat "$name_file")
|
|
case "$chip" in
|
|
nct6775|nct6779|nct6791|nct6792|nct6793|nct6795|nct6796|nct6797|nct6798|nct6799)
|
|
HWMON=$(dirname "$name_file")
|
|
break
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [[ -z "$HWMON" ]]; then
|
|
# Not an error — hardware without this chip just skips fan control.
|
|
exit 0
|
|
fi
|
|
|
|
case "${1:-}" in
|
|
max)
|
|
: > "$STATE_FILE"
|
|
for pwm in "$HWMON"/pwm[0-9]; do
|
|
[[ -w "$pwm" ]] || continue
|
|
enable="${pwm}_enable"
|
|
[[ -w "$enable" ]] || continue
|
|
old_pwm=$(cat "$pwm")
|
|
old_enable=$(cat "$enable")
|
|
printf '%s %s %s\n' "$pwm" "$old_enable" "$old_pwm" >> "$STATE_FILE"
|
|
echo 1 > "$enable" # Switch to manual mode.
|
|
echo 255 > "$pwm" # 255/255 = 100% speed.
|
|
done
|
|
;;
|
|
restore)
|
|
[[ -f "$STATE_FILE" ]] || exit 0
|
|
while read -r pwm old_enable old_pwm; do
|
|
[[ -w "$pwm" && -w "${pwm}_enable" ]] || continue
|
|
# Restore pwm value first, then restore the control mode.
|
|
echo "$old_pwm" > "$pwm"
|
|
echo "$old_enable" > "${pwm}_enable"
|
|
done < "$STATE_FILE"
|
|
rm -f "$STATE_FILE"
|
|
;;
|
|
*)
|
|
echo "Usage: $0 max | $0 restore" >&2
|
|
exit 1
|
|
;;
|
|
esac
|