Skip to content

Commit 25edd30

Browse files
authored
Encapsulate all LVGL library calls within examples/tutorials with lvgl_lock/lvgl_unlock. (#62)
1 parent 2fb04c1 commit 25edd30

File tree

12 files changed

+46
-8
lines changed

12 files changed

+46
-8
lines changed

examples/tutorials/lessons/01-programming-the-braccio-display/01_creating_a_button/01_creating_a_button.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#include <Braccio++.h>
22

33
void customMenu() {
4+
Braccio.lvgl_lock();
45
lv_obj_t * btn1 = lv_btn_create(lv_scr_act());
56
lv_obj_set_size(btn1, 120, 75);
67
lv_obj_t * label1 = lv_label_create(btn1);
78
lv_label_set_text(label1, "BTN 1");
89
lv_obj_align(btn1, LV_ALIGN_CENTER, 0, 0);
910
lv_obj_center(label1);
11+
Braccio.lvgl_unlock();
1012
}
1113

1214
void setup() {

examples/tutorials/lessons/01-programming-the-braccio-display/02_designing_the_button/02_designing_the_button.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010

1111
void customMenu() {
12+
Braccio.lvgl_lock();
1213
static lv_style_t style;
1314
lv_style_init(&style);
1415
lv_style_set_bg_color(&style, lv_color_hex(COLOR_WHITE));
@@ -26,6 +27,7 @@ void customMenu() {
2627
lv_obj_center(label1);
2728

2829
lv_obj_add_style(btn1, &style, 0);
30+
Braccio.lvgl_unlock();
2931
}
3032

3133
void setup() {

examples/tutorials/lessons/01-programming-the-braccio-display/03_creating_a_menu/03_creating_a_menu.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ static const char * btnm_map[] = {"OPTION 1", "OPTION 2", "\n",
1515
};
1616

1717
void customMenu() {
18+
Braccio.lvgl_lock();
1819
static lv_style_t style_bg;
1920
lv_style_init(&style_bg);
2021
lv_style_set_bg_color(&style_bg, lv_color_hex(COLOR_LIGHT_TEAL));
@@ -33,6 +34,7 @@ void customMenu() {
3334

3435
lv_obj_add_style(btnm1, &style_bg, 0);
3536
lv_obj_add_style(btnm1, &style_btn, LV_PART_ITEMS);
37+
Braccio.lvgl_unlock();
3638
}
3739

3840
void setup() {

examples/tutorials/lessons/01-programming-the-braccio-display/04_testing_it_out/04_testing_it_out.ino

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ static const char * btnm_map[] = {"OPTION 1", "OPTION 2", "OPTION 3", "\n",
1313
"OPTION 4", "OPTION 5", "\0"
1414
};
1515

16-
void customMenu(){
16+
void customMenu() {
17+
Braccio.lvgl_lock();
1718
static lv_style_t style_bg;
1819
lv_style_init(&style_bg);
1920
lv_style_set_bg_color(&style_bg, lv_color_hex(COLOR_LIGHT_TEAL));
@@ -33,6 +34,7 @@ void customMenu(){
3334

3435
lv_obj_add_style(btnm1, &style_bg, 0);
3536
lv_obj_add_style(btnm1, &style_btn, LV_PART_ITEMS);
37+
Braccio.lvgl_unlock();
3638
}
3739

3840
void setup() {

examples/tutorials/lessons/01-programming-the-braccio-display/05_display_challenge/05_display_challenge.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ static const char * btnm_map[] = {"BTN 1", "\n",
1414
};
1515

1616
void customMenu() {
17+
Braccio.lvgl_lock();
1718
static lv_style_t style_bg;
1819
lv_style_init(&style_bg);
1920
lv_style_set_bg_color(&style_bg, lv_color_hex(COLOR_BG));
@@ -33,6 +34,7 @@ void customMenu() {
3334

3435
lv_obj_add_style(btnm1, &style_bg, 0);
3536
lv_obj_add_style(btnm1, &style_btn, LV_PART_ITEMS);
37+
Braccio.lvgl_unlock();
3638
}
3739

3840
void setup() {

examples/tutorials/lessons/02-navigatting-the-display-menu/02_handling_events_in_the_menu/02_handling_events_in_the_menu.ino

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ static const char * btnm_map[] = {"Option 1", "Option 2", "\n",
1515
"Option 5", "Option 6", "\0"
1616
};
1717

18-
static void eventHandler(lv_event_t * e){
18+
static void eventHandler(lv_event_t * e) {
19+
Braccio.lvgl_lock();
1920
lv_event_code_t code = lv_event_get_code(e);
2021
lv_obj_t * obj = lv_event_get_target(e);
2122
if (code == LV_EVENT_PRESSED) {
@@ -25,9 +26,11 @@ static void eventHandler(lv_event_t * e){
2526
LV_LOG_USER("%s was selected\n", txt);
2627
Serial.println(String(txt) + " was selected.");
2728
}
29+
Braccio.lvgl_unlock();
2830
}
2931

30-
void customMenu(){
32+
void customMenu() {
33+
Braccio.lvgl_lock();
3134
static lv_style_t style_bg;
3235
lv_style_init(&style_bg);
3336
lv_style_set_bg_color(&style_bg, lv_color_hex(COLOR_WHITE));
@@ -57,7 +60,8 @@ void customMenu(){
5760
lv_btnmatrix_set_one_checked(btnm1, true);
5861

5962
lv_obj_add_event_cb(btnm1, eventHandler, LV_EVENT_ALL, NULL);
60-
63+
Braccio.lvgl_unlock();
64+
6165
Braccio.connectJoystickTo(btnm1);
6266
}
6367

examples/tutorials/lessons/02-navigatting-the-display-menu/03_navigate_challenge_I/03_navigate_challenge_I.ino

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ static const char * btnm_map[] = {"Option 1", "Option 2", "\n",
1515
"Option 5", "Option 6", "\0"
1616
};
1717

18-
static void eventHandler(lv_event_t * e){
18+
static void eventHandler(lv_event_t * e) {
19+
Braccio.lvgl_lock();
1920
lv_event_code_t code = lv_event_get_code(e);
2021
lv_obj_t * obj = lv_event_get_target(e);
2122
if (code == LV_EVENT_PRESSING) {
@@ -25,9 +26,11 @@ static void eventHandler(lv_event_t * e){
2526
LV_LOG_USER("%s is pressed\n", txt);
2627
Serial.println(String(txt) + " is pressed.");
2728
}
29+
Braccio.lvgl_unlock();
2830
}
2931

30-
void customMenu(){
32+
void customMenu() {
33+
Braccio.lvgl_lock();
3134
static lv_style_t style_bg;
3235
lv_style_init(&style_bg);
3336
lv_style_set_bg_color(&style_bg, lv_color_hex(COLOR_LIGHT_TEAL));
@@ -57,6 +60,7 @@ void customMenu(){
5760
lv_btnmatrix_set_one_checked(btnm1, true);
5861

5962
lv_obj_add_event_cb(btnm1, eventHandler, LV_EVENT_ALL, NULL);
63+
Braccio.lvgl_unlock();
6064

6165
Braccio.connectJoystickTo(btnm1);
6266
}

examples/tutorials/lessons/02-navigatting-the-display-menu/04_navigate_challenge_II/04_navigate_challenge_II.ino

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ static const char * btnm_map[] = {"Option 1", "Option 2", "\n",
1515
"Option 5", "Option 6", "\0"
1616
};
1717

18-
static void eventHandler(lv_event_t * e){
18+
static void eventHandler(lv_event_t * e) {
19+
Braccio.lvgl_lock();
1920
lv_event_code_t code = lv_event_get_code(e);
2021
lv_obj_t * obj = lv_event_get_target(e);
2122
if (code == LV_EVENT_RELEASED) {
@@ -25,9 +26,11 @@ static void eventHandler(lv_event_t * e){
2526
LV_LOG_USER("%s was released\n", txt);
2627
Serial.println(String(txt) + " was released.");
2728
}
29+
Braccio.lvgl_unlock();
2830
}
2931

30-
void customMenu(){
32+
void customMenu() {
33+
Braccio.lvgl_lock();
3134
static lv_style_t style_bg;
3235
lv_style_init(&style_bg);
3336
lv_style_set_bg_color(&style_bg, lv_color_hex(COLOR_LIGHT_TEAL));
@@ -57,6 +60,7 @@ void customMenu(){
5760
lv_btnmatrix_set_one_checked(btnm1, true);
5861

5962
lv_obj_add_event_cb(btnm1, eventHandler, LV_EVENT_ALL, NULL);
63+
Braccio.lvgl_unlock();
6064

6165
Braccio.connectJoystickTo(btnm1);
6266
}

examples/tutorials/lessons/04-integration-of-previous-learnings/01_playing_with_a_joint_angle_gauge/01_playing_with_a_joint_angle_gauge.ino

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@ lv_meter_indicator_t * indic;
2323

2424
static void eventHandlerMeter(lv_event_t * e) {
2525
/* Set the meter value */
26+
Braccio.lvgl_lock();
2627
lv_meter_set_indicator_end_value(meter, indic, (int32_t)angles[motorID - 1]);
28+
Braccio.lvgl_unlock();
2729
}
2830

2931

3032
void meterScreen(void)
3133
{
34+
Braccio.lvgl_lock();
3235
meter = lv_meter_create(lv_scr_act());
3336

3437
lv_obj_center(meter);
@@ -52,6 +55,7 @@ void meterScreen(void)
5255
indic = lv_meter_add_arc(meter, scale, 10, lv_color_hex(COLOR_LIGHT_TEAL), 0);
5356

5457
lv_obj_add_event_cb(meter, eventHandlerMeter, LV_EVENT_KEY, NULL);
58+
Braccio.lvgl_unlock();
5559

5660
Braccio.connectJoystickTo(meter);
5761
}

examples/tutorials/lessons/04-integration-of-previous-learnings/02_selecting_the_motor_in_the_LCD_menu/02_selecting_the_motor_in_the_LCD_menu.ino

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ static void eventHandlerMenu(lv_event_t * e) {
5858
// Screens functions
5959
void meterScreen(void)
6060
{
61+
Braccio.lvgl_lock();
6162
meter = lv_meter_create(lv_scr_act());
6263

6364
lv_obj_center(meter);
@@ -83,11 +84,13 @@ void meterScreen(void)
8384
lv_obj_add_event_cb(meter, eventHandlerMeter, LV_EVENT_KEY, NULL);
8485

8586
lv_meter_set_indicator_end_value(meter, indic, (int32_t)angles[motorID - 1]);
87+
Braccio.lvgl_unlock();
8688

8789
Braccio.connectJoystickTo(meter);
8890
}
8991

9092
void motorMenu() {
93+
Braccio.lvgl_lock();
9194
static lv_style_t style_bg;
9295
lv_style_init(&style_bg);
9396
lv_style_set_bg_color(&style_bg, lv_color_hex(COLOR_WHITE));
@@ -116,6 +119,7 @@ void motorMenu() {
116119
lv_btnmatrix_set_one_checked(btnm, true);
117120

118121
lv_obj_add_event_cb(btnm, eventHandlerMenu, LV_EVENT_PRESSED, NULL);
122+
Braccio.lvgl_unlock();
119123

120124
Braccio.connectJoystickTo(btnm);
121125
}

examples/tutorials/lessons/04-integration-of-previous-learnings/03_learnings_challenge_I/03_learnings_challenge_I.ino

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ static void eventHandlerMenu(lv_event_t * e) {
5858
// Screens functions
5959
void meterScreen(void)
6060
{
61+
Braccio.lvgl_lock();
6162
meter = lv_meter_create(lv_scr_act());
6263

6364
lv_obj_center(meter);
@@ -83,11 +84,13 @@ void meterScreen(void)
8384
lv_obj_add_event_cb(meter, eventHandlerMeter, LV_EVENT_KEY, NULL);
8485

8586
lv_meter_set_indicator_end_value(meter, indic, (int32_t)angles[motorID - 1]);
87+
Braccio.lvgl_unlock();
8688

8789
Braccio.connectJoystickTo(meter);
8890
}
8991

9092
void motorMenu() {
93+
Braccio.lvgl_lock();
9194
static lv_style_t style_bg;
9295
lv_style_init(&style_bg);
9396
lv_style_set_bg_color(&style_bg, lv_color_hex(COLOR_WHITE));
@@ -116,6 +119,7 @@ void motorMenu() {
116119
lv_btnmatrix_set_one_checked(btnm, true);
117120

118121
lv_obj_add_event_cb(btnm, eventHandlerMenu, LV_EVENT_PRESSED, NULL);
122+
Braccio.lvgl_unlock();
119123

120124
Braccio.connectJoystickTo(btnm);
121125
}

examples/tutorials/lessons/04-integration-of-previous-learnings/04_learnings_challenge_II/04_learnings_challenge_II.ino

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ static void eventHandlerMenu(lv_event_t * e) {
5858
// Screens functions
5959
void meterScreen(void)
6060
{
61+
Braccio.lvgl_lock();
6162
meter = lv_meter_create(lv_scr_act());
6263

6364
lv_obj_center(meter);
@@ -83,11 +84,13 @@ void meterScreen(void)
8384
lv_obj_add_event_cb(meter, eventHandlerMeter, LV_EVENT_KEY, NULL);
8485

8586
lv_meter_set_indicator_end_value(meter, indic, (int32_t)angles[motorID - 1]);
87+
Braccio.lvgl_unlock();
8688

8789
Braccio.connectJoystickTo(meter);
8890
}
8991

9092
void motorMenu() {
93+
Braccio.lvgl_lock();
9194
static lv_style_t style_bg;
9295
lv_style_init(&style_bg);
9396
lv_style_set_bg_color(&style_bg, lv_color_hex(COLOR_WHITE));
@@ -116,6 +119,7 @@ void motorMenu() {
116119
lv_btnmatrix_set_one_checked(btnm, true);
117120

118121
lv_obj_add_event_cb(btnm, eventHandlerMenu, LV_EVENT_PRESSED, NULL);
122+
Braccio.lvgl_unlock();
119123

120124
Braccio.connectJoystickTo(btnm);
121125
}

0 commit comments

Comments
 (0)