~ecs/dotfiles

8bf1985ac66d0277bef5bfc47fd85b453b385130 — Eyal Sawady 2 months ago 3492f0c
pfander: add a bunch of scripts
A bin/pfander/hwnotes => bin/pfander/hwnotes +35 -0
@@ 0,0 1,35 @@
#!/bin/cat

# Notes on random hardware bits in pfander, so that I don't forget

https://mlab.taik.fi/paja/?p=1263 is useful, as is
http://natisbad.org/N900/n900-commented-hardware-specs.html

## Accelerometer

lis3lv02d, see Documentation/misc-devices/lis3lv02d.rst

Position information can be found at /sys/devices/platform/lis3lv02d/position

## Ambient light sensor

tsl2563, see drivers/iio/light/tsl2563.c

Information can be found at
/sys/class/i2c-adapter/i2c-2/2-0029/iio:device1/in_*, I'm guesssing that the
first is visible light, second is combined visible + IR, third is IR.

## Vibrator

twl4030 vibrator, see drivers/input/misc/twl4030-vibra.c

/sys/class/leds/twl4030\:vibrator/brightness on Maemo, but that doesn't exist in
mainline

## Camera

TODO: check up on discussion in #postmarketos

https://github.com/maemo-foss/omap3camera-firmware might be useful?

et8ek8 module segfaults (?)

A bin/pfander/led => bin/pfander/led +17 -0
@@ 0,0 1,17 @@
#!/bin/sh -eu

base="/sys/class/leds/lp5523"

if [ $# -eq 0 ]; then
	echo 0 | $ROOT tee "$base:r/brightness" >/dev/null
	echo 0 | $ROOT tee "$base:g/brightness" >/dev/null
	echo 0 | $ROOT tee "$base:b/brightness" >/dev/null
elif [ $# -eq 1 ]; then
	echo "$1" | $ROOT tee "$base:r/brightness" >/dev/null
	echo "$1" | $ROOT tee "$base:g/brightness" >/dev/null
	echo "$1" | $ROOT tee "$base:b/brightness" >/dev/null
else
	echo "$1" | $ROOT tee "$base:r/brightness" >/dev/null
	echo "$2" | $ROOT tee "$base:g/brightness" >/dev/null
	echo "$3" | $ROOT tee "$base:b/brightness" >/dev/null
fi

A bin/pfander/ledupdate => bin/pfander/ledupdate +9 -0
@@ 0,0 1,9 @@
#!/bin/sh

pwr="$(echo "$(cat "/sys/class/power_supply/bq27200-0/current_now")/-2100+160" | bc)"
if [ $pwr -lt 0 ]; then
	pwr=0
elif [ $pwr -gt 255 ]; then
	pwr=255
fi
led "$pwr"

A bin/pfander/lightsensor => bin/pfander/lightsensor +11 -0
@@ 0,0 1,11 @@
#!/bin/sh

if [ $# -eq 0 ]; then
	cat /sys/class/i2c-adapter/i2c-2/2-0029/iio:device1/in_illuminance0_input
elif [ "z$1" = "zboth" ]; then
	cat /sys/class/i2c-adapter/i2c-2/2-0029/iio:device1/in_intensity_both_raw
elif [ "z$1" = "zir" ]; then
	cat /sys/class/i2c-adapter/i2c-2/2-0029/iio:device1/in_intensity_ir_raw
else
	cat /sys/class/i2c-adapter/i2c-2/2-0029/iio:device1/in_illuminance0_input
fi

A bin/pfander/menu => bin/pfander/menu +4 -0
@@ 0,0 1,4 @@
#!/bin/sh

exec dmenu -i -p "" -fn "DejaVu Sans Mono 10" -sf "#ffffff" -sb "#222222" \
		-nf "#aaaaaa" -nb "#000000" -m all "$@"

A bin/pfander/radio => bin/pfander/radio +7 -0
@@ 0,0 1,7 @@
#!/bin/sh -eu

if [ $# -gt 1 ]; then
	exec v4l2-ctl -d /dev/radio0 -c mute=0,tune_power_level9=920 -f "$1"
else
	exec v4l2-ctl -d /dev/radio0 -c mute=1
fi

A bin/pfander/upload => bin/pfander/upload +42 -0
@@ 0,0 1,42 @@
#!/bin/sh -eu

# You must configure:
# - REMOTE_HOST: Remote server
# - REMOTE_PATH: Files uploaded here must appear under https://$REMOTE_HOST/
# You may optionally configure:
# - REMOTE_PORT: Port on which the SSH server is running (defaults to 22)
# - REMOTE_USER: User on remote server (defaults to the current user)

# Dependencies: POSIX, xclip, mktemp, rsync

REMOTE_PORT=22
REMOTE_USER="$USER"

[ "z$XDG_CONFIG_HOME" == "z" ] && export XDG_CONFIG_HOME="$HOME/.config"

[ -f "$XDG_CONFIG_HOME/upload" ] && . "$XDG_CONFIG_HOME/upload"

localpath="$(mktemp)"
trap "rm $localpath" EXIT
remotefile=""

if [ $# -eq 0 ]; then
	xclip -o >"$localpath"
	remotefile=".txt"
elif [ "z$1" == "z-" ]; then
	cat >"$localpath"
	remotefile=".txt"
else
	cp "$@" "$localpath"
	remotefile=".${@##*.}"
fi

remotefile="$(cksum "$localpath" | cut -d' ' -f1)$remotefile"

chmod 644 "$localpath"

rsync -az -e "ssh -p '$REMOTE_PORT'" "$localpath" "$REMOTE_USER@$REMOTE_HOST:$REMOTE_PATH/$remotefile" >/dev/null

echo "https://$REMOTE_HOST/$remotefile"
xclip -i  "https://$REMOTE_HOST/$remotefile"
notify-send "Upload done" "https://$REMOTE_HOST/$remotefile" || true