]> defiant.homedns.org Git - ros_wild_thumper.git/commitdiff
added pyshared submodules, use i2c from pyshared
authorErik Andresen <erik@vontaene.de>
Tue, 27 Dec 2016 16:04:50 +0000 (17:04 +0100)
committerErik Andresen <erik@vontaene.de>
Tue, 27 Dec 2016 16:04:50 +0000 (17:04 +0100)
.gitmodules [new file with mode: 0644]
scripts/i2c.py
scripts/pyshared [new submodule]

diff --git a/.gitmodules b/.gitmodules
new file mode 100644 (file)
index 0000000..4a47d86
--- /dev/null
@@ -0,0 +1,3 @@
+[submodule "scripts/pyshared"]
+       path = scripts/pyshared
+       url = ssh://erik@defiant.homedns.org/home/erik_alt/git/pyshared.git
index 2bb9f94026849106394d92e9f3210d7feff14de6..79a7356161e355a984cf7b01b6a688c8ff36ab72 100755 (executable)
@@ -1,87 +1,7 @@
 #!/usr/bin/env python
 # -*- coding: iso-8859-15 -*-
 
-import threading
-import inspect
-import os
-import logging
-import struct
-import fcntl
-from ctypes import *
-from time import sleep
-
-DEBUG=0
-I2C_FILENAME = "/dev/i2c-2"
-logger = logging.getLogger(__name__)
-
-class i2c:
-       libc = CDLL("libc.so.6")
-       I2C_SLAVE = 0x0703  # Use this slave address
-       __single = None
-       __lock = threading.Lock()
-       __parent_owner = None
-
-       def __init__(self, addr):
-               with i2c.__lock:
-                       count = 0
-                       while(i2c.__single):
-                               parent = inspect.stack()[1][3]
-                               count += 1
-                               sleep(0.001)
-                       if DEBUG:
-                               if count > 10:
-                                       parent_owner = "%s (%d), %s()" % (self.__parent_owner[1], self.__parent_owner[2], self.__parent_owner[3])
-                                       logger.warning("Error: (%s) I2C blocked %fs by %s!", parent, count*0.001, parent_owner)
-                               i2c.__parent_owner = inspect.stack()[1]
-                       i2c.__single = True
-               self.dev = i2c.libc.open(I2C_FILENAME, os.O_RDWR)
-               if self.dev < 0:
-                       raise IOError("open")
-               fcntl.flock(self.dev, fcntl.LOCK_EX)
-               err = i2c.libc.ioctl(self.dev, i2c.I2C_SLAVE, addr>>1)
-               if err < 0:
-                       raise IOError("ioctl")
-
-       def write(self, s):
-               num_write = i2c.libc.write(self.dev, s, len(s))
-               if num_write != len(s):
-                       self.close()
-                       raise IOError("write: %d" % (num_write))
-       
-       def read(self, num):
-               buf = create_string_buffer(num)
-               num_read = i2c.libc.read(self.dev, buf, num)
-               if num_read != num:
-                       self.close()
-                       raise IOError("read: %d" % (num_read))
-               return buf.raw
-
-       def close(self):
-               if self.dev:
-                       i2c.libc.close(self.dev)
-                       self.dev = None
-                       #i2c.__parent_owner = None
-                       i2c.__single = None
-
-       def __del__(self):
-               self.close()
-
-
-def i2c_write_reg(addr, reg, buf):
-       dev = i2c(addr)
-       s = struct.pack(">B", reg) + buf
-       dev.write(s)
-       dev.close()
-
-
-def i2c_read_reg(addr, reg, num=1):
-       dev = i2c(addr)
-       s = struct.pack(">B", reg)
-       dev.write(s)
-       s = dev.read(num)
-       dev.close()
-       return s
-
+from pyshared.i2c import *
 
 if __name__ == "__main__":
        import struct
diff --git a/scripts/pyshared b/scripts/pyshared
new file mode 160000 (submodule)
index 0000000..44c7f36
--- /dev/null
@@ -0,0 +1 @@
+Subproject commit 44c7f3645d8839dbc49a54bf1481dd2f75199a7a