summaryrefslogtreecommitdiff
path: root/commandline/examples/lm75
blob: 2dfd9563ace945f8cf6d24a0381faadee0213c57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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