forked from j123b567/scpi-parser
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
618 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
__vm | ||
.vs | ||
test-arduino.vcxproj | ||
test-arduino.vcxproj.filters |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
''' | ||
This script creates scpi-parser library that is compatible with Arduino IDE. | ||
As a convinience, it also copies a newly create library into arduino libraries | ||
directory so any Arduino sketch can see it. | ||
Execute this script if scpi-parser is changed or scpi_user_config.h (from this directory) is changed. | ||
''' | ||
from __future__ import (print_function) | ||
|
||
import os | ||
import platform | ||
import sys | ||
import shutil | ||
|
||
# | ||
# make scpi-parser as arduino compatible library | ||
# | ||
scpi_parser_dir = os.path.join(os.path.dirname(__file__), 'scpi-parser') | ||
libscpi_dir = os.path.join(os.path.dirname(__file__), '../../libscpi') | ||
|
||
def rm_then_cp(src, dest): | ||
if os.path.exists(dest): | ||
shutil.rmtree(dest) | ||
shutil.copytree(src, dest) | ||
|
||
# copy *.h files | ||
rm_then_cp(os.path.join(libscpi_dir, 'inc/scpi'), os.path.join(scpi_parser_dir, 'src/scpi')) | ||
|
||
# modify config.h | ||
config_h_file_path = os.path.join(scpi_parser_dir, 'src/scpi/config.h') | ||
config_h_file = open(config_h_file_path) | ||
tmp_file_path = config_h_file_path + ".tmp" | ||
tmp_file = open(tmp_file_path, "w") | ||
for line in config_h_file: | ||
if line == '#ifdef SCPI_USER_CONFIG\n': | ||
tmp_file.write('// This is automatically added by the build-arduino-library.py\n') | ||
tmp_file.write('#define SCPI_USER_CONFIG 1\n') | ||
tmp_file.write('\n') | ||
tmp_file.write(line) | ||
config_h_file.close() | ||
tmp_file.close() | ||
os.unlink(config_h_file_path) | ||
os.rename(tmp_file_path, config_h_file_path) | ||
|
||
# copy scpi_user_config.h | ||
shutil.copyfile(os.path.join(os.path.dirname(__file__), 'scpi_user_config.h'), os.path.join(scpi_parser_dir, 'src/scpi/scpi_user_config.h')) | ||
|
||
# copy *.c files | ||
rm_then_cp(os.path.join(libscpi_dir, 'src'), os.path.join(scpi_parser_dir, 'src/impl')) | ||
|
||
# | ||
# find arduino libraries directory | ||
# | ||
ARDUINO_LIB_DIR_CANDIDATES = { | ||
'Linux': ['Arduino/libraries/', 'Documents/Arduino/libraries/'], | ||
'Darwin': ['Documents/Arduino/libraries/'], | ||
'Windows': ['Documents\\Arduino\\libraries\\', 'My Documents\\Arduino\\libraries\\'] | ||
} | ||
|
||
home_dir = os.path.expanduser('~') | ||
|
||
arduino_libs_dir = None | ||
|
||
candidates = ARDUINO_LIB_DIR_CANDIDATES.get(platform.system()) | ||
if candidates: | ||
for candidate_dir in ARDUINO_LIB_DIR_CANDIDATES.get(platform.system()): | ||
arduino_libs_dir = os.path.join(home_dir, candidate_dir) | ||
if os.path.exists(arduino_libs_dir): | ||
break | ||
|
||
if arduino_libs_dir: | ||
# copy arduino scpi-parser library to the arduino libraries folder | ||
rm_then_cp(scpi_parser_dir, os.path.join(arduino_libs_dir, 'scpi-parser')) | ||
else: | ||
print("Arduino libraries directory not found!") |
Oops, something went wrong.