Skip to content
This repository was archived by the owner on Apr 17, 2023. It is now read-only.

Commit eef24be

Browse files
committed
Modified find_arduino_library function to search for library's root directory.
This is enough to determine whether the library exists and adds support for libraries that don't specify the properties file. The properties file is found later in the `add_arduino_library` function. Added an example for a properties-less library named 'Skywriter'.
1 parent 67307b6 commit eef24be

File tree

10 files changed

+569
-14
lines changed

10 files changed

+569
-14
lines changed

cmake/Platform/Libraries/LibrariesFinder.cmake

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ function(find_arduino_library _target_name _library_name _board_id)
1717
convert_string_to_pascal_case(${_library_name} _library_name)
1818
endif ()
1919

20-
find_file(library_properties_file library.properties
21-
PATHS ${ARDUINO_SDK_LIBRARIES_PATH} ${ARDUINO_CMAKE_SKETCHBOOK_PATH}/libraries
22-
PATH_SUFFIXES ${_library_name}
20+
find_file(library_path
21+
NAMES ${_library_name}
22+
PATHS ${ARDUINO_SDK_LIBRARIES_PATH} ${ARDUINO_CMAKE_SKETCHBOOK_PATH}
23+
PATH_SUFFIXES libraries
2324
NO_DEFAULT_PATH
2425
NO_CMAKE_FIND_ROOT_PATH)
2526

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

30-
get_filename_component(library_path ${library_properties_file} DIRECTORY)
30+
else () # Library is found
3131

3232
find_library_header_files("${library_path}" library_headers)
3333

@@ -50,15 +50,13 @@ function(find_arduino_library _target_name _library_name _board_id)
5050
else ()
5151
set(sources ${library_headers} ${library_sources})
5252

53-
add_arduino_library(${_target_name} ${_board_id}
54-
LIB_PROPS_FILE ${library_properties_file}
55-
${sources})
53+
add_arduino_library(${_target_name} ${_board_id} ${sources})
5654
endif ()
5755

5856
endif ()
5957
endif ()
6058
endif ()
6159

62-
unset(library_properties_file CACHE)
60+
unset(library_path CACHE)
6361

6462
endfunction()

cmake/Platform/Libraries/LibrarySourcesArchitectureResolver.cmake

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ function(resolve_library_architecture _library_sources _return_var)
3838
else ()
3939

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

cmake/Platform/Utilities/LibraryUtils.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function(get_library_properties_file _library_root_directory _return_var)
1919
set(lib_props_file ${absolute_lib_root_dir}/${ARDUINO_CMAKE_LIBRARY_PROPERTIES_FILE_NAME})
2020

2121
if (NOT EXISTS ${lib_props_file})
22-
message(WARNING "Library's properties file doesn't exist under the given root directory.\n"
22+
message(STATUS "Library's properties file doesn't exist under the given root directory.\n\t"
2323
"Root directory: ${absolute_lib_root_dir}")
2424
return()
2525
endif ()

examples/3rd-party-library/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@ target_include_directories(Adafruit_NeoPixel PUBLIC libraries/Adafruit_NeoPixel)
1717
set(ARDUINO_CMAKE_SKETCHBOOK_PATH "${CMAKE_CURRENT_LIST_DIR}")
1818
find_arduino_library(Adafruit_GFX Adafruit-GFX-Library ${board_id} 3RD_PARTY)
1919
# We can also explicitly add additional directories to the target,
20-
# as only root dir and 'src' sub-dir are added by default
20+
# as only root dir and 'src' and 'utility' sub-dirs are added by default
2121
target_source_directories(Adafruit_GFX DIRS libraries/Adafruit-GFX-Library/Fonts)
2222

23+
# We can even automatically find a library that doesn't have a properties file!
24+
find_arduino_library(sky_writer Skywriter ${board_id} 3RD_PARTY)
25+
2326
# Link all libraries to our previously created target
2427
link_arduino_library(3rd_Party_Arduino_Library Adafruit_NeoPixel ${board_id})
2528
link_arduino_library(3rd_Party_Arduino_Library Adafruit_GFX ${board_id})
29+
link_arduino_library(3rd_Party_Arduino_Library sky_writer ${board_id})
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#include <Adafruit_NeoPixel.h>
2+
#include <Wire.h>
3+
4+
#define PIN 8
5+
6+
Adafruit_NeoPixel Neopixel = Adafruit_NeoPixel(64, PIN, NEO_GRB + NEO_KHZ800);
7+
8+
unsigned long brightness = 50;
9+
unsigned char color = 0;
10+
11+
// Include string names of gestures/touches for testing
12+
//#define SKYWRITER_INC_DEBUG_STRINGS
13+
#include "skywriter.h"
14+
15+
unsigned int max_x, max_y, max_z;
16+
unsigned int min_x, min_y, min_z;
17+
18+
void setup() {
19+
Serial.begin(9600);
20+
while(!Serial){};
21+
Serial.println("Hello world!");
22+
23+
Neopixel.begin();
24+
Neopixel.setBrightness(brightness);
25+
Neopixel.show(); // Initialize all pixels to 'off'
26+
27+
28+
Skywriter.begin(12, 13);
29+
Skywriter.onTouch(touch);
30+
//Skywriter.onAirwheel(airwheel);
31+
Skywriter.onGesture(gesture);
32+
Skywriter.onXYZ(xyz);
33+
}
34+
35+
void loop() {
36+
Skywriter.poll();
37+
/*int x;
38+
for(x = 0; x < 64; x++){
39+
Neopixel.setPixelColor(x, Wheel(color));
40+
}*/
41+
Neopixel.show();
42+
}
43+
44+
void xyz(unsigned int x, unsigned int y, unsigned int z){
45+
if (x < min_x) min_x = x;
46+
if (y < min_y) min_y = y;
47+
if (z < min_z) min_z = z;
48+
if (x > max_x) max_x = x;
49+
if (y > max_y) max_y = y;
50+
if (z > max_z) max_z = z;
51+
52+
unsigned char pixel_x = map(x, min_x, max_x, 0, 7);
53+
unsigned char pixel_y = map(y, min_y, max_y, 0, 7);
54+
uint32_t color = Wheel(map(z, min_z, max_z, 0, 255));
55+
56+
57+
Neopixel.setPixelColor(pixel_x*8 + pixel_y, color);
58+
59+
char buf[64];
60+
sprintf(buf, "%05u:%05u:%05u gest:%02u touch:%02u", x, y, z, Skywriter.last_gesture, Skywriter.last_touch);
61+
Serial.println(buf);
62+
}
63+
64+
void gesture(unsigned char type){
65+
Serial.println("Got gesture ");
66+
Serial.print(type,DEC);
67+
Serial.print('\n');
68+
69+
if( type == SW_FLICK_WEST_EAST ){
70+
Neopixel.clear();
71+
}
72+
}
73+
74+
void touch(unsigned char type){
75+
Serial.println("Got touch ");
76+
Serial.print(type,DEC);
77+
Serial.print('\n');
78+
79+
if( type == SW_TOUCH_CENTER ){
80+
Neopixel.setBrightness(map(Skywriter.x, min_x, max_x, 0, 255));
81+
//color = map(Skywriter.y, min_y, max_y, 0, 255);
82+
}
83+
/*else if( type == SW_TOUCH_EAST ){
84+
Neopixel.setBrightness(0);
85+
}
86+
else if( type == SW_TOUCH_WEST ){
87+
Neopixel.setBrightness(255);
88+
}*/
89+
}
90+
91+
void airwheel(int delta){
92+
Serial.println("Got airwheel ");
93+
Serial.print(delta);
94+
Serial.print('\n');
95+
96+
brightness += (delta/100.0);
97+
Neopixel.setBrightness(brightness % 255);
98+
}
99+
100+
uint32_t Wheel(byte WheelPos) {
101+
if(WheelPos < 85) {
102+
return Neopixel.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
103+
} else if(WheelPos < 170) {
104+
WheelPos -= 85;
105+
return Neopixel.Color(255 - WheelPos * 3, 0, WheelPos * 3);
106+
} else {
107+
WheelPos -= 170;
108+
return Neopixel.Color(0, WheelPos * 3, 255 - WheelPos * 3);
109+
}
110+
}
111+
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*
2+
SkyPainter
3+
An advanced example showing the SkyWriter board acting as a 3D paint input
4+
for a NeoPixel matrix.
5+
6+
Paint in the air with your finger, X/Y translate as normal, and Z is colour!
7+
*/
8+
#include <Adafruit_NeoPixel.h>
9+
#include <Wire.h>
10+
#include <skywriter.h>
11+
12+
#define PIN 8 // Pin for NeoPixel matrix
13+
#define PIN_TRFR 2 // TRFR Pin of Skywriter
14+
#define PIN_RESET 3 // Reset Pin of Skywriter
15+
16+
Adafruit_NeoPixel Neopixel = Adafruit_NeoPixel(64, PIN, NEO_GRB + NEO_KHZ800);
17+
18+
unsigned long brightness = 50;
19+
unsigned char color = 0;
20+
21+
long touch_timeout = 0;
22+
23+
/*
24+
Keep track of the minimum and maximum X, Y, Z values
25+
for on-the-fly calibration of finger-to-led relationship
26+
*/
27+
unsigned int max_x, max_y, max_z;
28+
unsigned int min_x, min_y, min_z;
29+
30+
void setup() {
31+
min_x = 255;
32+
min_y = 255;
33+
min_z = 255;
34+
35+
Serial.begin(9600);
36+
while(!Serial){};
37+
Serial.println("Hello world!");
38+
39+
Neopixel.begin();
40+
Neopixel.setBrightness(brightness);
41+
Neopixel.show();
42+
43+
Skywriter.begin(PIN_TRFR, PIN_RESET);
44+
Skywriter.onTouch(touch);
45+
46+
// Track gestures for clearing the screen
47+
Skywriter.onGesture(gesture);
48+
Skywriter.onXYZ(xyz);
49+
}
50+
51+
/*
52+
Poll from any updates form Skywriter
53+
*/
54+
void loop() {
55+
// Poll for any updates from Skywriter
56+
// And update the NeoPixel matrix
57+
Skywriter.poll();
58+
Neopixel.show();
59+
if( touch_timeout > 0 ) touch_timeout--;
60+
}
61+
62+
/*
63+
Handle the XYZ updates, determine min/max
64+
values and scale them to fit the display
65+
*/
66+
void xyz(unsigned int x, unsigned int y, unsigned int z){
67+
if( touch_timeout > 0 ) return;
68+
69+
if (x < min_x) min_x = x;
70+
if (y < min_y) min_y = y;
71+
if (z < min_z) min_z = z;
72+
if (x > max_x) max_x = x;
73+
if (y > max_y) max_y = y;
74+
if (z > max_z) max_z = z;
75+
76+
unsigned char pixel_x = map(x, min_x, max_x, 0, 7);
77+
unsigned char pixel_y = map(y, min_y, max_y, 0, 7);
78+
uint32_t color = Wheel(map(z, min_z, max_z, 0, 255));
79+
80+
Neopixel.setPixelColor(pixel_x*8 + pixel_y, color);
81+
82+
char buf[18];
83+
sprintf(buf, "%05u:%05u:%05u", x, y, z);
84+
Serial.println(buf);
85+
}
86+
87+
/*
88+
Flicking from West to East will clear
89+
the Matrix.
90+
*/
91+
void gesture(unsigned char type){
92+
Serial.println("Got gesture ");
93+
Serial.print(type,DEC);
94+
Serial.print('\n');
95+
96+
if( type == SW_FLICK_WEST_EAST ){
97+
Neopixel.clear();
98+
}
99+
}
100+
101+
/*
102+
Touching the center of Skywriter will switch
103+
to brightness control mode. Letting you
104+
adjust the brightness of the pixels.
105+
*/
106+
void touch(unsigned char type){
107+
Serial.println("Got touch ");
108+
Serial.print(type,DEC);
109+
Serial.print('\n');
110+
111+
if( type == SW_TOUCH_CENTER ){
112+
touch_timeout = 100;
113+
Neopixel.setBrightness(map(Skywriter.x, min_x, max_x, 0, 255));
114+
}
115+
}
116+
117+
uint32_t Wheel(byte WheelPos) {
118+
if(WheelPos < 85) {
119+
return Neopixel.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
120+
} else if(WheelPos < 170) {
121+
WheelPos -= 85;
122+
return Neopixel.Color(255 - WheelPos * 3, 0, WheelPos * 3);
123+
} else {
124+
WheelPos -= 170;
125+
return Neopixel.Color(0, WheelPos * 3, 255 - WheelPos * 3);
126+
}
127+
}
128+
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
Because interrupts vary from device to device,
3+
this example might not work out of the box for you.
4+
5+
Read: http://arduino.cc/en/Reference/attachInterrupt
6+
and adjust the code for your device accordingly.
7+
8+
*/
9+
#include <Wire.h>
10+
#include <skywriter.h>
11+
12+
/*
13+
Pin 2 is
14+
interrupt 0 on the Uno
15+
interrupt 0 on the Mega2560
16+
interrupt 1 on the Leonardo
17+
just referred to as pin 2 for Due
18+
*/
19+
#define PIN_TRFR 2
20+
#define PIN_RESET 3
21+
22+
void setup() {
23+
Serial.begin(9600);
24+
while(!Serial){};
25+
26+
Skywriter.begin(PIN_TRFR, PIN_RESET);
27+
Skywriter.onTouch(touch);
28+
29+
Serial.println("Hello world!");
30+
31+
/* Set up the initial interrupt */
32+
attachInterrupt(PIN_TRFR,poll,FALLING); // Arduino Due
33+
//attachInterrupt(0,poll,FALLING); // Arduino Uno
34+
//attachInterrupt(1,poll,FALLING); // Arduino Leonardo
35+
36+
}
37+
38+
void poll(){
39+
/* It doesn't matter how heavy this interrupt
40+
handler is. It will *not* fire again until
41+
Skywriter has finished processing the new data
42+
and we have re-attached the interrupt. */
43+
44+
/* Handle the new data */
45+
Skywriter.poll();
46+
47+
/* Skywriter must twiddle PIN_TRFR to tell
48+
the hardware it's processing the new data.
49+
Interrupt needs re-attaching afterwards! */
50+
attachInterrupt(PIN_TRFR,poll,FALLING); // Arduino Due
51+
//attachInterrupt(0,poll,FALLING); // Arduino Uno
52+
//attachInterrupt(1,poll,FALLING); // Arduino Leonardo
53+
}
54+
55+
void loop() {
56+
/* Do something in our loop! */
57+
Serial.println("I'm alive!");
58+
delay(1000);
59+
}
60+
61+
void touch(unsigned char type){
62+
Serial.println("Got touch ");
63+
Serial.print(type,DEC);
64+
Serial.print('\n');
65+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Skywriter KEYWORD1
2+
begin KEYWORD2
3+
poll KEYWORD2
4+
onGesture KEYWORD2
5+
onTouch KEYWORD2
6+
onAirwheel KEYWORD2
7+
onXYZ KEYWORD2
8+
x KEYWORD3
9+
y KEYWORD3
10+
z KEYWORD3
11+
last_gesture KEYWORD3
12+
last_touch KEYWORD3

0 commit comments

Comments
 (0)