diff options
author | Daniel Friesel <derf@finalrewind.org> | 2016-12-25 13:20:18 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2016-12-25 13:20:18 +0100 |
commit | 43084ffa34169369e4371fe5edac8790839b170b (patch) | |
tree | d283db89878ff6d1dcec37b35f9c257f5685eb63 | |
parent | cc8498297af44ab850dc17c77a978c06253be016 (diff) |
add example script for lm75 temperature sensors
-rwxr-xr-x | commandline/examples/lm75 | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/commandline/examples/lm75 b/commandline/examples/lm75 new file mode 100755 index 0000000..2dfd956 --- /dev/null +++ b/commandline/examples/lm75 @@ -0,0 +1,49 @@ +#!/bin/zsh + +addr=0x4f +cmd=$1 +arg=$2 + +function read_temp { + typeset buf num + + buf=($(vusb-i2cget $addr 2 $1)) + num=$buf[1] + + if (( buf[2] > 127 )); then + num="${num}.5" + fi + + echo $num +} + +function set_temp { + typeset buf1 buf2 reg=$1 num=$2 + + buf1=${num%.*} + if [[ $buf1 == $num ]]; then + buf2=0 + else + buf2=128 + fi + + vusb-i2cset $addr $reg $buf1 $buf2 +} + +case $cmd in + get_temp) + read_temp 0 + ;; + get_hyst) + read_temp 2 + ;; + get_os) + read_temp 3 + ;; + set_hyst) + set_temp 2 $arg + ;; + set_os) + set_temp 3 $arg + ;; +esac |