arduino_firmata 0.1.8 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,40 @@
1
+ #include <Firmata.h>
2
+
3
+ void setup()
4
+ {
5
+ Firmata.setFirmwareVersion(FIRMATA_MAJOR_VERSION, FIRMATA_MINOR_VERSION);
6
+ Firmata.attach(START_SYSEX, sysexCallback);
7
+ Firmata.begin(57600);
8
+ }
9
+
10
+ void loop()
11
+ {
12
+ while(Firmata.available()) {
13
+ Firmata.processInput();
14
+ }
15
+ }
16
+
17
+ void sysexCallback(byte command, byte argc, byte*argv)
18
+ {
19
+ switch(command){
20
+ case 0x01: // LED Blink Command
21
+ if(argc < 3) break;
22
+ byte blink_pin;
23
+ byte blink_count;
24
+ int delayTime;
25
+ blink_pin = argv[0];
26
+ blink_count = argv[1];
27
+ delayTime = argv[2] * 100;
28
+
29
+ pinMode(blink_pin, OUTPUT);
30
+ byte i;
31
+ for(i = 0; i < blink_count; i++){
32
+ digitalWrite(blink_pin, true);
33
+ delay(delayTime);
34
+ digitalWrite(blink_pin, false);
35
+ delay(delayTime);
36
+ }
37
+ Firmata.sendSysex(command, argc, argv); // callback
38
+ break;
39
+ }
40
+ }
@@ -0,0 +1,21 @@
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
+ puts "firmata version #{arduino.version}"
8
+
9
+ ## regist event
10
+ arduino.on :sysex do |command, data|
11
+ puts "command : #{command}"
12
+ puts "data : #{data.inspect}"
13
+ end
14
+
15
+ ## send sysex command
16
+ arduino.sysex 0x01, [13, 5, 2] # pin13, blink 5 times, 200 msec interval
17
+ arduino.sysex 0x01, [11, 3, 10] # pin11, blink 3 times, 1000 msec interval
18
+
19
+ loop do
20
+ sleep 1
21
+ end
data/test/test_helper.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'rubygems'
2
+ require 'bundler/setup'
2
3
  require 'backports'
3
4
  require 'minitest/autorun'
4
5
 
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.1.8
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-10 00:00:00.000000000 Z
12
+ date: 2013-01-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: serialport
@@ -43,6 +43,22 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: 0.1.2
46
+ - !ruby/object:Gem::Dependency
47
+ name: event_emitter
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 0.2.2
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.2.2
46
62
  description: Arduino Firmata protocol (http://firmata.org) implementation on Ruby.
47
63
  email:
48
64
  - hashimoto@shokai.org
@@ -62,7 +78,6 @@ files:
62
78
  - lib/arduino_firmata.rb
63
79
  - lib/arduino_firmata/arduino.rb
64
80
  - lib/arduino_firmata/const.rb
65
- - lib/arduino_firmata/event.rb
66
81
  - lib/arduino_firmata/main.rb
67
82
  - lib/arduino_firmata/version.rb
68
83
  - samples/README.md
@@ -71,9 +86,14 @@ files:
71
86
  - samples/digital_read.rb
72
87
  - samples/led_blink.rb
73
88
  - samples/led_fade.rb
74
- - samples/on_changed.rb
89
+ - samples/on_analog_read.rb
75
90
  - samples/servo.rb
76
91
  - samples/sinatra_arduino.rb
92
+ - samples/sysex/README.md
93
+ - samples/sysex/StandardFirmataWithLedBlink/LICENSE.txt
94
+ - samples/sysex/StandardFirmataWithLedBlink/StandardFirmataWithLedBlink.ino
95
+ - samples/sysex/SysexLedBlinkFirmata/SysexLedBlinkFirmata.ino
96
+ - samples/sysex/sysex_led_blink.rb
77
97
  - samples/tweet_temperature.rb
78
98
  - test/test_arduino_firmata.rb
79
99
  - test/test_block.rb
@@ -1,15 +0,0 @@
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