├── .gitignore ├── README.md ├── bin └── setup-dev ├── doc └── vim-arduino.txt └── plugin ├── kill-screen.sh ├── vim-arduino ├── vim-arduino-cli.jar ├── vim-arduino-serial └── vim-arduino.vim /.gitignore: -------------------------------------------------------------------------------- 1 | doc/tags 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Vim Arduino 2 | 3 | This script allows you to compile and deploy Arduino (*.pde) sketches 4 | directly from Vim. I haven't had the time or need to keep this project up to date, but it looks like [jplaut/vim-arduino-ino](https://github.com/jplaut/vim-arduino-ino/) is another good option for similar functionality. 5 | 6 | ## Install 7 | 8 | The plugin should be organized in a manner that works well with 9 | pathogen. I personally use [janus][janus] to manage my MacVim setup so 10 | adding this line to my `~/.janus.rake` file does the trick: 11 | 12 | ``` 13 | vim_plugin_task "vim-arduino", "https://github.com/tclem/vim-arduino.git" 14 | ``` 15 | 16 | ## Usage 17 | 18 | You must have a pde (Arduino sketch) open in the current buffer. 19 | 20 | `ac` - Compile the current sketch. 21 | 22 | `ad` - Compile and deploy the current sketch. 23 | 24 | `as` - Open a serial port in `screen`. 25 | 26 | 27 | The default key mapping can be turned off by doing this in your `.vimrc`: 28 | 29 | ``` 30 | let g:vim_arduino_map_keys = 0 31 | ``` 32 | 33 | ## Configuration 34 | 35 | There are a few settings you might need to set: 36 | 37 | ``` 38 | "Default: /Applications/Arduino.app/Contents/Resources/Java 39 | let g:vim_arduino_library_path = /path/to/arduino/installation 40 | "Default: result of `$(ls /dev/tty.* | grep usb)` 41 | let g:vim_arduino_serial_port = /my/serial/port 42 | ``` 43 | 44 | ## Requirements 45 | 46 | You must have the [Arduino][arduino] IDE installed. Currently only 47 | Version 0022 is supported. 48 | 49 | [arduino]: http://arduino.cc/en/Main/Software 50 | [janus]: https://github.com/carlhuda/janus 51 | -------------------------------------------------------------------------------- /bin/setup-dev: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | #/ Usage: setup-dev 3 | #/ Setup my environment to hack on vim-arduino. 4 | #/ 5 | 6 | repo=$HOME/github/public/vim-arduino/plugin 7 | plugin=$HOME/.vim/bundle/vim-arduino.vim/plugin 8 | 9 | rm $plugin/vim-arduino* 10 | 11 | ln -s $repo/vim-arduino $plugin/vim-arduino 12 | ln -s $repo/vim-arduino-cli.jar $plugin/vim-arduino-cli.jar 13 | ln -s $repo/vim-arduino-serial $plugin/vim-arduino-serial 14 | ln -s $repo/vim-arduino.vim $plugin/vim-arduino.vim 15 | -------------------------------------------------------------------------------- /doc/vim-arduino.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tclem/vim-arduino/edabf5c2ace0957fc5e9edb84661757dd044f5df/doc/vim-arduino.txt -------------------------------------------------------------------------------- /plugin/kill-screen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | for i in $(ps aux | grep \/dev\/tty.usb | awk '{print $2}') 4 | do 5 | kill $i > /dev/null 2>&1 6 | done 7 | -------------------------------------------------------------------------------- /plugin/vim-arduino: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | #/ Usage: vim-arduino [board] [serialport] 3 | #/ Invokes the Arduino IDE command line runner to compile and deploy 4 | #/ Arduino sketches. 5 | #/ 6 | 7 | # show usage 8 | [ $# -eq 0 -o "$1" = "--help" ] && { 9 | grep '^#/'< "$0" | cut -c4- 10 | exit 2 11 | } 12 | 13 | pde_file= 14 | board="uno" 15 | port= 16 | switch="-c" 17 | library_path="/Applications/Arduino.app/Contents/Resources/Java" 18 | 19 | while [ $# -gt 0 ] 20 | do 21 | case "$1" in 22 | -l|--library-path) 23 | shift 24 | library_path=$1 25 | shift 26 | ;; 27 | -s|--serialport) 28 | shift 29 | port=$1 30 | shift 31 | ;; 32 | -b|--board) 33 | shift 34 | board=$1 35 | shift 36 | ;; 37 | -d|--deploy) 38 | switch="-d" 39 | shift 40 | ;; 41 | -c|--compile) 42 | switch="-c" 43 | shift 44 | ;; 45 | *) 46 | if [ -z "$pde_file" ] 47 | then pde_file="$1" 48 | fi 49 | shift 50 | ;; 51 | esac 52 | done 53 | 54 | # bail out of pde file is not specified. 55 | [ -z "$pde_file" ] && { 56 | echo "$(basename $0): pde_file not specified" 1>&2 57 | exit 1 58 | } 59 | 60 | # try an find a serial port automatically if one is not passsed in. 61 | if [ -z "$port" ] 62 | then port=$(ls /dev/tty.* | grep usb) 63 | echo "Auto detecting serial port" 64 | fi 65 | if [ -z "$port" ] 66 | then port="/dev/tty." 67 | echo "No usb serial port found. Faking one so we can still compile." 68 | fi 69 | 70 | # bail out if no serial port found. 71 | [ -z "$port" ] && { 72 | echo "$(basename $0): serial port not specified" 1>&2 73 | exit 1 74 | } 75 | 76 | # bail out if no board specified. 77 | [ -z "$board" ] && { 78 | echo "$(basename $0): board not specified" 1>&2 79 | exit 1 80 | } 81 | 82 | # echo "Compiling '$pde_file' for board $board on serial port $port" 83 | 84 | sketchbook=$(echo $HOME/Documents/Arduino) 85 | 86 | DIR="$( cd "$( dirname "$0" )" && pwd )" 87 | java \ 88 | -Djava.library.path="$library_path" \ 89 | -Darduino.sketchbook="$sketchbook" \ 90 | -Djava.awt.headless=true \ 91 | -jar "$DIR/vim-arduino-cli.jar" "$switch" "$pde_file" "$port" "$board" 92 | -------------------------------------------------------------------------------- /plugin/vim-arduino-cli.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tclem/vim-arduino/edabf5c2ace0957fc5e9edb84661757dd044f5df/plugin/vim-arduino-cli.jar -------------------------------------------------------------------------------- /plugin/vim-arduino-serial: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "use Ctrl-a, k to exit the screen utility" 4 | 5 | port=$(ls /dev/tty.* | grep usb) 6 | # osascript -e 'tell application "Terminal" to do script "screen '.$port'"' 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" 19 | -------------------------------------------------------------------------------- /plugin/vim-arduino.vim: -------------------------------------------------------------------------------- 1 | " ============================================================================ 2 | " File: vim-arduino.vim 3 | " Description: vim plugin that enables arduino development 4 | " Maintainer: Tim Clem 5 | " Last Change: Sep 26, 2011 6 | " License: Copyright (C) 2011 Tim Clem. 7 | " 8 | " MIT License 9 | " 10 | " Permission is hereby granted, free of charge, to any person obtaining a copy 11 | " of this software and associated documentation files (the "Software"), to deal 12 | " in the Software without restriction, including without limitation the rights 13 | " to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | " copies of the Software, and to permit persons to whom the Software is 15 | " furnished to do so, subject to the following conditions: 16 | " 17 | " The above copyright notice and this permission notice shall be included in 18 | " all copies or substantial portions of the Software. 19 | " 20 | " THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | " IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | " FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | " AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | " LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | " OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 26 | " THE SOFTWARE. 27 | " 28 | " ============================================================================ 29 | " 30 | " NOTES 31 | " 32 | " Reference for how the Arduino IDE does compilation: 33 | " https://github.com/arduino/Arduino/blob/0022/app/src/processing/app/debug/Compiler.java 34 | 35 | let s:vim_arduino_version = '0.1.0' 36 | let s:vim_arduino_path=expand(":p:h") 37 | let s:vim_arduino_kill_path=s:vim_arduino_path . "/kill-screen.sh" 38 | 39 | " Load Once: {{{1 40 | if exists("loaded_vim_arduino") 41 | finish 42 | endif 43 | let loaded_vim_arduino = 1 44 | 45 | if !exists('g:vim_arduino_auto_open_serial') 46 | let g:vim_arduino_auto_open_serial = 0 47 | endif 48 | 49 | let s:helper_dir = expand(":h") 50 | 51 | " Private: Get the board to deploy to 52 | " 53 | " Boards can be defined in the first line of your pde file like this: 54 | " // board: atmega238 55 | " 56 | " Returns the board defined on the first line of the pde file. Otherwise 57 | " returns "uno". 58 | function! s:ArduinoGetBoard() 59 | let l:line = getline(1) 60 | let l:i = match(l:line, "board:") 61 | if l:i < 0 62 | return "uno" 63 | endif 64 | 65 | let l:board = substitute(strpart(l:line, l:i + 6, strlen(l:line)), " ", "", "") 66 | return l:board 67 | endfunction 68 | 69 | " Private: Check to see if a file can be compiled by the Aruino IDE 70 | " 71 | " Returns the filename of the current buffer if it is a *.pde file. Otherwise 72 | " empty string. 73 | function! s:CheckFile() 74 | let l:f_name = expand('%:p') 75 | if l:f_name =~ '.pde$' 76 | return l:f_name 77 | elseif l:f_name =~ '.ino$' 78 | return l:f_name 79 | else 80 | echo "Only *.pde and *.ino files can be compilied. File" l:f_name "does not have a recognized extention." 81 | return "" 82 | endif 83 | endfunction 84 | 85 | function! s:PrintStatus(result) 86 | if a:result == 0 87 | echohl Statement | echomsg "Succeeded." | echohl None 88 | else 89 | echohl WarningMsg | echomsg "Failed." | echohl None 90 | endif 91 | endfunction 92 | 93 | " Private: Compile or deploy code 94 | " 95 | " Returns nothing. 96 | function! s:InvokeArduinoCli(deploy) 97 | let l:flag = a:deploy ? "-d" : "-c" 98 | if exists("g:vim_arduino_serial_port") 99 | let l:flag = l:flag . " -s " . g:vim_arduino_serial_port 100 | endif 101 | if exists("g:vim_arduino_library_path") 102 | let l:flag = l:flag . " -l " . g:vim_arduino_library_path 103 | endif 104 | let l:f_name = s:CheckFile() 105 | if !empty(l:f_name) 106 | execute "w" 107 | if a:deploy 108 | call KillScreen() 109 | echomsg "Compiling and deploying..." l:f_name 110 | else 111 | echomsg "Compiling..." l:f_name 112 | endif 113 | 114 | let l:board = s:ArduinoGetBoard() 115 | let l:command = s:helper_dir . "/vim-arduino " . 116 | \ l:flag . " " . 117 | \ "-b " . l:board . " " . 118 | \ shellescape(l:f_name) 119 | " echo l:command 120 | let l:result = system(l:command) 121 | call s:PrintStatus(v:shell_error) 122 | echo l:result 123 | call s:PrintStatus(v:shell_error) 124 | endif 125 | 126 | endfunction 127 | 128 | " Public: Compile the current pde file. 129 | " 130 | " Returns nothing. 131 | function! ArduinoCompile() 132 | call s:InvokeArduinoCli(0) 133 | endfunction 134 | 135 | " Public: Compile and Deploy the current pde file. 136 | " 137 | " Returns nothing. 138 | function! ArduinoDeploy() 139 | call s:InvokeArduinoCli(1) 140 | 141 | " optionally auto open a serial port 142 | if g:vim_arduino_auto_open_serial 143 | call ArduinoSerialMonitor() 144 | endif 145 | endfunction 146 | 147 | " Public: kills all screens 148 | " 149 | " Returns nothing. 150 | function! KillScreen() 151 | :call system(s:vim_arduino_kill_path) 152 | endfunction 153 | 154 | " Public: Monitor a serial port 155 | " 156 | " Returns nothing. 157 | function! ArduinoSerialMonitor() 158 | echo system(s:helper_dir."/vim-arduino-serial") 159 | endfunction 160 | 161 | if !exists('g:vim_arduino_map_keys') 162 | let g:vim_arduino_map_keys = 1 163 | endif 164 | 165 | if g:vim_arduino_map_keys 166 | nnoremap ac :call ArduinoCompile() 167 | nnoremap ad :call ArduinoDeploy() 168 | nnoremap as :call ArduinoSerialMonitor() 169 | endif 170 | --------------------------------------------------------------------------------