i2c-devices 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/ChangeLog +2 -0
- data/Rakefile +14 -0
- data/lib/i2c.rb +18 -1
- data/lib/i2c/device/acm1602ni.rb +1 -1
- data/lib/i2c/device/adt7410.rb +1 -1
- data/lib/i2c/device/aqm0802.rb +1 -1
- data/lib/i2c/device/hd44780.rb +1 -1
- data/lib/i2c/device/mpl115a2.rb +1 -1
- data/lib/i2c/driver.rb +18 -0
- data/lib/i2c/driver/gpio.rb +2 -1
- data/lib/i2c/driver/i2c-dev.rb +2 -1
- data/spec/device/adt7410_spec.rb +7 -7
- data/spec/device/hd44780_spec.rb +4 -4
- data/{lib/i2c → spec}/mocki2cdevice.rb +0 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48ced98f8b85a2428ed61881a4cbca2de8df5c38
|
4
|
+
data.tar.gz: 8665b1e8b51a1fef07d4fe5347538543425769e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d061a08b7e0e07b70fd889d23caf9a8f9d8059a86ce2b87406db6a4190632fa94f805684a083149031cbd0fcbf5973903085a9cafa720fb433e150630f96d2a
|
7
|
+
data.tar.gz: bd3ee03c6f6120ee54f2d9862d390fa972e26c974ed8f831f3acda95f9c22e4bd8bfc14cffa36afd33c27beb0ed33a9706fe9585c4ca42fe1e91202571938351
|
data/.gitignore
CHANGED
data/ChangeLog
CHANGED
data/Rakefile
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'rdoc/task'
|
1
2
|
require 'rspec/core/rake_task'
|
2
3
|
require 'pathname'
|
3
4
|
|
@@ -12,6 +13,10 @@ RSpec::Core::RakeTask.new(:spec)
|
|
12
13
|
task :default => :spec
|
13
14
|
|
14
15
|
task :release do
|
16
|
+
tags = `git tag`.split(/\n/)
|
17
|
+
if tags.include? I2CDevice::VERSION
|
18
|
+
raise "Already exist tag #{I2CDevice::VERSION}"
|
19
|
+
end
|
15
20
|
sh %{gem build i2c-devices.gemspec}
|
16
21
|
sh %{gem push i2c-devices-#{I2CDevice::VERSION}.gem}
|
17
22
|
sh %{git add -u}
|
@@ -20,3 +25,12 @@ task :release do
|
|
20
25
|
sh %{git push}
|
21
26
|
sh %{git push --tags}
|
22
27
|
end
|
28
|
+
|
29
|
+
|
30
|
+
RDoc::Task.new do |rdoc|
|
31
|
+
rdoc.main = "README.md"
|
32
|
+
rdoc.rdoc_files.include(
|
33
|
+
"README.md",
|
34
|
+
"lib/**/*.rb"
|
35
|
+
)
|
36
|
+
end
|
data/lib/i2c.rb
CHANGED
@@ -1,12 +1,17 @@
|
|
1
|
+
# Generic abstract class for I2C manipulation.
|
1
2
|
class I2CDevice
|
2
|
-
VERSION = "0.0.
|
3
|
+
VERSION = "0.0.2"
|
3
4
|
|
5
|
+
# Super class of all of this library.
|
4
6
|
class I2CException < Exception; end
|
5
7
|
class I2CIOError < I2CException; end
|
6
8
|
class I2CBUSBusy < I2CIOError; end
|
7
9
|
|
10
|
+
# Slave address
|
8
11
|
attr_accessor :address
|
9
12
|
|
13
|
+
# <tt>args[:address]</tt> :: [Integer] 7-bit slave address without r/w bit. MSB is always 0.
|
14
|
+
# <tt>args[:driver]</tt> :: [I2CDevice::Driver::I2CDev] Instance of driver class
|
10
15
|
def initialize(args={})
|
11
16
|
if args[:driver].nil?
|
12
17
|
require "i2c/driver/i2c-dev"
|
@@ -17,10 +22,22 @@ class I2CDevice
|
|
17
22
|
@address = args[:address] or raise I2CException, "args[:address] required"
|
18
23
|
end
|
19
24
|
|
25
|
+
# This method read data from slave with following process:
|
26
|
+
#
|
27
|
+
# 1. Write `param` to slave
|
28
|
+
# 2. re-start
|
29
|
+
# 3. Read data until NACK or `length`
|
30
|
+
#
|
31
|
+
# <tt>param</tt> :: [Integer] First writing byte. Typically, this is slave memory address.
|
32
|
+
# <tt>length=1</tt> :: [Integer] Read bytes length
|
33
|
+
# Returns :: [String] Bytes
|
20
34
|
def i2cget(param, length=1)
|
21
35
|
@driver.i2cget(@address, param, length)
|
22
36
|
end
|
23
37
|
|
38
|
+
# Write _data_ to slave.
|
39
|
+
# <tt>data</tt> :: [Array[Integer]] Writing bytes array.
|
40
|
+
# Returns :: [String] Wrote bytes
|
24
41
|
def i2cset(*data)
|
25
42
|
@driver.i2cset(@address, *data)
|
26
43
|
end
|
data/lib/i2c/device/acm1602ni.rb
CHANGED
@@ -4,7 +4,7 @@ require "i2c/device/hd44780"
|
|
4
4
|
|
5
5
|
# Note: This device only run under speed=50kHz
|
6
6
|
# http://akizukidenshi.com/catalog/g/gP-05693/
|
7
|
-
class ACM1602NI < HD44780
|
7
|
+
class I2CDevice::ACM1602NI < I2CDevice::HD44780
|
8
8
|
def initialize(args={})
|
9
9
|
args[:address] ||= 0x50
|
10
10
|
super
|
data/lib/i2c/device/adt7410.rb
CHANGED
data/lib/i2c/device/aqm0802.rb
CHANGED
data/lib/i2c/device/hd44780.rb
CHANGED
data/lib/i2c/device/mpl115a2.rb
CHANGED
data/lib/i2c/driver.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
|
4
|
+
module I2CDevice::Driver
|
5
|
+
# Abstract class for I2CDevice::Driver
|
6
|
+
class I2CDevice::Driver::Base
|
7
|
+
include I2CDevice::Driver
|
8
|
+
end
|
9
|
+
|
10
|
+
def i2cget(address, param, length=1)
|
11
|
+
raise NotImplementedError
|
12
|
+
end
|
13
|
+
|
14
|
+
def i2cset(address, *data)
|
15
|
+
raise NotImplementedError
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
data/lib/i2c/driver/gpio.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
require "i2c"
|
2
|
+
require "i2c/driver"
|
2
3
|
=begin
|
3
4
|
Generic software I2C Driver based on /sys/class/gpio.
|
4
5
|
THIS MODULE WORKS WITH VERY SLOW SPEED ABOUT JUST 1kHz (normaly 100kHz).
|
5
6
|
=end
|
6
7
|
|
7
8
|
module I2CDevice::Driver
|
8
|
-
class GPIO
|
9
|
+
class GPIO < Base
|
9
10
|
@@DEBUG = false
|
10
11
|
|
11
12
|
def self.export(pin)
|
data/lib/i2c/driver/i2c-dev.rb
CHANGED
data/spec/device/adt7410_spec.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
#!rspec
|
2
2
|
|
3
3
|
|
4
|
-
$LOAD_PATH.unshift "lib"
|
4
|
+
$LOAD_PATH.unshift "lib", "."
|
5
5
|
|
6
6
|
require "tempfile"
|
7
7
|
|
8
8
|
require "i2c/device/adt7410"
|
9
9
|
require "i2c/driver/i2c-dev"
|
10
|
-
require "
|
10
|
+
require "spec/mocki2cdevice"
|
11
11
|
|
12
|
-
describe ADT7410 do
|
12
|
+
describe I2CDevice::ADT7410 do
|
13
13
|
before do
|
14
14
|
@mock = MockI2CDevice.new
|
15
15
|
File.stub(:open) do
|
@@ -27,7 +27,7 @@ describe ADT7410 do
|
|
27
27
|
@mock.memory[0x00] = 0b00000000
|
28
28
|
@mock.memory[0x01] = 0b00000001
|
29
29
|
|
30
|
-
device = ADT7410.new(address: 0x50, driver: @driver)
|
30
|
+
device = I2CDevice::ADT7410.new(address: 0x50, driver: @driver)
|
31
31
|
expect(device.read_configuration).to eq({
|
32
32
|
:fault_queue => 1,
|
33
33
|
:ct_pin_polarity => false,
|
@@ -46,7 +46,7 @@ describe ADT7410 do
|
|
46
46
|
@mock.memory[0x00] = 0b10000000
|
47
47
|
@mock.memory[0x01] = 0b00000000
|
48
48
|
|
49
|
-
device = ADT7410.new(address: 0x50, driver: @driver)
|
49
|
+
device = I2CDevice::ADT7410.new(address: 0x50, driver: @driver)
|
50
50
|
expect(device.calculate_temperature).to eq(-256)
|
51
51
|
end
|
52
52
|
end
|
@@ -59,7 +59,7 @@ describe ADT7410 do
|
|
59
59
|
@mock.memory[0x00] = 0b00000000
|
60
60
|
@mock.memory[0x01] = 0b00001000
|
61
61
|
|
62
|
-
device = ADT7410.new(address: 0x50, driver: @driver)
|
62
|
+
device = I2CDevice::ADT7410.new(address: 0x50, driver: @driver)
|
63
63
|
device.configuration({
|
64
64
|
resolution: 13,
|
65
65
|
})
|
@@ -74,7 +74,7 @@ describe ADT7410 do
|
|
74
74
|
@mock.memory[0x00] = 0b11100100
|
75
75
|
@mock.memory[0x01] = 0b10000000
|
76
76
|
|
77
|
-
device = ADT7410.new(address: 0x50, driver: @driver)
|
77
|
+
device = I2CDevice::ADT7410.new(address: 0x50, driver: @driver)
|
78
78
|
device.configuration({
|
79
79
|
resolution: 13,
|
80
80
|
})
|
data/spec/device/hd44780_spec.rb
CHANGED
@@ -8,7 +8,7 @@ require "tempfile"
|
|
8
8
|
require "i2c/device/hd44780"
|
9
9
|
require "i2c/driver/i2c-dev"
|
10
10
|
|
11
|
-
describe HD44780 do
|
11
|
+
describe I2CDevice::HD44780 do
|
12
12
|
before do
|
13
13
|
@i2cout = ""
|
14
14
|
@i2cin = ""
|
@@ -41,7 +41,7 @@ describe HD44780 do
|
|
41
41
|
|
42
42
|
describe "#initialize_lcd" do
|
43
43
|
it "should initialize lcd" do
|
44
|
-
lcd = HD44780.new(address: 0x10, driver: @driver)
|
44
|
+
lcd = I2CDevice::HD44780.new(address: 0x10, driver: @driver)
|
45
45
|
|
46
46
|
expect(@i2cout.unpack("C*")).to eq([
|
47
47
|
0b00000000,
|
@@ -62,7 +62,7 @@ describe HD44780 do
|
|
62
62
|
|
63
63
|
describe "#put_line" do
|
64
64
|
it "should be put_line 1/2" do
|
65
|
-
lcd = HD44780.new(address: 0x10, driver: @driver)
|
65
|
+
lcd = I2CDevice::HD44780.new(address: 0x10, driver: @driver)
|
66
66
|
|
67
67
|
@i2cout.clear
|
68
68
|
|
@@ -122,7 +122,7 @@ describe HD44780 do
|
|
122
122
|
|
123
123
|
describe "#define_character" do
|
124
124
|
it "should define character" do
|
125
|
-
lcd = HD44780.new(address: 0x10, driver: @driver)
|
125
|
+
lcd = I2CDevice::HD44780.new(address: 0x10, driver: @driver)
|
126
126
|
|
127
127
|
@i2cout.clear
|
128
128
|
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i2c-devices
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cho45
|
@@ -55,13 +55,14 @@ files:
|
|
55
55
|
- lib/i2c/device/aqm0802.rb
|
56
56
|
- lib/i2c/device/hd44780.rb
|
57
57
|
- lib/i2c/device/mpl115a2.rb
|
58
|
+
- lib/i2c/driver.rb
|
58
59
|
- lib/i2c/driver/gpio.rb
|
59
60
|
- lib/i2c/driver/i2c-dev.rb
|
60
|
-
- lib/i2c/mocki2cdevice.rb
|
61
61
|
- spec/device/adt7410_spec.rb
|
62
62
|
- spec/device/hd44780_spec.rb
|
63
63
|
- spec/driver/gpio_spec.rb
|
64
64
|
- spec/i2cdevice_spec.rb
|
65
|
+
- spec/mocki2cdevice.rb
|
65
66
|
- xt/acm1602ni.rb
|
66
67
|
- xt/driver-gpio.rb
|
67
68
|
- xt/i2cdetect.rb
|
@@ -95,3 +96,4 @@ test_files:
|
|
95
96
|
- spec/device/hd44780_spec.rb
|
96
97
|
- spec/driver/gpio_spec.rb
|
97
98
|
- spec/i2cdevice_spec.rb
|
99
|
+
- spec/mocki2cdevice.rb
|