summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTat-Chee Wan (USM)2011-03-01 12:04:13 +0800
committerTat-Chee Wan (USM)2011-03-01 12:04:13 +0800
commit4ac22d8834dd625876281de4fc4da4e5cd6d1b59 (patch)
tree717794ebdf7f3c6546200e46c9baaeb7039115e0
parent5b5271e98c6d7f0ffea9d6b3fbf2cec43d283d64 (diff)
added initial fantom glue to nxt-python, and fantom external module
-rw-r--r--nxt-python-fantom/.project11
-rw-r--r--nxt-python-fantom/nxt/fantomglue.py55
2 files changed, 66 insertions, 0 deletions
diff --git a/nxt-python-fantom/.project b/nxt-python-fantom/.project
new file mode 100644
index 0000000..1b06536
--- /dev/null
+++ b/nxt-python-fantom/.project
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>nxt-python-fantom</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ </buildSpec>
+ <natures>
+ </natures>
+</projectDescription>
diff --git a/nxt-python-fantom/nxt/fantomglue.py b/nxt-python-fantom/nxt/fantomglue.py
new file mode 100644
index 0000000..a987a7e
--- /dev/null
+++ b/nxt-python-fantom/nxt/fantomglue.py
@@ -0,0 +1,55 @@
+# fantom.py module -- Glue code from NXT_Python to Fantom, allowing
+# NXT_Python to run on Mac without modification. Supports subset of
+# PyBluez/bluetooth.py used by NXT_Python.
+#
+# Copyright (C) 2011 Tat-Chee Wan
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+import fantom
+
+FANTOM_BT='BT'
+FANTOM_USB='USB'
+
+
+def discover_devices(lookup_names=False): # parameter is ignored
+ pairs = []
+ d = fantom.finddevices(proto = FANTOM_BT)
+ for p in d:
+ h = p[0]
+ n = p[1]
+ pairs.append((h, n))
+ return pairs
+
+class BluetoothSocket:
+
+ def __init__(self, proto = FANTOM_BT, _sock=None):
+ if _sock is None:
+ _sock = fantom.socket(proto)
+ self._sock = _sock
+ self._proto = proto
+
+ def connect(self, addrport):
+ addr, port = addrport
+ self._sock.connect( (addr, port ))
+
+ def send(self, data):
+ return self._sock.send( data )
+
+ def recv(self, numbytes):
+ return self._sock.recv( numbytes )
+
+ def close(self):
+ return self._sock.close()
+
+class BluetoothError(IOError):
+ pass
+