-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy patharduino.vim
789 lines (723 loc) · 21.8 KB
/
arduino.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
if (exists('g:loaded_arduino_autoload') && g:loaded_arduino_autoload)
finish
endif
let g:loaded_arduino_autoload = 1
let s:has_cli = executable('arduino-cli') == 1
if has('win64') || has('win32') || has('win16')
let s:OS = 'Windows'
else
let s:OS = substitute(system('uname'), '\n', '', '')
endif
let s:HERE = resolve(expand('<sfile>:p:h:h'))
" In neovim, run the shell commands using :terminal to preserve interactivity
if has('nvim')
let s:TERM = 'botright split | terminal! '
elseif has('terminal')
" In vim, doing terminal! will automatically open in a new split
let s:TERM = 'terminal! '
else
" Backwards compatible with old versions of vim
let s:TERM = '!'
endif
let s:hardware_dirs = {}
let s:SKETCHFILE = v:null
" Initialization {{{1
" Set up all user configuration variables
function! arduino#InitializeConfig() abort
if !exists('g:arduino_board')
if exists('g:_cache_arduino_board')
let g:arduino_board = g:_cache_arduino_board
else
let g:arduino_board = 'arduino:avr:uno'
endif
endif
if !exists('g:arduino_programmer')
if exists('g:_cache_arduino_programmer')
let g:arduino_programmer = g:_cache_arduino_programmer
else
let g:arduino_programmer = ''
endif
endif
if !exists('g:arduino_args')
let g:arduino_args = '--verbose-upload'
endif
if !exists('g:arduino_cli_args')
let g:arduino_cli_args = '-v'
endif
if !exists('g:arduino_serial_cmd')
let g:arduino_serial_cmd = 'screen {port} {baud}'
endif
if !exists('g:arduino_build_path')
let g:arduino_build_path = '{project_dir}/build'
endif
if !exists('g:arduino_serial_baud')
let g:arduino_serial_baud = 9600
endif
if !exists('g:arduino_auto_baud')
let g:arduino_auto_baud = 1
endif
if !exists('g:arduino_use_slime')
let g:arduino_use_slime = 0
endif
if !exists('g:arduino_use_vimux') || !exists('$TMUX')
let g:arduino_use_vimux = 0
endif
if !exists('g:arduino_run_headless')
let g:arduino_run_headless = executable('Xvfb') == 1
endif
if !exists('g:arduino_serial_port_globs')
let g:arduino_serial_port_globs = ['/dev/ttyACM*',
\'/dev/ttyUSB*',
\'/dev/tty.usbmodem*',
\'/dev/tty.usbserial*',
\'/dev/tty.wchusbserial*']
endif
if !exists('g:arduino_use_cli')
let g:arduino_use_cli = s:has_cli
if g:arduino_use_cli
let g:arduino_serial_cmd = 'arduino-cli monitor -p {port} --config baudrate={baud}'
endif
elseif g:arduino_use_cli && !s:has_cli
echoerr 'arduino-cli: command not found'
endif
call arduino#ReloadBoards()
call s:ReadSketchJson(expand('%:p:h'))
aug ArduinoReadSketch
au!
au BufReadPost *.ino call s:ReadSketchJson(expand('<amatch>:p:h'))
aug END
endfunction
function! arduino#RunCmd(cmd) abort
if g:arduino_use_slime
call slime#send(a:cmd . "\r")
elseif g:arduino_use_vimux
call VimuxRunCommand(a:cmd)
else
exe s:TERM . a:cmd
endif
endfunction
" Boards and programmer definitions {{{1
function! arduino#ReloadBoards() abort
" TODO in the future if we're using arduino-cli we shouldn't have to do this,
" but at the moment I'm having issues where `arduino-cli board details
" adafruit:avr:gemma --list-programmers` is empty
" First let's search the arduino system install for boards
" The path looks like /hardware/<package>/<arch>/boards.txt
let arduino_dir = arduino#GetArduinoDir()
let filenames = split(globpath(arduino_dir . '/hardware', '**/boards.txt'), '\n')
for filename in filenames
let pieces = split(filename, '/')
let package = pieces[-3]
let arch = pieces[-2]
call arduino#AddHardwareDir(package, arch, filename)
endfor
" Now search any packages installed in the home dir
" The path looks like /packages/<package>/hardware/<arch>/<version>/boards.txt
let arduino_home_dir = arduino#GetArduinoHomeDir()
let packagedirs = split(globpath(arduino_home_dir . '/packages', '*'), '\n')
for packagedir in packagedirs
let package = fnamemodify(packagedir, ':t')
let archdirs = split(globpath(packagedir . '/hardware', '*'), '\n')
for archdir in archdirs
let arch = fnamemodify(archdir, ':t')
let filenames = split(globpath(archdir, '**/boards.txt'), '\n')
for filename in filenames
call arduino#AddHardwareDir(package, arch, filename)
endfor
endfor
endfor
" Some platforms put the default arduino boards/programmers in /etc/arduino
if filereadable('/etc/arduino/boards.txt')
call arduino#AddHardwareDir('arduino', 'avr', '/etc/arduino')
endif
if empty(s:hardware_dirs)
echoerr 'Could not find any boards.txt or programmers.txt files. Please set g:arduino_dir and/or g:arduino_home_dir (see help for details)'
endif
endfunction
function! arduino#AddHardwareDir(package, arch, file) abort
" If a boards.txt file was passed in, get the parent dir
if !isdirectory(a:file)
let filepath = fnamemodify(a:file, ':h')
else
let filepath = a:file
endif
if !isdirectory(filepath)
echoerr 'Could not find hardware directory or file '. a:file
return
endif
let s:hardware_dirs[filepath] = {
\ 'package': a:package,
\ 'arch': a:arch,
\}
endfunction
" Caching {{{1
" Load the saved defaults
function! arduino#LoadCache() abort
let s:cache_dir = exists('$XDG_CACHE_HOME') ? $XDG_CACHE_HOME : $HOME . '/.cache'
let s:cache = s:cache_dir . '/arduino_cache.vim'
if filereadable(s:cache)
exec 'source ' . s:cache
endif
endfunction
" Save settings to a source-able cache file
function! arduino#SaveCache() abort
if !isdirectory(s:cache_dir)
call mkdir(s:cache_dir, 'p')
endif
let lines = []
call s:CacheLine(lines, 'g:_cache_arduino_board')
call s:CacheLine(lines, 'g:_cache_arduino_programmer')
call writefile(lines, s:cache)
endfunction
" Arduino command helpers {{{1
function! arduino#GetArduinoExecutable() abort
if exists('g:arduino_cmd')
return g:arduino_cmd
elseif s:OS ==? 'Darwin'
return '/Applications/Arduino.app/Contents/MacOS/Arduino'
else
return 'arduino'
endif
endfunction
function! arduino#GetBuildPath() abort
if empty(g:arduino_build_path)
return ''
endif
let l:path = g:arduino_build_path
let l:path = substitute(l:path, '{file}', substitute(expand('%:p'), '\', '/', 'g'), 'g')
let l:path = substitute(l:path, '{project_dir}', substitute(expand('%:p:h'), '\', '/', 'g'), 'g')
return l:path
endfunction
function! arduino#GetCLICompileCommand(...) abort
let cmd = 'arduino-cli compile'
if s:SKETCHFILE == v:null
let cmd = cmd . ' -b ' . g:arduino_board
let port = arduino#GetPort()
if !empty(port)
let cmd = cmd . ' -p ' . port
endif
endif
if !empty(g:arduino_programmer)
let cmd = cmd . ' -P ' . g:arduino_programmer
endif
let l:build_path = arduino#GetBuildPath()
if !empty(l:build_path)
let cmd = cmd . ' --build-path "' . l:build_path . '"'
endif
if a:0
let cmd = cmd . ' ' . a:1
endif
return cmd . ' ' . g:arduino_cli_args . ' "' . expand('%:p') . '"'
endfunction
function! arduino#GetArduinoCommand(cmd) abort
let arduino = arduino#GetArduinoExecutable()
if g:arduino_run_headless
let arduino = s:HERE . '/bin/run-headless ' . arduino
endif
let cmd = arduino . ' ' . a:cmd . ' --board ' . g:arduino_board
let port = arduino#GetPort()
if !empty(port)
let cmd = cmd . ' --port ' . port
endif
if !empty(g:arduino_programmer)
let cmd = cmd . ' --pref programmer=' . g:arduino_programmer
endif
let l:build_path = arduino#GetBuildPath()
if !empty(l:build_path)
let cmd = cmd . ' --pref ' . '"build.path=' . l:build_path . '"'
endif
let cmd = cmd . ' ' . g:arduino_args . ' "' . expand('%:p') . '"'
return cmd
endfunction
function! arduino#GetBoards() abort
let boards = []
if g:arduino_use_cli
let boards_data = json_decode(system('arduino-cli board listall --format json'))
for board in boards_data['boards']
call add(boards, {
\ 'label': board['name'],
\ 'value': board['fqbn']
\ })
endfor
else
let seen = {}
for [dir,meta] in items(s:hardware_dirs)
if !isdirectory(dir)
continue
endif
let filename = dir . '/boards.txt'
if !filereadable(filename)
continue
endif
let lines = readfile(filename)
for line in lines
if line =~? '^[^.]*\.name=.*$'
let linesplit = split(line, '\.')
let board = linesplit[0]
let linesplit = split(line, '=')
let name = linesplit[1]
let board = meta.package . ':' . meta.arch . ':' . board
if !has_key(seen, board)
let seen[board] = 1
call add(boards, {
\ 'label': name,
\ 'value': board
\ })
endif
endif
endfor
unlet dir meta
endfor
endif
call sort(boards, 's:ChooserItemOrder')
return boards
endfunction
function! arduino#GetBoardOptions(board) abort
if g:arduino_use_cli
let ret = []
let data = json_decode(system('arduino-cli board details -b ' . a:board . ' --format json'))
if !has_key(data, 'config_options')
return ret
endif
let opts = data['config_options']
for opt in opts
let values = []
for entry in opt['values']
call add(values, {
\ 'label': entry['value_label'],
\ 'value': entry['value']
\ })
endfor
call add(ret, {
\ 'option': opt['option'],
\ 'option_label': opt['option_label'],
\ 'values': values
\ })
endfor
return ret
endif
" Board will be in the format package:arch:board
let [package, arch, boardname] = split(a:board, ':')
" Find all boards.txt files with that package/arch
let boardfiles = []
for [dir,meta] in items(s:hardware_dirs)
if meta.package == package && meta.arch == arch
call add(boardfiles, dir.'/boards.txt')
endif
unlet dir meta
endfor
" Find the boards.txt file with the board definition and read the options
for filename in boardfiles
if !filereadable(filename)
continue
endif
let lines = readfile(filename)
let pattern = '^' . boardname . '\.menu\.\([^.]*\)\.\([^.]*\)='
let options = {}
let matched = 0
for line in lines
if line =~? pattern
let matched = 1
let groups = matchlist(line, pattern)
let option = groups[1]
let value = groups[2]
if !has_key(options, option)
let options[option] = []
endif
let optlist = get(options, option)
call add(optlist, value)
endif
endfor
if matched
let ret = []
for value in keys(options)
call add(ret, {
\ 'option': value,
\ 'option_label': value,
\ 'values': options[value]
\ })
endfor
return ret
endif
endfor
return []
endfunction
function! arduino#GetProgrammers() abort
let programmers = [{
\ 'label': '-None-',
\ 'value': '',
\}]
if g:arduino_use_cli
let data = json_decode(system('arduino-cli board details -b ' . g:arduino_board . ' --list-programmers --format json'))
if has_key(data, 'programmers')
for entry in data['programmers']
call add(programmers, {
\ 'label': entry['name'],
\ 'value': entry['id'],
\ })
endfor
" I'm running into some issues with 3rd party boards (e.g. adafruit:avr:gemma) where the programmer list is empty. If so, fall back to the hardware directory method
if !empty(programmers)
return sort(programmers, 's:ChooserItemOrder')
endif
endif
endif
let seen = {}
for [dir,meta] in items(s:hardware_dirs)
if !isdirectory(dir)
continue
endif
let filename = dir . '/programmers.txt'
if !filereadable(filename)
continue
endif
let lines = readfile(filename)
for line in lines
if line =~? '^[^.]*\.name=.*$'
let linesplit = split(line, '\.')
let programmer = linesplit[0]
let linesplit = split(line, '=')
let name = linesplit[1]
let prog = meta.package . ':' . programmer
if !has_key(seen, prog)
let seen[prog] = 1
call add(programmers, {
\ 'label': name,
\ 'value': prog
\ })
endif
endif
endfor
endfor
return sort(programmers)
endfunction
function! arduino#RebuildMakePrg() abort
if g:arduino_use_cli
let &l:makeprg = arduino#GetCLICompileCommand()
else
let &l:makeprg = arduino#GetArduinoCommand('--verify')
endif
endfunction
function! s:ChooserItemOrder(i1, i2) abort
let l1 = has_key(a:i1, 'label') ? a:i1['label'] : a:i1['value']
let l2 = has_key(a:i2, 'label') ? a:i2['label'] : a:i2['value']
return l1 == l2 ? 0 : l1 > l2 ? 1 : -1
endfunction
function! arduino#Attach(...) abort
if !s:has_cli
echoerr 'ArduinoAttach requires arduino-cli'
return
end
let port = v:null
if a:0
let port = a:1
let dir = expand('%:p:h')
function PostAttach() closure
call s:ReadSketchJson(dir)
call s:notify('Arduino attached to board ' . g:arduino_board)
endfunction
call arduino#job#run(['arduino-cli', 'board', 'attach', '-p', port], funcref('PostAttach'))
else
let ports = arduino#GetPorts()
if empty(ports)
echoerr 'No likely serial ports detected!'
elseif len(ports) == 1
call arduino#Attach(ports[0])
else
call arduino#chooser#Choose('Select Port', ports, 'arduino#Attach')
endif
endif
endfunction
" Port selection {{{2
function! arduino#ChoosePort(...) abort
if a:0
let g:arduino_serial_port = a:1
return
endif
let ports = arduino#GetPorts()
if empty(ports)
echoerr 'No likely serial ports detected!'
else
call arduino#chooser#Choose('Select Port', ports, 'arduino#SelectPort')
endif
endfunction
function! arduino#SelectPort(port) abort
let g:arduino_serial_port = a:port
call s:WriteSketchKey('port', 'serial://' . g:arduino_serial_port)
endfunction
" Board selection {{{2
let s:callback_data = {}
" Display a list of boards to the user and allow them to choose the active one
function! arduino#ChooseBoard(...) abort
if a:0
call arduino#SetBoard(a:1)
return
endif
let boards = arduino#GetBoards()
call arduino#chooser#Choose('Select Board', boards, 'arduino#SelectBoard')
endfunction
" Callback from board selection. Sets the board and prompts for any options
function! arduino#SelectBoard(board) abort
let options = arduino#GetBoardOptions(a:board)
call arduino#SetBoard(a:board)
let s:callback_data = {
\ 'board': a:board,
\ 'available_opts': options,
\ 'opts': {},
\ 'active_option': '',
\}
" Have to delay this to give the previous chooser UI time to clear
call timer_start(10, {tid -> arduino#ChooseBoardOption()})
if empty(options)
call s:WriteSketchKey('fqbn', g:arduino_board)
endif
endfunction
" Prompt user for the next unselected board option
function! arduino#ChooseBoardOption() abort
let available_opts = s:callback_data.available_opts
for opt in available_opts
if !has_key(s:callback_data.opts, opt.option)
let s:callback_data.active_option = opt.option
call arduino#chooser#Choose(opt.option_label, opt.values, 'arduino#SelectOption')
return v:true
endif
endfor
return v:false
endfunction
" Callback from option selection
function! arduino#SelectOption(value) abort
let opt = s:callback_data.active_option
let s:callback_data.opts[opt] = a:value
call arduino#SetBoard(s:callback_data.board, s:callback_data.opts)
let choosing = arduino#ChooseBoardOption()
if !choosing
call s:WriteSketchKey('fqbn', g:arduino_board)
endif
endfunction
" Programmer selection {{{2
function! arduino#ChooseProgrammer(...) abort
if a:0
call arduino#SetProgrammer(a:1)
return
endif
let programmers = arduino#GetProgrammers()
call arduino#chooser#Choose('Select Programmer', programmers, 'arduino#SetProgrammer')
endfunction
function! arduino#SetProgrammer(programmer) abort
let g:_cache_arduino_programmer = a:programmer
let g:arduino_programmer = a:programmer
call arduino#RebuildMakePrg()
call arduino#SaveCache()
endfunction
" Command functions {{{2
" Set the active board
function! arduino#SetBoard(board, ...) abort
let board = a:board
if a:0
let options = a:1
let prevchar = ':'
for key in keys(options)
let board = board . prevchar . key . '=' . options[key]
let prevchar = ','
endfor
endif
let g:arduino_board = board
let g:_cache_arduino_board = board
call arduino#RebuildMakePrg()
call arduino#SaveCache()
endfunction
function! arduino#Verify() abort
if g:arduino_use_cli
let cmd = arduino#GetCLICompileCommand()
else
let cmd = arduino#GetArduinoCommand('--verify')
endif
call arduino#RunCmd(cmd)
return v:shell_error
endfunction
function! arduino#Upload() abort
let cmd = arduino#UploadGetCmd()
call arduino#RunCmd(cmd)
return v:shell_error
endfunction
function! arduino#UploadGetCmd() abort
if g:arduino_use_cli
let cmd = arduino#GetCLICompileCommand('-u')
else
if empty(g:arduino_programmer)
let cmd_options = '--upload'
else
let cmd_options = '--upload --useprogrammer'
endif
let cmd = arduino#GetArduinoCommand(cmd_options)
endif
return cmd
endfunction
function! arduino#Serial() abort
let cmd = arduino#GetSerialCmd()
if empty(cmd) | return | endif
call arduino#RunCmd(cmd)
endfunction
function! arduino#UploadAndSerial()
let upload = arduino#UploadGetCmd()
let serial = arduino#GetSerialCmd()
if empty(serial) | return | endif
call arduino#RunCmd(upload . " && " . serial)
endfunction
" Serial helpers {{{2
function! arduino#GetSerialCmd() abort
let port = arduino#GetPort()
if empty(port)
echoerr 'Error! No serial port found'
return ''
endif
let l:cmd = substitute(g:arduino_serial_cmd, '{port}', port, 'g')
let l:cmd = substitute(l:cmd, '{baud}', g:arduino_serial_baud, 'g')
return l:cmd
endfunction
function! arduino#SetBaud(baud) abort
let g:arduino_serial_baud = a:baud
endfunction
function! arduino#SetAutoBaud() abort
let n = 1
while n < line('$')
let match = matchlist(getline(n), 'Serial[0-9]*\.begin(\([0-9]*\)')
if len(match) >= 2
let g:arduino_serial_baud = match[1]
return
endif
let n = n + 1
endwhile
endfunction
function! arduino#GetPorts() abort
let ports = []
for l:glob in g:arduino_serial_port_globs
let found = glob(l:glob, 1, 1)
for port in found
call add(ports, port)
endfor
endfor
if s:OS ==? 'Windows'
let boards_data = json_decode(system('arduino-cli board list --format json'))
for board in boards_data
call add(ports, board['port']['address'])
endfor
endif
return ports
endfunction
function! arduino#GuessSerialPort() abort
let ports = arduino#GetPorts()
if empty(ports)
return 0
else
return ports[0]
endif
endfunction
function! arduino#GetPort() abort
if exists('g:arduino_serial_port')
return g:arduino_serial_port
else
return arduino#GuessSerialPort()
endif
endfunction
"}}}2
" Utility functions {{{1
function! s:ReadSketchJson(dir) abort
let dir = a:dir
while v:true
let sketch = dir . '/sketch.json'
if filereadable(sketch)
let data = json_decode(join(readfile(sketch)))
let cpu = get(data, 'cpu', {})
if !empty(cpu)
let s:SKETCHFILE = sketch
let board = get(cpu, 'fqbn', '')
if !empty(board)
let g:arduino_board = board
endif
let port = get(cpu, 'port', '')
if !empty(port)
if port =~? '^serial://'
let port = strcharpart(port, 9)
endif
let g:arduino_serial_port = port
endif
endif
return
endif
let next_dir = fnamemodify(dir, ':h')
if next_dir == dir
break
else
let dir = next_dir
endif
endwhile
let s:SKETCHFILE = v:null
endfunction
function s:WriteSketchKey(key, value) abort
if s:SKETCHFILE == v:null
return
endif
let data = json_decode(join(readfile(s:SKETCHFILE)))
let cpu = get(data, 'cpu', {})
let cpu[a:key] = a:value
call writefile([json_encode(data)], s:SKETCHFILE)
endfunction
function! s:CacheLine(lines, varname) abort
if exists(a:varname)
let value = eval(a:varname)
call add(a:lines, 'let ' . a:varname . ' = "' . value . '"')
endif
endfunction
function! arduino#GetArduinoDir() abort
if exists('g:arduino_dir')
return g:arduino_dir
endif
let executable = arduino#GetArduinoExecutable()
let arduino_cmd = exepath(executable)
let arduino_dir = fnamemodify(arduino_cmd, ':h')
if s:OS ==? 'Darwin'
let arduino_dir = fnamemodify(arduino_dir, ':h') . '/Java'
endif
return arduino_dir
endfunction
function! arduino#GetArduinoHomeDir() abort
if exists('g:arduino_home_dir')
return g:arduino_home_dir
endif
if s:OS ==? 'Darwin'
return $HOME . '/Library/Arduino15'
elseif s:OS ==? 'Windows'
return $HOME . '/AppData/Local/Arduino15'
endif
return $HOME . '/.arduino15'
endfunction
" Print the current configuration
function! arduino#GetInfo() abort
let port = arduino#GetPort()
if empty(port)
let port = 'none'
endif
let dirs = join(keys(s:hardware_dirs), ', ')
if empty(dirs)
let dirs = 'None'
endif
echo 'Board : ' . g:arduino_board
echo 'Programmer : ' . g:arduino_programmer
echo 'Port : ' . port
echo 'Baud rate : ' . g:arduino_serial_baud
echo 'Hardware dirs : ' . dirs
if g:arduino_use_cli
echo 'Verify command: ' . arduino#GetCLICompileCommand()
else
echo 'Verify command: ' . arduino#GetArduinoCommand('--verify')
endif
endfunction
function! s:notify(msg) abort
if has('nvim')
call luaeval('vim.notify(_A)', a:msg)
else
echo a:msg
endif
endfunction
" vim:fen:fdm=marker:fmr={{{,}}}