- #!/usr/bin/ksh93
 - #
 - # Simatic LED demo #001
 - #
 - # Binary counter from hell - counts fron 0 to pow(2,number_of_leds),
 - # and turns the LEDs on/off based on the binary value
 - #
 - compound c # ksh93 compound variable (sort of |struct|)
 - compound -a c.ar
 - integer c.num_leds
 - typeset f # filename
 - integer i
 - typeset -i2 bin_counter # binary counter 0000...0001...0010...
 - #
 - # Enumerate all available LEDs
 - # (the simatic-ipc-leds.ko driver will register it's LEDs
 - # via the Linux LED driver, see
 - # https://www.kernel.org/doc/html/latest/leds/leds-class.html how to
 - # use it)
 - #
 - (( i=0 ))
 - for f in $(find '/sys/devices/platform/simatic_ipc_leds/leds/' -name 'brightness') ; do
 - c.ar[i].filename="$f"
 - (( c.ar[i].index=i ))
 - # open file FD for later usage, this is more efficient than
 - # doing an |open(),write(),close()|-cycle for each time
 - # we flash an LED
 - redirect {c.ar[i].fd}<> "$f"
 - (( i++ ))
 - done
 - # count LEDs
 - (( c.num_leds=${#c.ar[@]} ))
 - #
 - # print configuration
 - #
 - print -v c
 - # Bail out if there is no hardware
 - if (( c.num_leds == 0 )) ; then
 - print -u2 -f $"%s: No leds available.\n" "$0"
 - exit 1
 - fi
 - #
 - # main
 - #
 - typeset -R${c.num_leds} s # string with field width c.num_leds
 - while true ; do
 - for (( bin_counter=0 ; bin_counter < pow(2,c.num_leds) ; bin_counter++ )) ; do
 - # strip the '2#' prefix
 - s="${bin_counter:2:c.num_leds}"
 - printf $"Value: |%s|\n" "$s"
 - for i in "${!c.ar[@]}" ; do
 - print -u ${c.ar[i].fd} $(( ${s:$((c.ar[i].index)):1} ))
 - done
 - sleep 0.2
 - done
 - done
 - # EOF.
 
Simatic LED demo #001
Posted by Anonymous on Mon 9th Aug 2021 12:37
raw | new post
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.
 rovema.kpaste.net RSS