Skip to content

Commit 5b4054d

Browse files
committed
add missing wasm app
1 parent 4c1558a commit 5b4054d

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed
File renamed without changes.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright (C) 2019 Intel Corporation. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
CC = /opt/wasi-sdk/bin/clang
5+
APP_DIR = ${shell pwd}
6+
IWASM_DIR = $(APP_DIR)/../../../../core/iwasm
7+
SDK_DIR = $(APP_DIR)/../../../../wamr-sdk/out/gui/app-sdk
8+
APP_FRAMEWORK_DIR = $(APP_DIR)/../../../../wamr-sdk/out/gui/app-sdk/wamr-app-framework
9+
DEPS_DIR = $(APP_DIR)/../../../../core/deps
10+
11+
CFLAGS += -O3 \
12+
-Wno-int-conversion \
13+
-I$(APP_DIR)/src \
14+
-I$(APP_FRAMEWORK_DIR)/include \
15+
-I${DEPS_DIR}
16+
17+
SRCS += $(APP_DIR)/src/main.c
18+
19+
all:
20+
@$(CC) $(CFLAGS) $(SRCS) \
21+
--target=wasm32 -O3 -z stack-size=2048 -Wl,--initial-memory=65536 \
22+
--sysroot=$(SDK_DIR)/libc-builtin-sysroot \
23+
-L$(APP_FRAMEWORK_DIR)/lib -lapp_framework \
24+
-Wl,--allow-undefined-file=$(SDK_DIR)/libc-builtin-sysroot/share/defined-symbols.txt \
25+
-Wl,--no-threads,--strip-all,--no-entry -nostdlib \
26+
-Wl,--export=on_init -Wl,--export=on_timer_callback \
27+
-Wl,--export=on_widget_event \
28+
-Wl,--export=__heap_base,--export=__data_end \
29+
-o ui_decrease.wasm
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright (C) 2019 Intel Corporation. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
*/
5+
6+
#include <stdlib.h>
7+
#include "wasm_app.h"
8+
#include "wa-inc/lvgl/lvgl.h"
9+
#include "wa-inc/timer_wasm_app.h"
10+
11+
extern char g_widget_text[];
12+
13+
static void btn_event_cb(lv_obj_t *btn, lv_event_t event);
14+
15+
uint32_t count = 0;
16+
char count_str[11] = { 0 };
17+
lv_obj_t *hello_world_label;
18+
lv_obj_t *count_label;
19+
lv_obj_t *btn1;
20+
lv_obj_t *label_count1;
21+
int label_count1_value = 100;
22+
char label_count1_str[11] = { 0 };
23+
24+
void timer1_update(user_timer_t timer1)
25+
{
26+
if ((count % 100) == 0) {
27+
snprintf(count_str, sizeof(count_str), "%d", count / 100);
28+
lv_label_set_text(count_label, count_str);
29+
}
30+
++count;
31+
}
32+
33+
void on_init()
34+
{
35+
char *text;
36+
37+
hello_world_label = lv_label_create(NULL, NULL);
38+
lv_label_set_text(hello_world_label, "Hello world!");
39+
text = lv_label_get_text(hello_world_label);
40+
printf("Label text %lu %s \n", strlen(text), text);
41+
lv_obj_align(hello_world_label, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0);
42+
43+
count_label = lv_label_create(NULL, NULL);
44+
lv_obj_align(count_label, NULL, LV_ALIGN_IN_TOP_MID, 0, 0);
45+
46+
btn1 = lv_btn_create(NULL, NULL); /*Create a button on the currently loaded screen*/
47+
lv_obj_set_event_cb(btn1, btn_event_cb); /*Set function to be called when the button is released*/
48+
lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, 0); /*Align below the label*/
49+
50+
/*Create a label on the button*/
51+
lv_obj_t *btn_label = lv_label_create(btn1, NULL);
52+
lv_label_set_text(btn_label, "Click --");
53+
54+
label_count1 = lv_label_create(NULL, NULL);
55+
lv_label_set_text(label_count1, "100");
56+
lv_obj_align(label_count1, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
57+
58+
/* set up a timer */
59+
user_timer_t timer;
60+
timer = api_timer_create(10, true, false, timer1_update);
61+
if (timer)
62+
api_timer_restart(timer, 10);
63+
else
64+
printf("Fail to create timer.\n");
65+
}
66+
67+
static void btn_event_cb(lv_obj_t *btn, lv_event_t event)
68+
{
69+
if(event == LV_EVENT_RELEASED) {
70+
label_count1_value--;
71+
snprintf(label_count1_str, sizeof(label_count1_str),
72+
"%d", label_count1_value);
73+
lv_label_set_text(label_count1, label_count1_str);
74+
if (label_count1_value == 0)
75+
label_count1_value = 100;
76+
}
77+
}

0 commit comments

Comments
 (0)