@@ -9,19 +9,28 @@ class ArduinoCmd
9
9
# @param name [String] What the flag will be called (prefixed with 'flag_')
10
10
# @return [void]
11
11
# @macro [attach] flag
12
+ # The text of the command line flag for $1
12
13
# @!attribute [r] flag_$1
13
- # @return String $2 the text of the command line flag
14
+ # @return [ String] the text of the command line flag (`$2` in this case)
14
15
def self . flag ( name , text = nil )
15
16
text = "(flag #{ name } not defined)" if text . nil?
16
17
self . class_eval ( "def flag_#{ name } ;\" #{ text } \" ;end" )
17
18
end
18
19
19
- attr_accessor :installation
20
+ # the path to the Arduino executable
21
+ # @return [String]
20
22
attr_accessor :base_cmd
21
23
24
+ # part of a workaround for https://github.com/arduino/Arduino/issues/3535
22
25
attr_reader :library_is_indexed
26
+
27
+ # @return [String] STDOUT of the most recently-run command
23
28
attr_reader :last_out
29
+
30
+ # @return [String] STDERR of the most recently-run command
24
31
attr_reader :last_err
32
+
33
+ # @return [String] the most recently-run command
25
34
attr_reader :last_msg
26
35
27
36
# set the command line flags (undefined for now).
@@ -43,6 +52,9 @@ def initialize
43
52
@last_msg = ""
44
53
end
45
54
55
+ # Convert a preferences dump into a flat hash
56
+ # @param arduino_output [String] The raw Arduino executable output
57
+ # @return [Hash] preferences as a hash
46
58
def parse_pref_string ( arduino_output )
47
59
lines = arduino_output . split ( "\n " ) . select { |l | l . include? "=" }
48
60
ret = lines . each_with_object ( { } ) do |e , acc |
@@ -53,17 +65,21 @@ def parse_pref_string(arduino_output)
53
65
ret
54
66
end
55
67
68
+ # @return [String] the path to the Arduino libraries directory
56
69
def _lib_dir
57
70
"<lib dir not defined>"
58
71
end
59
72
60
- # fetch preferences to a string
73
+ # fetch preferences in their raw form
74
+ # @return [String] Preferences as a set of lines
61
75
def _prefs_raw
62
76
resp = run_and_capture ( flag_get_pref )
63
77
return nil unless resp [ :success ]
64
78
resp [ :out ]
65
79
end
66
80
81
+ # Get the Arduino preferences, from cache if possible
82
+ # @return [Hash] The full set of preferences
67
83
def prefs
68
84
prefs_raw = _prefs_raw unless @prefs_fetched
69
85
return nil if prefs_raw . nil?
@@ -72,12 +88,16 @@ def prefs
72
88
end
73
89
74
90
# get a preference key
91
+ # @param key [String] The preferences key to look up
92
+ # @return [String] The preference value
75
93
def get_pref ( key )
76
94
data = @prefs_fetched ? @prefs_cache : prefs
77
95
data [ key ]
78
96
end
79
97
80
98
# underlying preference-setter.
99
+ # @param key [String] The preference name
100
+ # @param value [String] The value to set to
81
101
# @return [bool] whether the command succeeded
82
102
def _set_pref ( key , value )
83
103
run_and_capture ( flag_set_pref , "#{ key } =#{ value } " , flag_save_prefs ) [ :success ]
@@ -141,6 +161,8 @@ def run_wrap(*args, **kwargs)
141
161
# check whether a board is installed
142
162
# we do this by just selecting a board.
143
163
# the arduino binary will error if unrecognized and do a successful no-op if it's installed
164
+ # @param boardname [String] The board to test
165
+ # @return [bool] Whether the board is installed
144
166
def board_installed? ( boardname )
145
167
run_and_capture ( flag_use_board , boardname ) [ :success ]
146
168
end
@@ -176,23 +198,30 @@ def install_library(library_name)
176
198
end
177
199
178
200
# generate the (very likely) path of a library given its name
201
+ # @param library_name [String] The name of the library
202
+ # @return [String] The fully qualified library name
179
203
def library_path ( library_name )
180
204
File . join ( _lib_dir , library_name )
181
205
end
182
206
183
207
# update the library index
208
+ # @return [bool] Whether the update succeeded
184
209
def update_library_index
185
210
# install random lib so the arduino IDE grabs a new library index
186
211
# see: https://github.com/arduino/Arduino/issues/3535
187
212
install_library ( "USBHost" )
188
213
end
189
214
190
215
# use a particular board for compilation
216
+ # @param boardname [String] The board to use
217
+ # @return [bool] whether the command succeeded
191
218
def use_board ( boardname )
192
219
run_and_capture ( flag_use_board , boardname , flag_save_prefs ) [ :success ]
193
220
end
194
221
195
222
# use a particular board for compilation, installing it if necessary
223
+ # @param boardname [String] The board to use
224
+ # @return [bool] whether the command succeeded
196
225
def use_board! ( boardname )
197
226
return true if use_board ( boardname )
198
227
boardfamily = boardname . split ( ":" ) [ 0 ..1 ] . join ( ":" )
@@ -201,6 +230,8 @@ def use_board!(boardname)
201
230
use_board ( boardname )
202
231
end
203
232
233
+ # @param path [String] The sketch to verify
234
+ # @return [bool] whether the command succeeded
204
235
def verify_sketch ( path )
205
236
ext = File . extname path
206
237
unless ext . casecmp ( ".ino" ) . zero?
@@ -217,6 +248,8 @@ def verify_sketch(path)
217
248
218
249
# ensure that the given library is installed, or symlinked as appropriate
219
250
# return the path of the prepared library, or nil
251
+ # @param path [String] library to use
252
+ # @return [String] the path of the installed library
220
253
def install_local_library ( path )
221
254
realpath = File . expand_path ( path )
222
255
library_name = File . basename ( realpath )
@@ -244,6 +277,8 @@ def install_local_library(path)
244
277
destination_path
245
278
end
246
279
280
+ # @param installed_library_path [String] The library to query
281
+ # @return [Array<String>] Example sketch files
247
282
def library_examples ( installed_library_path )
248
283
example_path = File . join ( installed_library_path , "examples" )
249
284
examples = Pathname . new ( example_path ) . children . select ( &:directory? ) . map ( &:to_path ) . map ( &File . method ( :basename ) )
0 commit comments