application/main.c

branch
newapi
changeset 347
6f0d0b0d97f5
parent 345
d2ccc543f432
--- a/application/main.c	Wed Oct 23 15:05:20 2024 +0200
+++ b/application/main.c	Wed Oct 23 15:57:59 2024 +0200
@@ -51,6 +51,35 @@
 
 UIWIDGET tabview;
 
+static UiCondVar *cond;
+static int thr_end = 0;
+static int thr_started = 0;
+
+int threadfunc(void *data) {
+    printf("thr wait for data...\n");
+    ui_condvar_wait(cond);
+    printf("thr data received: {%s} [%d]\n", cond->data, cond->intdata);
+    ui_condvar_destroy(cond);
+    cond = NULL;
+    
+    return 0;
+}
+
+void action_start_thread(UiEvent *event, void *data) {
+    if(!thr_started) {
+        cond = ui_condvar_create();
+        ui_job(event->obj, threadfunc, NULL, NULL, NULL);
+        thr_started = 1;
+    }
+}
+
+void action_notify_thread(UiEvent *event, void *data) {
+    if(!thr_end) {
+        ui_condvar_signal(cond, "hello thread", 123);
+        thr_end = 1;
+    }
+}
+
 void action_menu(UiEvent *event, void *userdata) {
     
 }
@@ -252,8 +281,8 @@
             }
         }
         ui_tab(obj, "Tab 2") {
-            ui_button(obj, .label = "Button 1", .onclick=action_tab2_button);
-            ui_button(obj, .label = "Button 2", .onclick=action_tab2_button);
+            ui_button(obj, .label = "Button 1 Start Thread", .onclick=action_start_thread);
+            ui_button(obj, .label = "Button 2 Notify Thread", .onclick=action_notify_thread);
             ui_button(obj, .label = "Button 3", .onclick=action_tab2_button);
             ui_button(obj, .label = "Button 4", .onclick=action_tab2_button);
             ui_button(obj, .label = "Button 5", .onclick=action_tab2_button);

mercurial