i2c-devices 0.0.4 → 0.0.5

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: 545b2f935babca05be80d95a4e6090ae7c6bc716
4
- data.tar.gz: cf85f13b1ca3bd7ffbc256ab34fd552cc74227b9
3
+ metadata.gz: 246d5743687852c69c063e4bdcb689320446ce70
4
+ data.tar.gz: ca1a2ca228efb4273a950b5f6cf75f54c4abb2d7
5
5
  SHA512:
6
- metadata.gz: b2fbfb0e4ecaccfc4659c792cc1e31ffd3fba4583f35be37343840ed0b388bf4629b43642c8258b7f1c8ccbc8ceb0269358bcfaa5ccff659d14a227fab0421db
7
- data.tar.gz: e847ef178a80c01a434fa8a3932bfe6dfc360d9e553876371a9d66d754ca20e82be6b70fc3fa24c3d55ddd39f5e26f760c5a37e46af2e6de2dcb500fb43f9652
6
+ metadata.gz: a5275d90cca868f5529428dcc26498883a61979b36e35ff7306086665a3df190cdffb8cb46204f8668cdfd833264ab67229a23a7fc368c3983feb38481444c5a
7
+ data.tar.gz: c1526218e9e11d57affcc896dbe0f747e1ccdc7d7ba69e1fc4c629eb41e0bcdd90531fb58d4d4c32935713b7feca3b42fdd51b69e0a281c49d85886fdc892705
data/ChangeLog CHANGED
@@ -1,3 +1,11 @@
1
+ 2015-08-14 SATOH Hiroh <cho45@lowreal.net>
2
+
3
+ * 0.0.5:
4
+ [MOD] i2cget acceprt nil as param (by hotchpotch)
5
+ [ADD] add device HDC1000 (by hotchpotch)
6
+ [FIX] fix device AQM0802a (by hotchpotch)
7
+
8
+
1
9
  2014-02-20 SATOH Hiroh <cho45@lowreal.net>
2
10
 
3
11
  * 0.0.1: initial release
data/README.md CHANGED
@@ -27,7 +27,7 @@ or pre-defiend device driver class:
27
27
  ```
28
28
  require "i2c/device/acm1602ni"
29
29
 
30
- lcd = ACM1602NI.new
30
+ lcd = I2CDevice::ACM1602NI.new
31
31
 
32
32
  lcd.put_line(0, "0123456789ABCDEF")
33
33
  ```
@@ -39,7 +39,7 @@ with driver class
39
39
  require "i2c/device/mpl115a2"
40
40
  require "i2c/driver/i2c-dev"
41
41
 
42
- mpl = MPL115A2.new(driver: I2CDevice::Driver::I2CDev.new("/dev/i2c-0"))
42
+ mpl = I2CDevice::MPL115A2.new(driver: I2CDevice::Driver::I2CDev.new("/dev/i2c-0"))
43
43
  p mpl.calculate_hPa
44
44
  ```
45
45
 
@@ -49,7 +49,7 @@ or GPIO backend driver (this is very slow)
49
49
  require "i2c/device/mpl115a2"
50
50
  require "i2c/driver/gpio"
51
51
 
52
- mpl = MPL115A2.new(driver: I2CDevice::Driver::GPIO.new(
52
+ mpl = I2CDevice::MPL115A2.new(driver: I2CDevice::Driver::GPIO.new(
53
53
  sda: 23, # pin 16 in raspberry pi
54
54
  scl: 24, # pin 18 in raspberry pi
55
55
  ))
data/lib/i2c.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # Generic abstract class for I2C manipulation.
2
2
  class I2CDevice
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
 
5
5
  # Super class of all of this library.
6
6
  class I2CException < Exception; end
@@ -53,6 +53,18 @@ class I2CDevice::AQM0802A < I2CDevice::HD44780
53
53
  i2cset(0, 0b00100000 | (dl<<4) | (n<<3) | (f<<2) | (is))
54
54
  sleep 37e-6
55
55
  end
56
- end
57
-
58
56
 
57
+ def put_line(line, str, force=false)
58
+ str.force_encoding(Encoding::BINARY)
59
+ str.gsub!(/#{MAP.keys.join('|')}/, MAP)
60
+ str = "%- 8s" % str
61
+ if force || str != @lines[line]
62
+ # set ddram address
63
+ set_ddram_address(line<<6) # line is 0 or 1
64
+ sleep 60e-6
65
+ i2cset(0b01000000, *str.unpack("C*"))
66
+ sleep 60e-6
67
+ end
68
+ @lines[line] = str
69
+ end
70
+ end
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+
3
+ require "i2c"
4
+
5
+ # http://www.ti.com/product/HDC1000
6
+ # A Digital humidity/temperature sensor
7
+
8
+ class I2CDevice::HDC1000 < I2CDevice
9
+ def initialize(args = {})
10
+ args = {
11
+ address: 0x40
12
+ }.merge(args)
13
+ super args
14
+ configuration
15
+ end
16
+
17
+ def configuration
18
+ i2cset(
19
+ 0x02, # Configuration register
20
+ 0x10, # TRES 14bit
21
+ 0x00 # HRES 14bit
22
+ )
23
+ end
24
+
25
+ def get_data
26
+ i2cset(0x00)
27
+ sleep 6.35e-3 + 6.5e-3
28
+ raw = i2cget(nil, 4).unpack("C4")
29
+ {
30
+ temperature: calc_temperature(raw[0], raw[1]),
31
+ humidity: calc_humidity(raw[2], raw[3])
32
+ }
33
+ end
34
+
35
+ def calc_temperature(d1, d2)
36
+ ((d1<<8 | d2).to_f / 2**16 * 165) - 40
37
+ end
38
+
39
+ def calc_humidity(d1, d2)
40
+ (d1<<8 | d2).to_f / 2**16 * 100
41
+ end
42
+ end
@@ -35,7 +35,7 @@ class I2CDevice::Driver::GPIO < I2CDevice::Driver::Base
35
35
 
36
36
  def self.write(pin, val) #:nodoc:
37
37
  File.open("/sys/class/gpio/gpio#{pin}/value", "w") do |f|
38
- f.syswrite(val && val.nonzero?? "1" : "0")
38
+ f.syswrite(val ? "1" : "0")
39
39
  end
40
40
  end
41
41
 
@@ -36,7 +36,7 @@ class I2CDevice::Driver::I2CDev < I2CDevice::Driver::Base
36
36
  def i2cget(address, param, length)
37
37
  i2c = File.open(@path, "r+")
38
38
  i2c.ioctl(I2C_SLAVE, address)
39
- i2c.syswrite(param.chr)
39
+ i2c.syswrite(param.chr) unless param.nil?
40
40
  ret = i2c.sysread(length)
41
41
  i2c.close
42
42
  ret
@@ -0,0 +1,7 @@
1
+ # coding: utf-8
2
+
3
+ require "i2c/device/aqm0802"
4
+
5
+ aqm0802 = I2CDevice::AQM0802A.new
6
+ aqm0802.put_line(0, 'helloォ')
7
+ aqm0802.put_line(1, ' world!')
@@ -13,22 +13,22 @@ driver = I2CDevice::Driver::GPIO.new(
13
13
  )
14
14
 
15
15
 
16
- device = I2CDevice.new(address: 0x20, driver: driver)
17
- loop do
18
- seq = Array.new(8) { rand(0x10) }
19
- seq = (0..7).map {|n| 0x10 + n }
20
- seq = (1..10).to_a
21
- p seq
22
- p device.i2cset(0x00, *seq)
23
- # p device.i2cget(0x00, 8).unpack("C*")
24
-
25
- exit 1
26
- sleep 1
27
- end
28
-
29
- #mpl = MPL115A2.new(driver: driver)
16
+ #device = I2CDevice.new(address: 0x20, driver: driver)
30
17
  #loop do
31
- # p mpl.calculate_hPa
18
+ # seq = Array.new(8) { rand(0x10) }
19
+ # seq = (0..7).map {|n| 0x10 + n }
20
+ # seq = (1..10).to_a
21
+ # p seq
22
+ # p device.i2cset(0x00, *seq)
23
+ # # p device.i2cget(0x00, 8).unpack("C*")
24
+ #
25
+ # exit 1
32
26
  # sleep 1
33
27
  #end
34
28
 
29
+ mpl = I2CDevice::MPL115A2.new(driver: driver)
30
+ loop do
31
+ p mpl.calculate_hPa
32
+ sleep 1
33
+ end
34
+
@@ -0,0 +1,6 @@
1
+
2
+ require 'i2c/device/hdc1000'
3
+ require 'pp'
4
+
5
+ hdc = I2CDevice::HDC1000.new
6
+ pp hdc.get_data
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift "lib"
4
4
 
5
5
  require "i2c/device/mpl115a2"
6
6
 
7
- mpl = MPL115A2.new
7
+ mpl = I2CDevice::MPL115A2.new
8
8
 
9
9
  loop do
10
10
  p mpl.calculate_hPa
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
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - cho45
@@ -14,28 +14,28 @@ dependencies:
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.5'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  description: i2c-devices is a drivers for i2c devices
@@ -45,7 +45,7 @@ extensions: []
45
45
  extra_rdoc_files:
46
46
  - README.md
47
47
  files:
48
- - .gitignore
48
+ - ".gitignore"
49
49
  - ChangeLog
50
50
  - README.md
51
51
  - Rakefile
@@ -55,6 +55,7 @@ files:
55
55
  - lib/i2c/device/adt7410.rb
56
56
  - lib/i2c/device/aqm0802.rb
57
57
  - lib/i2c/device/hd44780.rb
58
+ - lib/i2c/device/hdc1000.rb
58
59
  - lib/i2c/device/mpl115a2.rb
59
60
  - lib/i2c/driver.rb
60
61
  - lib/i2c/driver/gpio.rb
@@ -65,7 +66,9 @@ files:
65
66
  - spec/i2cdevice_spec.rb
66
67
  - spec/mocki2cdevice.rb
67
68
  - xt/acm1602ni.rb
69
+ - xt/aqm0802a.rb
68
70
  - xt/driver-gpio.rb
71
+ - xt/hdc1000.rb
69
72
  - xt/i2cdetect.rb
70
73
  - xt/mpl115a2.rb
71
74
  homepage: https://github.com/cho45/ruby-i2c-devices
@@ -74,23 +77,23 @@ licenses:
74
77
  metadata: {}
75
78
  post_install_message:
76
79
  rdoc_options:
77
- - --main
80
+ - "--main"
78
81
  - README.md
79
82
  require_paths:
80
83
  - lib
81
84
  required_ruby_version: !ruby/object:Gem::Requirement
82
85
  requirements:
83
- - - '>='
86
+ - - ">="
84
87
  - !ruby/object:Gem::Version
85
88
  version: '0'
86
89
  required_rubygems_version: !ruby/object:Gem::Requirement
87
90
  requirements:
88
- - - '>='
91
+ - - ">="
89
92
  - !ruby/object:Gem::Version
90
93
  version: '0'
91
94
  requirements: []
92
95
  rubyforge_project:
93
- rubygems_version: 2.2.2
96
+ rubygems_version: 2.4.5
94
97
  signing_key:
95
98
  specification_version: 4
96
99
  summary: i2c device drivers