summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2013-10-05 00:40:43 +0200
committerDaniel Friesel <derf@finalrewind.org>2013-10-05 00:40:43 +0200
commite1c76b9f608288adce84cd054618b492cd64935f (patch)
tree73a6c4bc445452cb94edcaa519a466600b8f0aa5
parent33ed3a3f0d71c45118901590738b81721cca2a0f (diff)
add ds2482-100-searchrom (onewire SEARCH ROM)
-rwxr-xr-xcommandline/examples/ds2482-100-searchrom41
1 files changed, 41 insertions, 0 deletions
diff --git a/commandline/examples/ds2482-100-searchrom b/commandline/examples/ds2482-100-searchrom
new file mode 100755
index 0000000..db478e7
--- /dev/null
+++ b/commandline/examples/ds2482-100-searchrom
@@ -0,0 +1,41 @@
+#!/bin/sh
+# DS2482-100 Single Channel 1-Wire Master
+
+
+CONFIG=0xf0
+if [ "${1}" = overdrive ]; then
+ CONFIG=0x78
+fi
+
+vusb-i2cset 0x18 0xf0 || echo "Failed to reset chip"
+vusb-i2cset 0x18 0xd2 $CONFIG || echo "Failed to set config"
+vusb-i2cset 0x18 0xb4 || echo "Failed to initiate presence detection (OWR)"
+
+ret=$(( $(vusb-i2cget 0x18 0xe1 0xf0) & 0x02 ))
+
+if [ "${ret}" = 0 ]; then
+ echo "No presence detected"
+ exit 1
+fi
+
+vusb-i2cset 0x18 0xa5 0xf0 || echo "failed to issue SEARCH ROM"
+
+reply=
+
+for i in $(seq 1 8); do
+ byte=0
+ for j in $(seq 0 7); do
+ vusb-i2cset 0x18 0x78 0x00 || echo "failed to send triplet"
+
+ bit=$(vusb-i2cget 0x18 0xe1 0xf0)
+
+ if [ "${bit}" -ge 80 ]; then
+ byte=$((byte | (1 << j)))
+ fi
+ echo -n .
+ done
+ reply="$(printf '%02X' "${byte}")${reply}"
+ echo -n +
+done
+
+echo "\n${reply}"