Skip to content
This repository was archived by the owner on Apr 17, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions cmake/Platform/Libraries/LibrariesFinder.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# _library_name - Name of the Arduino library to find.
# _board_id - Board ID associated with the linked Core Lib.
# [3RD_PARTY] - Whether library should be treated as a 3rd Party library.
# [HEADER_ONLY] - Whether library should be treated as header-only library.
#=============================================================================#
function(find_arduino_library _target_name _library_name _board_id)

Expand All @@ -17,22 +18,24 @@ function(find_arduino_library _target_name _library_name _board_id)
convert_string_to_pascal_case(${_library_name} _library_name)
endif ()

find_file(library_properties_file library.properties
PATHS ${ARDUINO_SDK_LIBRARIES_PATH} ${ARDUINO_CMAKE_SKETCHBOOK_PATH}/libraries
PATH_SUFFIXES ${_library_name}
find_file(library_path
NAMES ${_library_name}
PATHS ${ARDUINO_SDK_LIBRARIES_PATH} ${ARDUINO_CMAKE_SKETCHBOOK_PATH}
${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}
PATH_SUFFIXES libraries dependencies
NO_DEFAULT_PATH
NO_CMAKE_FIND_ROOT_PATH)

if (${library_properties_file} MATCHES "NOTFOUND")
message(SEND_ERROR "Couldn't find library named ${_library_name}")
else () # Library is found

get_filename_component(library_path ${library_properties_file} DIRECTORY)
else () # Library is found

find_library_header_files("${library_path}" library_headers)

if (NOT library_headers)
message(SEND_ERROR "Couldn't find any header files for the ${_library_name} library")

else ()

if (parsed_args_HEADER_ONLY)
Expand All @@ -47,18 +50,21 @@ function(find_arduino_library _target_name _library_name _board_id)
"${_library_name} library - Is it a header-only library?"
"If so, please pass the HEADER_ONLY option "
"as an argument to the function")

else ()

set(sources ${library_headers} ${library_sources})

add_arduino_library(${_target_name} ${_board_id}
LIB_PROPS_FILE ${library_properties_file}
${sources})
add_arduino_library(${_target_name} ${_board_id} ${sources})

endif ()

endif ()

endif ()

endif ()

unset(library_properties_file CACHE)
unset(library_path CACHE)

endfunction()
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ function(resolve_library_architecture _library_sources _return_var)
else ()

# Warn user and assume library is arch-agnostic
message(STATUS "Library's properties file can't be found "
"under its' root directory - Assuming the library "
"is architecture-agnostic (supports all architectures)")
message(STATUS "Library's properties file can't be found under its' root directory.\n\t"
"Assuming the library is architecture-agnostic (supports all architectures)")
set(${_return_var} "${_library_sources}" PARENT_SCOPE)
return()

Expand Down
20 changes: 18 additions & 2 deletions cmake/Platform/Sources/ArduinoLibrarySourcesSeeker.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@
function(find_library_header_files _base_path _return_var)

if (EXISTS ${_base_path}/src) # 'src' sub-dir exists and should contain sources

# Headers are always searched recursively under the 'src' sub-dir
find_header_files(${_base_path}/src headers RECURSE)

else ()
find_header_files(${_base_path} headers)

# Both root-dir and 'utility' sub-dir are searched when 'src' doesn't exist
find_header_files(${_base_path} root_headers)
find_header_files(${_base_path}/utility utility_headers)

set(headers ${root_headers} ${utility_headers})

endif ()

set(${_return_var} "${headers}" PARENT_SCOPE)
Expand All @@ -28,10 +36,18 @@ endfunction()
function(find_library_source_files _base_path _return_var)

if (EXISTS ${_base_path}/src)

# Sources are always searched recursively under the 'src' sub-dir
find_source_files(${_base_path}/src sources RECURSE)

else ()
find_source_files(${_base_path} sources)

# Both root-dir and 'utility' sub-dir are searched when 'src' doesn't exist
find_source_files(${_base_path} root_sources)
find_source_files(${_base_path}/utility utility_sources)

set(sources ${root_sources} ${utility_sources})

endif ()

set(${_return_var} "${sources}" PARENT_SCOPE)
Expand Down
25 changes: 8 additions & 17 deletions cmake/Platform/Targets/ArduinoLibraryTarget.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,22 @@
# As it's an Arduino library, it also finds and links all dependent platform libraries (if any).
# _target_name - Name of the library target to be created. Usually library's real name.
# _board_id - Board ID associated with the linked Core Lib.
# [LIB_PROPS_FILE] - Full path to the library's properties file. Optional.
# [Sources] - List of source files (Could also be headers for code-inspection in some IDEs)
# to create the executable from, similar to CMake's built-in add_executable.
#=============================================================================#
function(add_arduino_library _target_name _board_id)

cmake_parse_arguments(parsed_args "" "LIB_PROPS_FILE" "" ${ARGN})
parse_sources_arguments(parsed_sources "" "LIB_PROPS_FILE" "" "${ARGN}")
parse_sources_arguments(parsed_sources "" "" "" "${ARGN}")

if (parsed_args_LIB_PROPS_FILE)
resolve_library_architecture("${parsed_sources}" arch_resolved_sources
LIB_PROPS_FILE ${parsed_args_LIB_PROPS_FILE})
else ()

get_sources_root_directory("${parsed_sources}" library_root_dir)
get_sources_root_directory("${parsed_sources}" library_root_dir)

get_library_properties_file(${library_root_dir} library_properties_file)

if (library_properties_file) # Properties file has been found
resolve_library_architecture("${parsed_sources}" arch_resolved_sources
LIB_PROPS_FILE ${library_properties_file})
else ()
resolve_library_architecture("${parsed_sources}" arch_resolved_sources)
endif ()
get_library_properties_file(${library_root_dir} library_properties_file)

if (library_properties_file) # Properties file has been found
resolve_library_architecture("${parsed_sources}" arch_resolved_sources
LIB_PROPS_FILE ${library_properties_file})
else ()
resolve_library_architecture("${parsed_sources}" arch_resolved_sources)
endif ()

_add_arduino_cmake_library(${_target_name} ${_board_id} "${arch_resolved_sources}")
Expand Down
2 changes: 1 addition & 1 deletion cmake/Platform/Utilities/LibraryUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function(get_library_properties_file _library_root_directory _return_var)
set(lib_props_file ${absolute_lib_root_dir}/${ARDUINO_CMAKE_LIBRARY_PROPERTIES_FILE_NAME})

if (NOT EXISTS ${lib_props_file})
message(WARNING "Library's properties file doesn't exist under the given root directory.\n"
message(STATUS "Library's properties file doesn't exist under the given root directory.\n\t"
"Root directory: ${absolute_lib_root_dir}")
return()
endif ()
Expand Down
22 changes: 12 additions & 10 deletions examples/3rd-party-library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ add_arduino_executable(3rd_Party_Arduino_Library ${board_id} 3rd_party.cpp
target_include_directories(3rd_Party_Arduino_Library PRIVATE include)

# Add the "NeoPixel" library manually using the library addition API
add_arduino_library(Adafruit_NeoPixel ${board_id} libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp)
target_include_directories(Adafruit_NeoPixel PUBLIC libraries/Adafruit_NeoPixel)
add_arduino_library(adafruit_NeoPixel ${board_id} libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp)
target_include_directories(adafruit_NeoPixel PUBLIC libraries/Adafruit_NeoPixel)

# Find the "GFX" library by 'tricking' the framework to use current directory as the Sketchbook path,
# allowing us to use the 'find' API
set(ARDUINO_CMAKE_SKETCHBOOK_PATH "${CMAKE_CURRENT_LIST_DIR}")
find_arduino_library(Adafruit_GFX Adafruit-GFX-Library ${board_id} 3RD_PARTY)
# Find the "GFX" library - It's located under the 'libraries' sub-dir, which is a valid search path
find_arduino_library(adafruit_GFX Adafruit-GFX-Library ${board_id} 3RD_PARTY)
# We can also explicitly add additional directories to the target,
# as only root dir and 'src' sub-dir are added by default
target_source_directories(Adafruit_GFX DIRS libraries/Adafruit-GFX-Library/Fonts)
# as only root dir and 'src' and 'utility' sub-dirs are added by default
target_source_directories(adafruit_GFX DIRS libraries/Adafruit-GFX-Library/Fonts)

# We can even automatically find a library that doesn't have a properties file!
find_arduino_library(sky_writer Skywriter ${board_id} 3RD_PARTY)

# Link all libraries to our previously created target
link_arduino_library(3rd_Party_Arduino_Library Adafruit_NeoPixel ${board_id})
link_arduino_library(3rd_Party_Arduino_Library Adafruit_GFX ${board_id})
link_arduino_library(3rd_Party_Arduino_Library adafruit_NeoPixel ${board_id})
link_arduino_library(3rd_Party_Arduino_Library adafruit_GFX ${board_id})
link_arduino_library(3rd_Party_Arduino_Library sky_writer ${board_id})
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#include <Adafruit_NeoPixel.h>
#include <Wire.h>

#define PIN 8

Adafruit_NeoPixel Neopixel = Adafruit_NeoPixel(64, PIN, NEO_GRB + NEO_KHZ800);

unsigned long brightness = 50;
unsigned char color = 0;

// Include string names of gestures/touches for testing
//#define SKYWRITER_INC_DEBUG_STRINGS
#include "skywriter.h"

unsigned int max_x, max_y, max_z;
unsigned int min_x, min_y, min_z;

void setup() {
Serial.begin(9600);
while(!Serial){};
Serial.println("Hello world!");

Neopixel.begin();
Neopixel.setBrightness(brightness);
Neopixel.show(); // Initialize all pixels to 'off'


Skywriter.begin(12, 13);
Skywriter.onTouch(touch);
//Skywriter.onAirwheel(airwheel);
Skywriter.onGesture(gesture);
Skywriter.onXYZ(xyz);
}

void loop() {
Skywriter.poll();
/*int x;
for(x = 0; x < 64; x++){
Neopixel.setPixelColor(x, Wheel(color));
}*/
Neopixel.show();
}

void xyz(unsigned int x, unsigned int y, unsigned int z){
if (x < min_x) min_x = x;
if (y < min_y) min_y = y;
if (z < min_z) min_z = z;
if (x > max_x) max_x = x;
if (y > max_y) max_y = y;
if (z > max_z) max_z = z;

unsigned char pixel_x = map(x, min_x, max_x, 0, 7);
unsigned char pixel_y = map(y, min_y, max_y, 0, 7);
uint32_t color = Wheel(map(z, min_z, max_z, 0, 255));


Neopixel.setPixelColor(pixel_x*8 + pixel_y, color);

char buf[64];
sprintf(buf, "%05u:%05u:%05u gest:%02u touch:%02u", x, y, z, Skywriter.last_gesture, Skywriter.last_touch);
Serial.println(buf);
}

void gesture(unsigned char type){
Serial.println("Got gesture ");
Serial.print(type,DEC);
Serial.print('\n');

if( type == SW_FLICK_WEST_EAST ){
Neopixel.clear();
}
}

void touch(unsigned char type){
Serial.println("Got touch ");
Serial.print(type,DEC);
Serial.print('\n');

if( type == SW_TOUCH_CENTER ){
Neopixel.setBrightness(map(Skywriter.x, min_x, max_x, 0, 255));
//color = map(Skywriter.y, min_y, max_y, 0, 255);
}
/*else if( type == SW_TOUCH_EAST ){
Neopixel.setBrightness(0);
}
else if( type == SW_TOUCH_WEST ){
Neopixel.setBrightness(255);
}*/
}

void airwheel(int delta){
Serial.println("Got airwheel ");
Serial.print(delta);
Serial.print('\n');

brightness += (delta/100.0);
Neopixel.setBrightness(brightness % 255);
}

uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return Neopixel.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return Neopixel.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return Neopixel.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}

Loading