Class: I2CDevice::Driver::I2CDev
Constant Summary collapse
- I2C_RETRIES =
ioctl command Ref. www.kernel.org/pub/linux/kernel/people/marcelo/linux-2.4/include/linux/i2c.h
0x0701
- I2C_TIMEOUT =
0x0702
- I2C_SLAVE =
0x0703
- I2C_SLAVE_FORCE =
0x0706
- I2C_TENBIT =
0x0704
- I2C_FUNCS =
0x0705
- I2C_RDWR =
0x0707
- I2C_SMBUS =
0x0720
- I2C_UDELAY =
0x0705
- I2C_MDELAY =
0x0706
Instance Method Summary collapse
- #i2cget(address, param, length) ⇒ Object
- #i2cset(address, *data) ⇒ Object
-
#initialize(path = nil) ⇒ I2CDev
constructor
A new instance of I2CDev.
Constructor Details
#initialize(path = nil) ⇒ I2CDev
Returns a new instance of I2CDev.
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/i2c/driver/i2c-dev.rb', line 20 def initialize(path=nil) if path.nil? path = Dir.glob("/dev/i2c-*").sort.last end unless File.exist?(path) raise I2CDevice::I2CIOError, "/dev/i2c-0 is required" end @path = path end |
Instance Method Details
#i2cget(address, param, length) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/i2c/driver/i2c-dev.rb', line 32 def i2cget(address, param, length) i2c = File.open(@path, "r+") i2c.ioctl(I2C_SLAVE, address) i2c.syswrite(param.chr) ret = i2c.sysread(length) i2c.close ret rescue Errno::EIO => e raise I2CDevice::I2CIOError, e. end |
#i2cset(address, *data) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/i2c/driver/i2c-dev.rb', line 43 def i2cset(address, *data) i2c = File.open(@path, "r+") i2c.ioctl(I2C_SLAVE, address) i2c.syswrite(data.pack("C*")) i2c.close rescue Errno::EIO => e raise I2CDevice::I2CIOError, e. end |