Replies: 1 comment
-
|
Here is a suggestion: static knob_handle_t knob;
// Use of std::optional as a static.
static std::optional<slint::ComponentHandle<MainWindow>> ui;
// callback function to update count property
void input_cb (void *arg, void *data) {
auto v = iot_knob_get_count_value(knob);
printf("encoder value: %d\n", v);
(*ui)->set_count(v);
// But I'm afraid the previous line will be problematic, depending how input_cb is called.
// Because if it is in a different task, you need to use invoke_from_event_loop like so:
slint::invoke_from_event_loop([v]{ (*ui)->set_count(v); })
};
extern "C" void app_main(void)
{
// setup slint, knob, etc
// assign dirrectly to the optional.
ui = MainWindow::create();
ESP_ERROR_CHECK(iot_knob_register_cb(knob, KNOB_LEFT, input_cb, NULL));
ESP_ERROR_CHECK(iot_knob_register_cb(knob, KNOB_RIGHT, input_cb, NULL));
// test set count
(*ui)->set_count(20);
(*ui)->run();
}(I did not test this code.) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello! I'm trying to call a set function of the ui, but ouside my main function, on a callback. How do i do this?
For context, I'm using slint on the esp-idf framework. What i've tried is something like this:
When running, the count property is updated to 20, as I can see on the text component. But when the knob callback is triggered, i can see the "encoder value: %d" log being printed out with the right value, but the ui is not changed
Beta Was this translation helpful? Give feedback.
All reactions