Created
February 23, 2024 20:27
-
-
Save Habbie/d95efadf7361c9bce815997754cef339 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/HAEntity.cpp b/src/HAEntity.cpp | |
index 8656cc5..e4ebb5e 100644 | |
--- a/src/HAEntity.cpp | |
+++ b/src/HAEntity.cpp | |
@@ -82,8 +82,11 @@ void HAEntity::detach(IObserver* observer) | |
observers.erase(observer); | |
} | |
+extern std::mutex LVlock; | |
+ | |
void HAEntity::notify() | |
{ | |
+ std::unique_lock<std::mutex> lvlock(LVlock); | |
for (const auto& obs : observers) { | |
obs->uiupdate(); | |
} | |
diff --git a/src/front-lvgl.cpp b/src/front-lvgl.cpp | |
index 9fc1201..66e42e5 100644 | |
--- a/src/front-lvgl.cpp | |
+++ b/src/front-lvgl.cpp | |
@@ -82,6 +82,8 @@ static void slider_event_cb(lv_event_t* e) | |
} | |
} | |
+extern std::mutex LVlock; | |
+ | |
void uithread(HABackend& backend, int argc, char* argv[]) | |
{ | |
argparse::ArgumentParser program("client-lvgl"); | |
@@ -232,8 +234,11 @@ void uithread(HABackend& backend, int argc, char* argv[]) | |
i = 0; | |
while (true) { | |
usleep(5 * 1000); // 5000 usec = 5 ms | |
- lv_tick_inc(5); // 5 ms | |
- lv_task_handler(); | |
+ { | |
+ std::unique_lock<std::mutex> lvlock(LVlock); | |
+ lv_tick_inc(5); // 5 ms | |
+ lv_task_handler(); | |
+ } | |
if (i++ == (1000 / 5)) { | |
cerr << "." << flush; | |
i = 0; | |
diff --git a/src/lv_conf.h b/src/lv_conf.h | |
index 9c6b729..ebe127f 100644 | |
--- a/src/lv_conf.h | |
+++ b/src/lv_conf.h | |
@@ -230,7 +230,7 @@ | |
*-----------*/ | |
/*Enable the log module*/ | |
-#define LV_USE_LOG 0 | |
+#define LV_USE_LOG 1 | |
#if LV_USE_LOG | |
/*How important log should be added: | |
diff --git a/src/main.cpp b/src/main.cpp | |
index f603072..bb50c0f 100644 | |
--- a/src/main.cpp | |
+++ b/src/main.cpp | |
@@ -19,6 +19,8 @@ using std::string; | |
extern void uithread(HABackend& backend, int /* argc */, char*[] /* argv[] */); | |
+std::mutex LVlock; | |
+ | |
std::string GetEnv(std::string key) | |
{ | |
auto value = getenv(key.c_str()); | |
diff --git a/src/uicomponents/uirgblight.cpp b/src/uicomponents/uirgblight.cpp | |
index 0daec57..3184f26 100644 | |
--- a/src/uicomponents/uirgblight.cpp | |
+++ b/src/uicomponents/uirgblight.cpp | |
@@ -175,10 +175,13 @@ void UIRGBLight::uiupdate() | |
auto state = entity->getJsonState(); | |
string colormode = getColorMode(); | |
// std::cerr << "COLOR MODE: " << colormode << std::endl; | |
+ std::cerr<<"this="<<this<<std::endl; | |
std::cerr << "UPDATED STATE FOR " << entity->name << ":" << state.dump(2) << std::endl; | |
if (state["state"] == "on") { // FIXME: We should get rid of parsing JSON here | |
lv_obj_add_state(btnOnOff, LV_STATE_CHECKED); | |
int brightness = state["attributes"]["brightness"].get<int>(); // brightness is NULL If the thing is off | |
+ std::cerr<<"got brightness "<<brightness<<std::endl; | |
+ std::cerr<<"slider="<<brightnessSlider<<std::endl; | |
lv_slider_set_value(brightnessSlider, brightness, LV_ANIM_OFF); | |
int brightnessPercent = static_cast<int>(brightness / 2.55); | |
std::string strBrightnessPercent = std::to_string(brightnessPercent); | |
@@ -295,6 +298,7 @@ void UIRGBLight::btnColorTemp_cb(lv_event_t* e) | |
void UIRGBLight::brightness_slide_cb(lv_event_t* e) | |
{ | |
+ std::cerr<<"brightness_slide_cb"<<std::endl; | |
lv_event_code_t code = lv_event_get_code(e); | |
if (code == LV_EVENT_VALUE_CHANGED) { | |
auto slidervalue = lv_slider_get_value(e->target); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment