Last active
August 29, 2015 14:12
-
-
Save jossef/218bffcaa4bd181114ce to your computer and use it in GitHub Desktop.
Arduino firmware upload script using `Eclipse Arduino IDE` and `inotool`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import os | |
import shutil | |
import subprocess | |
import tempfile | |
def get_hex_files(): | |
for root, dirs, files in os.walk(os.getcwd()): | |
for file in files: | |
if file.lower().endswith('.hex'): | |
yield os.path.join(root, file) | |
def main(): | |
if os.getuid() != 0: | |
raise Exception('this must be run as root') | |
hex_files = [file for file in get_hex_files()] | |
if len(hex_files) > 1: | |
raise Exception('to many hex files. clean your project and proceed') | |
if not len(hex_files): | |
raise Exception('hex file are missing. build and run again') | |
hex_file_path = hex_files[0] | |
if not os.path.isfile(hex_file_path): | |
raise Exception('hex file {0} not found'.format(hex_file_path)) | |
temp_dir_path = tempfile.mkdtemp() | |
os.makedirs(os.path.join(temp_dir_path, 'src')) | |
leonardo_build_path = os.path.join(temp_dir_path, '.build', 'leonardo') | |
os.makedirs(leonardo_build_path) | |
shutil.copy2(hex_file_path, os.path.join(leonardo_build_path, 'firmware.hex')) | |
os.chdir(temp_dir_path) | |
subprocess.call(['ino', 'upload', '--board', 'leonardo']) | |
shutil.rmtree(temp_dir_path) | |
if __name__ == '__main__': | |
try: | |
main() | |
except Exception as ex: | |
print ex |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
place it in
/opt/arduino-upload/upload.py
add execution permissions
create a symlink to run from everywhere
build your eclipse project using Eclipse Arduino IDE
cd to your eclipse project dir and run
sudo arduino-upload