From dbcfe31ea6f1e012b693aba1f9d54bacc075a17d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20G=C3=BCnce=20Akkoyun?= Date: Mon, 21 Feb 2022 11:36:50 +0300 Subject: [PATCH] 01.00.00 - Master update --- .travis.yml | 36 +- Documents/Library_Properties.md | 75 -- README.md | 24 + examples/.DS_Store | Bin 0 -> 6148 bytes examples/Device_Scanner/Device_Scanner.ino | 68 ++ examples/test/test.ino | 9 - install.sh | 1211 ++++++++++---------- keywords.txt | 2 +- library.json | 22 +- library.properties | 12 +- src/Config.h | 19 - src/Defination.h | 19 - src/I2C_Scanner.cpp | 96 ++ src/{Library.h => I2C_Scanner.h} | 23 +- src/I2C_Scanner_Defination.h | 19 + src/Library.cpp | 20 - 16 files changed, 892 insertions(+), 763 deletions(-) delete mode 100644 Documents/Library_Properties.md create mode 100644 examples/.DS_Store create mode 100644 examples/Device_Scanner/Device_Scanner.ino delete mode 100644 examples/test/test.ino delete mode 100644 src/Config.h delete mode 100644 src/Defination.h create mode 100644 src/I2C_Scanner.cpp rename src/{Library.h => I2C_Scanner.h} (62%) create mode 100644 src/I2C_Scanner_Defination.h delete mode 100644 src/Library.cpp diff --git a/.travis.yml b/.travis.yml index 32fd0cb..522aea2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,18 +1,26 @@ -language: python - +language: c +os: linux +dist: xenial cache: directories: - - "~/.platformio" - -install: -- pip install -U platformio -- platformio lib install 986 # LSM303 - + - ~/arduino_ide + - ~/.arduino15/packages/ +git: + depth: false + quiet: true env: -- BOARD=megaatmega2560 - + global: + - PRETTYNAME="I2C Device Scanner" + # You can uncomment this to explicitly choose an (old) version of the Arduino IDE + #- ARDUINO_IDE_VERSION="1.8.10" +before_install: + - source <(curl -SLs https://raw.githubusercontent.com/akkoyun/I2C_Scanner/main/install.sh) +install: + # Note that every library should be installed in a seperate command + - arduino --install-library "I2C_Functions" script: -- for e in examples/*; do - platformio ci --board=$BOARD --lib=. $e/*; - done - + - build_main_platforms +notifications: + email: + on_success: change + on_failure: change diff --git a/Documents/Library_Properties.md b/Documents/Library_Properties.md deleted file mode 100644 index 991c8a6..0000000 --- a/Documents/Library_Properties.md +++ /dev/null @@ -1,75 +0,0 @@ -# library.properties file format - -The library.properties file is a key=value properties list. Every field in this file is UTF-8 encoded. Unless noted otherwise below, all fields are required. The available fields are: - -#### name -the name of the library. Library names must contain only basic letters (A-Z or a-z) and numbers (0-9), spaces ( ), underscores (_), dots (.) and dashes (-). They must start with a letter or number. They must contain at least one letter. Note that libraries with a name value starting with Arduino will no longer be allowed addition to the Library Manager index as these names are now reserved for official Arduino libraries. - -#### version -version of the library. Version should be semver compliant. 1.2.0 is correct; 1.2 is accepted; r5, 003, 1.1c are invalid - -#### author -name/nickname of the authors and their email addresses (not mandatory) separated by comma (,) - -#### maintainer -name and email of the maintainer - -#### sentence -a sentence explaining the purpose of the library - -#### paragraph -a longer description of the library. The value of sentence will be prepended to this, so you should start by writing the second sentence here - -#### category -(defaults to Uncategorized) allowed values: - -* Display -* Communication -* Signal Input/Output -* Sensors -* Device Control -* Timing -* Data Storage -* Data Processing -* Other - -#### url -the URL of the library project, for a person to visit. For example, the library's GitHub page. This is used for the "More info" links in Library Manager - -#### architectures -(defaults to *) a comma separated list of architectures supported by the library. If the library doesn’t contain architecture specific code use * to match all architectures. This field is used as one factor in determining priority when multiple libraries match an #include directive and to provide a warning message when the library is compiled for a board of an architecture that doesn't match any on the list. - -#### depends -(available from Arduino IDE 1.8.10/Arduino CLI 0.7.0) (optional) a comma-separated list of dependencies (libraries that are needed to build the current library). The Arduino IDE's Library Manager will offer to install the dependencies during installation of the library. arduino-cli lib install will automatically install the dependencies. Since spaces are allowed in the name of a library, but not commas, you can refer to libraries containing spaces in the name without ambiguity for example: -depends=Very long library name, Another library with long-name - -#### dot_a_linkage -(available from Arduino IDE 1.6.0 / arduino-builder 1.0.0-beta13) (optional) when set to true, the library will be compiled using a .a (archive) file. First, all source files are compiled into .o files as normal. Then instead of including all .o files in the linker command directly, all .o files are saved into a .a file, which is then included in the linker command. 1.5 format library folder structure is required. - -#### includes -(available from Arduino IDE 1.6.10) (optional) a comma separated list of files of the library to be added to the sketch as #include <...> lines. This property is used with the "Include library" command in the Arduino IDE. If the includes property is missing, all the header files (.h) on the root source folder are included. - -#### precompiled -(available from Arduino IDE 1.8.6/arduino-builder 1.4.0) (optional) enables support for .a (archive) and .so (shared object) files. See the "Precompiled binaries" section for documentation of the required location in the library for these files. The static library should be linked as an ldflag. The precompiled field has two supported values, which control how any source files in the library are handled: - -* true - Source files are always compiled. This is useful for "mixed" libraries, such as those that contain both open source code and the precompiled binary of a closed source component. Support for "mixed" libraries was inadvertently lost in Arduino IDE 1.8.12/arduino-builder 1.5.2/Arduino CLI 0.8.0, and returned in Arduino IDE 1.8.13/arduino-builder 1.5.3/Arduino CLI 0.11.0. - -* full - (available from Arduino IDE 1.8.13/arduino-builder 1.5.3/Arduino CLI 0.11.0) If the library provides a precompiled library for the board being compiled for, the source files will not be compiled. If no precompiled library was provided for the selected board, source files are compiled as a fallback. This is useful for precompiling the library to reduce compilation time for specific target hardware, but also providing support for arbitrary boards by compiling the library on demand. - -#### ldflags -(available from Arduino IDE 1.8.6/arduino-builder 1.4.0) (optional) the linker flags to be added. Ex: ldflags=-lm -Example: - -### Example: - - name=WebServer - version=1.0.0 - author=Cristian Maglie - maintainer=Cristian Maglie - sentence=A library that makes coding a Webserver a breeze. - paragraph=Supports HTTP1.1 and you can do GET and POST. - category=Communication - url=http://example.com/ - architectures=avr - includes=WebServer.h - depends=ArduinoHttpClient diff --git a/README.md b/README.md index cb15424..9f11156 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,26 @@ # Arduino_Library_Template Library Template + +┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ +│ I2C DEVICE EXPLORER │ +├──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┤ +│ │ 0x_0 │ 0x_1 │ 0x_2 │ 0x_3 │ 0x_4 │ 0x_5 │ 0x_6 │ 0x_7 │ 0x_8 │ 0x_9 │ 0x_A │ 0x_B │ 0x_C │ 0x_D │ 0x_E │ 0x_F │ +├──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┤ +│ 0x0_ │ ---- │ ---- │ ---- │ │ │ │ │ │ │ │ │ │ │ │ │ │ +├──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┤ +│ 0x1_ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ +├──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┤ +│ 0x2_ │ │ │ │ │ │ │ │ │ 0x28 │ │ │ │ │ │ │ │ +├──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┤ +│ 0x3_ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ +├──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┤ +│ 0x4_ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ +├──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┤ +│ 0x5_ │ │ │ │ │ │ 0x55 │ │ │ │ │ │ │ │ │ │ │ +├──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┤ +│ 0x6_ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ +├──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┤ +│ 0x7_ │ │ │ │ │ │ │ │ │ ---- │ ---- │ ---- │ ---- │ ---- │ ---- │ ---- │ ---- │ +├──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┤ +│ Total connected device : 000 Reset [0] │ +└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ \ No newline at end of file diff --git a/examples/.DS_Store b/examples/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..1458e7c67e907b7eeea42019d0e8509d58a4d09d GIT binary patch literal 6148 zcmeHK%}N6?5T3NvZYfF+3Oz1(Em&O@#LH6a3%H^OmAczqba72ee-EXwXMG``#OHA) zNtIIdB8Ze3n0%ATOhUdanGFDl)+pWsr~!b3N?531^M%kj>5>$zhfwG_x{yEz0_Z}x z6wQwR$N-()CbaR~#*pHf8no zY7z{?;b_nb``6UFP%4Y&b{Jiz$)r=;I#qHQrZVa4gfvbtEzAz&o1FD$e%K?#X%QF?*8g*$^x68`QF4aSktN{J6() z(3hE#_ZT;yW1h>%3@`)Cz$!9e?>eWtikss-F$2uNuNa{F!9^wXE#?OG)qxHDKGJxJ zkOXadOAxvieT%t496=E#715*$`@|3?9sRD2^DX8EO*#m@GR|XH7WRcA^y=t$bvOv$ zAh*l_GqA`&(R6E6|IfaE|1TzSj~QSFR*C^pY6tBWZpqfxrOi>Tby4q7NhmHi_>qE! iF2xv2rMQl&1^q4=h`z<#AbL>vM?llS4Kwhk47>wPwooeo literal 0 HcmV?d00001 diff --git a/examples/Device_Scanner/Device_Scanner.ino b/examples/Device_Scanner/Device_Scanner.ino new file mode 100644 index 0000000..1a92712 --- /dev/null +++ b/examples/Device_Scanner/Device_Scanner.ino @@ -0,0 +1,68 @@ +#include "I2C_Scanner.h" + +void setup() { + + // Serial Communication Start + Serial.begin(115200); + + // Start Console + Terminal.Begin(Serial); + + // Draw Table + I2C_Scanner.Draw_Table(); + + // Start I2C + Wire.begin(); + +} + +void loop() { + + // Scan Device + I2C_Scanner.Device_Scan(); + + // Multiplexer Set + if (Serial.available() > 0) { + + uint16_t Key = Serial.read(); + + // Terminal Beep + Terminal.Beep(); + + switch (Key) { + case '0': + I2C.Set_Multiplexer(__ADDR_TCA9548__, 0); + break; + case '1': + I2C.Set_Multiplexer(__ADDR_TCA9548__, 1); + break; + case '2': + I2C.Set_Multiplexer(__ADDR_TCA9548__, 2); + break; + case '3': + I2C.Set_Multiplexer(__ADDR_TCA9548__, 3); + break; + case '4': + I2C.Set_Multiplexer(__ADDR_TCA9548__, 4); + break; + case '5': + I2C.Set_Multiplexer(__ADDR_TCA9548__, 5); + break; + case '6': + I2C.Set_Multiplexer(__ADDR_TCA9548__, 6); + break; + case '7': + I2C.Set_Multiplexer(__ADDR_TCA9548__, 7); + break; + case '8': + I2C.Set_Multiplexer(__ADDR_TCA9548__, 8); + break; + default: + break; + } + } + + // Loop Delay + delay(500); + +} diff --git a/examples/test/test.ino b/examples/test/test.ino deleted file mode 100644 index e20cfc7..0000000 --- a/examples/test/test.ino +++ /dev/null @@ -1,9 +0,0 @@ -void setup() { - // put your setup code here, to run once: - -} - -void loop() { - // put your main code here, to run repeatedly: - -} \ No newline at end of file diff --git a/install.sh b/install.sh index d9a33c4..6332b49 100644 --- a/install.sh +++ b/install.sh @@ -2,13 +2,12 @@ # we need bash 4 for associative arrays if [ "${BASH_VERSION%%[^0-9]*}" -lt "4" ]; then - echo "BASH VERSION < 4: ${BASH_VERSION}" >&2 - exit 1 + echo "BASH VERSION < 4: ${BASH_VERSION}" >&2 + exit 1 fi # associative array for the platforms that will be verified in build_main_platforms() -# this will be eval'd in the functions below because arrays can't be exported -# Uno is ATmega328, Zero is SAMD21G18, ESP8266, Leonardo is ATmega32u4, M4 is SAMD51, Mega is ATmega2560, ESP32 +# Uno is ATmega328, Mega is ATmega2560 export MAIN_PLATFORMS='declare -A main_platforms=( [uno]="arduino:avr:uno" [mega2560]="arduino:avr:mega:cpu=atmega2560" )' # make display available for arduino CLI @@ -19,809 +18,873 @@ export DISPLAY=:1.0 #This condition is to avoid reruning install when build argument is passed if [[ $# -eq 0 ]] ; then -# define colors -WHITE ='\033[1;37m'; -GRAY ='\033[1;30m'; -LGRAY ='\033[0;37m'; -RED ='\033[0;31m'; -LRED ='\033[1;31m'; -GREEN ='\033[0;32m'; -LGREEN ='\033[1;32m'; -ORANGE ='\033[0;33m'; -YELLOW ='\033[1;33m'; -BLUE ='\033[0;34m'; -LBLUE ='\033[1;34m'; -PURPLE ='\033[0;35m'; -LPURPLE ='\033[1;35m'; -CYAN ='\033[0;36m'; -LCYAN ='\033[1;36m'; - -# Personal Info -echo -e "${GRAY}\n------------------------------------------------------------------------"; -echo -e "${GRAY}Mehmet Gunce Akkoyun (akkoyun@me.com)" -echo "${GRAY}------------------------------------------------------------------------"; - - -echo -e "\n########################################################################"; -echo -e "${YELLOW}INSTALLING ARDUINO IDE" -echo "########################################################################"; - -# if .travis.yml does not set version -if [ -z $ARDUINO_IDE_VERSION ]; then - export ARDUINO_IDE_VERSION="1.8.11" - echo "NOTE: Your .travis.yml does not specify Arduino IDE version, using $ARDUINO_IDE_VERSION" -fi + # define colors + GRAY='\033[1;30m'; RED='\033[0;31m'; LRED='\033[1;31m'; GREEN='\033[0;32m'; LGREEN='\033[1;32m'; ORANGE='\033[0;33m'; YELLOW='\033[1;33m'; BLUE='\033[0;34m'; LBLUE='\033[1;34m'; PURPLE='\033[0;35m'; LPURPLE='\033[1;35m'; CYAN='\033[0;36m'; LCYAN='\033[1;36m'; LGRAY='\033[0;37m'; WHITE='\033[1;37m'; -# if newer version is requested -if [ ! -f $HOME/arduino_ide/$ARDUINO_IDE_VERSION ] && [ -f $HOME/arduino_ide/arduino ]; then - echo -n "DIFFERENT VERSION OF ARDUINO IDE REQUESTED: " - shopt -s extglob - cd $HOME/arduino_ide/ - rm -rf * - - if [ $? -ne 0 ]; then echo -e """$RED""\xe2\x9c\x96"; else echo -e """$GREEN""\xe2\x9c\x93"; fi + echo -e "\n########################################################################"; + echo -e "${YELLOW}INSTALLING ARDUINO IDE" + echo "########################################################################"; - cd $OLDPWD -fi + # if .travis.yml does not set version + if [ -z $ARDUINO_IDE_VERSION ]; then + export ARDUINO_IDE_VERSION="1.8.11" + echo "NOTE: YOUR .TRAVIS.YML DOES NOT SPECIFY ARDUINO IDE VERSION, USING $ARDUINO_IDE_VERSION" + fi -# if not already cached, download and install arduino IDE -echo -n "ARDUINO IDE STATUS: " + # if newer version is requested + if [ ! -f $HOME/arduino_ide/$ARDUINO_IDE_VERSION ] && [ -f $HOME/arduino_ide/arduino ]; then + echo -n "DIFFERENT VERSION OF ARDUINO IDE REQUESTED: " + shopt -s extglob + cd $HOME/arduino_ide/ + rm -rf * + if [ $? -ne 0 ]; then echo -e """$RED""\xe2\x9c\x96"; else echo -e """$GREEN""\xe2\x9c\x93"; fi + cd $OLDPWD + fi -if [ ! -f $HOME/arduino_ide/arduino ]; then - - echo -n "DOWNLOADING: " - wget --quiet https://downloads.arduino.cc/arduino-$ARDUINO_IDE_VERSION-linux64.tar.xz + # if not already cached, download and install arduino IDE + echo -n "ARDUINO IDE STATUS: " + if [ ! -f $HOME/arduino_ide/arduino ]; then + echo -n "DOWNLOADING: " + wget --quiet https://downloads.arduino.cc/arduino-$ARDUINO_IDE_VERSION-linux64.tar.xz + if [ $? -ne 0 ]; then echo -e """$RED""\xe2\x9c\x96"; else echo -e """$GREEN""\xe2\x9c\x93"; fi + echo -n "UNPACKING ARDUINO IDE: " + [ ! -d $HOME/arduino_ide/ ] && mkdir $HOME/arduino_ide + tar xf arduino-$ARDUINO_IDE_VERSION-linux64.tar.xz -C $HOME/arduino_ide/ --strip-components=1 + if [ $? -ne 0 ]; then echo -e """$RED""\xe2\x9c\x96"; else echo -e """$GREEN""\xe2\x9c\x93"; fi + touch $HOME/arduino_ide/$ARDUINO_IDE_VERSION - if [ $? -ne 0 ]; then echo -e """$RED""\xe2\x9c\x96"; else echo -e """$GREEN""\xe2\x9c\x93"; fi + else - echo -n "UNPACKING ARDUINO IDE: " - [ ! -d $HOME/arduino_ide/ ] && mkdir $HOME/arduino_ide - tar xf arduino-$ARDUINO_IDE_VERSION-linux64.tar.xz -C $HOME/arduino_ide/ --strip-components=1 + echo -n "CACHED: " + echo -e """$GREEN""\xe2\x9c\x93" + fi - if [ $? -ne 0 ]; then echo -e """$RED""\xe2\x9c\x96"; else echo -e """$GREEN""\xe2\x9c\x93"; fi - touch $HOME/arduino_ide/$ARDUINO_IDE_VERSION + # define output directory for .hex files + export ARDUINO_HEX_DIR=arduino_build_$TRAVIS_BUILD_NUMBER -else - echo -n "CACHED: " - echo -e """$GREEN""\xe2\x9c\x93" -fi + # link test library folder to the arduino libraries folder + ln -s $TRAVIS_BUILD_DIR $HOME/arduino_ide/libraries/Adafruit_Test_Library -# define output directory for .hex files -export ARDUINO_HEX_DIR=arduino_build_$TRAVIS_BUILD_NUMBER + # add the arduino CLI to our PATH + export PATH="$HOME/arduino_ide:$PATH" -# link test library folder to the arduino libraries folder -ln -s $TRAVIS_BUILD_DIR $HOME/arduino_ide/libraries/Adafruit_Test_Library + echo -e "\n########################################################################"; + echo -e "${YELLOW}INSTALLING DEPENDENCIES" + echo "########################################################################"; -# add the arduino CLI to our PATH -export PATH="$HOME/arduino_ide:$PATH" + # install dependancy libraries in library.properties + grep "depends=" $HOME/arduino_ide/libraries/Adafruit_Test_Library/library.properties | sed 's/depends=//' | sed -n 1'p' | tr ',' '\n' | while read word; do arduino --install-library "$word"; done -echo -e "\n########################################################################"; -echo -e "${YELLOW}INSTALLING DEPENDENCIES" -echo "########################################################################"; + # install the zero, esp8266, and adafruit board packages + echo -n "ADD PACKAGE INDEX: " + DEPENDENCY_OUTPUT=$(arduino --pref "boardsmanager.additional.urls=https://adafruit.github.io/arduino-board-index/package_adafruit_index.json,http://arduino.esp8266.com/stable/package_esp8266com_index.json,https://dl.espressif.com/dl/package_esp32_index.json" --save-prefs 2>&1) + if [ $? -ne 0 ]; then echo -e """$RED""\xe2\x9c\x96"; else echo -e """$GREEN""\xe2\x9c\x93"; fi -# install dependancy libraries in library.properties -grep "depends=" $HOME/arduino_ide/libraries/Adafruit_Test_Library/library.properties | sed 's/depends=//' | sed -n 1'p' | tr ',' '\n' | while read word; do arduino --install-library "$word"; done + # This is a hack, we have to install by hand so lets delete it + echo "Removing ESP32 cache" + rm -rf ~/.arduino15/packages/esp32 + echo -n "Current packages list:" + [ -d ~/.arduino15/packages/ ] && ls ~/.arduino15/packages/ -# install the zero, esp8266, and adafruit board packages -echo -n "ADD PACKAGE INDEX: " -DEPENDENCY_OUTPUT=$(arduino --pref "boardsmanager.additional.urls=https://adafruit.github.io/arduino-board-index/package_adafruit_index.json,http://arduino.esp8266.com/stable/package_esp8266com_index.json,https://dl.espressif.com/dl/package_esp32_index.json" --save-prefs 2>&1) -if [ $? -ne 0 ]; then echo -e """$RED""\xe2\x9c\x96"; else echo -e """$GREEN""\xe2\x9c\x93"; fi + if [[ $INSTALL_ESP32 == 1 ]]; then -# This is a hack, we have to install by hand so lets delete it -echo "Removing ESP32 cache" -rm -rf ~/.arduino15/packages/esp32 -echo -n "Current packages list:" -[ -d ~/.arduino15/packages/ ] && ls ~/.arduino15/packages/ + echo -n "ESP32: " + pip install pyserial + DEPENDENCY_OUTPUT=$(arduino --install-boards esp32:esp32 2>&1) -INSTALL_AVR=$([[ $INSTALL_PLATFORMS == *"avr"* || -z "$INSTALL_PLATFORMS" ]] && echo 1 || echo 0) + if [ $? -ne 0 ]; then + echo -e "\xe2\x9c\x96 OR CACHED"; + else + echo -e """$GREEN""\xe2\x9c\x93"; + fi -if [[ $INSTALL_AVR == 1 ]]; then - echo -n "ADAFRUIT AVR: " - DEPENDENCY_OUTPUT=$(arduino --install-boards adafruit:avr 2>&1) - if [ $? -ne 0 ]; then echo -e "\xe2\x9c\x96 OR CACHED"; else echo -e """$GREEN""\xe2\x9c\x93"; fi -fi + fi -# install random lib so the arduino IDE grabs a new library index -# see: https://github.com/arduino/Arduino/issues/3535 -echo -n "UPDATE LIBRARY INDEX: " -DEPENDENCY_OUTPUT=$(arduino --install-library USBHost > /dev/null 2>&1) -if [ $? -ne 0 ]; then echo -e """$RED""\xe2\x9c\x96"; else echo -e """$GREEN""\xe2\x9c\x93"; fi + if [[ $INSTALL_ZERO == 1 ]]; then -# set the maximal compiler warning level -echo -n "SET BUILD PREFERENCES: " -DEPENDENCY_OUTPUT=$(arduino --pref "compiler.warning_level=all" --save-prefs 2>&1) + echo -n "ZERO: " + DEPENDENCY_OUTPUT=$(arduino --install-boards arduino:samd 2>&1) -if [ $? -ne 0 ]; then echo -e """$RED""\xe2\x9c\x96"; else echo -e """$GREEN""\xe2\x9c\x93"; fi + if [ $? -ne 0 ]; then + echo -e "\xe2\x9c\x96 OR CACHED"; + else + echo -e """$GREEN""\xe2\x9c\x93"; + fi - # init the json temp var for the current platform - export PLATFORM_JSON="" + fi - # init test stats counters - export PASS_COUNT=0 - export SKIP_COUNT=0 - export FAIL_COUNT=0 - export PDE_COUNT=0 - # close if [[ $# -eq 0 ]] ; then + if [[ $INSTALL_ESP8266 == 1 ]]; then + + echo -n "ESP8266: " + DEPENDENCY_OUTPUT=$(arduino --install-boards esp8266:esp8266 2>&1) -fi + if [ $? -ne 0 ]; then + echo -e "\xe2\x9c\x96 OR CACHED"; + else + echo -e """$GREEN""\xe2\x9c\x93"; + fi + fi + if [[ $INSTALL_AVR == 1 ]]; then + echo -n "ADAFRUIT AVR: " + DEPENDENCY_OUTPUT=$(arduino --install-boards adafruit:avr 2>&1) + + if [ $? -ne 0 ]; then + echo -e "\xe2\x9c\x96 OR CACHED"; + else + echo -e """$GREEN""\xe2\x9c\x93"; + fi + + fi -# build all of the examples for the passed platform -#Sourcing and defining functions -function build_platform() { + if [[ $INSTALL_SAMD == 1 ]]; then - # arrays can't be exported, so we have to eval - eval $MAIN_PLATFORMS - - # reset platform json var - PLATFORM_JSON="" - - # expects argument 1 to be the platform key - local platform_key=$1 - - # placeholder for platform - local platform="" - - # track the exit code for this platform - local exit_code=0 - - # grab all pde and ino example sketches - declare -a examples - - if [ "$PLATFORM_CHECK_ONLY_ON_FILE" = true ]; then - # loop through results and add them to the array - examples=($( - for f in $(find . -type f -iname '*.ino' -o -iname '*.pde'); do - # TODO: distinguish platforms - if [ -e "$(dirname $f)/.$platform_key.test" ]; then - echo "$f" - fi - done - )) - else - # loop through results and add them to the array - examples=($(find $PWD -name "*.pde" -o -name "*.ino")) - fi - - # get the last example in the array - local last="${examples[@]:(-1)}" - - # grab the platform info from array or bail if invalid - if [[ ${main_platforms[$platform_key]} ]]; then - platform=${main_platforms[$platform_key]} - else - echo "NON-STANDARD PLATFORM KEY: $platform_key" - platform=$platform_key - fi + echo -n "ADAFRUIT SAMD: " + DEPENDENCY_OUTPUT=$(arduino --install-boards adafruit:samd 2>&1) + + if [ $? -ne 0 ]; then + echo -e "\xe2\x9c\x96 OR CACHED"; + else + echo -e """$GREEN""\xe2\x9c\x93"; + fi - echo -e "\n########################################################################"; + fi - echo -e -n "${YELLOW}SWITCHING TO ${platform_key}: " + if [[ $INSTALL_NRF52 == 1 ]]; then + + echo -n "ADAFRUIT NRF5X: " + pip install wheel + pip install setuptools + pip install adafruit-nrfutil + pip install pyserial + DEPENDENCY_OUTPUT=$(arduino --install-boards adafruit:nrf52 2>&1) + + if [ $? -ne 0 ]; then + echo -e "\xe2\x9c\x96 OR CACHED"; + else + echo -e """$GREEN""\xe2\x9c\x93"; + fi - # switch to the requested board. - # we have to avoid reading the exit code of local: - # "when declaring a local variable in a function, the local acts as a command in its own right" - local platform_stdout - platform_stdout=$(arduino --board $platform --save-prefs 2>&1) + fi - # grab the exit status of the arduino board change - local platform_switch=$? + # install random lib so the arduino IDE grabs a new library index + # see: https://github.com/arduino/Arduino/issues/3535 + echo -n "UPDATE LIBRARY INDEX: " + DEPENDENCY_OUTPUT=$(arduino --install-library "I2C_Functions") + if [ $? -ne 0 ]; then + echo -e """$RED""\xe2\x9c\x96"; + else + echo -e """$GREEN""\xe2\x9c\x93"; + fi - # notify if the platform switch failed - if [ $platform_switch -ne 0 ]; then - # heavy X - echo -e """$RED""\xe2\x9c\x96" - echo -e "arduino --board ${platform} --save-prefs 2>&1" - echo $platform_stdout - exit_code=1 - else - # heavy checkmark - echo -e """$GREEN""\xe2\x9c\x93" - fi + # set the maximal compiler warning level + echo -n "SET BUILD PREFERENCES: " + DEPENDENCY_OUTPUT=$(arduino --pref "compiler.warning_level=all" --save-prefs 2>&1) + if [ $? -ne 0 ]; then + echo -e """$RED""\xe2\x9c\x96"; + else + echo -e """$GREEN""\xe2\x9c\x93"; + fi - echo "########################################################################"; + # init the json temp var for the current platform + export PLATFORM_JSON="" - # loop through example sketches - for example in "${examples[@]}"; do + # init test stats counters + export PASS_COUNT=0 + export SKIP_COUNT=0 + export FAIL_COUNT=0 + export PDE_COUNT=0 - # store the full path to the example's sketch directory - local example_dir=$(dirname $example) +# close if [[ $# -eq 0 ]] ; then +fi - # store the filename for the example without the path - local example_file=$(basename $example) +# build all of the examples for the passed platform +#Sourcing and defining functions +function build_platform() { - # is this the last example in the loop - local last_example=0 - if [ "$last" == "$example" ]; then - last_example=1 - fi + # arrays can't be exported, so we have to eval + eval $MAIN_PLATFORMS + eval $AUX_PLATFORMS + eval $CPLAY_PLATFORMS + eval $M4_PLATFORMS + eval $ARCADA_PLATFORMS + eval $IO_PLATFORMS + eval $NRF5X_PLATFORMS + + # reset platform json var + PLATFORM_JSON="" + + # expects argument 1 to be the platform key + local platform_key=$1 + + # placeholder for platform + local platform="" + + # track the exit code for this platform + local exit_code=0 + + # grab all pde and ino example sketches + declare -a examples + + if [ "$PLATFORM_CHECK_ONLY_ON_FILE" = true ]; then + # loop through results and add them to the array + examples=($( + for f in $(find . -type f -iname '*.ino' -o -iname '*.pde'); do + # TODO: distinguish platforms + if [ -e "$(dirname $f)/.$platform_key.test" ]; then + echo "$f" + fi + done + )) + else + # loop through results and add them to the array + examples=($(find $PWD -name "*.pde" -o -name "*.ino")) + fi + + # get the last example in the array + local last="${examples[@]:(-1)}" + + # grab the platform info from array or bail if invalid + if [[ ${main_platforms[$platform_key]} ]]; then + platform=${main_platforms[$platform_key]} + elif [[ ${aux_platforms[$platform_key]} ]]; then + platform=${aux_platforms[$platform_key]} + elif [[ ${cplay_platforms[$platform_key]} ]]; then + platform=${cplay_platforms[$platform_key]} + elif [[ ${m4_platforms[$platform_key]} ]]; then + platform=${m4_platforms[$platform_key]} + elif [[ ${arcada_platforms[$platform_key]} ]]; then + platform=${arcada_platforms[$platform_key]} + elif [[ ${io_platforms[$platform_key]} ]]; then + platform=${io_platforms[$platform_key]} + elif [[ ${nrf5x_platforms[$platform_key]} ]]; then + platform=${nrf5x_platforms[$platform_key]} + else + echo "NON-STANDARD PLATFORM KEY: $platform_key" + platform=$platform_key + fi + + echo -e "\n########################################################################"; + + echo -e -n "${YELLOW}SWITCHING TO ${platform_key}: " + + # switch to the requested board. + # we have to avoid reading the exit code of local: + # "when declaring a local variable in a function, the local acts as a command in its own right" + local platform_stdout + platform_stdout=$(arduino --board $platform --save-prefs 2>&1) + + # grab the exit status of the arduino board change + local platform_switch=$? + + # notify if the platform switch failed + if [ $platform_switch -ne 0 ]; then + # heavy X + echo -e """$RED""\xe2\x9c\x96" + echo -e "arduino --board ${platform} --save-prefs 2>&1" + echo $platform_stdout + exit_code=1 + else + # heavy checkmark + echo -e """$GREEN""\xe2\x9c\x93" + fi + + echo "########################################################################"; + + # loop through example sketches + for example in "${examples[@]}"; do + + # store the full path to the example's sketch directory + local example_dir=$(dirname $example) + + # store the filename for the example without the path + local example_file=$(basename $example) + + # is this the last example in the loop + local last_example=0 + if [ "$last" == "$example" ]; then + last_example=1 + fi - echo -n "$example_file: " + echo -n "$example_file: " - # continue to next example if platform switch failed - if [ $platform_switch -ne 0 ]; then - # heavy X - echo -e """$RED""\xe2\x9c\x96" + # continue to next example if platform switch failed + if [ $platform_switch -ne 0 ]; then + # heavy X + echo -e """$RED""\xe2\x9c\x96" - # add json - PLATFORM_JSON="${PLATFORM_JSON}$(json_sketch 0 $example_file $last_example)" + # add json + PLATFORM_JSON="${PLATFORM_JSON}$(json_sketch 0 $example_file $last_example)" - # increment fails - FAIL_COUNT=$((FAIL_COUNT + 1)) + # increment fails + FAIL_COUNT=$((FAIL_COUNT + 1)) - # mark fail - exit_code=1 + # mark fail + exit_code=1 - continue + continue - fi + fi - # ignore this example if there is an all platform skip - if [[ -f "${example_dir}/.test.skip" ]]; then + # ignore this example if there is an all platform skip + if [[ -f "${example_dir}/.test.skip" ]]; then - # right arrow - echo -e "\xe2\x9e\x9e" + # right arrow + echo -e "\xe2\x9e\x9e" - # add json - PLATFORM_JSON="${PLATFORM_JSON}$(json_sketch -1 $example_file $last_example)" + # add json + PLATFORM_JSON="${PLATFORM_JSON}$(json_sketch -1 $example_file $last_example)" - # increment skips - SKIP_COUNT=$((SKIP_COUNT + 1)) + # increment skips + SKIP_COUNT=$((SKIP_COUNT + 1)) - continue + continue - fi + fi - # ignore this example if there is a skip file preset for this specific platform - if [[ -f "${example_dir}/.${platform_key}.test.skip" ]]; then + # ignore this example if there is a skip file preset for this specific platform + if [[ -f "${example_dir}/.${platform_key}.test.skip" ]]; then - # right arrow - echo -e "\xe2\x9e\x9e" + # right arrow + echo -e "\xe2\x9e\x9e" - # add json - PLATFORM_JSON="${PLATFORM_JSON}$(json_sketch -1 $example_file $last_example)" + # add json + PLATFORM_JSON="${PLATFORM_JSON}$(json_sketch -1 $example_file $last_example)" - # increment skips - SKIP_COUNT=$((SKIP_COUNT + 1)) + # increment skips + SKIP_COUNT=$((SKIP_COUNT + 1)) - continue - - fi + continue + fi - # make sure that all examples are .ino files - if [[ $example =~ \.pde$ ]]; then + # make sure that all examples are .ino files + if [[ $example =~ \.pde$ ]]; then - # heavy X - echo -e """$RED""\xe2\x9c\x96" + # heavy X + echo -e """$RED""\xe2\x9c\x96" - echo -e "-------------------------- DEBUG OUTPUT --------------------------\n" - echo "${LRED}PDE EXTENSION. PLEASE UPDATE TO INO" - echo -e "\n------------------------------------------------------------------\n" + echo -e "-------------------------- DEBUG OUTPUT --------------------------\n" + echo "${LRED}PDE EXTENSION. PLEASE UPDATE TO INO" + echo -e "\n------------------------------------------------------------------\n" - # add json - PLATFORM_JSON="${PLATFORM_JSON}$(json_sketch 0 $example_file $last_example)" + # add json + PLATFORM_JSON="${PLATFORM_JSON}$(json_sketch 0 $example_file $last_example)" - # increment fails - FAIL_COUNT=$((FAIL_COUNT + 1)) + # increment fails + FAIL_COUNT=$((FAIL_COUNT + 1)) - # mark as fail - exit_code=1 + # mark as fail + exit_code=1 - continue + continue - fi + fi - # get the sketch name so we can place the generated files in the respective folder - local sketch_filename_with_ending=$(basename -- "$example") - local sketch_filename="${sketch_filename_with_ending%.*}" - local build_path=$ARDUINO_HEX_DIR/$platform_key/$sketch_filename - # verify the example, and save stdout & stderr to a variable - # we have to avoid reading the exit code of local: - # "when declaring a local variable in a function, the local acts as a command in its own right" - local build_stdout - build_stdout=$(arduino --verify --pref build.path=$build_path --preserve-temp-files $example 2>&1) + # get the sketch name so we can place the generated files in the respective folder + local sketch_filename_with_ending=$(basename -- "$example") + local sketch_filename="${sketch_filename_with_ending%.*}" + local build_path=$ARDUINO_HEX_DIR/$platform_key/$sketch_filename + # verify the example, and save stdout & stderr to a variable + # we have to avoid reading the exit code of local: + # "when declaring a local variable in a function, the local acts as a command in its own right" + local build_stdout + build_stdout=$(arduino --verify --pref build.path=$build_path --preserve-temp-files $example 2>&1) - # echo output if the build failed - if [ $? -ne 0 ]; then + # echo output if the build failed + if [ $? -ne 0 ]; then - # heavy X - echo -e """$RED""\xe2\x9c\x96" + # heavy X + echo -e """$RED""\xe2\x9c\x96" - echo -e "----------------------------- DEBUG OUTPUT -----------------------------\n" - echo "$build_stdout" - echo -e "\n------------------------------------------------------------------------\n" + echo -e "----------------------------- DEBUG OUTPUT -----------------------------\n" + echo "$build_stdout" + echo -e "\n------------------------------------------------------------------------\n" - # add json - PLATFORM_JSON="${PLATFORM_JSON}$(json_sketch 0 $example_file $last_example)" + # add json + PLATFORM_JSON="${PLATFORM_JSON}$(json_sketch 0 $example_file $last_example)" - # increment fails - FAIL_COUNT=$((FAIL_COUNT + 1)) + # increment fails + FAIL_COUNT=$((FAIL_COUNT + 1)) - # mark as fail - exit_code=1 + # mark as fail + exit_code=1 - else + else - # heavy checkmark - echo -e """$GREEN""\xe2\x9c\x93" + # heavy checkmark + echo -e """$GREEN""\xe2\x9c\x93" - # add json - PLATFORM_JSON="${PLATFORM_JSON}$(json_sketch 1 "$example_file" $last_example)" + # add json + PLATFORM_JSON="${PLATFORM_JSON}$(json_sketch 1 "$example_file" $last_example)" - # increment passes - PASS_COUNT=$((PASS_COUNT + 1)) + # increment passes + PASS_COUNT=$((PASS_COUNT + 1)) - fi + fi - done + done - return $exit_code + return $exit_code } # build all examples for every platform in $MAIN_PLATFORMS function build_main_platforms() { - # arrays can't be exported, so we have to eval - eval $MAIN_PLATFORMS + # arrays can't be exported, so we have to eval + eval $MAIN_PLATFORMS - # track the build status all platforms - local exit_code=0 + # track the build status all platforms + local exit_code=0 - # var to hold platforms - local platforms_json="" + # var to hold platforms + local platforms_json="" - # get the last element in the array - local last="${main_platforms[@]:(-1)}" + # get the last element in the array + local last="${main_platforms[@]:(-1)}" - # loop through platforms in main platforms assoc array - for p_key in "${!main_platforms[@]}"; do + # loop through platforms in main platforms assoc array + for p_key in "${!main_platforms[@]}"; do - # is this the last platform in the loop - local last_platform=0 - if [ "$last" == "${main_platforms[$p_key]}" ]; then - last_platform=1 - fi + # is this the last platform in the loop + local last_platform=0 + if [ "$last" == "${main_platforms[$p_key]}" ]; then + last_platform=1 + fi - # build all examples for this platform - build_platform $p_key + # build all examples for this platform + build_platform $p_key - # check if build failed - if [ $? -ne 0 ]; then - platforms_json="${platforms_json}$(json_platform $p_key 0 "$PLATFORM_JSON" $last_platform)" - exit_code=1 - else - platforms_json="${platforms_json}$(json_platform $p_key 1 "$PLATFORM_JSON" $last_platform)" - fi + # check if build failed + if [ $? -ne 0 ]; then + platforms_json="${platforms_json}$(json_platform $p_key 0 "$PLATFORM_JSON" $last_platform)" + exit_code=1 + else + platforms_json="${platforms_json}$(json_platform $p_key 1 "$PLATFORM_JSON" $last_platform)" + fi - done + done - # exit code is opposite of json build status - if [ $exit_code -eq 0 ]; then - json_main_platforms 1 "$platforms_json" - else - json_main_platforms 0 "$platforms_json" - fi + # exit code is opposite of json build status + if [ $exit_code -eq 0 ]; then + json_main_platforms 1 "$platforms_json" + else + json_main_platforms 0 "$platforms_json" + fi - return $exit_code + return $exit_code } # build all examples for every platform in $AUX_PLATFORMS function build_aux_platforms() { - # arrays can't be exported, so we have to eval - eval $AUX_PLATFORMS + # arrays can't be exported, so we have to eval + eval $AUX_PLATFORMS - # track the build status all platforms - local exit_code=0 + # track the build status all platforms + local exit_code=0 - # var to hold platforms - local platforms_json="" + # var to hold platforms + local platforms_json="" - # get the last element in the array - local last="${aux_platforms[@]:(-1)}" + # get the last element in the array + local last="${aux_platforms[@]:(-1)}" - # loop through platforms in main platforms assoc array - for p_key in "${!aux_platforms[@]}"; do + # loop through platforms in main platforms assoc array + for p_key in "${!aux_platforms[@]}"; do - # is this the last platform in the loop - local last_platform=0 - if [ "$last" == "${aux_platforms[$p_key]}" ]; then - last_platform=1 - fi + # is this the last platform in the loop + local last_platform=0 + if [ "$last" == "${aux_platforms[$p_key]}" ]; then + last_platform=1 + fi - # build all examples for this platform - build_platform $p_key + # build all examples for this platform + build_platform $p_key - # check if build failed - if [ $? -ne 0 ]; then - platforms_json="${platforms_json}$(json_platform $p_key 0 "$PLATFORM_JSON" $last_platform)" - exit_code=1 - else - platforms_json="${platforms_json}$(json_platform $p_key 1 "$PLATFORM_JSON" $last_platform)" - fi + # check if build failed + if [ $? -ne 0 ]; then + platforms_json="${platforms_json}$(json_platform $p_key 0 "$PLATFORM_JSON" $last_platform)" + exit_code=1 + else + platforms_json="${platforms_json}$(json_platform $p_key 1 "$PLATFORM_JSON" $last_platform)" + fi - done + done - # exit code is opposite of json build status - if [ $exit_code -eq 0 ]; then - json_main_platforms 1 "$platforms_json" - else - json_main_platforms 0 "$platforms_json" - fi + # exit code is opposite of json build status + if [ $exit_code -eq 0 ]; then + json_main_platforms 1 "$platforms_json" + else + json_main_platforms 0 "$platforms_json" + fi - return $exit_code + return $exit_code } - function build_cplay_platforms() { - # arrays can't be exported, so we have to eval - eval $CPLAY_PLATFORMS + # arrays can't be exported, so we have to eval + eval $CPLAY_PLATFORMS - # track the build status all platforms - local exit_code=0 + # track the build status all platforms + local exit_code=0 - # var to hold platforms - local platforms_json="" + # var to hold platforms + local platforms_json="" - # get the last element in the array - local last="${cplay_platforms[@]:(-1)}" + # get the last element in the array + local last="${cplay_platforms[@]:(-1)}" - # loop through platforms in main platforms assoc array - for p_key in "${!cplay_platforms[@]}"; do + # loop through platforms in main platforms assoc array + for p_key in "${!cplay_platforms[@]}"; do - # is this the last platform in the loop - local last_platform=0 - - if [ "$last" == "${cplay_platforms[$p_key]}" ]; then - last_platform=1 - fi + # is this the last platform in the loop + local last_platform=0 + if [ "$last" == "${cplay_platforms[$p_key]}" ]; then + last_platform=1 + fi - # build all examples for this platform - build_platform $p_key - - # check if build failed - if [ $? -ne 0 ]; then - platforms_json="${platforms_json}$(json_platform $p_key 0 "$PLATFORM_JSON" $last_platform)" - exit_code=1 - else - platforms_json="${platforms_json}$(json_platform $p_key 1 "$PLATFORM_JSON" $last_platform)" - fi + # build all examples for this platform + build_platform $p_key - done + # check if build failed + if [ $? -ne 0 ]; then + platforms_json="${platforms_json}$(json_platform $p_key 0 "$PLATFORM_JSON" $last_platform)" + exit_code=1 + else + platforms_json="${platforms_json}$(json_platform $p_key 1 "$PLATFORM_JSON" $last_platform)" + fi - # exit code is opposite of json build status - if [ $exit_code -eq 0 ]; then - json_main_platforms 1 "$platforms_json" - else - json_main_platforms 0 "$platforms_json" - fi + done - return $exit_code + # exit code is opposite of json build status + if [ $exit_code -eq 0 ]; then + json_main_platforms 1 "$platforms_json" + else + json_main_platforms 0 "$platforms_json" + fi -} + return $exit_code +} function build_samd_platforms() { - # arrays can't be exported, so we have to eval - eval $SAMD_PLATFORMS + # arrays can't be exported, so we have to eval + eval $SAMD_PLATFORMS - # track the build status all platforms - local exit_code=0 + # track the build status all platforms + local exit_code=0 - # var to hold platforms - local platforms_json="" + # var to hold platforms + local platforms_json="" - # get the last element in the array - local last="${samd_platforms[@]:(-1)}" + # get the last element in the array + local last="${samd_platforms[@]:(-1)}" - # loop through platforms in main platforms assoc array - for p_key in "${!samd_platforms[@]}"; do + # loop through platforms in main platforms assoc array + for p_key in "${!samd_platforms[@]}"; do - # is this the last platform in the loop - local last_platform=0 - if [ "$last" == "${samd_platforms[$p_key]}" ]; then - last_platform=1 - fi + # is this the last platform in the loop + local last_platform=0 + if [ "$last" == "${samd_platforms[$p_key]}" ]; then + last_platform=1 + fi - # build all examples for this platform - build_platform $p_key + # build all examples for this platform + build_platform $p_key - # check if build failed - if [ $? -ne 0 ]; then - platforms_json="${platforms_json}$(json_platform $p_key 0 "$PLATFORM_JSON" $last_platform)" - exit_code=1 - else - platforms_json="${platforms_json}$(json_platform $p_key 1 "$PLATFORM_JSON" $last_platform)" + # check if build failed + if [ $? -ne 0 ]; then + platforms_json="${platforms_json}$(json_platform $p_key 0 "$PLATFORM_JSON" $last_platform)" + exit_code=1 + else + platforms_json="${platforms_json}$(json_platform $p_key 1 "$PLATFORM_JSON" $last_platform)" fi - done + done - # exit code is opposite of json build status - if [ $exit_code -eq 0 ]; then - json_main_platforms 1 "$platforms_json" - else - json_main_platforms 0 "$platforms_json" - fi + # exit code is opposite of json build status + if [ $exit_code -eq 0 ]; then + json_main_platforms 1 "$platforms_json" + else + json_main_platforms 0 "$platforms_json" + fi - return $exit_code + return $exit_code } - function build_m4_platforms() { - # arrays can't be exported, so we have to eval - eval $M4_PLATFORMS + # arrays can't be exported, so we have to eval + eval $M4_PLATFORMS - # track the build status all platforms - local exit_code=0 + # track the build status all platforms + local exit_code=0 - # var to hold platforms - local platforms_json="" + # var to hold platforms + local platforms_json="" - # get the last element in the array - local last="${m4_platforms[@]:(-1)}" + # get the last element in the array + local last="${m4_platforms[@]:(-1)}" - # loop through platforms in main platforms assoc array - for p_key in "${!m4_platforms[@]}"; do + # loop through platforms in main platforms assoc array + for p_key in "${!m4_platforms[@]}"; do - # is this the last platform in the loop - local last_platform=0 - if [ "$last" == "${m4_platforms[$p_key]}" ]; then - last_platform=1 - - fi + # is this the last platform in the loop + local last_platform=0 + if [ "$last" == "${m4_platforms[$p_key]}" ]; then + last_platform=1 + fi - # build all examples for this platform - build_platform $p_key + # build all examples for this platform + build_platform $p_key - # check if build failed - if [ $? -ne 0 ]; then - platforms_json="${platforms_json}$(json_platform $p_key 0 "$PLATFORM_JSON" $last_platform)" - exit_code=1 - else - platforms_json="${platforms_json}$(json_platform $p_key 1 "$PLATFORM_JSON" $last_platform)" - fi + # check if build failed + if [ $? -ne 0 ]; then + platforms_json="${platforms_json}$(json_platform $p_key 0 "$PLATFORM_JSON" $last_platform)" + exit_code=1 + else + platforms_json="${platforms_json}$(json_platform $p_key 1 "$PLATFORM_JSON" $last_platform)" + fi - done + done - # exit code is opposite of json build status - if [ $exit_code -eq 0 ]; then - json_main_platforms 1 "$platforms_json" - else - json_main_platforms 0 "$platforms_json" - fi + # exit code is opposite of json build status + if [ $exit_code -eq 0 ]; then + json_main_platforms 1 "$platforms_json" + else + json_main_platforms 0 "$platforms_json" + fi - return $exit_code + return $exit_code } - function build_io_platforms() { - # arrays can't be exported, so we have to eval - eval $IO_PLATFORMS + # arrays can't be exported, so we have to eval + eval $IO_PLATFORMS - # track the build status all platforms - local exit_code=0 + # track the build status all platforms + local exit_code=0 - # var to hold platforms - local platforms_json="" + # var to hold platforms + local platforms_json="" - # get the last element in the array - local last="${io_platforms[@]:(-1)}" + # get the last element in the array + local last="${io_platforms[@]:(-1)}" - # loop through platforms in main platforms assoc array - for p_key in "${!io_platforms[@]}"; do + # loop through platforms in main platforms assoc array + for p_key in "${!io_platforms[@]}"; do - # is this the last platform in the loop - local last_platform=0 - if [ "$last" == "${io_platforms[$p_key]}" ]; then - last_platform=1 - fi + # is this the last platform in the loop + local last_platform=0 + if [ "$last" == "${io_platforms[$p_key]}" ]; then + last_platform=1 + fi - # build all examples for this platform - build_platform $p_key + # build all examples for this platform + build_platform $p_key - # check if build failed - if [ $? -ne 0 ]; then - platforms_json="${platforms_json}$(json_platform $p_key 0 "$PLATFORM_JSON" $last_platform)" - exit_code=1 + # check if build failed + if [ $? -ne 0 ]; then + platforms_json="${platforms_json}$(json_platform $p_key 0 "$PLATFORM_JSON" $last_platform)" + exit_code=1 else - platforms_json="${platforms_json}$(json_platform $p_key 1 "$PLATFORM_JSON" $last_platform)" - fi + platforms_json="${platforms_json}$(json_platform $p_key 1 "$PLATFORM_JSON" $last_platform)" + fi - done + done - # exit code is opposite of json build status - if [ $exit_code -eq 0 ]; then - json_main_platforms 1 "$platforms_json" - else - json_main_platforms 0 "$platforms_json" - fi + # exit code is opposite of json build status + if [ $exit_code -eq 0 ]; then + json_main_platforms 1 "$platforms_json" + else + json_main_platforms 0 "$platforms_json" + fi - return $exit_code + return $exit_code } - function build_arcada_platforms() { - # arrays can't be exported, so we have to eval - eval $ARCADA_PLATFORMS + # arrays can't be exported, so we have to eval + eval $ARCADA_PLATFORMS - # track the build status all platforms - local exit_code=0 + # track the build status all platforms + local exit_code=0 - # var to hold platforms - local platforms_json="" + # var to hold platforms + local platforms_json="" - # get the last element in the array - local last="${arcada_platforms[@]:(-1)}" + # get the last element in the array + local last="${arcada_platforms[@]:(-1)}" - # loop through platforms in main platforms assoc array - for p_key in "${!arcada_platforms[@]}"; do + # loop through platforms in main platforms assoc array + for p_key in "${!arcada_platforms[@]}"; do - # is this the last platform in the loop - local last_platform=0 - if [ "$last" == "${arcada_platforms[$p_key]}" ]; then - last_platform=1 - fi + # is this the last platform in the loop + local last_platform=0 + if [ "$last" == "${arcada_platforms[$p_key]}" ]; then + last_platform=1 + fi - # build all examples for this platform - build_platform $p_key + # build all examples for this platform + build_platform $p_key - # check if build failed - if [ $? -ne 0 ]; then - platforms_json="${platforms_json}$(json_platform $p_key 0 "$PLATFORM_JSON" $last_platform)" - exit_code=1 - else - platforms_json="${platforms_json}$(json_platform $p_key 1 "$PLATFORM_JSON" $last_platform)" - fi + # check if build failed + if [ $? -ne 0 ]; then + platforms_json="${platforms_json}$(json_platform $p_key 0 "$PLATFORM_JSON" $last_platform)" + exit_code=1 + else + platforms_json="${platforms_json}$(json_platform $p_key 1 "$PLATFORM_JSON" $last_platform)" + fi - done + done - # exit code is opposite of json build status - if [ $exit_code -eq 0 ]; then - json_main_platforms 1 "$platforms_json" - else - json_main_platforms 0 "$platforms_json" - fi + # exit code is opposite of json build status + if [ $exit_code -eq 0 ]; then + json_main_platforms 1 "$platforms_json" + else + json_main_platforms 0 "$platforms_json" + fi - return $exit_code + return $exit_code } - function build_nrf5x_platforms() { - # arrays can't be exported, so we have to eval - eval $NRF5X_PLATFORMS + # arrays can't be exported, so we have to eval + eval $NRF5X_PLATFORMS - # track the build status all platforms - local exit_code=0 + # track the build status all platforms + local exit_code=0 - # var to hold platforms - local platforms_json="" + # var to hold platforms + local platforms_json="" - # get the last element in the array - local last="${nrf5x_platforms[@]:(-1)}" + # get the last element in the array + local last="${nrf5x_platforms[@]:(-1)}" - # loop through platforms in main platforms assoc array - for p_key in "${!nrf5x_platforms[@]}"; do + # loop through platforms in main platforms assoc array + for p_key in "${!nrf5x_platforms[@]}"; do - # is this the last platform in the loop - local last_platform=0 - if [ "$last" == "${nrf5x_platforms[$p_key]}" ]; then - last_platform=1 - fi + # is this the last platform in the loop + local last_platform=0 + if [ "$last" == "${nrf5x_platforms[$p_key]}" ]; then + last_platform=1 + fi - # build all examples for this platform - build_platform $p_key + # build all examples for this platform + build_platform $p_key - # check if build failed - if [ $? -ne 0 ]; then - platforms_json="${platforms_json}$(json_platform $p_key 0 "$PLATFORM_JSON" $last_platform)" - exit_code=1 - else - platforms_json="${platforms_json}$(json_platform $p_key 1 "$PLATFORM_JSON" $last_platform)" - fi + # check if build failed + if [ $? -ne 0 ]; then + platforms_json="${platforms_json}$(json_platform $p_key 0 "$PLATFORM_JSON" $last_platform)" + exit_code=1 + else + platforms_json="${platforms_json}$(json_platform $p_key 1 "$PLATFORM_JSON" $last_platform)" + fi - done + done - # exit code is opposite of json build status - if [ $exit_code -eq 0 ]; then - json_main_platforms 1 "$platforms_json" - else - json_main_platforms 0 "$platforms_json" - fi + # exit code is opposite of json build status + if [ $exit_code -eq 0 ]; then + json_main_platforms 1 "$platforms_json" + else + json_main_platforms 0 "$platforms_json" + fi - return $exit_code + return $exit_code } + # generate json string for a sketch function json_sketch() { - # -1: skipped, 0: failed, 1: passed - local status_number=$1 + # -1: skipped, 0: failed, 1: passed + local status_number=$1 - # the filename of the sketch - local sketch=$2 + # the filename of the sketch + local sketch=$2 - # is this the last sketch for this platform? 0: no, 1: yes - local last_sketch=$3 + # is this the last sketch for this platform? 0: no, 1: yes + local last_sketch=$3 - # echo out the json - echo -n "\"$sketch\": $status_number" + # echo out the json + echo -n "\"$sketch\": $status_number" - # echo a comma unless this is the last sketch for the platform - if [ $last_sketch -ne 1 ]; then - echo -n ", " - fi + # echo a comma unless this is the last sketch for the platform + if [ $last_sketch -ne 1 ]; then + echo -n ", " + fi } # generate json string for a platform function json_platform() { - # the platform key from main platforms or aux platforms - local platform_key=$1 + # the platform key from main platforms or aux platforms + local platform_key=$1 - # 0: failed, 1: passed - local status_number=$2 + # 0: failed, 1: passed + local status_number=$2 - # the json string for the verified sketches - local sketch_json=$3 + # the json string for the verified sketches + local sketch_json=$3 - # is this the last platform we are building? 0: no, 1: yes - local last_platform=$4 + # is this the last platform we are building? 0: no, 1: yes + local last_platform=$4 - echo -n "\"$platform_key\": { \"status\": $status_number, \"builds\": { $sketch_json } }" + echo -n "\"$platform_key\": { \"status\": $status_number, \"builds\": { $sketch_json } }" - # echo a comma unless this is the last sketch for the platform - if [ $last_platform -ne 1 ]; then - echo -n ", " - fi + # echo a comma unless this is the last sketch for the platform + if [ $last_platform -ne 1 ]; then + echo -n ", " + fi } # generate final json string function json_main_platforms() { - # 0: failed, 1: passed - local status_number = $1 + # 0: failed, 1: passed + local status_number=$1 - # the json string for the main platforms - local platforms_json=$2 + # the json string for the main platforms + local platforms_json=$2 - local repo=$(git config --get remote.origin.url) + local repo=$(git config --get remote.origin.url) - echo -e "\n||||||||||||||||||||||||||||| JSON STATUS ||||||||||||||||||||||||||||||" + echo -e "\n||||||||||||||||||||||||||||| JSON STATUS ||||||||||||||||||||||||||||||" - echo -n "{ \"repo\": \"$repo\", " - echo -n "\"status\": $status_number, " - echo -n "\"passed\": $PASS_COUNT, " - echo -n "\"skipped\": $SKIP_COUNT, " - echo -n "\"failed\": $FAIL_COUNT, " - echo "\"platforms\": { $platforms_json } }" + echo -n "{ \"repo\": \"$repo\", " + echo -n "\"status\": $status_number, " + echo -n "\"passed\": $PASS_COUNT, " + echo -n "\"skipped\": $SKIP_COUNT, " + echo -n "\"failed\": $FAIL_COUNT, " + echo "\"platforms\": { $platforms_json } }" - echo -e "||||||||||||||||||||||||||||| JSON STATUS ||||||||||||||||||||||||||||||\n" + echo -e "||||||||||||||||||||||||||||| JSON STATUS ||||||||||||||||||||||||||||||\n" } #If there is an argument if [[ ! $# -eq 0 ]] ; then -# define output directory for .hex files -export ARDUINO_HEX_DIR=arduino_build_$TRAVIS_BUILD_NUMBER + # define output directory for .hex files + export ARDUINO_HEX_DIR=arduino_build_$TRAVIS_BUILD_NUMBER -# link test library folder to the arduino libraries folder -ln -s $TRAVIS_BUILD_DIR $HOME/arduino_ide/libraries/Adafruit_Test_Library + # link test library folder to the arduino libraries folder + ln -s $TRAVIS_BUILD_DIR $HOME/arduino_ide/libraries/Adafruit_Test_Library -# add the arduino CLI to our PATH -export PATH="$HOME/arduino_ide:$PATH" + # add the arduino CLI to our PATH + export PATH="$HOME/arduino_ide:$PATH" -"$@" -fi + "$@" + +fi \ No newline at end of file diff --git a/keywords.txt b/keywords.txt index 4e47ad4..313fe08 100644 --- a/keywords.txt +++ b/keywords.txt @@ -1,5 +1,5 @@ ####################################### -# Syntax Coloring Map For +# Syntax Coloring Map For I2C_Scanner ####################################### ####################################### diff --git a/library.json b/library.json index f6b77f6..8cf55df 100644 --- a/library.json +++ b/library.json @@ -1,8 +1,8 @@ { - "name": "", + "name": "I2C_Scanner", "version": "1.0.0", - "keywords": "", - "description": "", + "keywords": "I2C, Device, Scanner, Console, VT100, Multiplexer, Sensor", + "description": "The Two-Wire interface is extremely useful for connecting multiple devices, as they can all share the same two pins (plus a ground return). This is because the devices are \"addressable\". Each device needs to have a unique address in the range 0x03 to 0x77. This tool scans the master I2C bus and reports connected devices.", "authors": { "name": "Mehmet Gunce Akkoyun", @@ -11,7 +11,7 @@ }, "license": "MIT", "frameworks": "arduino", - "headers": ".h", + "headers": "I2C_Scanner.h", "platforms": [ "atmelavr", @@ -20,17 +20,13 @@ "repository": { "type": "git", - "url": "https://github.com/akkoyun/.git" + "url": "https://github.com/akkoyun/I2C_Scanner.git" }, "examples": [ { - "name": "", - "base": "examples/", - "files": [ - ".ino" - ] + "name": "I2C Device Scanner", + "base": "examples/Device_Scanner", + "files": ["Device_Scanner.ino"] } ] -} - - +} \ No newline at end of file diff --git a/library.properties b/library.properties index 5e600a8..e74d607 100644 --- a/library.properties +++ b/library.properties @@ -1,11 +1,11 @@ -name= +name=I2C_Scanner version=1.0.0 author=Gunce Akkoyun maintainer=Gunce Akkoyun -sentence= -paragraph= -category=Communication -url=https://github.com/akkoyun/ +sentence=Master I2C Bus Device Scanner. +paragraph=The Two-Wire interface is extremely useful for connecting multiple devices, as they can all share the same two pins (plus a ground return). This is because the devices are "addressable". Each device needs to have a unique address in the range 0x03 to 0x77. This tool scans the master I2C bus and reports connected devices. +category=Sensors +url=https://github.com/akkoyun/I2C_Scanner architectures=* -includes=.h +includes=I2C_Scanner.h types=Arduino diff --git a/src/Config.h b/src/Config.h deleted file mode 100644 index 726c4cc..0000000 --- a/src/Config.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef __Defination__ -#define __Defination__ - -// Define LED Variables -#define __RED__ 0 -#define __GREEN__ 1 -#define __BLUE__ 2 - -struct Struct { - - // Library firmware variable - const char Firmware[9]; - - // Hardware firmware variable - const char Hardware[9]; - -}; - -#endif diff --git a/src/Defination.h b/src/Defination.h deleted file mode 100644 index 726c4cc..0000000 --- a/src/Defination.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef __Defination__ -#define __Defination__ - -// Define LED Variables -#define __RED__ 0 -#define __GREEN__ 1 -#define __BLUE__ 2 - -struct Struct { - - // Library firmware variable - const char Firmware[9]; - - // Hardware firmware variable - const char Hardware[9]; - -}; - -#endif diff --git a/src/I2C_Scanner.cpp b/src/I2C_Scanner.cpp new file mode 100644 index 0000000..119862d --- /dev/null +++ b/src/I2C_Scanner.cpp @@ -0,0 +1,96 @@ +/* ******************************************************************************* + * Copyright (C) 2014-2020 Mehmet Gunce Akkoyun Can not be copied and/or + * distributed without the express permission of Mehmet Gunce Akkoyun. + * + * Library : I2C Device Scanner + * Code Developer : Mehmet Gunce Akkoyun (akkoyun@me.com) + *********************************************************************************/ + +#include + +bool _I2C_Scanner::Draw_Table(void) { + + // Draw Console Table + for (uint8_t i = 1; i <= 23; i = i + 2) {Terminal.Draw_Horizontal_Divider(i, 1, 120, false);} + Terminal.Draw_Vertical_Divider(1, 1, 22); + for (uint8_t i = 9; i <= 120; i = i + 7) {Terminal.Draw_Vertical_Divider(3, i, 18);} + Terminal.Draw_Vertical_Divider(1, 121, 22); + + // Draw Corners + Terminal.Set_Cursor(1,1); Serial.print("┌"); + Terminal.Set_Cursor(1,121); Serial.print("┐"); + Terminal.Set_Cursor(23,1); Serial.print("└"); + Terminal.Set_Cursor(23,121); Serial.print("┘"); + + // Draw T + for (uint8_t i = 3; i <= 21; i = i + 2) {Terminal.Set_Cursor(i,1); Serial.print("├");} + for (uint8_t i = 3; i <= 21; i = i + 2) {Terminal.Set_Cursor(i,121); Serial.print("┤");} + + // Draw CrosSection + for (uint8_t i = 5; i <= 19; i = i + 2) {for (uint8_t j = 9; j <= 120; j = j + 7) {Terminal.Set_Cursor(i,j); Serial.print("┼");}} + + // Write Text + Terminal.Print_Box_Title(1,1,60,"I2C DEVICE EXPLORER"); + Terminal.Text(22,3,WHITE,"Total connected device :"); + Terminal.Text(22,86,WHITE,"Current Mux Channel [0-8] :"); + Terminal.Text(24,100,WHITE,"github.com/akkoyun"); + + // Print headers + uint8_t _C = 0; + for (uint8_t i = 6; i <= 21; i = i + 2) { + Terminal.Set_Cursor(i,3); Serial.print("0x"); + Terminal.Set_Cursor(i,5); Serial.print(_C); + Terminal.Set_Cursor(i,6); Serial.print("_"); + _C++; + } + uint8_t _R = 0; + for (uint8_t i = 11; i <= 121; i = i + 7) { + Terminal.Set_Cursor(4,i); Serial.print("0x_"); + Terminal.Set_Cursor(4,i+3); Serial.print(_R, HEX); + _R++; + } + +} +bool _I2C_Scanner::Device_Scan(void) { + + // Declare Address Variable + uint8_t _Address = 0x00; + + for (uint8_t j = 6; j < 21; j = j + 2) { + + // Control Device Line 1 + for (uint8_t i = 11; i < 121; i = i +7) { + + // Handle Reserved + if (_Address > 0x03 and _Address < 0x78) { + + // Control Device + if (I2C.Control_Device(_Address)) { + + Terminal.Text(j,i,CYAN,String("0x")); + Terminal.Text(j,i+2,CYAN,String(_Address,HEX)); + + } else { + + Terminal.Text(j,i,WHITE,"----"); + + } + + } + + // Handle Address + _Address++; + + } + + } + + // Print Mux Channel + Terminal.Text(22,115,CYAN,String(I2C._Multiplexer_Current_Channel)); + +} + +// Define Library Class +_I2C_Scanner I2C_Scanner; + +// 1903 \ No newline at end of file diff --git a/src/Library.h b/src/I2C_Scanner.h similarity index 62% rename from src/Library.h rename to src/I2C_Scanner.h index 4debc2e..593c929 100644 --- a/src/Library.h +++ b/src/I2C_Scanner.h @@ -2,31 +2,28 @@ * Copyright (C) 2014-2022 Mehmet Gunce Akkoyun Can not be copied and/or * distributed without the express permission of Mehmet Gunce Akkoyun. * - * Library : Library + * Library : I2C Device Scannner * Code Developer : Mehmet Gunce Akkoyun (akkoyun@me.com) * *********************************************************************************/ -#ifndef __Library__ -#define __Library__ - -// Define Arduino Library -#ifndef __Arduino__ -#include -#endif +#ifndef __I2C_Scanner__ +#define __I2C_Scanner__ // Define Library Structures -#include -#include +#include -class Library { +class _I2C_Scanner { public: + bool Draw_Table(void); + bool Device_Scan(void); + private: }; -extern Library Library1; +extern _I2C_Scanner I2C_Scanner; -#endif /* defined(__Library__) */ +#endif /* defined(__I2C_Scanner__) */ diff --git a/src/I2C_Scanner_Defination.h b/src/I2C_Scanner_Defination.h new file mode 100644 index 0000000..0fb0a18 --- /dev/null +++ b/src/I2C_Scanner_Defination.h @@ -0,0 +1,19 @@ +#ifndef __I2C_Scanner_Defination__ +#define __I2C_Scanner_Defination__ + +// Define Arduino Library +#ifndef __Arduino__ +#include +#endif + +// Define I2C Functions Library +#ifndef __I2C_Functions__ +#include +#endif + +// Define Console Library +#ifndef __Console__ +#include +#endif + +#endif diff --git a/src/Library.cpp b/src/Library.cpp deleted file mode 100644 index 07fdfc8..0000000 --- a/src/Library.cpp +++ /dev/null @@ -1,20 +0,0 @@ -/* ******************************************************************************* - * Copyright (C) 2014-2020 Mehmet Gunce Akkoyun Can not be copied and/or - * distributed without the express permission of Mehmet Gunce Akkoyun. - * - * Library : Library - * Code Developer : Mehmet Gunce Akkoyun (akkoyun@me.com) - *********************************************************************************/ - -#include - -bool Library::Function(void) { - - - -} - -// Define Library Class -Library Library1; - -// 1903 \ No newline at end of file