Last active
February 10, 2023 16:01
-
-
Save neogeographica/863cfb5d72998ddf520d669f330073b7 to your computer and use it in GitHub Desktop.
WIP scripts for Apple II demo loop on Raspberry Pi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Script for running the LinApple emulator fullscreen and with autoboot. | |
# The intention is to keep it running unattended. | |
# System is set to autologin as a particular user without requiring password. | |
# This script can be run from a .desktop file in .config/autostart so that it | |
# runs on system boot. | |
# The demo loop I want to run seems to freeze sometimes. So, every 5 minutes | |
# we'll take a screenshot, alternating between "shot1.png" and "shot2.png". | |
# If the two shots are the same, tell LinApple to do an emulated system reboot. | |
# Also since LinApple isn't meant to be an always-running application -- who | |
# knows if there are issues lurking there -- I'll just completely restart the | |
# LinApple process between 3:00 and 3:05 AM. | |
# Screenshot courtesy of fbgrab from https://github.com/GunnarMonell/fbgrab | |
# Conservatively, sleep first to let the booted system get its footing a bit. | |
sleep 3 | |
# Define the periodic check, and start it going in the background. | |
bindir=/home/demouser/bin | |
shotdir=/home/demouser | |
nextshot=shot1.png | |
function checkloop { | |
while true | |
do | |
# Sleep for 5 minutes. | |
sleep 300 | |
# If in [3:00, 3:05) interval do a shutdown (process will restart), else | |
# do the screenshot check. I'm aware there are at least two ways this code | |
# could miss that window, but it's good enough... the daily shutdown doesn't | |
# need to be absolutely 100% bulletproof. If that turns out to be an issue | |
# then I'll do this differently. | |
hour=$(date +%H) | |
minute=$(date +%M) | |
if [[ $hour == 03 && $minute =~ 0[0-4] ]] | |
then | |
# Shutdown time! | |
# Arguably we should check to see if this graceful shutdown works, and if | |
# not then do a process kill. But, meh. | |
$bindir/linapple-quit | |
else | |
# OK let's take a screenshoot... | |
$bindir/fbgrab $shotdir/$nextshot > /dev/null 2>&1 | |
# Toggle the name for the next one. | |
if [[ $nextshot == shot1.png ]] | |
then | |
nextshot=shot2.png | |
else | |
nextshot=shot1.png | |
fi | |
if cmp $shotdir/shot1.png $shotdir/shot2.png > /dev/null | |
then | |
# Screen is frozen, let's ask for a reset. | |
$bindir/linapple-reset | |
fi | |
fi | |
done | |
} | |
checkloop & | |
# Now run the emulator, restarting if it exits. | |
while true | |
do | |
/path/to/LinApple/build/bin/linapple -f --autoboot | |
sleep 1 | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Desktop Entry] | |
Name=LinApple Loop | |
Exec=/home/demouser/bin/linapple-loop | |
Type=Application | |
Encoding=UTF-8 | |
Categories=Other; | |
Terminal=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Ask LinApple to shut down. Used by linapple-loop; also can be handy for | |
# manual use (sets DISPLAY so it doesn't need to be invoked from the desktop | |
# session... e.g. can be used while ssh'ing in). | |
DISPLAY=:0.0 xdotool search --class linapple windowactivate --sync %1 key F12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Ask LinApple to do an emulated reboot. Used by linapple-loop; also can | |
# be handy for manual use (sets DISPLAY so it doesn't need to be invoked | |
# from the desktop session... e.g. can be used while ssh'ing in). | |
# Normally LinApple uses Ctrl+F2 for an emulated reboot, but for whatever | |
# reason I can't seem to send that key combo to it in this way. Instead I | |
# modified LinApple to accept plain F2 for reboot. | |
DISPLAY=:0.0 xdotool search --class linapple windowactivate --sync %1 key F2 windowactivate $(DISPLAY=:0.0 xdotool getactivewindow) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment