From: Einar Jørgen Haraldseid Date: Fri, 13 Sep 2024 07:04:06 +0000 (+0200) Subject: Merge branch 'master' of ssh://git.slaskete.net/srv/git/einar-bin X-Git-Url: https://git.slaskete.net/einar-bin/commitdiff_plain/75ab68fc868e38c52ac87d5d6686e6985c6131d6?hp=f864072b93bf89fc47ef6e4fa265cd3f34a2d94c Merge branch 'master' of ssh://git.slaskete.net/srv/git/einar-bin --- diff --git a/scan b/scan new file mode 100755 index 0000000..4af4c7d --- /dev/null +++ b/scan @@ -0,0 +1,40 @@ +#!/bin/bash +SANE_DEFAULT_DEVICE="epsonscan2:EPSON Scanner:001:011:esci2:usb:ES00EB:315" +export SANE_DEFAULT_DEVICE +scans=$(ls -1 scan*.jpg | wc -l) + +if [ "$1" == "1" ] || [ "$1" == "en" ]; then + echo "Scanner ett bilde og avslutter, pass pÃ¥ at bildet er plassert oppe til høyre med ca. 1 cm klaring til kantene." + ((scans++)) + file1=$(printf %03d $scans) + if scanimage -x 165 -y 115 --mode Color --resolution=1200 --format=tiff > /tmp/temp.tiff; then + echo "Scanning ferdig, konverterer til jpeg" + convert /tmp/temp.tiff "scan-${file1}.jpg" + echo "Lagret scan-${file1}.jpg" + rm /tmp/temp.tiff + else + echo "Scanning feilet, prøv igjen." + exit 1 + fi +else + echo "Automatisk scanning av to bilder om gangen, pass pÃ¥ at bildene er plassert oppe til høyre med ca. 1 cm klaring fra kantene." + while true; do + ((scans++)) + file1=$(printf %03d $scans) + ((scans++)) + file2=$(printf %03d $scans) + echo "Starter scanning …" + if scanimage -x 165 -y 230 --mode Color --resolution=1200 --format=tiff > /tmp/temp.tiff; then + echo "Scanning ferdig, lagrer bilder" + convert -chop 0x5200+0+0 -gravity South /tmp/temp.tiff "scan-${file1}.jpg" + echo "Lagret scan-${file1}.jpg" + convert -chop 0x5000+0+0 /tmp/temp.tiff "scan-${file2}.jpg" + echo "Lagret scan-${file2}.jpg" + rm /tmp/temp.tiff + else + echo "Scanning feilet, prøv igjen." + exit 1 + fi + read -p "Trykk enter for Ã¥ scanne igjen, eller ctrl+C for Ã¥ avslutte" + done +fi diff --git a/screencontrol.sh b/screencontrol.sh new file mode 100755 index 0000000..b01fc91 --- /dev/null +++ b/screencontrol.sh @@ -0,0 +1,61 @@ +#!/bin/bash +# Script to control and query a connected screen +# For infoscreen purposes +# Tries to use cec-client and falls back to DPMS +# Usage: ./screencontrol.sh [query | on | off] + +export DISPLAY=:0 +if [ -z "${1}" ]; then + set -- "query" +fi + +if [ "${1}" == "query" ]; then + if status=$(echo "pow 0" | cec-client -s -d 1); then + if [[ ${status} =~ (power status: on) ]]; then + echo "Screen is on" + else + echo "Screen is off" + fi + else + if status=$(xset q); then + if [[ ${status} =~ (Monitor is Off) ]]; then + echo "Screen is off" + else + echo "Screen is on" + fi + else + echo "Unable to determine status of screen" + exit 1 + fi + fi +elif [ "${1}" == "on" ]; then + if echo "on 0" | cec-client -s -d 1 >/dev/null; then + xset s off + xset s noblank + xset -dpms + echo "Screen turned on (CEC)" + else + if xset dpms force on; then + xset s off + xset s noblank + xset -dpms + echo "Screen turned on (DPMS)" + else + echo "Unable to turn screen on" + exit 1 + fi + fi +elif [ "${1}" == "off" ]; then + if echo "standby 0" | cec-client -s -d 1 >/dev/null; then + echo "Screen turned off (CEC)" + else + if xset dpms force off; then + echo "Screen turned off (DPMS)" + else + echo "Unable to turn screen off" + fi + fi +else + echo "Error: Unknown command" + exit 1 +fi diff --git a/sun.py b/sun.py new file mode 100644 index 0000000..c46cc67 --- /dev/null +++ b/sun.py @@ -0,0 +1,52 @@ +#!/usr/bin/python3 +from suncalc import get_position, get_times +from datetime import datetime, timedelta, date + +debug = False +#debug = True + +now = datetime.now() +#now = datetime(2023, 12, 13, 0, 0) +date = now.replace(hour=12, minute=0, second=0, microsecond=0) + +lon = 10.71 +lat = 60.772 +height = 100 + +sun = get_times(date, lon, lat, height) + +if type(sun["nautical_dawn"]) is datetime: + sunup = sun["nautical_dawn"] + timedelta(hours=1) +else: + sunup = now +if type(sun["nautical_dusk"]) is datetime: + sundown = sun["nautical_dusk"] + timedelta(hours=1) +else: + sundown = now + timedelta(hours=23, minutes=59, seconds=50) + +# If sunup is in the future +if now < sunup: + countdown = (sunup - now).total_seconds() + countdown_read = sunup - now + duration = (sundown - sunup).total_seconds() * 1000 + duration_read = sundown - sunup +else: + countdown = 0 + countdown_read = 0 + duration = (sundown - now).total_seconds() * 1000 + duration_read = sundown - now + +if int(duration) < 0: + print("Sun already set, fool") + exit(1) + +if debug: + print(" Now is ", now) + print(" Date is ", date) + print(" Sun up is ", sunup) + print(" Sun down is ", sundown) + print("Countdown is ", countdown_read) + print(" Duration is ", duration_read) + print("") + +print(int(countdown), int(duration), sep='\t')