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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b3513dbcf14f87bf4c6f8c53b3b5e26a0c82f406
4
- data.tar.gz: bf21da782f160272187c5631fa50c8f8b22d11f1
3
+ metadata.gz: 48ced98f8b85a2428ed61881a4cbca2de8df5c38
4
+ data.tar.gz: 8665b1e8b51a1fef07d4fe5347538543425769e4
5
5
  SHA512:
6
- metadata.gz: 03e1802fbca28f590fda962582901c34dcd35755c93d7d050ca02eb7808853110eb1b7e30254edd666f9a6d69bfbe57985aab31c2c77ef10354a23d098e967f8
7
- data.tar.gz: 5309612e7dd287a78e315566b707da4deb4e9466d3e26b699ed4e0b568e1bc481830304948e07c251c7fa3cc454a699307a0e12c5e3dbe692971fc58bee78beb
6
+ metadata.gz: 3d061a08b7e0e07b70fd889d23caf9a8f9d8059a86ce2b87406db6a4190632fa94f805684a083149031cbd0fcbf5973903085a9cafa720fb433e150630f96d2a
7
+ data.tar.gz: bd3ee03c6f6120ee54f2d9862d390fa972e26c974ed8f831f3acda95f9c22e4bd8bfc14cffa36afd33c27beb0ed33a9706fe9585c4ca42fe1e91202571938351
data/.gitignore CHANGED
@@ -1,3 +1,3 @@
1
1
  *.gem
2
2
  sketch.rb
3
-
3
+ html
data/ChangeLog CHANGED
@@ -2,3 +2,5 @@
2
2
 
3
3
  * 0.0.1: initial release
4
4
 
5
+ * 0.0.2: Update module namespaces.
6
+
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.1"
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
@@ -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
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "i2c"
4
4
 
5
- class ADT7410 < I2CDevice
5
+ class I2CDevice::ADT7410 < I2CDevice
6
6
  OPERATION_MODE = {
7
7
  0b00 => :continuous_conversion,
8
8
  0b01 => :one_shot,
@@ -3,7 +3,7 @@
3
3
  require "i2c"
4
4
  require "i2c/device/hd44780"
5
5
 
6
- class AQM0802A < HD44780
6
+ class I2CDevice::AQM0802A < I2CDevice::HD44780
7
7
  def initialize(args={})
8
8
  args[:address] ||= 0x3e
9
9
  super
@@ -3,7 +3,7 @@
3
3
  require "i2c"
4
4
 
5
5
  # I2C interface with HD44780 compatible commands
6
- class HD44780 < I2CDevice
6
+ class I2CDevice::HD44780 < I2CDevice
7
7
  MAP = Hash[
8
8
  [
9
9
  "。「」、・ヲァィゥェォャュョッーアイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙゚".split(//).map {|c|
@@ -1,7 +1,7 @@
1
1
 
2
2
  require "i2c"
3
3
 
4
- class MPL115A2 < I2CDevice
4
+ class I2CDevice::MPL115A2 < I2CDevice
5
5
  def initialize(args={})
6
6
  args[:address] = 0x60
7
7
  super
@@ -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
+
@@ -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)
@@ -1,8 +1,9 @@
1
1
 
2
2
  require "i2c"
3
+ require "i2c/driver"
3
4
 
4
5
  module I2CDevice::Driver
5
- class I2CDev
6
+ class I2CDev < Base
6
7
  # ioctl command
7
8
  # Ref. https://www.kernel.org/pub/linux/kernel/people/marcelo/linux-2.4/include/linux/i2c.h
8
9
  I2C_RETRIES = 0x0701
@@ -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 "i2c/mocki2cdevice"
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
  })
@@ -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.1
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