rintcore 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module RintCore
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/rintcore.gemspec CHANGED
@@ -6,7 +6,7 @@ require 'rint_core/version'
6
6
  Gem::Specification.new do |gem|
7
7
  gem.name = "rintcore"
8
8
  gem.version = RintCore::VERSION
9
- gem.authors = ["Kaz Walker","Rob Gilson"]
9
+ gem.authors = ["Kaz Walker"]
10
10
  gem.email = ["kaz.walker@doopli.co"]
11
11
  gem.description = %q{RepRap/GCode utilities written in Ruby.}
12
12
  gem.summary = %q{A Ruby implementation of PrintCore.}
@@ -18,5 +18,7 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ["lib"]
19
19
  gem.add_runtime_dependency 'serialport', '1.1.0'
20
20
  gem.add_runtime_dependency 'activesupport'
21
+ gem.add_runtime_dependency 'thor'
21
22
  gem.add_development_dependency 'rake'
23
+ gem.add_development_dependency 'rspec'
22
24
  end
metadata CHANGED
@@ -1,21 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rintcore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.0.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Kaz Walker
9
- - Rob Gilson
10
8
  autorequire:
11
9
  bindir: bin
12
10
  cert_chain: []
13
- date: 2013-02-18 00:00:00.000000000 Z
11
+ date: 2013-02-26 00:00:00.000000000 Z
14
12
  dependencies:
15
13
  - !ruby/object:Gem::Dependency
16
14
  name: serialport
17
15
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
16
  requirements:
20
17
  - - '='
21
18
  - !ruby/object:Gem::Version
@@ -23,7 +20,6 @@ dependencies:
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
23
  requirements:
28
24
  - - '='
29
25
  - !ruby/object:Gem::Version
@@ -31,82 +27,111 @@ dependencies:
31
27
  - !ruby/object:Gem::Dependency
32
28
  name: activesupport
33
29
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
30
  requirements:
36
- - - ! '>='
31
+ - - '>='
37
32
  - !ruby/object:Gem::Version
38
33
  version: '0'
39
34
  type: :runtime
40
35
  prerelease: false
41
36
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
37
  requirements:
44
- - - ! '>='
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
45
53
  - !ruby/object:Gem::Version
46
54
  version: '0'
47
55
  - !ruby/object:Gem::Dependency
48
56
  name: rake
49
57
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
58
  requirements:
52
- - - ! '>='
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
53
74
  - !ruby/object:Gem::Version
54
75
  version: '0'
55
76
  type: :development
56
77
  prerelease: false
57
78
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
79
  requirements:
60
- - - ! '>='
80
+ - - '>='
61
81
  - !ruby/object:Gem::Version
62
82
  version: '0'
63
83
  description: RepRap/GCode utilities written in Ruby.
64
84
  email:
65
85
  - kaz.walker@doopli.co
66
- executables: []
86
+ executables:
87
+ - rintcore
67
88
  extensions: []
68
89
  extra_rdoc_files: []
69
90
  files:
70
91
  - .gitignore
92
+ - .ruby-version
71
93
  - CONTRIBUTING.md
72
94
  - Gemfile
73
95
  - LICENSE.md
74
96
  - README.md
75
97
  - Rakefile
98
+ - bin/rintcore
76
99
  - lib/rint_core.rb
100
+ - lib/rint_core/cli.rb
101
+ - lib/rint_core/driver.rb
102
+ - lib/rint_core/driver/operating_system.rb
103
+ - lib/rint_core/driver/operations.rb
104
+ - lib/rint_core/driver/parsing.rb
105
+ - lib/rint_core/driver/queueing.rb
106
+ - lib/rint_core/driver/state.rb
77
107
  - lib/rint_core/g_code.rb
78
108
  - lib/rint_core/g_code/codes.rb
79
- - lib/rint_core/printer_driver.rb
109
+ - lib/rint_core/g_code/line.rb
110
+ - lib/rint_core/g_code/object.rb
111
+ - lib/rint_core/printer.rb
80
112
  - lib/rint_core/version.rb
81
113
  - rintcore.gemspec
82
114
  homepage: https://github.com/KazW/RintCore
83
115
  licenses: []
116
+ metadata: {}
84
117
  post_install_message:
85
118
  rdoc_options: []
86
119
  require_paths:
87
120
  - lib
88
121
  required_ruby_version: !ruby/object:Gem::Requirement
89
- none: false
90
122
  requirements:
91
- - - ! '>='
123
+ - - '>='
92
124
  - !ruby/object:Gem::Version
93
125
  version: '0'
94
- segments:
95
- - 0
96
- hash: -1346737977531935577
97
126
  required_rubygems_version: !ruby/object:Gem::Requirement
98
- none: false
99
127
  requirements:
100
- - - ! '>='
128
+ - - '>='
101
129
  - !ruby/object:Gem::Version
102
130
  version: '0'
103
- segments:
104
- - 0
105
- hash: -1346737977531935577
106
131
  requirements: []
107
132
  rubyforge_project:
108
- rubygems_version: 1.8.25
133
+ rubygems_version: 2.0.0
109
134
  signing_key:
110
- specification_version: 3
135
+ specification_version: 4
111
136
  summary: A Ruby implementation of PrintCore.
112
137
  test_files: []
@@ -1,312 +0,0 @@
1
- require 'rint_core/g_code/codes'
2
- require 'serialport'
3
- require 'active_support/core_ext/object/blank'
4
- require 'active_support/configurable'
5
-
6
- module RintCore
7
- class PrinterDriver
8
- include ActiveSupport::Configurable
9
-
10
- # Callbacks are typically given a string argument, usually the current line
11
- config_accessor :port, :baud, :start_callback, :temperature_callback,
12
- :receive_callback, :send_callback, :error_callback,
13
- :end_callback, :online_callback, :debug_callback,
14
- :connect_callback
15
-
16
- def control_ttyhup(port, disable_hup)
17
- if /linux/ =~ RUBY_PLATFORM
18
- if disable_hup
19
- `stty -F #{port} -hup`
20
- else
21
- `stty -F #{port} hup`
22
- end
23
- end
24
- end
25
-
26
- def enable_hup(port)
27
- control_ttyhup(port, true)
28
- end
29
-
30
- def disable_hup(port)
31
- control_ttyhup(port, false)
32
- end
33
-
34
- def initialize(port = nil, baud = nil)
35
- @baud = nil
36
- @port = nil
37
- @printer = nil # Serial instance connected to the printer, nil when disconnected
38
- @clear = 0 # clear to send, enabled after responses
39
- @online = false # The printer has responded to the initial command and is active
40
- @printing = false # is a print currently running, true if printing, false if paused
41
- @main_queue = []
42
- @priority_queue = []
43
- @queue_index = 0
44
- @line_number = 0
45
- @resend_from = -1
46
- @paused = false
47
- @sent_lines = []
48
- @log = []
49
- @sent = []
50
- @loud = false # emit sent and received lines to terminal
51
- @greetings = ['start','Grbl ']
52
- @wait = 0 # default wait period for send(), send_now()
53
- @read_thread = nil
54
- @stop_read_thread = false
55
- @print_thread = nil
56
- @good_response = 'ok'
57
- @resend_response = ['rs','resend']
58
- @sleep_time = 0.001
59
- @encoding = 'us-ascii'
60
- connect(port, baud) if port.present? && baud.present?
61
- end
62
-
63
- def disconnect
64
- if @printer
65
- if @read_thread
66
- @stop_read_thread = true
67
- @read_thread.join
68
- @read_thread = nil
69
- end
70
- @printer.close
71
- end
72
- @printer = nil
73
- @online = false
74
- @printing = false
75
- end
76
-
77
- def connect(port = nil, baud = nil)
78
- disconnect if @printer
79
- @port = port if port.present?
80
- @baud = baud if baud.present?
81
- @port = self.port if self.port.present?
82
- @baud = self.baud if self.baud.present?
83
- if @port.present? && @baud.present?
84
- disable_hup(@port)
85
- @printer = SerialPort.new(@port, @baud)
86
- @printer.read_timeout = 0
87
- @stop_read_thread = false
88
- @read_thread = Thread.new(_listen)
89
- eval(connect_callback) if connect_callback.present?
90
- end
91
- end
92
-
93
- def reset
94
- @printer.dtr = 0
95
- sleep 0.2
96
- @printer.dtr = 1
97
- end
98
-
99
- def _readline
100
- begin
101
- line = @printer.readline
102
- if line.length > 1
103
- @log.push line
104
- eval(receive_callback+'(line)') if receive_callback.present?
105
- end
106
- line # return the line
107
- rescue EOFError, Errno::ENODEV => e
108
- # TODO: Do something useful
109
- end
110
- end
111
-
112
- def _listen_can_continue?
113
- !@stop_read_thread && @printer
114
- end
115
-
116
- def _listen_until_online
117
- catch 'BreakOut' do
118
- while !@online && _listen_can_continue? do
119
- _send(RintCore::GCode::Codes::GET_EXT_TEMP)
120
- empty_lines = 0
121
- while _listen_can_continue? do
122
- line = _readline
123
- throw 'BreakOut' if line.nil?
124
- line.blank? ? empty_lines += 1 : empty_lines = 0
125
- throw 'BreakOut' if empty_lines == 5
126
- if line.start_with?(*@greetings, @good_response)
127
- eval(online_callback) if online_callback.present?
128
- @online = true
129
- return true
130
- end
131
- sleep 0.25
132
- end
133
- end
134
- end
135
- end
136
-
137
- def _listen
138
- @clear = true
139
- _listen_until_online unless @printing
140
- while _listen_can_continue? do
141
- line = _readline
142
- break if line.nil?
143
- eval(debug_callback+'(line)') if line.start_with?('DEBUG_') && debug_callback.present?
144
- @clear = true if line.start_with?(*@greetings, @good_response)
145
- eval(temperature_callback+'(line)') if line.start_with?(@good_response) && line.include?('T:') && temperature_callback.present?
146
- eval(error_callback+'(line)') if line.start_with?('Error') && error_callback.present?
147
- if line.downcase.start_with?(*@resend_response)
148
- line = line.sub('N:', ' ').sub('N', ' ').sub(':', ' ')
149
- linewords = line.split
150
- @resend_from = linewords.pop(0).to_i
151
- @clear = true
152
- end
153
- end
154
- @clear = true
155
- end
156
-
157
- def _checksum(command)
158
- command.bytes.inject{|a,b| a^b}.to_s
159
- end
160
-
161
- def start_print(data, start_index = 0)
162
- return false if @printing || !@online || !@printer
163
- @printing = true
164
- @main_queue = [] + data
165
- @line_number = 0
166
- @queue_index = start_index
167
- @resend_from = -1
168
- _send(RintCore::GCode::Codes::SET_LINE_NUM, -1, true)
169
- return true if data.blank?
170
- @clear = false
171
- @print_thread = Thread.new(_print)
172
- return true
173
- end
174
-
175
- def pause
176
- return false unless @printing
177
- @paused = true
178
- @printing = false
179
- @print_thread.join
180
- @print_thread = nil
181
- end
182
-
183
- def resume
184
- return false unless @paused
185
- @paused = false
186
- @printing = true
187
- @print_thread = Thread.new(_print)
188
- end
189
-
190
- def send(command, wait = 0)
191
- if @online
192
- if @printing
193
- @main_queue.push(command)
194
- else
195
- while @printer && @printing && !@clear do
196
- sleep(@sleep_time)
197
- end
198
- wait = @wait if wait == 0 && @wait > 0
199
- @clear = false if wait > 0
200
- _send(command, @line_number, true)
201
- @line_number += 1
202
- while wait > 0 && @printer && @printing && !@clear do
203
- sleep @sleep_time
204
- wait -= 1
205
- end
206
- end
207
- else
208
- # TODO: log something about not being connected to printer
209
- end
210
- end
211
-
212
- def send_now(command, wait = 0)
213
- if @online
214
- if @printing
215
- @priority_queue.append(command)
216
- else
217
- while @printer && @printing && !@clear do
218
- sleep(@sleep_time)
219
- end
220
- wait = @wait if wait == 0 && @wait > 0
221
- @clear = false if wait > 0
222
- _send(command)
223
- while wait > 0 && @printer && @printing && !@clear do
224
- sleep @sleep_time
225
- wait -= 1
226
- end
227
- end
228
- else
229
- # TODO: log something about not being connected to printer
230
- end
231
- end
232
-
233
- def _print
234
- eval(start_callback) if start_callback.present?
235
- while @printing && @printer && @online do
236
- _send_next
237
- end
238
- @sent_lines = []
239
- @log = []
240
- @sent = []
241
- @print_thread.join
242
- @print_thread = nil
243
- eval(end_callback) if end_callback.present?
244
- return true
245
- end
246
-
247
- def _send_next
248
- return false unless @printer
249
- while @printer && @printing && !@clear do
250
- sleep(@sleep_time)
251
- end
252
- @clear = false
253
- unless @printing && @printer && @online
254
- @clear = true
255
- return true
256
- end
257
- if @resendfrom < @lineno && @resendfrom > -1
258
- _send(@sent_lines[@resend_from], @resend_from, false)
259
- @resend_from += 1
260
- return true
261
- end
262
- @resend_from = -1
263
- unless @priority_queue.blank?
264
- _send(@priority_queue.pop(0))
265
- return true
266
- end
267
- if @printing && @queue_index < @main_queue.length
268
- current_line = @main_queue[@queue_index]
269
- current_line = current_line.split(RintCore::GCode::Codes::COMMENT_SYMBOL)[0]
270
- unless current_line.blank?
271
- _send(current_line, @line_number, true)
272
- @line_number += 1
273
- else
274
- @clear = true
275
- end
276
- @queue_index += 1
277
- else
278
- @printing = false
279
- @clear = true
280
- unless @paused
281
- @queue_index = 0
282
- @line_number = 0
283
- _send(RintCore::GCode::Codes::SET_LINE_NUM, -1, true)
284
- end
285
- end
286
- end
287
-
288
- def _send(command, line_number = 0, calc_checksum = false)
289
- if calc_checksum
290
- prefix = 'N' + line_number.to_s + ' ' + command
291
- command = prefix + '*' + _checksum(prefix)
292
- @sent_lines[line_number] = command unless command.include?(RintCore::GCode::Codes::SET_LINE_NUM)
293
- end
294
- if @printer
295
- @sent.push(command)
296
- eval(send_callback+'(command)') if send_callback.present?
297
- command = command+"\n"
298
- command = command.encode(@encoding)
299
- @printer.write(command)
300
- end
301
- end
302
-
303
- def online?
304
- @online
305
- end
306
-
307
- def printing?
308
- @printing
309
- end
310
-
311
- end
312
- end