Skip to content

Commit dbb1115

Browse files
committed
No longer require g:arduino_dir and small tweaks to help docs
1 parent f560dd1 commit dbb1115

File tree

2 files changed

+30
-35
lines changed

2 files changed

+30
-35
lines changed

autoload/arduino.vim

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,18 @@ endfunction
7777
" Boards and programmer definitions {{{1
7878
function! arduino#ReloadBoards() abort
7979
" First let's search the arduino system install for boards
80+
" The path looks like /hardware/<package>/<arch>/boards.txt
8081
let arduino_dir = arduino#GetArduinoDir()
8182
let filenames = split(globpath(arduino_dir . '/hardware', '**/boards.txt'), '\n')
8283
for filename in filenames
8384
let pieces = split(filename, '/')
8485
let package = pieces[-3]
8586
let arch = pieces[-2]
86-
call arduino#AddBoard(package, arch, filename)
87+
call arduino#AddHardwareDir(package, arch, filename)
8788
endfor
8889

8990
" Now search any packages installed in the home dir
91+
" The path looks like /packages/<package>/hardware/<arch>/<version>/boards.txt
9092
let arduino_home_dir = arduino#GetArduinoHomeDir()
9193
let packagedirs = split(globpath(arduino_home_dir . '/packages', '*'), '\n')
9294
for packagedir in packagedirs
@@ -96,25 +98,29 @@ function! arduino#ReloadBoards() abort
9698
let arch = fnamemodify(archdir, ':t')
9799
let filenames = split(globpath(archdir, '**/boards.txt'), '\n')
98100
for filename in filenames
99-
call arduino#AddBoard(package, arch, filename)
101+
call arduino#AddHardwareDir(package, arch, filename)
100102
endfor
101103
endfor
102104
endfor
103105

104106
" Some platforms put the default arduino boards/programmers in /etc/arduino
105107
if filereadable('/etc/arduino/boards.txt')
106-
call arduino#AddBoard('arduino', 'avr', '/etc/arduino')
108+
call arduino#AddHardwareDir('arduino', 'avr', '/etc/arduino')
109+
endif
110+
if empty(s:hardware_dirs)
111+
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)"
107112
endif
108113
endfunction
109114

110-
function! arduino#AddBoard(package, arch, file) abort
111-
if a:file =~? '\.txt$'
115+
function! arduino#AddHardwareDir(package, arch, file) abort
116+
" If a boards.txt file was passed in, get the parent dir
117+
if !isdirectory(a:file)
112118
let filepath = fnamemodify(a:file, ':h')
113119
else
114120
let filepath = a:file
115121
endif
116122
if !isdirectory(filepath)
117-
echoerr 'Could not find hardware directory '. filepath
123+
echoerr 'Could not find hardware directory or file '. a:file
118124
return
119125
endif
120126
let s:hardware_dirs[filepath] = {
@@ -218,8 +224,6 @@ function! arduino#GetBoards() abort
218224
endfunction
219225

220226
function! arduino#GetBoardOptions(board) abort
221-
let arduino_dir = arduino#GetArduinoDir()
222-
let arduino_home_dir = arduino#GetArduinoHomeDir()
223227
" Board will be in the format package:arch:board
224228
let [package, arch, boardname] = split(a:board, ':')
225229

@@ -566,9 +570,6 @@ function! arduino#GetArduinoDir() abort
566570
if s:OS == 'Darwin'
567571
let arduino_dir = fnamemodify(arduino_dir, ':h') . '/Java'
568572
endif
569-
if !isdirectory(arduino_dir . '/hardware/arduino/')
570-
throw "Could not find arduino directory. Please set g:arduino_dir"
571-
endif
572573
return arduino_dir
573574
endfunction
574575

@@ -589,10 +590,15 @@ function! arduino#GetInfo() abort
589590
if empty(port)
590591
let port = "none"
591592
endif
592-
echo "Board: " . g:arduino_board
593-
echo "Programmer: " . g:arduino_programmer
594-
echo "Port: " . port
595-
echo "Baud rate: " . g:arduino_serial_baud
593+
let dirs = join(keys(s:hardware_dirs), ', ')
594+
if empty(dirs)
595+
let dirs = 'None'
596+
endif
597+
echo "Board : " . g:arduino_board
598+
echo "Programmer : " . g:arduino_programmer
599+
echo "Port : " . port
600+
echo "Baud rate : " . g:arduino_serial_baud
601+
echo "Hardware dirs : " . dirs
596602
echo "Verify command: " . arduino#GetArduinoCommand("--verify")
597603
endfunction
598604

doc/arduino.txt

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,15 @@ Applications on Mac. >
4848
<
4949
*'g:arduino_dir'*
5050
The path to your 'arduino' directory. Usually vim-arduino will be able to
51-
detect it, but if it cannot you can set the value manually. >
51+
detect it, but if it cannot you can set the value manually. This is used to
52+
search for the built-in board definitions (i.e. the Uno and Nano) >
5253
let g:arduino_dir = '/usr/share/local/arduino'
5354
<
5455

5556
*'g:arduino_home_dir'*
5657
The path to your user's 'arduino' data directory. Usually vim-arduino will be
57-
able to detect it, but if it cannot you can set the value manually. >
58+
able to detect it, but if it cannot you can set the value manually. This is used
59+
to search for board definitions installed by the IDE Board Manager. >
5860
let g:arduino_home_dir = $HOME . ".arduino15"
5961
<
6062

@@ -162,31 +164,18 @@ COMMANDS *arduino-commands
162164

163165
*:ArduinoVerify*
164166
:ArduinoVerify
165-
Compile your project. You may wish to bind this to a key combination. >
166-
nnoremap <leader>c :ArduinoVerify<CR>
167-
<
168-
You can also call :make directly. >
169-
nnoremap <leader>m :make!<CR>
170-
<
167+
Compile your project. This will also be the default behavior of the |:make|
168+
command.
171169
*:ArduinoUpload*
172170
:ArduinoUpload
173-
Compile and upload your project. You may wish to bind this to a key
174-
combination. >
175-
nnoremap <leader>u :ArduinoUpload<CR>
176-
<
171+
Compile and upload your project.
177172
*:ArduinoSerial*
178173
:ArduinoSerial
179-
Open a connection to the serial port for debugging. You may wish to bind
180-
this to a key combination. >
181-
nnoremap <leader>s :ArduinoSerial<CR>
182-
<
174+
Open a connection to the serial port for debugging.
183175
*:ArduinoUploadAndSerial*
184176
:ArduinoUploadAndSerial
185177
Compile and upload your project. If successful, open a connection to the
186-
serial port for debugging. You may with to bind this to a key combination.
187-
>
188-
nnoremap <leader>d :ArduinoUploadAndSerial<CR>
189-
<
178+
serial port for debugging.
190179
*:ArduinoInfo*
191180
:ArduinoInfo
192181
Display information about the internal state of vim-arduino, including the

0 commit comments

Comments
 (0)