Skip to content

Commit bdc0589

Browse files
committed
Following #5 Add auto downloader libraries
1 parent b3cb073 commit bdc0589

File tree

3 files changed

+90
-14
lines changed

3 files changed

+90
-14
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@
33

44
build/
55
# IDE
6-
.vscode/
6+
.vscode/
7+
# Do not commit libraries
8+
# Are located in firmware folder
9+
libraries/
+25-13
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,32 @@
11
cmake_minimum_required(VERSION 2.8.3)
22

3-
include_directories(${ROS_LIB_DIR})
3+
# REFERENCE
4+
# http://wiki.ros.org/rosserial_arduino/Tutorials/CMake
5+
# https://github.com/queezythegreat/arduino-cmake#creating-firmware-images
6+
#set(led_controller_SRCS chatter.cpp ${ROS_LIB_DIR}/time.cpp)
7+
set(led_controller_SRCS led_controller/led_controller.ino led_controller/led_effect.ino led_controller/system.ino ${ROS_LIB_DIR}/time.cpp)
8+
#set(led_controller_HDRS chatter.h)
9+
set(led_controller_PORT /dev/ttyUSB0)
10+
# Arduino nano328 is the same of uno!
11+
# See: http://code.google.com/p/arduino/wiki/Platforms
12+
set(led_controller_BOARD uno)
413

14+
include_directories(${ROS_LIB_DIR})
515
# Remove this if using an Arduino without native USB (eg, other than Leonardo)
616
add_definitions(-DUSB_CON)
717

8-
# ARDUINO_SDK in /usr/share/arduino
9-
#${ARDUINO_SDK}/libraries
10-
# link_directories(${ARDUINO_SDK}/libraries)
11-
12-
# https://github.com/adafruit/Adafruit_NeoPixel
13-
link_directories(/home/nvidia/Adafruit_NeoPixel)
18+
# Set author to download
19+
set(GIT_AUTHOR "adafruit")
20+
set(GIT_REPO "Adafruit_NeoPixel")
21+
# Check existence library
22+
set(PATH "${CMAKE_CURRENT_SOURCE_DIR}/libraries/${GIT_REPO}")
23+
if (NOT EXISTS "${PATH}")
24+
message(STATUS "Library does not exist. Downloading now ...")
25+
# https://stackoverflow.com/questions/35689501/cmakes-execute-process-and-arbitrary-shell-scripts
26+
execute_process(COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/arduino_libraries.sh ${CMAKE_CURRENT_SOURCE_DIR} ${GIT_AUTHOR} ${GIT_REPO})
27+
endif()
1428

15-
generate_arduino_firmware(led_controller
16-
SKETCH led_controller
17-
# SRCS led_controller/led_controller.ino led_controller/led_effect.ino led_controller/system.ino ${ROS_LIB_DIR}/time.cpp
18-
BOARD nano
19-
PORT /dev/nano
20-
)
29+
# Link directories libraries
30+
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/libraries)
31+
# Generate arduino firmware
32+
generate_arduino_firmware(led_controller)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
# Copyright (C) 2020, Raffaello Bonghi <[email protected]>
3+
# All rights reserved
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions are met:
6+
# 1. Redistributions of source code must retain the above copyright
7+
# notice, this list of conditions and the following disclaimer.
8+
# 2. Redistributions in binary form must reproduce the above copyright
9+
# notice, this list of conditions and the following disclaimer in the
10+
# documentation and/or other materials provided with the distribution.
11+
# 3. Neither the name of the copyright holder nor the names of its
12+
# contributors may be used to endorse or promote products derived
13+
# from this software without specific prior written permission.
14+
#
15+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
16+
# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
17+
# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18+
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19+
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22+
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
24+
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
25+
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
27+
red=`tput setaf 1`
28+
green=`tput setaf 2`
29+
reset=`tput sgr0`
30+
31+
# Check if a path is included
32+
if [ -z $1 ] ; then
33+
echo "${red}Require to pass a path!${reset}"
34+
exit 1
35+
fi
36+
# Get path
37+
LIBRARY_PATH="$1/libraries"
38+
# Library to download
39+
AUTHOR=$2
40+
REPOSITORY=$3
41+
# Get latest release from GitHub api, Get tag line
42+
echo "Find last version of $AUTHOR $REPOSITORY"
43+
TAG_VERSION=$(curl --silent "https://api.github.com/repos/$AUTHOR/$REPOSITORY/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
44+
# Print version
45+
echo "Download $TAG_VERSION last version $REPOSITORY"
46+
# Download Adafruit library
47+
if [ ! -d "$LIBRARY_PATH" ] ; then
48+
echo "Make folder $LIBRARY_PATH"
49+
mkdir "$LIBRARY_PATH"
50+
fi
51+
# Download latest version
52+
wget --output-document "$LIBRARY_PATH/latest.tar.gz" "https://github.com/$AUTHOR/$REPOSITORY/archive/$TAG_VERSION.tar.gz"
53+
# Unzip file
54+
tar -xf "$LIBRARY_PATH/latest.tar.gz" -C "$LIBRARY_PATH"
55+
# Remove file
56+
rm "$LIBRARY_PATH/latest.tar.gz"
57+
# Rename folder
58+
mv "$LIBRARY_PATH/$REPOSITORY-$TAG_VERSION" "$LIBRARY_PATH/$REPOSITORY"
59+
# Download complete
60+
echo "${green}$REPOSITORY added in $LIBRARY_PATH ${reset}"
61+
# EOF

0 commit comments

Comments
 (0)