From fbf29170f59535371bdac0e4a076ea6ca4056855 Mon Sep 17 00:00:00 2001 From: Dmitry Surin Date: Mon, 26 Jun 2023 22:51:23 +0400 Subject: [PATCH 1/3] Draft: Added Windows support --- autoload/arduino.vim | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/autoload/arduino.vim b/autoload/arduino.vim index a444a42..26dbc02 100644 --- a/autoload/arduino.vim +++ b/autoload/arduino.vim @@ -4,11 +4,11 @@ endif let g:loaded_arduino_autoload = 1 let s:has_cli = executable('arduino-cli') == 1 if has('win64') || has('win32') || has('win16') - echoerr 'vim-arduino does not support windows :(' - finish + let s:OS = 'Windows' +else + let s:OS = substitute(system('uname'), '\n', '', '') endif let s:HERE = resolve(expand(':p:h:h')) -let s:OS = substitute(system('uname'), '\n', '', '') " In neovim, run the shell commands using :terminal to preserve interactivity if has('nvim') let s:TERM = 'botright split | terminal! ' @@ -47,6 +47,11 @@ function! arduino#InitializeConfig() abort endif if !exists('g:arduino_serial_cmd') let g:arduino_serial_cmd = 'screen {port} {baud}' + if s:OS ==? 'Windows' + let g:arduino_serial_cmd = 'arduino-cli monitor -p {port} --config baudrate={baud}' + else + let g:arduino_serial_cmd = 'screen {port} {baud}' + endif endif if !exists('g:arduino_build_path') let g:arduino_build_path = '{project_dir}/build' @@ -195,8 +200,8 @@ function! arduino#GetBuildPath() abort return '' endif let l:path = g:arduino_build_path - let l:path = substitute(l:path, '{file}', expand('%:p'), 'g') - let l:path = substitute(l:path, '{project_dir}', expand('%:p:h'), 'g') + 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 @@ -648,6 +653,12 @@ function! arduino#GetPorts() abort call add(ports, port) endfor endfor + if s:OS ==? 'Windows' + let found = split(system('pwsh -nop -c "arduino-cli board list | Select-String -Pattern \"^(COM\d) \" | ForEach-Object { $_.Matches.Value }"'), '\n') + for port in found + call add(ports, port) + endfor + endif return ports endfunction @@ -741,6 +752,8 @@ function! arduino#GetArduinoHomeDir() abort endif if s:OS ==? 'Darwin' return $HOME . '/Library/Arduino15' + elseif s:OS ==? 'Windows' + return $HOME . '/AppData/Local/Arduino15' endif return $HOME . '/.arduino15' From 8739195fa47d3d247172cd34d2e706782fa42be7 Mon Sep 17 00:00:00 2001 From: Dmitry Surin Date: Wed, 28 Jun 2023 21:08:38 +0400 Subject: [PATCH 2/3] Removed pwsh dep. arduino-cli monitor by default. --- autoload/arduino.vim | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/autoload/arduino.vim b/autoload/arduino.vim index 26dbc02..19ded8d 100644 --- a/autoload/arduino.vim +++ b/autoload/arduino.vim @@ -47,16 +47,10 @@ function! arduino#InitializeConfig() abort endif if !exists('g:arduino_serial_cmd') let g:arduino_serial_cmd = 'screen {port} {baud}' - if s:OS ==? 'Windows' - let g:arduino_serial_cmd = 'arduino-cli monitor -p {port} --config baudrate={baud}' - else - let g:arduino_serial_cmd = 'screen {port} {baud}' - endif 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 @@ -69,11 +63,9 @@ function! arduino#InitializeConfig() abort 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*', @@ -83,6 +75,9 @@ function! arduino#InitializeConfig() abort 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 @@ -654,9 +649,9 @@ function! arduino#GetPorts() abort endfor endfor if s:OS ==? 'Windows' - let found = split(system('pwsh -nop -c "arduino-cli board list | Select-String -Pattern \"^(COM\d) \" | ForEach-Object { $_.Matches.Value }"'), '\n') - for port in found - call add(ports, port) + 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 From bc739e640c0e46e49c7dcdc23e821c8842fa13eb Mon Sep 17 00:00:00 2001 From: Dmitry Surin Date: Wed, 12 Jul 2023 22:40:31 +0400 Subject: [PATCH 3/3] Fixed Upload & Serial --- autoload/arduino.vim | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/autoload/arduino.vim b/autoload/arduino.vim index 19ded8d..380b064 100644 --- a/autoload/arduino.vim +++ b/autoload/arduino.vim @@ -578,6 +578,13 @@ function! arduino#Verify() abort 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 @@ -588,9 +595,7 @@ function! arduino#Upload() abort endif let cmd = arduino#GetArduinoCommand(cmd_options) endif - - call arduino#RunCmd(cmd) - return v:shell_error + return cmd endfunction function! arduino#Serial() abort @@ -601,14 +606,11 @@ function! arduino#Serial() abort endfunction function! arduino#UploadAndSerial() - " Since 'terminal!' is non-blocking '!' must be used to provide this functionality - let termBackup = s:TERM - let s:TERM = '!' - let ret = arduino#Upload() - if ret == 0 - call arduino#Serial() - endif - let s:TERM = termBackup + let upload = arduino#UploadGetCmd() + let serial = arduino#GetSerialCmd() + if empty(serial) | return | endif + + call arduino#RunCmd(upload . " && " . serial) endfunction " Serial helpers {{{2