]> git.zerfleddert.de Git - fhem-stuff/blob - COC/init-coc
cul-terminal
[fhem-stuff] / COC / init-coc
1 #!/bin/sh
2
3 #RPi v1: BUS=0
4 #RPi v2: BUS=1
5 #Auto: BUS=-1
6 BUS=-1
7
8 #BATTERY=0: trickle charger for supercap enabled
9 #BATTERY=1: trickle charger for supercap disabled
10 BATTERY=0
11
12 if [ "`id -u`" != "0" ]; then
13 exec sudo "${0}" "${@}"
14 fi
15
16 if [ "${BUS}" = "-1" ]; then
17 rev="0x`awk '{if ($1 == "Revision") {print $NF};}' /proc/cpuinfo`"
18 rev=$((rev & 0xffff))
19 if [ "${rev}" -ge "4" ]; then
20 echo "RPi version 2 detected"
21 BUS=1
22 else
23 echo "RPi version 1 detected"
24 BUS=0
25 fi
26 fi
27
28 if [ ! -e "/dev/i2c-${BUS}" ]; then
29 modprobe i2c-dev
30 fi
31
32 if [ ! -e "/sys/bus/i2c/devices/${BUS}-0068" ]; then
33 echo "enabling RTC"
34 modprobe rtc-ds1307
35
36 tcharger="0xa5"
37 tchargertext="enabling"
38 if [ "${BATTERY}" = "1" ]; then
39 tcharger="0x00"
40 tchargertext="disabling"
41 fi
42
43 if [ "`i2cget -y "${BUS}" 0x68 0x10`" != "${tcharger}" ]; then
44 echo "${tchargertext} trickle-charger for supercap"
45 i2cset -y "${BUS}" 0x68 0x10 "${tcharger}"
46 fi
47 echo "ds1339 0x68" >"/sys/class/i2c-adapter/i2c-${BUS}/new_device"
48 fi
49
50 if [ ! -e "/sys/bus/i2c/devices/${BUS}-0018" ]; then
51 echo "enabling 1wire"
52 modprobe ds2482
53 echo "ds2482 0x18" >"/sys/class/i2c-adapter/i2c-${BUS}/new_device"
54 fi
55
56 echo "resetting 868MHz extension..."
57 if test ! -d /sys/class/gpio/gpio17; then echo 17 > /sys/class/gpio/export; fi
58 if test ! -d /sys/class/gpio/gpio18; then echo 18 > /sys/class/gpio/export; fi
59 echo out > /sys/class/gpio/gpio17/direction
60 echo out > /sys/class/gpio/gpio18/direction
61 echo 1 > /sys/class/gpio/gpio18/value
62 echo 0 > /sys/class/gpio/gpio17/value
63 sleep 1
64 echo 1 > /sys/class/gpio/gpio17/value
65 sleep 1
Impressum, Datenschutz