arduino_firmata 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 0.0.7 2012-10-25
2
+
3
+ * ArduinoFirmata::Arduino#on_analog_changed
4
+
1
5
  === 0.0.6 2012-10-24
2
6
 
3
7
  * block syntax on ArduinoFirmata::connect
data/Manifest.txt CHANGED
@@ -8,6 +8,7 @@ Rakefile
8
8
  lib/arduino_firmata.rb
9
9
  lib/arduino_firmata/arduino.rb
10
10
  lib/arduino_firmata/const.rb
11
+ lib/arduino_firmata/event.rb
11
12
  lib/arduino_firmata/main.rb
12
13
  samples/README.md
13
14
  samples/analog_read_write.rb
@@ -15,6 +16,7 @@ samples/block.rb
15
16
  samples/digital_read.rb
16
17
  samples/led_blink.rb
17
18
  samples/led_fade.rb
19
+ samples/on_changed.rb
18
20
  samples/tweet_temperature.rb
19
21
  script/console
20
22
  script/destroy
data/README.rdoc CHANGED
@@ -46,6 +46,10 @@ Analog Write (PWM)
46
46
  Analog Read
47
47
 
48
48
  puts arduino.analog_read 0 # => 0 ~ 1023
49
+
50
+ arduino.on_analog_changed 0 do |value|
51
+ puts value # => 0 ~ 1023
52
+ end
49
53
 
50
54
 
51
55
  Close
@@ -6,7 +6,8 @@ require 'stringio'
6
6
  require 'arduino_firmata/main'
7
7
  require 'arduino_firmata/const'
8
8
  require 'arduino_firmata/arduino'
9
+ require 'arduino_firmata/event'
9
10
 
10
11
  module ArduinoFirmata
11
- VERSION = '0.0.6'
12
+ VERSION = '0.0.7'
12
13
  end
@@ -18,6 +18,8 @@ module ArduinoFirmata
18
18
 
19
19
  @version = nil
20
20
 
21
+ @on_analog_changed = []
22
+
21
23
  @serial = SerialPort.new(serial_name, params[:bps], params[:bit], params[:stopbit], params[:parity])
22
24
  @serial.read_timeout = 3
23
25
  sleep 3
@@ -112,7 +114,11 @@ module ArduinoFirmata
112
114
  when DIGITAL_MESSAGE
113
115
  @digital_input_data[@multi_byte_channel] = (@stored_input_data[0] << 7) + @stored_input_data[1]
114
116
  when ANALOG_MESSAGE
115
- @analog_input_data[@multi_byte_channel] = (@stored_input_data[0] << 7) + @stored_input_data[1]
117
+ analog_value = (@stored_input_data[0] << 7) + @stored_input_data[1]
118
+ unless @analog_input_data[@multi_byte_channel] == analog_value
119
+ on_analog_changed @multi_byte_channel, analog_value
120
+ end
121
+ @analog_input_data[@multi_byte_channel] = analog_value
116
122
  when REPORT_VERSION
117
123
  @version = "#{@stored_input_data[1]}.#{@stored_input_data[0]}"
118
124
  end
@@ -0,0 +1,15 @@
1
+ module ArduinoFirmata
2
+ class Arduino
3
+
4
+ def on_analog_changed(pin, value=nil, &block)
5
+ if block_given?
6
+ @on_analog_changed.push(:pin => pin, :callback => block)
7
+ else
8
+ @on_analog_changed.each do |func|
9
+ func[:callback].call value if func[:pin] == pin
10
+ end
11
+ end
12
+ end
13
+
14
+ end
15
+ end
@@ -1,6 +1,6 @@
1
1
  #usr/bin/env ruby
2
- require 'rubygems'
3
2
  $:.unshift File.expand_path '../lib', File.dirname(__FILE__)
3
+ require 'rubygems'
4
4
  require 'arduino_firmata'
5
5
 
6
6
  arduino = ArduinoFirmata.connect ARGV.shift
@@ -11,3 +11,4 @@ loop do
11
11
  arduino.analog_write 11, an/4
12
12
  sleep 0.1
13
13
  end
14
+
@@ -1,6 +1,6 @@
1
1
  #usr/bin/env ruby
2
- require 'rubygems'
3
2
  $:.unshift File.expand_path '../lib', File.dirname(__FILE__)
3
+ require 'rubygems'
4
4
  require 'arduino_firmata'
5
5
 
6
6
  arduino = ArduinoFirmata.connect ARGV.shift
data/samples/led_blink.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  #usr/bin/env ruby
2
- require 'rubygems'
3
2
  $:.unshift File.expand_path '../lib', File.dirname(__FILE__)
3
+ require 'rubygems'
4
4
  require 'arduino_firmata'
5
5
 
6
6
  arduino = ArduinoFirmata.connect ARGV.shift
data/samples/led_fade.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  #usr/bin/env ruby
2
- require 'rubygems'
3
2
  $:.unshift File.expand_path '../lib', File.dirname(__FILE__)
3
+ require 'rubygems'
4
4
  require 'arduino_firmata'
5
5
 
6
6
  arduino = ArduinoFirmata.connect ARGV.shift
@@ -0,0 +1,18 @@
1
+ #usr/bin/env ruby
2
+ $:.unshift File.expand_path '../lib', File.dirname(__FILE__)
3
+ require 'rubygems'
4
+ require 'arduino_firmata'
5
+
6
+ arduino = ArduinoFirmata.connect ARGV.shift
7
+
8
+ arduino.on_analog_changed 0 do |value|
9
+ puts "analog pin 0 changed #{value}"
10
+ arduino.analog_write 11, value
11
+ end
12
+
13
+ led_stat = false
14
+ loop do
15
+ arduino.digital_write 13, led_stat
16
+ led_stat = !led_stat
17
+ sleep 1
18
+ end
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #usr/bin/env ruby
3
- require 'rubygems'
4
3
  $:.unshift File.expand_path '../lib', File.dirname(__FILE__)
4
+ require 'rubygems'
5
5
  require 'arduino_firmata'
6
6
  require 'tw'
7
7
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arduino_firmata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -101,6 +101,7 @@ files:
101
101
  - lib/arduino_firmata.rb
102
102
  - lib/arduino_firmata/arduino.rb
103
103
  - lib/arduino_firmata/const.rb
104
+ - lib/arduino_firmata/event.rb
104
105
  - lib/arduino_firmata/main.rb
105
106
  - samples/README.md
106
107
  - samples/analog_read_write.rb
@@ -108,6 +109,7 @@ files:
108
109
  - samples/digital_read.rb
109
110
  - samples/led_blink.rb
110
111
  - samples/led_fade.rb
112
+ - samples/on_changed.rb
111
113
  - samples/tweet_temperature.rb
112
114
  - script/console
113
115
  - script/destroy
@@ -132,7 +134,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
132
134
  version: '0'
133
135
  segments:
134
136
  - 0
135
- hash: 3290928914737067579
137
+ hash: -4444289282427680470
136
138
  required_rubygems_version: !ruby/object:Gem::Requirement
137
139
  none: false
138
140
  requirements: