arduino_firmata 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ === 0.1.6 2012-11-13
2
+
3
+ * bugfix closing serialport
4
+ * show SerialPort status with ArduinoFirmata#status
5
+ * support Duemillanove on Raspberry Pi(Raspbian)
6
+
1
7
  === 0.1.5 2012-11-13
2
8
 
3
9
  * add --list option in arduino_firmata command
@@ -9,5 +9,5 @@ require 'arduino_firmata/arduino'
9
9
  require 'arduino_firmata/event'
10
10
 
11
11
  module ArduinoFirmata
12
- VERSION = '0.1.5'
12
+ VERSION = '0.1.6'
13
13
  end
@@ -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
- loop do
48
+ @thread_status = true
49
+ while status == Status::OPEN do
42
50
  process_input
43
- sleep 0.1
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
 
@@ -11,6 +11,11 @@ module ArduinoFirmata
11
11
  end
12
12
  end
13
13
 
14
+ class Status
15
+ CLOSE = 0
16
+ OPEN = 1
17
+ end
18
+
14
19
  INPUT = 0
15
20
  OUTPUT = 1
16
21
  ANALOG = 2
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.5
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 00:00:00.000000000 Z
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: -1874626047901362687
164
+ hash: 4489983546483547192
165
165
  required_rubygems_version: !ruby/object:Gem::Requirement
166
166
  none: false
167
167
  requirements: