Skip to content

Commit 1c750f4

Browse files
Merge branch 'dev'
2 parents 9f2a978 + b85ed28 commit 1c750f4

File tree

43 files changed

+916
-121
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+916
-121
lines changed

CMakeLists.txt

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
cmake_minimum_required(VERSION 2.8)
22

3-
project(LetMeCreate)
3+
project(LetMeCreate C)
44

55

66
set(LETMECREATE_MAJOR_VERSION 1)
7-
set(LETMECREATE_MINOR_VERSION 0)
8-
set(LETMECREATE_PATCH_VERSION 3)
7+
set(LETMECREATE_MINOR_VERSION 1)
8+
set(LETMECREATE_PATCH_VERSION 0)
99
set(LETMECREATE_VERSION ${LETMECREATE_MAJOR_VERSION}.${LETMECREATE_MINOR_VERSION}.${LETMECREATE_PATCH_VERSION})
1010
set(PROJECT_VERSION ${LETMECREATE_VERSION})
1111

@@ -15,11 +15,14 @@ option(BUILD_TESTS "Build tests" OFF)
1515
file(GLOB core_srcs src/core/*.c)
1616
file(GLOB click_srcs src/click/*.c)
1717

18+
file(GLOB core_hdrs include/letmecreate/core/*.h)
19+
file(GLOB click_hdrs include/letmecreate/click/*.h)
20+
1821
include_directories(include)
1922

2023
# Create targets
21-
add_library(letmecreate_core SHARED ${core_srcs})
22-
add_library(letmecreate_click SHARED ${click_srcs})
24+
add_library(letmecreate_core SHARED ${core_srcs} ${core_hdrs})
25+
add_library(letmecreate_click SHARED ${click_srcs} ${click_hdrs})
2326
target_link_libraries(letmecreate_click letmecreate_core)
2427

2528
target_compile_definitions(letmecreate_core PUBLIC "LETMECREATE_CORE_DEBUG=$<CONFIG:Debug>")
@@ -51,27 +54,16 @@ set(targets_export_name "${PROJECT_NAME}Targets")
5154
# Include module with fuction 'write_basic_package_version_file'
5255
include(CMakePackageConfigHelpers)
5356

54-
# Configure '<PROJECT-NAME>ConfigVersion.cmake'
55-
# Note: PROJECT_VERSION is used as a VERSION
5657
write_basic_package_version_file(
5758
"${version_config}" COMPATIBILITY SameMajorVersion
5859
)
5960

60-
# Configure '<PROJECT-NAME>Config.cmake'
61-
# Use variables:
62-
# * targets_export_name
63-
# * PROJECT_NAME
6461
configure_package_config_file(
6562
"cmake/Config.cmake.in"
6663
"${project_config}"
6764
INSTALL_DESTINATION "${config_install_dir}"
6865
)
6966

70-
# Targets:
71-
# * <prefix>/lib/libbar.a
72-
# * <prefix>/lib/libbaz.a
73-
# * header location after install: <prefix>/include/foo/Bar.hpp
74-
# * headers can be included by C++ code `#include <foo/Bar.hpp>`
7567
install(
7668
TARGETS letmecreate_core letmecreate_click
7769
EXPORT "${targets_export_name}"
@@ -81,25 +73,17 @@ install(
8173
INCLUDES DESTINATION "${include_install_dir}"
8274
)
8375

84-
# Headers:
85-
# * Source/foo/Bar.hpp -> <prefix>/include/foo/Bar.hpp
86-
# * Source/foo/Baz.hpp -> <prefix>/include/foo/Baz.hpp
8776
install(
8877
DIRECTORY "include/letmecreate"
8978
DESTINATION "${include_install_dir}"
9079
FILES_MATCHING PATTERN "*.h"
9180
)
9281

93-
# Config
94-
# * <prefix>/lib/cmake/Foo/FooConfig.cmake
95-
# * <prefix>/lib/cmake/Foo/FooConfigVersion.cmake
9682
install(
9783
FILES "${project_config}" "${version_config}"
9884
DESTINATION "${config_install_dir}"
9985
)
10086

101-
# Config
102-
# * <prefix>/lib/cmake/Foo/FooTargets.cmake
10387
install(
10488
EXPORT "${targets_export_name}"
10589
DESTINATION "${config_install_dir}"

Doxyfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ PROJECT_NAME = "LetMeCreate"
3838
# could be handy for archiving the generated documentation or if some version
3939
# control system is used.
4040

41-
PROJECT_NUMBER = 1.0.3
41+
PROJECT_NUMBER = 1.1.0
4242

4343
# Using the PROJECT_BRIEF tag one can provide an optional one line description
4444
# for a project that appears at the top of each page and should give viewer a

Readme.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,38 @@ MikroClick board supported:
1616
- Thermo3
1717
- Proximity
1818
- Motion
19-
- Relay
19+
- Relay (partial support)
2020
- Relay2
2121
- Joystick
2222
- Air quality
23-
- Accel (SPI only)
23+
- Accel
2424
- 8x8R (Led Matrix)
2525
- Alcohol
2626
- IR eclipse
27+
- IR distance
28+
- Color
29+
- Color2
30+
- Bargraph
31+
- 7Seg
32+
- ADC
2733

2834
Examples are installed in /usr/bin/letmecreate_examples.
2935
Tests are installed in /usr/bin/letmecreate_tests.
3036

37+
## Contributing to LetMeCreate
38+
39+
The master branch is the stable branch and the dev branch is merged to master just before doing a release. All pull requests must be done on dev branch.
40+
Before creating a wrapper for a click board, make sure that it is not already supported in the dev branch. To avoid any overlap, contact me my email ([email protected]).
41+
42+
43+
About code style, I follow roughly the [linux kernel coding style](https://www.kernel.org/doc/Documentation/CodingStyle) (two notable exceptions: indentation is set to 4 spaces and no 80 characters limit per line). Keep the style of your wrapper consistent with the rest of the code. For instance, most functions return 0 if they succeed and a negative number if not.
44+
45+
46+
Each wrapper must implement features provided by only one click board. Do not mix code related to different click boards in a wrapper. Add doxygen documentation to all of your functions and do not forget to add a doxygen header on top of your header file otherwise the documentation will not be generated by doxygen.
47+
48+
49+
Keep examples very simple and avoid parsing arguments. Examples are there to show one or two features of a **single** click board. Do not use multiple click boards in an example. The idea behind writing examples is to show how easy the library makes it using click boards. Hence, the shorter the example is, the better it is.
50+
3151
## Integration in Openwrt
3252

3353
To add new packages, Openwrt relies on feeds: a collection of packages.

examples/7seg/main.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <letmecreate/letmecreate.h>
2+
#include "examples/common.h"
3+
4+
5+
int main(void)
6+
{
7+
int i = 0;
8+
spi_init();
9+
seven_seg_click_set_intensity(MIKROBUS_1, 100.f);
10+
11+
for (; i < 100; ++i) {
12+
seven_seg_click_display_decimal_number(i);
13+
sleep_ms(100);
14+
}
15+
16+
spi_release();
17+
18+
return 0;
19+
}

examples/CMakeLists.txt

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/examples/bin)
22

3+
add_library(examples_common OBJECT common.c)
4+
35
add_executable(letmecreate_proximity_example proximity/main.c)
46
target_link_libraries(letmecreate_proximity_example letmecreate_click letmecreate_core)
57
install(TARGETS letmecreate_proximity_example RUNTIME DESTINATION bin)
@@ -16,26 +18,42 @@ add_executable(letmecreate_joystick_example joystick/main.c)
1618
target_link_libraries(letmecreate_joystick_example letmecreate_click letmecreate_core)
1719
install(TARGETS letmecreate_joystick_example RUNTIME DESTINATION bin)
1820

19-
add_executable(letmecreate_accel_example accel/main.c)
21+
add_executable(letmecreate_accel_example accel/main.c $<TARGET_OBJECTS:examples_common>)
2022
target_link_libraries(letmecreate_accel_example letmecreate_click letmecreate_core)
2123
install(TARGETS letmecreate_accel_example RUNTIME DESTINATION bin)
2224

23-
add_executable(letmecreate_led_matrix_example led_matrix/main.c)
25+
add_executable(letmecreate_led_matrix_example led_matrix/main.c $<TARGET_OBJECTS:examples_common>)
2426
target_link_libraries(letmecreate_led_matrix_example letmecreate_click letmecreate_core)
2527
install(TARGETS letmecreate_led_matrix_example RUNTIME DESTINATION bin)
2628

2729
add_executable(letmecreate_color_example color/main.c)
2830
target_link_libraries(letmecreate_color_example letmecreate_click letmecreate_core)
2931
install(TARGETS letmecreate_color_example RUNTIME DESTINATION bin)
3032

31-
add_executable(letmecreate_led_example led/main.c)
33+
add_executable(letmecreate_led_example led/main.c $<TARGET_OBJECTS:examples_common>)
3234
target_link_libraries(letmecreate_led_example letmecreate_core)
3335
install(TARGETS letmecreate_led_example RUNTIME DESTINATION bin)
3436

35-
add_executable(letmecreate_buzz_example buzz/main.c)
37+
add_executable(letmecreate_buzz_example buzz/main.c $<TARGET_OBJECTS:examples_common>)
3638
target_link_libraries(letmecreate_buzz_example letmecreate_core)
3739
install(TARGETS letmecreate_buzz_example RUNTIME DESTINATION bin)
3840

39-
add_executable(letmecreate_motion_example motion/main.c)
41+
add_executable(letmecreate_motion_example motion/main.c $<TARGET_OBJECTS:examples_common>)
4042
target_link_libraries(letmecreate_motion_example letmecreate_click letmecreate_core)
4143
install(TARGETS letmecreate_motion_example RUNTIME DESTINATION bin)
44+
45+
add_executable(letmecreate_color2_example color2/main.c)
46+
target_link_libraries(letmecreate_color2_example letmecreate_click letmecreate_core)
47+
install(TARGETS letmecreate_color2_example RUNTIME DESTINATION bin)
48+
49+
add_executable(letmecreate_bargraph_example bargraph/main.c $<TARGET_OBJECTS:examples_common>)
50+
target_link_libraries(letmecreate_bargraph_example letmecreate_click letmecreate_core)
51+
install(TARGETS letmecreate_bargraph_example RUNTIME DESTINATION bin)
52+
53+
add_executable(letmecreate_7seg_example 7seg/main.c $<TARGET_OBJECTS:examples_common>)
54+
target_link_libraries(letmecreate_7seg_example letmecreate_click letmecreate_core)
55+
install(TARGETS letmecreate_7seg_example RUNTIME DESTINATION bin)
56+
57+
add_executable(letmecreate_adc_example adc/main.c)
58+
target_link_libraries(letmecreate_adc_example letmecreate_click letmecreate_core)
59+
install(TARGETS letmecreate_adc_example RUNTIME DESTINATION bin)

examples/accel/main.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
#include <signal.h>
33
#include <stdbool.h>
44
#include <stdio.h>
5-
#include <time.h>
65
#include <letmecreate/letmecreate.h>
6+
#include "examples/common.h"
77

88
static volatile bool running = true;
99

@@ -12,16 +12,6 @@ static void exit_program(int signo)
1212
running = false;
1313
}
1414

15-
static void sleep_100ms(void)
16-
{
17-
struct timespec rem, req = {
18-
.tv_sec = 0,
19-
.tv_nsec = 100000000
20-
};
21-
22-
while (nanosleep(&req, &rem))
23-
req = rem;
24-
}
2515

2616
int main(void)
2717
{
@@ -47,7 +37,7 @@ int main(void)
4737
printf("\33[2K\r"); /* Erase current line */
4838
printf("%-9.3f%-9.3f%-9.3f", x, y, z);
4939
fflush(stdout);
50-
sleep_100ms();
40+
sleep_ms(100);
5141
}
5242

5343
accel_click_disable();

examples/adc/main.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <stdio.h>
2+
#include <letmecreate/letmecreate.h>
3+
4+
5+
int main(void)
6+
{
7+
uint16_t value;
8+
int i = 0;
9+
10+
spi_init();
11+
for (; i < 4; ++i) {
12+
adc_click_get_raw_value(i, &value);
13+
printf("channel %d value: %u\n", i, value);
14+
}
15+
spi_release();
16+
17+
return 0;
18+
}

examples/bargraph/main.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <letmecreate/letmecreate.h>
2+
#include "examples/common.h"
3+
4+
5+
int main(void)
6+
{
7+
uint16_t value = 1;
8+
spi_init();
9+
10+
/* Set LED's to max intensity */
11+
bargraph_click_set_intensity(MIKROBUS_1, 100.f);
12+
13+
/* Gradually turn on each LED. */
14+
for (; value < 0x400; value <<= 1, value |= 1) {
15+
bargraph_click_set_value(value);
16+
sleep_ms(200);
17+
}
18+
19+
spi_release();
20+
21+
return 0;
22+
}

examples/buzz/main.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
1-
#include <time.h>
21
#include <letmecreate/letmecreate.h>
2+
#include "examples/common.h"
33

44

5-
static void sleep_ms(unsigned int ms)
6-
{
7-
struct timespec req, rem;
8-
9-
req.tv_sec = ms / 1000;
10-
ms -= req.tv_sec * 1000;
11-
req.tv_nsec = ms * 1000000;
12-
13-
while (nanosleep(&req, &rem))
14-
req = rem;
15-
}
16-
175
int main(void)
186
{
197
int x = 0;

examples/color2/main.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* This example shows how to use the Color2 Click wrapper of the LetMeCreate
3+
* library.
4+
*
5+
* The Color2 Click must be plugged in Mikrobus 1 of Ci40.
6+
*/
7+
8+
#include <stdio.h>
9+
#include <letmecreate/letmecreate.h>
10+
11+
12+
int main(void)
13+
{
14+
uint16_t r, g, b;
15+
16+
/* Initialise I2C and color2 click */
17+
i2c_init();
18+
color2_click_enable();
19+
20+
/* Read measurement from Colo2 Click */
21+
color2_click_get_color(&r, &g, &b);
22+
printf("red: %u\n", r);
23+
printf("green: %u\n", g);
24+
printf("blue: %u\n\n", b);
25+
26+
/* Disable color2 click and I2C */
27+
color2_click_disable();
28+
i2c_release();
29+
30+
return 0;
31+
}

0 commit comments

Comments
 (0)