Skip to content

Instantly share code, notes, and snippets.

@0x4a
Created July 5, 2013 06:46
Show Gist options
  • Save 0x4a/5932454 to your computer and use it in GitHub Desktop.
Save 0x4a/5932454 to your computer and use it in GitHub Desktop.
control the arduino ide from inside your favorite editor/ide - provides commands to: start ide, open, compile and upload a file, start serial monitor #arduino #dev #ahk
ArduCmd v0.2.5
by Daniel Jackel
dev@0x4a.net
Description
===========
This is a simple tool to operate the Arduino IDE from the commandline or an external IDE.
Usage
=====
Run the script/executable like this:
ArduCmd.ahk [option] <file>
OR
ArduCmd.exe [option] <file>
FILE is the path to your .ino file and is mandatory,
OPTION is one of the following:
<empty> - show the file in the Arduino IDE
-c, --compile - compile the file
-u, --upload - compile and upload the file
-m, --monitor - open serial monitor
Disclaimer
==========
The software is provided "AS IS" without any warranty, either expressed
or implied, including, but not limited to, the implied warranties of
merchantability and fitness for a particular purpose. The author will not
be liable for any special, incidental, consequential or indirect damages
due to loss of data or any other reason.
; ArduCmd v0.2
; by Daniel Jackel, dev@0x4a.net
; todo:
; file not found error
; return stdout.txt
; %0% contains number of arguments!
; http://www.autohotkey.com/community/viewtopic.php?t=53996
; http://www.autohotkey.com/community/viewtopic.php?t=46226
; http://www.autohotkey.com/docs/commands/IniRead.htm
; http://www.autohotkey.com/docs/commands/IniWrite.htm
; http://www.autohotkey.com/docs/commands/FileSelectFile.htm
; http://www.autohotkey.com/docs/commands/LoopFile.htm
; http://www.autohotkey.com/docs/commands/FileGetTime.htm
; http://www.autohotkey.com/community/viewtopic.php?t=62020
#SingleInstance
#NoEnv
applicationname = ArduCmd
version = v0.2.5
ini_file := A_ScriptDir "\" SubStr( A_ScriptName, 1, -3 ) . "ini"
ardu_version = 1.0.1
ardu_path = %A_ProgramFiles%\Arduino\arduino.exe
; check for ini
IfNotExist, %ini_file%
{
GoSub SETUP
}
; read ini
IniRead, ardu_version, %ini_file%, main, version ; arduino version
IniRead, ardu_path, %ini_file%, main, path ; arduino path
ardu_title := "| Arduino " . ardu_version ; window title
ACTION:
IfExist, %2% ;file exists
{
ino_path = %2%
SplitPath, 2, , , , ino_file, ;get just file name
IfWinExist, %ino_file% %ardu_title% ;file is opened in arduino ide
{
if 1 in -c,--compile ;show ide and compile
{
WinActivate
Sleep, 25
Send ^{r}
}
else if 1 in -u,--upload ;show ide, compile & upload
{
WinActivate
Sleep, 25
Send ^{u}
}
else if 1 in -m,--monitor ;show ide & serial monitor
{
WinActivate
Sleep, 25
Send ^+{m}
}
else ;wrong parameter
{
WinActivate
Msgbox, 16, Error, Unknown Option:`n%1%,15
}
}
else
launchArduino(ino_path)
}
else IfExist, %1% ;no other parameter
{
ino_path = %1%
SplitPath, 1, , , , ino_file, ;get just file name
IfWinExist, %ino_file% %ardu_title% ;file is opened in arduino ide
WinActivate
else
launchArduino(ino_path)
}
else ; file does not exist
{
GoSub HELP
}
ExitApp
launchArduino(ino_path)
{
global ardu_title, ardu_path
SplitPath, ino_path, , , , ino_file,
IfNotExist, %ardu_path%
{
GoSub SETUP
}
Run "%ardu_path%" "%ino_path%"
WinWait, %ino_file% %ardu_title%,, 15
if ErrorLevel
{
Msgbox,17,,Arduino IDE not responding...`nPlease check for correct version number
Ifmsgbox Cancel
Exitapp
else
{
Gosub SETUP
Gosub ACTION
}
}
else
GoSub ACTION
return
}
SETUP:
; prompt for arduino.exe
FileSelectFile, ardu_path, 3, %ardu_path%, Select Arduino Executable - %A_SCRIPTNAME%,Arduino executable (*.exe)
if ErrorLevel
ExitApp
else
IniWrite, %ardu_path%, %ini_file%, main, path
; prompt for version
InputBox, ardu_version,, current Arduino version:,,200,110,,,,,%ardu_version%
if ErrorLevel
ExitApp
else
IniWrite, %ardu_version%, %ini_file%, main, version
return
HELP:
; GUI Code by Areilius:
; http://www.autohotkey.com/community/viewtopic.php?t=10248
Gui,66:Destroy
Gui,66:Font,s8
Gui,66:Font,bold
Gui,66:Add, Text,x12,%applicationname% %version%
Gui,66:Font,norm s7
Gui,66:Add, Text,x180 y6,copyright 2012 by D.Jackel
Gui,66:Add, Text,x180 y20,eMail: dev@0x4a.net
Gui,66:Font,s8
Gui,66:Add, Text, x12 w301 0x10 ;Horizontal Line > Etched Gray
Gui,66:Add,Text,x12 y50,you must run the script with arguments:
Gui,66:Font,bold
If (A_IsCompiled)
Gui,66:Add,Text,x12,%A_ScriptName% [option] file
else
Gui,66:Add,Text,x12,autohotkey.exe %A_ScriptName% [option] file
Gui,66:Font,norm
Gui,66:Add,Text,x12,
(
FILE is the path to a .ino file and is mandatory
OPTION is one of the following and is optional:
)
Gui,66:Font,bold
Gui,66:Add,Text,x12 y125,
(
<empty>
-c, --compile
-u, --upload
-m, --monitor
)
Gui,66:Font,norm
Gui,66:Add,Text, x112 y125,
(
open the file in the Arduino IDE
compile the file
compile and upload the file
open serial monitor
)
Gui,66:Font
GuiControlGet,Text,66:Pos,Static1
Gui,66:Add,Button,% "Default y+10 w75 g66OK xp+" (TextW / 2) - 38 ,OK
Gui,66:-MinimizeBox
Gui,66:-MaximizeBox
SoundPlay,*-1
Gui,66:Show,w325,%applicationname%: Help
Gui,66:+LastFound
WinWaitClose
Gui,66:Destroy
return
66OK:
Gui,66:Destroy
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment