Skip to content

Commit 8a00010

Browse files
committed
first commit
0 parents  commit 8a00010

File tree

5 files changed

+162
-0
lines changed

5 files changed

+162
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store

doc/vim-arduino.txt

Whitespace-only changes.

plugin/vim-arduino

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/sh
2+
#/ Usage: vim-arduino [-dc]
3+
#/ Invokes the ino command that corresponds to the given flag ( (d)eploy or (c)ompile )
4+
#/
5+
6+
# show usage
7+
[ $# -eq 0 -o "$1" = "--help" ] && {
8+
grep '^#/'< "$0" | cut -c4-
9+
exit 2
10+
}
11+
12+
command=""
13+
correct_dir_structure=false
14+
port_available=false
15+
16+
17+
if [ -z $(ls /dev/tty.* | grep usb) ]
18+
then
19+
echo "can't find serial port"
20+
exit 1
21+
fi
22+
23+
while [ $(basename `pwd`) != '/' ]
24+
do
25+
if [ $(basename `pwd`) == 'src' ] || [ $(basename `pwd`) == 'lib' ]
26+
then
27+
correct_dir_structure=true
28+
cd ..
29+
break
30+
elif [ $(ls | egrep "lib|src" | wc -l) -eq 2 ]
31+
then
32+
correct_dir_structure=true
33+
break
34+
fi
35+
36+
cd ..
37+
done
38+
39+
echo "correct_dir_structure" . $correct_dir_structure
40+
if ! $correct_dir_structure
41+
then
42+
exit 1
43+
fi
44+
45+
while [ $# -gt 0 ]
46+
do
47+
case "$1" in
48+
-d|--deploy)
49+
command="ino build && ino upload"
50+
shift
51+
;;
52+
-c|--compile)
53+
command="ino build"
54+
shift
55+
;;
56+
esac
57+
done
58+
59+
if [ "$command" != "" ]
60+
then
61+
eval $command
62+
else
63+
exit 1
64+
fi
65+

plugin/vim-arduino-serial

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
3+
echo "use Ctrl-a, k to exit the screen utility"
4+
5+
port=$(ls /dev/tty.* | grep usb)
6+
7+
osascript -e \
8+
"tell application \"iTerm\"
9+
activate
10+
set myterm to (make new terminal)
11+
tell myterm
12+
launch session \"Default\"
13+
set _session to current session
14+
tell _session
15+
write text \"screen $port\"
16+
end tell
17+
end tell
18+
end tell"

plugin/vim-arduino.vim

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
let s:vim_arduino_version = '0.1.0'
2+
3+
" Load Once: {{{1
4+
if exists("loaded_vim_arduino")
5+
finish
6+
endif
7+
let loaded_vim_arduino = 1
8+
9+
if !exists('g:vim_arduino_auto_open_serial')
10+
let g:vim_arduino_auto_open_serial = 0
11+
endif
12+
13+
let s:helper_dir = expand("<sfile>:h")
14+
15+
function! s:PrintStatus(result)
16+
if a:result == 0
17+
echohl Statement | echomsg "Succeeded." | echohl None
18+
else
19+
echohl WarningMsg | echomsg "Failed." | echohl None
20+
endif
21+
endfunction
22+
23+
" Private: Compile or deploy code
24+
"
25+
" Returns nothing.
26+
function! s:InvokeArduinoCli(deploy)
27+
let l:flag = a:deploy ? "-d" : "-c"
28+
let l:f_name = expand('%:p')
29+
execute "w"
30+
if a:deploy
31+
echomsg "Compiling and deploying..." l:f_name
32+
else
33+
echomsg "Compiling..." l:f_name
34+
endif
35+
36+
let l:command = s:helper_dir . "/vim-arduino " . l:flag
37+
let l:result = system(l:command)
38+
call s:PrintStatus(v:shell_error)
39+
echo l:result
40+
call s:PrintStatus(v:shell_error)
41+
endfunction
42+
43+
" Public: Compile the current pde file.
44+
"
45+
" Returns nothing.
46+
function! ArduinoCompile()
47+
call s:InvokeArduinoCli(0)
48+
endfunction
49+
50+
" Public: Compile and Deploy the current pde file.
51+
"
52+
" Returns nothing.
53+
function! ArduinoDeploy()
54+
call s:InvokeArduinoCli(1)
55+
56+
" optionally auto open a serial port
57+
if g:vim_arduino_auto_open_serial
58+
call ArduinoSerialMonitor()
59+
endif
60+
endfunction
61+
62+
" Public: Monitor a serial port
63+
"
64+
" Returns nothing.
65+
function! ArduinoSerialMonitor()
66+
call ArduinoDeploy()
67+
echo system(s:helper_dir."/vim-arduino-serial")
68+
endfunction
69+
70+
if !exists('g:vim_arduino_map_keys')
71+
let g:vim_arduino_map_keys = 1
72+
endif
73+
74+
if g:vim_arduino_map_keys
75+
nnoremap <leader>ac :call ArduinoCompile()<CR>
76+
nnoremap <leader>ad :call ArduinoDeploy()<CR>
77+
nnoremap <leader>as :call ArduinoSerialMonitor()<CR>
78+
endif

0 commit comments

Comments
 (0)