]> git.zerfleddert.de Git - fhem-stuff/commitdiff
COC helper-scripts with RPi version detection
authorMichael Gernoth <michael@gernoth.net>
Sun, 2 Jun 2013 09:41:00 +0000 (11:41 +0200)
committerMichael Gernoth <michael@gernoth.net>
Sun, 2 Jun 2013 09:41:00 +0000 (11:41 +0200)
COC/.gitignore [new file with mode: 0644]
COC/coc-as-cuno [new file with mode: 0755]
COC/coc-terminal [new file with mode: 0755]
COC/init-coc [new file with mode: 0755]
COC/update-coc [new file with mode: 0755]

diff --git a/COC/.gitignore b/COC/.gitignore
new file mode 100644 (file)
index 0000000..3e0efd8
--- /dev/null
@@ -0,0 +1 @@
+culfw
diff --git a/COC/coc-as-cuno b/COC/coc-as-cuno
new file mode 100755 (executable)
index 0000000..46de8fd
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+DEVICE=/dev/ttyAMA0,b38400
+PORT=2323
+#OPTIONS="-ly -lh"
+#OPTIONS="-v -x"
+
+"`dirname "${0}"`"/init-coc
+
+while true; do
+       echo "Listening on port ${PORT} for new connection requests"
+       socat ${OPTIONS} "${DEVICE},raw,echo=0" "TCP-LISTEN:${PORT},reuseaddr"
+done
diff --git a/COC/coc-terminal b/COC/coc-terminal
new file mode 100755 (executable)
index 0000000..fc2ca52
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh -x
+
+socat /dev/ttyAMA0,b38400,raw,echo=0 -
diff --git a/COC/init-coc b/COC/init-coc
new file mode 100755 (executable)
index 0000000..97166c5
--- /dev/null
@@ -0,0 +1,65 @@
+#!/bin/sh
+
+#RPi v1: BUS=0
+#RPi v2: BUS=1
+#Auto: BUS=-1
+BUS=-1
+
+#BATTERY=0: trickle charger for supercap enabled
+#BATTERY=1: trickle charger for supercap disabled
+BATTERY=0
+
+if [ "`id -u`" != "0" ]; then
+       exec sudo "${0}" "${@}"
+fi
+
+if [ "${BUS}" = "-1" ]; then
+       rev="0x`awk '{if ($1 == "Revision") {print $NF};}' /proc/cpuinfo`"
+       rev=$((rev & 0xffff))
+       if [ "${rev}" -ge "4" ]; then
+               echo "RPi version 2 detected"
+               BUS=1
+       else
+               echo "RPi version 1 detected"
+               BUS=0
+       fi
+fi
+
+if [ ! -e "/dev/i2c-${BUS}" ]; then
+       modprobe i2c-dev
+fi
+
+if [ ! -e "/sys/bus/i2c/devices/${BUS}-0068" ]; then
+       echo "enabling RTC"
+       modprobe rtc-ds1307
+       
+       tcharger="0xa5"
+       tchargertext="enabling"
+       if [ "${BATTERY}" = "1" ]; then
+               tcharger="0x00"
+               tchargertext="disabling"
+       fi
+
+       if [ "`i2cget -y "${BUS}" 0x68 0x10`" != "${tcharger}" ]; then
+               echo "${tchargertext} trickle-charger for supercap"
+               i2cset -y "${BUS}" 0x68 0x10 "${tcharger}"
+       fi
+       echo "ds1339 0x68" >"/sys/class/i2c-adapter/i2c-${BUS}/new_device"
+fi
+
+if [ ! -e "/sys/bus/i2c/devices/1-0018" ]; then
+       echo "enabling 1wire"
+       modprobe ds2482
+       echo "ds2482 0x18" >"/sys/class/i2c-adapter/i2c-${BUS}/new_device"
+fi
+
+echo "resetting 868MHz extension..."
+if test ! -d /sys/class/gpio/gpio17; then echo 17 > /sys/class/gpio/export; fi
+if test ! -d /sys/class/gpio/gpio18; then echo 18 > /sys/class/gpio/export; fi
+echo out > /sys/class/gpio/gpio17/direction
+echo out > /sys/class/gpio/gpio18/direction
+echo 1 > /sys/class/gpio/gpio18/value
+echo 0 > /sys/class/gpio/gpio17/value
+sleep 1
+echo 1 > /sys/class/gpio/gpio17/value
+sleep 1
diff --git a/COC/update-coc b/COC/update-coc
new file mode 100755 (executable)
index 0000000..7e50dfe
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+if [ "`id -u`" != "0" ]; then
+       exec sudo "${0}" "${@}"
+fi
+
+echo "calling COC bootloader..."
+if test ! -d /sys/class/gpio/gpio17; then echo 17 > /sys/class/gpio/export; fi
+if test ! -d /sys/class/gpio/gpio18; then echo 18 > /sys/class/gpio/export; fi
+echo out > /sys/class/gpio/gpio17/direction
+echo out > /sys/class/gpio/gpio18/direction
+echo 0 > /sys/class/gpio/gpio18/value
+echo 0 > /sys/class/gpio/gpio17/value
+sleep 1
+echo 1 > /sys/class/gpio/gpio17/value
+sleep 1
+echo 1 > /sys/class/gpio/gpio18/value
+
+avrdude -v -p atmega1284p -P /dev/ttyAMA0 -b 38400 -c avr109 -U flash:w:COC.hex
Impressum, Datenschutz