Skip to content

Commit 8e0de8a

Browse files
Merge branch 'dev'
2 parents 7e7c65f + fcb090b commit 8e0de8a

File tree

6 files changed

+148
-29
lines changed

6 files changed

+148
-29
lines changed

CMakeLists.txt

Lines changed: 68 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ project(LetMeCreate)
55

66
set(LETMECREATE_MAJOR_VERSION 1)
77
set(LETMECREATE_MINOR_VERSION 5)
8-
set(LETMECREATE_PATCH_VERSION 1)
8+
set(LETMECREATE_PATCH_VERSION 2)
99
set(LETMECREATE_VERSION ${LETMECREATE_MAJOR_VERSION}.${LETMECREATE_MINOR_VERSION}.${LETMECREATE_PATCH_VERSION})
1010
set(PROJECT_VERSION ${LETMECREATE_VERSION})
1111

1212
option(BUILD_EXAMPLES "Build examples" OFF)
1313
option(BUILD_TESTS "Build tests" OFF)
14+
option(BUILD_SHARED "Build shared libraries" ON)
15+
option(BUILD_STATIC "Build static libraries" ON)
1416

1517
file(GLOB bosch_srcs src/bosch/*.c)
1618
file(GLOB core_srcs src/core/*.c)
@@ -25,30 +27,38 @@ file(GLOB rpisensehat_hdrs include/letmecreate/rpisensehat/*.h)
2527
include_directories(include)
2628

2729
# Create targets
28-
add_library(letmecreate_core SHARED ${core_srcs} ${core_hdrs})
29-
add_library(letmecreate_click SHARED ${click_srcs} ${click_hdrs})
30-
add_library(letmecreate_bosch SHARED ${bosch_srcs} ${bosch_hdrs})
31-
add_library(letmecreate_rpisensehat SHARED ${rpisensehat_srcs} ${rpisensehat_hdrs})
32-
target_link_libraries(letmecreate_core pthread)
33-
target_link_libraries(letmecreate_click letmecreate_core letmecreate_bosch)
34-
target_link_libraries(letmecreate_rpisensehat letmecreate_core)
35-
36-
# Export symbols
37-
include(GenerateExportHeader)
38-
generate_export_header(letmecreate_bosch EXPORT_FILE_NAME "include/letmecreate/bosch/export.h")
39-
generate_export_header(letmecreate_core EXPORT_FILE_NAME "include/letmecreate/core/export.h")
40-
generate_export_header(letmecreate_click EXPORT_FILE_NAME "include/letmecreate/click/export.h")
41-
generate_export_header(letmecreate_rpisensehat EXPORT_FILE_NAME "include/letmecreate/rpisensehat/export.h")
42-
set_target_properties(letmecreate_bosch PROPERTIES C_VISIBILITY_PRESET hidden)
43-
set_target_properties(letmecreate_core PROPERTIES C_VISIBILITY_PRESET hidden)
44-
set_target_properties(letmecreate_click PROPERTIES C_VISIBILITY_PRESET hidden)
45-
set_target_properties(letmecreate_rpisensehat PROPERTIES C_VISIBILITY_PRESET hidden)
30+
if(BUILD_SHARED)
31+
add_library(letmecreate_core SHARED ${core_srcs} ${core_hdrs})
32+
add_library(letmecreate_click SHARED ${click_srcs} ${click_hdrs})
33+
add_library(letmecreate_bosch SHARED ${bosch_srcs} ${bosch_hdrs})
34+
add_library(letmecreate_rpisensehat SHARED ${rpisensehat_srcs} ${rpisensehat_hdrs})
35+
target_link_libraries(letmecreate_core pthread)
36+
target_link_libraries(letmecreate_click letmecreate_core letmecreate_bosch)
37+
target_link_libraries(letmecreate_rpisensehat letmecreate_core)
38+
# Export symbols
39+
include(GenerateExportHeader)
40+
generate_export_header(letmecreate_bosch EXPORT_FILE_NAME "include/letmecreate/bosch/export.h")
41+
generate_export_header(letmecreate_core EXPORT_FILE_NAME "include/letmecreate/core/export.h")
42+
generate_export_header(letmecreate_click EXPORT_FILE_NAME "include/letmecreate/click/export.h")
43+
generate_export_header(letmecreate_rpisensehat EXPORT_FILE_NAME "include/letmecreate/rpisensehat/export.h")
44+
set_target_properties(letmecreate_bosch PROPERTIES C_VISIBILITY_PRESET hidden)
45+
set_target_properties(letmecreate_core PROPERTIES C_VISIBILITY_PRESET hidden)
46+
set_target_properties(letmecreate_click PROPERTIES C_VISIBILITY_PRESET hidden)
47+
set_target_properties(letmecreate_rpisensehat PROPERTIES C_VISIBILITY_PRESET hidden)
48+
endif()
49+
50+
if(BUILD_STATIC)
51+
add_library(letmecreate_core_s STATIC ${core_srcs} ${core_hdrs})
52+
add_library(letmecreate_click_s STATIC ${click_srcs} ${click_hdrs})
53+
add_library(letmecreate_bosch_s STATIC ${bosch_srcs} ${bosch_hdrs})
54+
add_library(letmecreate_rpisensehat_s STATIC ${rpisensehat_srcs} ${rpisensehat_hdrs})
55+
endif()
4656

4757
# Enable warnings
4858
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -Wextra -ggdb3")
4959
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wall -Wextra -O2")
5060

51-
61+
if(BUILD_SHARED)
5262
target_include_directories(
5363
letmecreate_core PUBLIC
5464
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
@@ -69,6 +79,30 @@ target_include_directories(
6979
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
7080
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
7181
)
82+
endif()
83+
84+
if(BUILD_STATIC)
85+
target_include_directories(
86+
letmecreate_core_s PUBLIC
87+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
88+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
89+
)
90+
target_include_directories(
91+
letmecreate_click_s PUBLIC
92+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
93+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
94+
)
95+
target_include_directories(
96+
letmecreate_bosch_s PUBLIC
97+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
98+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
99+
)
100+
target_include_directories(
101+
letmecreate_rpisensehat_s PUBLIC
102+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
103+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
104+
)
105+
endif()
72106

73107

74108
set(config_install_dir "lib/cmake/${PROJECT_NAME}")
@@ -94,6 +128,7 @@ configure_package_config_file(
94128
INSTALL_DESTINATION "${config_install_dir}"
95129
)
96130

131+
if(BUILD_SHARED)
97132
install(
98133
TARGETS letmecreate_core letmecreate_click letmecreate_bosch letmecreate_rpisensehat
99134
EXPORT "${targets_export_name}"
@@ -102,6 +137,19 @@ install(
102137
RUNTIME DESTINATION "bin"
103138
INCLUDES DESTINATION "${include_install_dir}"
104139
)
140+
endif()
141+
142+
if(BUILD_STATIC)
143+
install(
144+
TARGETS letmecreate_core_s letmecreate_click_s letmecreate_bosch_s letmecreate_rpisensehat_s
145+
EXPORT "${targets_export_name}"
146+
LIBRARY DESTINATION "lib"
147+
ARCHIVE DESTINATION "lib"
148+
RUNTIME DESTINATION "bin"
149+
INCLUDES DESTINATION "${include_install_dir}"
150+
)
151+
endif()
152+
105153

106154
install(
107155
DIRECTORY "include/letmecreate"

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.5.1
41+
PROJECT_NUMBER = 1.5.2
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

src/click/adc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
int adc_click_get_raw_value(uint8_t channel, uint16_t *value)
1010
{
11-
uint8_t tx_buffer[3], rx_buffer[3] = {};
11+
uint8_t tx_buffer[3], rx_buffer[3];
1212

1313
if (channel >= ADC_CLICK_CHANNEL_COUNT) {
1414
fprintf(stderr, "adc click: Invalid channel.\n");

src/click/relay4.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
#define RELAY4_PIN_COUNT (4)
2727

28-
static uint8_t relay4_pins[RELAY4_PIN_COUNT] = {};
28+
static uint8_t relay4_pins[RELAY4_PIN_COUNT];
2929

3030
static bool check_valid_pin_index(uint8_t pin_index)
3131
{

src/core/gpio_monitor.c

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,53 @@ static int find_event_type(uint8_t gpio_pin, uint8_t *event_type)
7474
static void call_callbacks(uint8_t gpio_pin, uint8_t event_type)
7575
{
7676
struct gpio_watch *cur = NULL;
77+
struct callback_list {
78+
struct callback_list *next;
79+
void(*callback)(uint8_t);
80+
};
81+
struct callback_list *head = NULL, *current_callback = NULL;
7782

78-
/* Call callbacks */
83+
84+
/* Create list of callback which must be called */
7985
pthread_mutex_lock(&gpio_watch_mutex);
8086
cur = gpio_watch_list_head;
8187
while (cur) {
82-
if (cur->gpio_pin == gpio_pin && cur->event_mask & event_type)
83-
cur->callback(event_type);
88+
if (cur->gpio_pin != gpio_pin || (cur->event_mask & event_type) == 0) {
89+
cur = cur->next;
90+
continue;
91+
}
92+
93+
struct callback_list *entry = malloc(sizeof(struct callback_list));
94+
if (entry == NULL) {
95+
fprintf(stderr, "gpio_monitor: Failed to create callback list entry.\n");
96+
cur = cur->next;
97+
continue;
98+
}
99+
entry->callback = cur->callback;
84100

101+
/* Add entry at the beginning of the list */
102+
if (head == NULL)
103+
entry->next = NULL;
104+
else
105+
entry->next = head;
106+
head = entry;
85107
cur = cur->next;
86108
}
87109
pthread_mutex_unlock(&gpio_watch_mutex);
110+
111+
/* Iterate through callbacks in the list */
112+
current_callback = head;
113+
while (current_callback) {
114+
current_callback->callback(event_type);
115+
current_callback = current_callback->next;
116+
}
117+
118+
/* Free all elements of the list */
119+
while (head) {
120+
struct callback_list *tmp = head->next;
121+
free(head);
122+
head = tmp;
123+
}
88124
}
89125

90126
static void* monitor_gpio(void __attribute__ ((unused))*arg)

src/core/switch.c

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,51 @@ static int find_file_descriptor(char *file_descriptor_path)
100100
static void process_event(uint8_t switch_event)
101101
{
102102
struct switch_callback *cur = NULL;
103+
struct switch_callback_list {
104+
void (*callback)(void);
105+
struct switch_callback_list *next;
106+
};
107+
struct switch_callback_list *head = NULL, *current_callback = NULL;
103108

109+
/* Create list of callback which must be called */
104110
pthread_mutex_lock(&mutex);
105111
cur = callback_list_head;
106112
while (cur) {
107-
if (cur->event_mask & switch_event)
108-
cur->f();
109-
113+
if ((cur->event_mask & switch_event) == 0) {
114+
cur = cur->next;
115+
continue;
116+
}
117+
struct switch_callback_list *entry = malloc(sizeof(struct switch_callback_list));
118+
if (entry == NULL) {
119+
fprintf(stderr, "switch: Failed to create callback list entry.\n");
120+
cur = cur->next;
121+
continue;
122+
}
123+
entry->callback = cur->f;
124+
125+
/* Add entry at the beginning of the list */
126+
if (head == NULL)
127+
entry->next = NULL;
128+
else
129+
entry->next = head;
130+
head = entry;
110131
cur = cur->next;
111132
}
112133
pthread_mutex_unlock(&mutex);
134+
135+
/* Iterate through callbacks in the list */
136+
current_callback = head;
137+
while (current_callback) {
138+
current_callback->callback();
139+
current_callback = current_callback->next;
140+
}
141+
142+
/* Free all elements of the list */
143+
while (head) {
144+
struct switch_callback_list *tmp = head->next;
145+
free(head);
146+
head = tmp;
147+
}
113148
}
114149

115150
static void* switch_update(void __attribute__ ((unused))*arg)

0 commit comments

Comments
 (0)