]> git.zerfleddert.de Git - fhem-stuff/blame_incremental - COC/init-coc
COC helper-scripts with RPi version detection
[fhem-stuff] / COC / init-coc
... / ...
CommitLineData
1#!/bin/sh
2
3#RPi v1: BUS=0
4#RPi v2: BUS=1
5#Auto: BUS=-1
6BUS=-1
7
8#BATTERY=0: trickle charger for supercap enabled
9#BATTERY=1: trickle charger for supercap disabled
10BATTERY=0
11
12if [ "`id -u`" != "0" ]; then
13 exec sudo "${0}" "${@}"
14fi
15
16if [ "${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
26fi
27
28if [ ! -e "/dev/i2c-${BUS}" ]; then
29 modprobe i2c-dev
30fi
31
32if [ ! -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"
48fi
49
50if [ ! -e "/sys/bus/i2c/devices/1-0018" ]; then
51 echo "enabling 1wire"
52 modprobe ds2482
53 echo "ds2482 0x18" >"/sys/class/i2c-adapter/i2c-${BUS}/new_device"
54fi
55
56echo "resetting 868MHz extension..."
57if test ! -d /sys/class/gpio/gpio17; then echo 17 > /sys/class/gpio/export; fi
58if test ! -d /sys/class/gpio/gpio18; then echo 18 > /sys/class/gpio/export; fi
59echo out > /sys/class/gpio/gpio17/direction
60echo out > /sys/class/gpio/gpio18/direction
61echo 1 > /sys/class/gpio/gpio18/value
62echo 0 > /sys/class/gpio/gpio17/value
63sleep 1
64echo 1 > /sys/class/gpio/gpio17/value
65sleep 1
Impressum, Datenschutz