#!/bin/sh -Cefu # # Copyright (c) 2025 Sulev-Madis Silber # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # set -Cefu rtprio 0 "-$$" || : _ppid() { ps -ax -o ppid,pid | awk -v "v=$$" '$2==v{print$1}' } case "`sysctl -ni hw.fdt.compatible`" in *allwinner*h3*) cd /root/tmp || exit 1 rtprio 0 "-`_ppid`" ;; *) cd /root/files/ws2812 || exit 1 ;; esac perl_script=./spi.pl shell_script=tmp/spi.sh custom_spi_binary=./spi if [ "${1:-}" -a "${2:-}" -a "${3:-}" -a "${4:-}" ] then device="$2" speed="$3" buffer="$4" else device=spigen0.0 speed=3000000 buffer="`\"$perl_script\" bin | wc -c`" fi case "${1:-}" in *local-sh*) "$perl_script" loop | while read line do echo -n "$line" | spi -f "$device" -A -d w -m 0 \ -s "$speed" -c "$buffer" done ;; *local-direct*) pkill -9 spi || : "$perl_script" loop,bin | "$custom_spi_binary" -f "$device" \ -S -d w -m 0 -s "$speed" -c "$buffer" ;; *remote-sh*) while read line do echo -n "$line" | spi -f "$device" -A -d w -m 0 \ -s "$speed" -c "$buffer" done ;; *remote-direct-text*) pkill -9 spi || : exec "$custom_spi_binary" -f "$device" -A -S -d w -m 0 \ -s "$speed" -c "$buffer" ;; *remote-direct-bin*) pkill -9 spi || : exec "$custom_spi_binary" -f "$device" -S -d w -m 0 \ -s "$speed" -c "$buffer" ;; *remote-perl*) exec "$perl_script" wrap "$device" "$speed" "$buffer" ;; *run*) host="`cat .host`" ssh "$host" sysctl dev.aw_thermal.0.cpu ssh "$host" pkill -9 spi || : set +f scp -pr /home/ketas/files/ws2812/* "$host:tmp" cp -av /home/ketas/files/ws2812/* ~/files/ws2812 set -f cp -av /home/ketas/files/ws2812/.host ~/files/ws2812 chown -vvR 0:0 /root/files/ws2812 ./spi.sh ;; *) host="`cat .host`" "$perl_script" loop,bin | ssh "$host" exec "$shell_script" \ remote-direct-bin "$device" "$speed" "$buffer" ;; esac