arduino_firmata 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/lib/arduino_firmata.rb +1 -1
- data/lib/arduino_firmata/arduino.rb +23 -4
- data/lib/arduino_firmata/const.rb +5 -0
- metadata +3 -3
data/History.txt
CHANGED
data/lib/arduino_firmata.rb
CHANGED
@@ -2,9 +2,10 @@ module ArduinoFirmata
|
|
2
2
|
|
3
3
|
class Arduino
|
4
4
|
|
5
|
-
attr_reader :version
|
5
|
+
attr_reader :version, :status
|
6
6
|
|
7
7
|
def initialize(serial_name, params)
|
8
|
+
@status = Status::CLOSE
|
8
9
|
@wait_for_data = 0
|
9
10
|
@execute_multi_byte_command = 0
|
10
11
|
@multi_byte_channel = 0
|
@@ -23,25 +24,33 @@ module ArduinoFirmata
|
|
23
24
|
@serial = SerialPort.new(serial_name, params[:bps], params[:bit], params[:stopbit], params[:parity])
|
24
25
|
@serial.read_timeout = 3
|
25
26
|
sleep 3
|
27
|
+
@status = Status::OPEN
|
26
28
|
|
27
29
|
trap 'SIGHUP' do
|
28
30
|
close
|
31
|
+
exit
|
29
32
|
end
|
30
33
|
trap 'SIGINT' do
|
31
34
|
close
|
35
|
+
exit
|
32
36
|
end
|
33
37
|
trap 'SIGKILL' do
|
34
38
|
close
|
39
|
+
exit
|
35
40
|
end
|
36
41
|
trap 'SIGTERM' do
|
37
42
|
close
|
43
|
+
exit
|
38
44
|
end
|
39
45
|
|
46
|
+
@thread_status = false
|
40
47
|
Thread.new{
|
41
|
-
|
48
|
+
@thread_status = true
|
49
|
+
while status == Status::OPEN do
|
42
50
|
process_input
|
43
|
-
sleep 0.
|
51
|
+
sleep 0.01
|
44
52
|
end
|
53
|
+
@thread_status = false
|
45
54
|
}.run
|
46
55
|
|
47
56
|
(0...6).each do |i|
|
@@ -53,16 +62,24 @@ module ArduinoFirmata
|
|
53
62
|
write 1
|
54
63
|
end
|
55
64
|
|
65
|
+
write REPORT_VERSION
|
56
66
|
loop do
|
57
67
|
break if @version
|
58
68
|
sleep 0.3
|
59
69
|
end
|
60
70
|
sleep 0.5
|
61
|
-
|
62
71
|
end
|
63
72
|
|
64
73
|
def close
|
74
|
+
return if status == Status::CLOSE
|
75
|
+
@status = Status::CLOSE
|
65
76
|
@serial.close
|
77
|
+
loop do
|
78
|
+
if @serial.closed? and @thread_status != true
|
79
|
+
break
|
80
|
+
end
|
81
|
+
sleep 0.01
|
82
|
+
end
|
66
83
|
end
|
67
84
|
|
68
85
|
def digital_read(pin)
|
@@ -108,10 +125,12 @@ module ArduinoFirmata
|
|
108
125
|
|
109
126
|
private
|
110
127
|
def write(cmd)
|
128
|
+
return if status == Status::CLOSE
|
111
129
|
@serial.write_nonblock cmd.chr
|
112
130
|
end
|
113
131
|
|
114
132
|
def read
|
133
|
+
return if status == Status::CLOSE
|
115
134
|
@serial.read_nonblock 9600 rescue EOFError
|
116
135
|
end
|
117
136
|
|
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.
|
4
|
+
version: 0.1.6
|
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: 2012-11-
|
12
|
+
date: 2012-11-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: serialport
|
@@ -161,7 +161,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
161
161
|
version: '0'
|
162
162
|
segments:
|
163
163
|
- 0
|
164
|
-
hash:
|
164
|
+
hash: 4489983546483547192
|
165
165
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
166
166
|
none: false
|
167
167
|
requirements:
|