artoo-i2c 0.2.1 → 0.3.0

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: 775dbfe330b314c190b6639669cf17e379733455
4
- data.tar.gz: 1a1ce68c0a5a6c711278a8d803a22aa3780e783e
3
+ metadata.gz: f2209b7bcac30ba1d6f3dc652a3025d80814ea41
4
+ data.tar.gz: 7a8fb2d6bf69e153408abadb941c580002c64873
5
5
  SHA512:
6
- metadata.gz: 9e0dafbf120f4a81df7430feec402b2e75793f8f689cc6d3161e7357a2c0868cb21afbd9e7d7e899023e56cc2bb27ebcf931500b7e0731d61c158918ef4162bf
7
- data.tar.gz: 5b05c4dc181bf88884942ca864144a7082b95dc10395156ef5ac745a640a73768c1f65e6014bae3ad42a287593f5adc1ae5218dd01b52f1ac8cc7752b3d66e9f
6
+ metadata.gz: 38f0948ddfda8cf14d9094014f9070e58123551705f7f9cc66f4746fa64142b4b89ab3090e28e2be9a2494ebba4d0720824c16adac92bbca22989db7b1b3fe3b
7
+ data.tar.gz: fa8bc0fb643e7efe123ef755a49d013f0393c8304d421a12e87c422a3980c17635ea7840a4d83e7670f0dec84c672bcf77fe4b59ef5edd71fc67b50349cde7a2
data/Gemfile.lock CHANGED
@@ -1,13 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- artoo-i2c (0.2.1)
5
- artoo (>= 1.2.2)
4
+ artoo-i2c (0.3.0)
5
+ artoo (>= 1.3.0)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- artoo (1.2.2)
10
+ artoo (1.3.0)
11
11
  celluloid (~> 0.15.0)
12
12
  celluloid-io (~> 0.15.0)
13
13
  multi_json (~> 1.6)
@@ -30,7 +30,7 @@ GEM
30
30
  minitest-happy (1.0.0)
31
31
  mocha (0.14.0)
32
32
  metaclass (~> 0.0.1)
33
- multi_json (1.8.0)
33
+ multi_json (1.8.1)
34
34
  nio4r (0.5.0)
35
35
  pry (0.9.12.2)
36
36
  coderay (~> 1.0.5)
data/README.md CHANGED
@@ -27,8 +27,10 @@ puts "Example here"
27
27
  ## Devices supported
28
28
 
29
29
  The following i2c hardware devices have driver support:
30
- - Wiichuck
31
- - Wiiclassic
30
+ - BlinkM RGB LED
31
+ - HMC6352 Digial Compass
32
+ - Wii Nunchuck Controller
33
+ - Wii Classic Controller
32
34
 
33
35
 
34
36
  ## Contributing
data/artoo-i2c.gemspec CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
20
20
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
21
  s.require_paths = ["lib"]
22
22
 
23
- s.add_runtime_dependency 'artoo', '>= 1.2.2'
23
+ s.add_runtime_dependency 'artoo', '>= 1.3.0'
24
24
  s.add_development_dependency 'minitest', '>= 5.0'
25
25
  s.add_development_dependency 'minitest-happy'
26
26
  s.add_development_dependency 'mocha', '>= 0.14.0'
@@ -0,0 +1,21 @@
1
+ require 'artoo'
2
+
3
+ #connection :firmata, :adaptor => :firmata, :port => '/dev/ttyACM0'
4
+ connection :digispark, :adaptor => :littlewire, :vendor => 0x1781, :product => 0x0c9f
5
+ device :blink_m, :driver => :blink_m
6
+
7
+ work do
8
+ puts blink_m.color.inspect
9
+
10
+ every 1.second do
11
+ unless @on
12
+ blink_m.rgb(0xff, 0xff, 0xff)
13
+ puts blink_m.color.inspect
14
+ @on = true
15
+ else
16
+ blink_m.rgb(0, 0, 0)
17
+ puts blink_m.color.inspect
18
+ @on = false
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ require 'artoo'
2
+
3
+ #connection :arduino, :adaptor => :firmata, :port => '/dev/ttyACM0'
4
+ connection :digispark, :adaptor => :littlewire, :vendor => 0x1781, :product => 0x0c9f
5
+ device :compass, :driver => :hmc_6352_compass, :connection => :arduino, :interval => 0.5
6
+
7
+ work do
8
+ on compass, :heading => proc { |caller, data| puts "heading: #{data}"}
9
+ end
@@ -1,5 +1,5 @@
1
1
  module Artoo
2
2
  module I2c
3
- VERSION = '0.2.1'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
@@ -0,0 +1,50 @@
1
+ require 'artoo/drivers/driver'
2
+
3
+ module Artoo
4
+ module Drivers
5
+ # BlinkM LED driver behaviors for i2c
6
+ class BlinkM < Driver
7
+ COMMANDS = [:rgb, :fade, :color, :firmware_version].freeze
8
+
9
+ def address; 0x09; end
10
+
11
+ def start_driver
12
+ begin
13
+ connection.i2c_start(address)
14
+ connection.i2c_write("o".bytes.first) # stops any scripts already running
15
+ rgb(0, 0, 0)
16
+
17
+ super
18
+ rescue Exception => e
19
+ Logger.error "Error starting BlinkM driver!"
20
+ Logger.error e.message
21
+ Logger.error e.backtrace.inspect
22
+ end
23
+ end
24
+
25
+ def rgb(r=0, g=0, b=0)
26
+ connection.i2c_write('n'.bytes.first)
27
+ connection.i2c_write(r, g, b)
28
+ end
29
+
30
+ def fade(r=0, g=0, b=0)
31
+ connection.i2c_write('c'.bytes.first)
32
+ connection.i2c_write(r, g, b)
33
+ end
34
+
35
+ def firmware_version
36
+ connection.i2c_write('Z'.bytes.first)
37
+ @data = connection.i2c_read(2)
38
+ return nil if @data.nil? || @data.empty?
39
+ return "#{@data[0]}.#{@data[1]}"
40
+ end
41
+
42
+ def color
43
+ connection.i2c_write('g'.bytes.first)
44
+ @data = connection.i2c_read(3)
45
+ return nil if @data.nil? || @data.empty?
46
+ return @data[0], @data[1], @data[2]
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,52 @@
1
+ require 'artoo/drivers/driver'
2
+
3
+ module Artoo
4
+ module Drivers
5
+ # Hmc6352 digital compass driver behaviors for i2c
6
+ class Hmc6352Compass < Driver
7
+ COMMANDS = [:heading].freeze
8
+
9
+ attr_reader :heading
10
+
11
+ def address; 0x42; end
12
+
13
+ def initialize(params={})
14
+ @heading = 0.0
15
+ super
16
+ end
17
+
18
+ def start_driver
19
+ begin
20
+ connection.i2c_start(address >> 1)
21
+ connection.i2c_write("A".bytes.first)
22
+
23
+ every(interval) do
24
+ connection.i2c_write("A".bytes.first)
25
+ new_value = connection.i2c_read(2)
26
+ update(new_value) unless new_value.nil? || new_value.empty?
27
+ end
28
+
29
+ super
30
+ rescue Exception => e
31
+ Logger.error "Error starting HMC6352 driver!"
32
+ Logger.error e.message
33
+ Logger.error e.backtrace.inspect
34
+ end
35
+ end
36
+
37
+ def update(val)
38
+ puts val.inspect
39
+ return if val.nil? || val == "bad byte"
40
+ @heading = parse(val)
41
+ publish(event_topic_name("update"), "heading", heading)
42
+ publish(event_topic_name("heading"), heading)
43
+ end
44
+
45
+ protected
46
+
47
+ def parse(val=[0, 0])
48
+ (val[1] + val[0] * 256) / 10.0
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,27 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
2
+ require 'artoo/drivers/blink_m'
3
+
4
+ describe Artoo::Drivers::BlinkM do
5
+ before do
6
+ @device = mock('device')
7
+ @connection = mock('connection')
8
+ @connection.expects(:i2c_start)
9
+ @connection.expects(:i2c_write).with("o".bytes.first)
10
+
11
+ @device.stubs(:connection).returns(@connection)
12
+ @driver = Artoo::Drivers::BlinkM.new(:parent => @device)
13
+ @driver.start_driver
14
+ end
15
+
16
+ it 'Artoo::Drivers::BlinkM#rgb' do
17
+ @connection.expects(:i2c_write).with("n".bytes.first)
18
+ @connection.expects(:i2c_write).with(5, 10, 15)
19
+ @driver.rgb(5, 10, 15)
20
+ end
21
+
22
+ it 'Artoo::Drivers::BlinkM#fade' do
23
+ @connection.expects(:i2c_write).with("c".bytes.first)
24
+ @connection.expects(:i2c_write).with(5, 10, 15)
25
+ @driver.fade(5, 10, 15)
26
+ end
27
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: artoo-i2c
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ron Evans
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-27 00:00:00.000000000 Z
12
+ date: 2013-10-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: artoo
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - '>='
19
19
  - !ruby/object:Gem::Version
20
- version: 1.2.2
20
+ version: 1.3.0
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - '>='
26
26
  - !ruby/object:Gem::Version
27
- version: 1.2.2
27
+ version: 1.3.0
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: minitest
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -81,11 +81,16 @@ files:
81
81
  - README.md
82
82
  - Rakefile
83
83
  - artoo-i2c.gemspec
84
+ - examples/blinkm.rb
85
+ - examples/compass.rb
84
86
  - lib/artoo-i2c.rb
85
87
  - lib/artoo-i2c/version.rb
88
+ - lib/artoo/drivers/blink_m.rb
89
+ - lib/artoo/drivers/hmc_6352_compass.rb
86
90
  - lib/artoo/drivers/wiichuck.rb
87
91
  - lib/artoo/drivers/wiiclassic.rb
88
92
  - lib/artoo/drivers/wiidriver.rb
93
+ - test/drivers/blinkm_test.rb
89
94
  - test/drivers/wiichuck_test.rb
90
95
  - test/drivers/wiiclassic_test.rb
91
96
  - test/drivers/wiidriver_test.rb