Skip to content

Encapsulate all LVGL library calls within examples/tutorials with lvgl_lock/lvgl_unlock. #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 28, 2022
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
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#include <Braccio++.h>

void customMenu() {
Braccio.lvgl_lock();
lv_obj_t * btn1 = lv_btn_create(lv_scr_act());
lv_obj_set_size(btn1, 120, 75);
lv_obj_t * label1 = lv_label_create(btn1);
lv_label_set_text(label1, "BTN 1");
lv_obj_align(btn1, LV_ALIGN_CENTER, 0, 0);
lv_obj_center(label1);
Braccio.lvgl_unlock();
}

void setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


void customMenu() {
Braccio.lvgl_lock();
static lv_style_t style;
lv_style_init(&style);
lv_style_set_bg_color(&style, lv_color_hex(COLOR_WHITE));
Expand All @@ -26,6 +27,7 @@ void customMenu() {
lv_obj_center(label1);

lv_obj_add_style(btn1, &style, 0);
Braccio.lvgl_unlock();
}

void setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ static const char * btnm_map[] = {"OPTION 1", "OPTION 2", "\n",
};

void customMenu() {
Braccio.lvgl_lock();
static lv_style_t style_bg;
lv_style_init(&style_bg);
lv_style_set_bg_color(&style_bg, lv_color_hex(COLOR_LIGHT_TEAL));
Expand All @@ -33,6 +34,7 @@ void customMenu() {

lv_obj_add_style(btnm1, &style_bg, 0);
lv_obj_add_style(btnm1, &style_btn, LV_PART_ITEMS);
Braccio.lvgl_unlock();
}

void setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ static const char * btnm_map[] = {"OPTION 1", "OPTION 2", "OPTION 3", "\n",
"OPTION 4", "OPTION 5", "\0"
};

void customMenu(){
void customMenu() {
Braccio.lvgl_lock();
static lv_style_t style_bg;
lv_style_init(&style_bg);
lv_style_set_bg_color(&style_bg, lv_color_hex(COLOR_LIGHT_TEAL));
Expand All @@ -33,6 +34,7 @@ void customMenu(){

lv_obj_add_style(btnm1, &style_bg, 0);
lv_obj_add_style(btnm1, &style_btn, LV_PART_ITEMS);
Braccio.lvgl_unlock();
}

void setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ static const char * btnm_map[] = {"BTN 1", "\n",
};

void customMenu() {
Braccio.lvgl_lock();
static lv_style_t style_bg;
lv_style_init(&style_bg);
lv_style_set_bg_color(&style_bg, lv_color_hex(COLOR_BG));
Expand All @@ -33,6 +34,7 @@ void customMenu() {

lv_obj_add_style(btnm1, &style_bg, 0);
lv_obj_add_style(btnm1, &style_btn, LV_PART_ITEMS);
Braccio.lvgl_unlock();
}

void setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ static const char * btnm_map[] = {"Option 1", "Option 2", "\n",
"Option 5", "Option 6", "\0"
};

static void eventHandler(lv_event_t * e){
static void eventHandler(lv_event_t * e) {
Braccio.lvgl_lock();
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t * obj = lv_event_get_target(e);
if (code == LV_EVENT_PRESSED) {
Expand All @@ -25,9 +26,11 @@ static void eventHandler(lv_event_t * e){
LV_LOG_USER("%s was selected\n", txt);
Serial.println(String(txt) + " was selected.");
}
Braccio.lvgl_unlock();
}

void customMenu(){
void customMenu() {
Braccio.lvgl_lock();
static lv_style_t style_bg;
lv_style_init(&style_bg);
lv_style_set_bg_color(&style_bg, lv_color_hex(COLOR_WHITE));
Expand Down Expand Up @@ -57,7 +60,8 @@ void customMenu(){
lv_btnmatrix_set_one_checked(btnm1, true);

lv_obj_add_event_cb(btnm1, eventHandler, LV_EVENT_ALL, NULL);

Braccio.lvgl_unlock();

Braccio.connectJoystickTo(btnm1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ static const char * btnm_map[] = {"Option 1", "Option 2", "\n",
"Option 5", "Option 6", "\0"
};

static void eventHandler(lv_event_t * e){
static void eventHandler(lv_event_t * e) {
Braccio.lvgl_lock();
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t * obj = lv_event_get_target(e);
if (code == LV_EVENT_PRESSING) {
Expand All @@ -25,9 +26,11 @@ static void eventHandler(lv_event_t * e){
LV_LOG_USER("%s is pressed\n", txt);
Serial.println(String(txt) + " is pressed.");
}
Braccio.lvgl_unlock();
}

void customMenu(){
void customMenu() {
Braccio.lvgl_lock();
static lv_style_t style_bg;
lv_style_init(&style_bg);
lv_style_set_bg_color(&style_bg, lv_color_hex(COLOR_LIGHT_TEAL));
Expand Down Expand Up @@ -57,6 +60,7 @@ void customMenu(){
lv_btnmatrix_set_one_checked(btnm1, true);

lv_obj_add_event_cb(btnm1, eventHandler, LV_EVENT_ALL, NULL);
Braccio.lvgl_unlock();

Braccio.connectJoystickTo(btnm1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ static const char * btnm_map[] = {"Option 1", "Option 2", "\n",
"Option 5", "Option 6", "\0"
};

static void eventHandler(lv_event_t * e){
static void eventHandler(lv_event_t * e) {
Braccio.lvgl_lock();
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t * obj = lv_event_get_target(e);
if (code == LV_EVENT_RELEASED) {
Expand All @@ -25,9 +26,11 @@ static void eventHandler(lv_event_t * e){
LV_LOG_USER("%s was released\n", txt);
Serial.println(String(txt) + " was released.");
}
Braccio.lvgl_unlock();
}

void customMenu(){
void customMenu() {
Braccio.lvgl_lock();
static lv_style_t style_bg;
lv_style_init(&style_bg);
lv_style_set_bg_color(&style_bg, lv_color_hex(COLOR_LIGHT_TEAL));
Expand Down Expand Up @@ -57,6 +60,7 @@ void customMenu(){
lv_btnmatrix_set_one_checked(btnm1, true);

lv_obj_add_event_cb(btnm1, eventHandler, LV_EVENT_ALL, NULL);
Braccio.lvgl_unlock();

Braccio.connectJoystickTo(btnm1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ lv_meter_indicator_t * indic;

static void eventHandlerMeter(lv_event_t * e) {
/* Set the meter value */
Braccio.lvgl_lock();
lv_meter_set_indicator_end_value(meter, indic, (int32_t)angles[motorID - 1]);
Braccio.lvgl_unlock();
}


void meterScreen(void)
{
Braccio.lvgl_lock();
meter = lv_meter_create(lv_scr_act());

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

lv_obj_add_event_cb(meter, eventHandlerMeter, LV_EVENT_KEY, NULL);
Braccio.lvgl_unlock();

Braccio.connectJoystickTo(meter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ static void eventHandlerMenu(lv_event_t * e) {
// Screens functions
void meterScreen(void)
{
Braccio.lvgl_lock();
meter = lv_meter_create(lv_scr_act());

lv_obj_center(meter);
Expand All @@ -83,11 +84,13 @@ void meterScreen(void)
lv_obj_add_event_cb(meter, eventHandlerMeter, LV_EVENT_KEY, NULL);

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

Braccio.connectJoystickTo(meter);
}

void motorMenu() {
Braccio.lvgl_lock();
static lv_style_t style_bg;
lv_style_init(&style_bg);
lv_style_set_bg_color(&style_bg, lv_color_hex(COLOR_WHITE));
Expand Down Expand Up @@ -116,6 +119,7 @@ void motorMenu() {
lv_btnmatrix_set_one_checked(btnm, true);

lv_obj_add_event_cb(btnm, eventHandlerMenu, LV_EVENT_PRESSED, NULL);
Braccio.lvgl_unlock();

Braccio.connectJoystickTo(btnm);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ static void eventHandlerMenu(lv_event_t * e) {
// Screens functions
void meterScreen(void)
{
Braccio.lvgl_lock();
meter = lv_meter_create(lv_scr_act());

lv_obj_center(meter);
Expand All @@ -83,11 +84,13 @@ void meterScreen(void)
lv_obj_add_event_cb(meter, eventHandlerMeter, LV_EVENT_KEY, NULL);

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

Braccio.connectJoystickTo(meter);
}

void motorMenu() {
Braccio.lvgl_lock();
static lv_style_t style_bg;
lv_style_init(&style_bg);
lv_style_set_bg_color(&style_bg, lv_color_hex(COLOR_WHITE));
Expand Down Expand Up @@ -116,6 +119,7 @@ void motorMenu() {
lv_btnmatrix_set_one_checked(btnm, true);

lv_obj_add_event_cb(btnm, eventHandlerMenu, LV_EVENT_PRESSED, NULL);
Braccio.lvgl_unlock();

Braccio.connectJoystickTo(btnm);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ static void eventHandlerMenu(lv_event_t * e) {
// Screens functions
void meterScreen(void)
{
Braccio.lvgl_lock();
meter = lv_meter_create(lv_scr_act());

lv_obj_center(meter);
Expand All @@ -83,11 +84,13 @@ void meterScreen(void)
lv_obj_add_event_cb(meter, eventHandlerMeter, LV_EVENT_KEY, NULL);

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

Braccio.connectJoystickTo(meter);
}

void motorMenu() {
Braccio.lvgl_lock();
static lv_style_t style_bg;
lv_style_init(&style_bg);
lv_style_set_bg_color(&style_bg, lv_color_hex(COLOR_WHITE));
Expand Down Expand Up @@ -116,6 +119,7 @@ void motorMenu() {
lv_btnmatrix_set_one_checked(btnm, true);

lv_obj_add_event_cb(btnm, eventHandlerMenu, LV_EVENT_PRESSED, NULL);
Braccio.lvgl_unlock();

Braccio.connectJoystickTo(btnm);
}
Expand Down