Refactor the wasm graphic layer (wgl) and the gui sample (#231)
This commit is contained in:
@ -40,16 +40,14 @@ Build and Run
|
||||
|
||||
- Build</br>
|
||||
`./build.sh`</br>
|
||||
All binaries are in "out", which contains "host_tool", "lvgl_native_ui_app", "ui_app.wasm", "ui_app_lvgl_compatible.wasm" and "wasm_runtime_wgl".
|
||||
- Run native Linux application</br>
|
||||
`./lvgl_native_ui_app`</br>
|
||||
All binaries are in "out", which contains "host_tool", "ui_decrease.wasm", "ui_increase.wasm" and "wasm_runtime_wgl".
|
||||
|
||||
- Run WASM VM Linux applicaton & install WASM APP</br>
|
||||
First start wasm_runtime_wgl in server mode.</br>
|
||||
`./wasm_runtime_wgl -s`</br>
|
||||
Then install wasm APP use host tool.</br>
|
||||
`./host_tool -i ui_app -f ui_app.wasm`</br>
|
||||
`./host_tool -i ui_app -f ui_app_lvgl_compatible.wasm`</br>
|
||||
`./host_tool -i inc -f ui_increase.wasm`</br>
|
||||
`./host_tool -i dec -f ui_decrease.wasm`</br>
|
||||
|
||||
|
||||
|
||||
@ -107,11 +105,11 @@ https://docs.zephyrproject.org/latest/getting_started/index.html</br>
|
||||
|
||||
- Install WASM application to Zephyr using host_tool</br>
|
||||
First, connect PC and STM32 with UART. Then install to use host_tool.</br>
|
||||
`./host_tool -D /dev/ttyUSBXXX -i ui_app -f ui_app.wasm`
|
||||
`./host_tool -D /dev/ttyUSBXXX -i inc -f ui_increase.wasm`
|
||||
|
||||
- Install AOT version WASM application
|
||||
`wamrc --target=thumbv7 --target-abi=eabi --cpu=cortex-m7 -o ui_app.aot ui_app.wasm`
|
||||
`./host_tool -D /dev/ttyUSBXXX -i ui_app -f ui_app.aot`
|
||||
`wamrc --target=thumbv7 --target-abi=eabi --cpu=cortex-m7 -o ui_app.aot ui_increase.wasm`
|
||||
`./host_tool -D /dev/ttyUSBXXX -i inc -f ui_app.aot`
|
||||
|
||||
|
||||
|
||||
|
||||
@ -25,21 +25,8 @@ rm -rf ${OUT_DIR}
|
||||
mkdir ${OUT_DIR}
|
||||
|
||||
|
||||
cd ${WAMR_DIR}/core/shared/mem-alloc
|
||||
if [ ! -d "tlsf" ]; then
|
||||
git clone https://github.com/mattconte/tlsf
|
||||
fi
|
||||
|
||||
cd ${WAMR_DIR}/core/deps
|
||||
if [ ! -d "lvgl" ]; then
|
||||
git clone https://github.com/littlevgl/lvgl.git --branch v6.0.1
|
||||
fi
|
||||
if [ ! -d "lv_drivers" ]; then
|
||||
git clone https://github.com/littlevgl/lv_drivers.git
|
||||
fi
|
||||
|
||||
echo -e "\n\n"
|
||||
echo "##################### 0. build wamr-sdk gui start#####################"
|
||||
echo "##################### 1. build wamr-sdk gui start#####################"
|
||||
cd ${WAMR_DIR}/wamr-sdk
|
||||
./build_sdk.sh -n gui -x ${WAMR_RUNTIME_CFG} -e ${LV_CFG_PATH}
|
||||
[ $? -eq 0 ] || exit $?
|
||||
@ -47,23 +34,6 @@ cd ${WAMR_DIR}/wamr-sdk
|
||||
echo "#####################build wamr-sdk success"
|
||||
|
||||
|
||||
echo -e "\n\n"
|
||||
echo "##################### 1. build native-ui-app start#####################"
|
||||
cd $BUILD_DIR
|
||||
mkdir -p lvgl-native-ui-app
|
||||
cd lvgl-native-ui-app
|
||||
$cmakewrap ${PROJECT_DIR}/lvgl-native-ui-app
|
||||
[ $? -eq 0 ] || exit $?
|
||||
$makewrap
|
||||
if [ $? != 0 ];then
|
||||
echo "BUILD_FAIL native-ui-app $?\n"
|
||||
exit 2
|
||||
fi
|
||||
echo $PWD
|
||||
cp lvgl_native_ui_app ${OUT_DIR}
|
||||
echo "#####################build native-ui-app success"
|
||||
echo -e "\n\n"
|
||||
|
||||
|
||||
echo "##################### 2. build wasm runtime start#####################"
|
||||
cd $BUILD_DIR
|
||||
@ -94,20 +64,7 @@ echo "#####################build host-tool success"
|
||||
echo -e "\n\n"
|
||||
|
||||
echo "##################### 3. build wasm ui app start#####################"
|
||||
cd ${PROJECT_DIR}/wasm-apps/wgl
|
||||
cd ${PROJECT_DIR}/wasm-apps
|
||||
export OUT_DIR=${OUT_DIR}
|
||||
./build_apps.sh
|
||||
|
||||
rm -rf build
|
||||
mkdir build && cd build
|
||||
$cmakewrap .. -DCMAKE_TOOLCHAIN_FILE=${WAMR_DIR}/wamr-sdk/out/gui/app-sdk/wamr_toolchain.cmake
|
||||
$makewrap
|
||||
[ $? -eq 0 ] || exit $?
|
||||
mv ui_app.wasm ${OUT_DIR}/
|
||||
|
||||
# $makewrap
|
||||
# mv ui_app.wasm ${OUT_DIR}/
|
||||
|
||||
cd ${PROJECT_DIR}/wasm-apps/lvgl-compatible
|
||||
$makewrap
|
||||
[ $? -eq 0 ] || exit $?
|
||||
mv ui_app_lvgl_compatible.wasm ${OUT_DIR}/
|
||||
echo "##################### build wasm ui app end#####################"
|
||||
|
||||
@ -1,43 +0,0 @@
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
cmake_minimum_required (VERSION 2.8.2)
|
||||
message ("lvgl_native_ui_app...")
|
||||
project (lvgl_native_ui_app)
|
||||
|
||||
#################################################################
|
||||
|
||||
# Currently build as 64-bit by default. Set to "NO" to build 32-bit binaries.
|
||||
set (BUILD_AS_64BIT_SUPPORT "YES")
|
||||
|
||||
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
if (${BUILD_AS_64BIT_SUPPORT} STREQUAL "YES")
|
||||
# Add -fPIC flag if build as 64-bit
|
||||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
|
||||
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC")
|
||||
else ()
|
||||
add_definitions (-m32)
|
||||
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
|
||||
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
set(WAMR_DEPS_DIR ../../../core/deps)
|
||||
set(LVGL_SOURCE_DIR ${WAMR_DEPS_DIR}/lvgl)
|
||||
set(LVGL_DRIVER_DIR ${WAMR_DEPS_DIR}/lv_drivers)
|
||||
|
||||
#################################
|
||||
|
||||
add_definitions(-DLV_CONF_INCLUDE_SIMPLE)
|
||||
|
||||
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR})
|
||||
INCLUDE_DIRECTORIES(${WAMR_DEPS_DIR})
|
||||
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/../lv_config)
|
||||
|
||||
|
||||
file(GLOB_RECURSE INCLUDES "${LVGL_DRIVER_DIR}/*.h" "${LVGL_SOURCE_DIR}/*.h" "./*.h" )
|
||||
file(GLOB_RECURSE SOURCES "${LVGL_DRIVER_DIR}/*.c" "${LVGL_SOURCE_DIR}/*.c" )
|
||||
|
||||
add_executable(lvgl_native_ui_app main.c get_time.c ${SOURCES} ${INCLUDES})
|
||||
target_link_libraries(lvgl_native_ui_app PRIVATE SDL2 )
|
||||
|
||||
@ -1,8 +0,0 @@
|
||||
MIT licence
|
||||
Copyright (c) 2016 Gábor Kiss-Vámosi
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@ -1,11 +0,0 @@
|
||||
#include <sys/time.h>
|
||||
#include "system_header.h"
|
||||
|
||||
int time_get_ms()
|
||||
{
|
||||
static struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
long long time_in_mill = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000;
|
||||
|
||||
return (int) time_in_mill;
|
||||
}
|
||||
@ -1,153 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file main
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#define _DEFAULT_SOURCE /* needed for usleep() */
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#define SDL_MAIN_HANDLED /*To fix SDL's "undefined reference to WinMain" issue*/
|
||||
#include <SDL2/SDL.h>
|
||||
#include "lvgl/lvgl.h"
|
||||
#include "lv_drivers/display/monitor.h"
|
||||
#include "lv_drivers/indev/mouse.h"
|
||||
#include "lv_drivers/indev/mousewheel.h"
|
||||
#include "lv_drivers/indev/keyboard.h"
|
||||
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/*On OSX SDL needs different handling*/
|
||||
#if defined(__APPLE__) && defined(TARGET_OS_MAC)
|
||||
# if __APPLE__ && TARGET_OS_MAC
|
||||
#define SDL_APPLE
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static void hal_init(void);
|
||||
static void btn_event_cb(lv_obj_t * btn, lv_event_t event);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
uint32_t count = 0;
|
||||
char count_str[11] = { 0 };
|
||||
lv_obj_t *hello_world_label;
|
||||
lv_obj_t *count_label;
|
||||
lv_obj_t * btn1;
|
||||
lv_obj_t * label_count1;
|
||||
int label_count1_value = 0;
|
||||
char label_count1_str[11] = { 0 };
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
(void) argc; /*Unused*/
|
||||
(void) argv; /*Unused*/
|
||||
|
||||
/*Initialize LittlevGL*/
|
||||
lv_init();
|
||||
|
||||
/*Initialize the HAL (display, input devices, tick) for LittlevGL*/
|
||||
hal_init();
|
||||
|
||||
hello_world_label = lv_label_create(lv_disp_get_scr_act(NULL), NULL);
|
||||
lv_label_set_text(hello_world_label, "Hello world!");
|
||||
lv_obj_align(hello_world_label, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0);
|
||||
|
||||
count_label = lv_label_create(lv_disp_get_scr_act(NULL), NULL);
|
||||
lv_obj_align(count_label, NULL, LV_ALIGN_IN_TOP_MID, 0, 0);
|
||||
btn1 = lv_btn_create(lv_disp_get_scr_act(NULL), NULL); /*Create a button on the currently loaded screen*/
|
||||
lv_obj_set_event_cb(btn1, btn_event_cb); /*Set function to be called when the button is released*/
|
||||
lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, 20); /*Align below the label*/
|
||||
|
||||
/*Create a label on the button*/
|
||||
lv_obj_t * btn_label = lv_label_create(btn1, NULL);
|
||||
lv_label_set_text(btn_label, "Click ++");
|
||||
|
||||
label_count1 = lv_label_create(lv_disp_get_scr_act(NULL), NULL);
|
||||
lv_label_set_text(label_count1, "0");
|
||||
lv_obj_align(label_count1, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
|
||||
while(1) {
|
||||
/* Periodically call the lv_task handler.
|
||||
* It could be done in a timer interrupt or an OS task too.*/
|
||||
if ((count % 100) == 0) {
|
||||
snprintf(count_str, sizeof(count_str), "%d", count/ 100);
|
||||
lv_label_set_text(count_label, count_str);
|
||||
}
|
||||
lv_task_handler();
|
||||
++count;
|
||||
usleep(10 * 1000); /*Just to let the system breath*/
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initialize the Hardware Abstraction Layer (HAL) for the Littlev graphics library
|
||||
*/
|
||||
static void hal_init(void)
|
||||
{
|
||||
/* Use the 'monitor' driver which creates window on PC's monitor to simulate a display*/
|
||||
monitor_init();
|
||||
|
||||
/*Create a display buffer*/
|
||||
static lv_disp_buf_t disp_buf1;
|
||||
static lv_color_t buf1_1[320*10];
|
||||
lv_disp_buf_init(&disp_buf1, buf1_1, NULL, 320*10);
|
||||
|
||||
/*Create a display*/
|
||||
lv_disp_drv_t disp_drv;
|
||||
lv_disp_drv_init(&disp_drv); /*Basic initialization*/
|
||||
disp_drv.buffer = &disp_buf1;
|
||||
disp_drv.flush_cb = monitor_flush; /*Used when `LV_VDB_SIZE != 0` in lv_conf.h (buffered drawing)*/
|
||||
// disp_drv.hor_res = 200;
|
||||
// disp_drv.ver_res = 100;
|
||||
lv_disp_drv_register(&disp_drv);
|
||||
|
||||
/* Add the mouse as input device
|
||||
* Use the 'mouse' driver which reads the PC's mouse*/
|
||||
mouse_init();
|
||||
lv_indev_drv_t indev_drv;
|
||||
lv_indev_drv_init(&indev_drv); /*Basic initialization*/
|
||||
indev_drv.type = LV_INDEV_TYPE_POINTER;
|
||||
indev_drv.read_cb = mouse_read; /*This function will be called periodically (by the library) to get the mouse position and state*/
|
||||
lv_indev_drv_register(&indev_drv);
|
||||
}
|
||||
|
||||
static void btn_event_cb(lv_obj_t * btn, lv_event_t event)
|
||||
{
|
||||
if(event == LV_EVENT_RELEASED) {
|
||||
label_count1_value++;
|
||||
snprintf(label_count1_str, sizeof(label_count1_str),
|
||||
"%d", label_count1_value);
|
||||
lv_label_set_text(label_count1, label_count1_str);
|
||||
}
|
||||
}
|
||||
44
samples/gui/wasm-apps/build_apps.sh
Executable file
44
samples/gui/wasm-apps/build_apps.sh
Executable file
@ -0,0 +1,44 @@
|
||||
#!/bin/bash
|
||||
|
||||
APPS_ROOT=$(cd "$(dirname "$0")/" && pwd)
|
||||
cd ${APPS_ROOT}
|
||||
|
||||
echo "OUT_DIR: ${OUT_DIR}"
|
||||
|
||||
if [ -z ${OUT_DIR} ]; then
|
||||
OUT_DIR=${APPS_ROOT}/out
|
||||
echo "set the wasm app folder: ${OUT_DIR}"
|
||||
|
||||
if [ -d ${OUT_DIR} ]; then
|
||||
rm -rf ${OUT_DIR}
|
||||
echo "removed the present output folder: ${OUT_DIR}"
|
||||
fi
|
||||
mkdir ${OUT_DIR}
|
||||
|
||||
fi
|
||||
|
||||
if [ -z ${WAMR_DIR} ]; then
|
||||
WAMR_DIR=${APPS_ROOT}/../../..
|
||||
fi
|
||||
|
||||
|
||||
cd ${APPS_ROOT}/increase
|
||||
|
||||
rm -rf build
|
||||
mkdir build && cd build
|
||||
cmake .. -DCMAKE_TOOLCHAIN_FILE=${WAMR_DIR}/wamr-sdk/out/gui/app-sdk/wamr_toolchain.cmake
|
||||
make
|
||||
[ $? -eq 0 ] || exit $?
|
||||
mv ui_increase.wasm ${OUT_DIR}/
|
||||
|
||||
# $makewrap
|
||||
# mv ui_app.wasm ${OUT_DIR}/
|
||||
|
||||
cd ${APPS_ROOT}/decrease
|
||||
make
|
||||
[ $? -eq 0 ] || exit $?
|
||||
mv ui_decrease.wasm ${OUT_DIR}/
|
||||
|
||||
echo "WASM files generated in folder ${OUT_DIR}"
|
||||
|
||||
echo "##################### build WASM APPs finished #####################"
|
||||
@ -26,4 +26,4 @@ all:
|
||||
-Wl,--export=on_init -Wl,--export=on_timer_callback \
|
||||
-Wl,--export=on_widget_event \
|
||||
-Wl,--export=__heap_base,--export=__data_end \
|
||||
-o ui_app_lvgl_compatible.wasm
|
||||
-o ui_decrease.wasm
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "wasm_app.h"
|
||||
#include "wa-inc/lvgl.h"
|
||||
#include "wa-inc/lvgl/lvgl.h"
|
||||
#include "wa-inc/timer_wasm_app.h"
|
||||
|
||||
extern char g_widget_text[];
|
||||
@ -13,8 +13,8 @@ set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS},-L${WAMR_ROOT_DIR}/wamr-s
|
||||
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS},--export=on_init,--export=on_timer_callback,--export=on_widget_event,--export=__heap_base,--export=__data_end")
|
||||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -Wno-unused-command-line-argument")
|
||||
|
||||
add_executable(ui_app.wasm
|
||||
add_executable(ui_increase.wasm
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/main.c
|
||||
)
|
||||
|
||||
target_link_libraries(ui_app.wasm app_framework)
|
||||
target_link_libraries(ui_increase.wasm app_framework)
|
||||
78
samples/gui/wasm-apps/increase/src/main.c
Normal file
78
samples/gui/wasm-apps/increase/src/main.c
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "wasm_app.h"
|
||||
#include "wa-inc/lvgl/lvgl.h"
|
||||
#include "wa-inc/timer_wasm_app.h"
|
||||
|
||||
extern char g_widget_text[];
|
||||
|
||||
static void btn_event_cb(lv_obj_t *btn, lv_event_t event);
|
||||
|
||||
uint32_t count = 0;
|
||||
char count_str[11] = { 0 };
|
||||
lv_obj_t *hello_world_label;
|
||||
lv_obj_t *count_label;
|
||||
lv_obj_t *btn1;
|
||||
lv_obj_t *label_count1;
|
||||
int label_count1_value = 1;
|
||||
char label_count1_str[11] = { 0 };
|
||||
|
||||
void timer1_update(user_timer_t timer1)
|
||||
{
|
||||
if ((count % 100) == 0) {
|
||||
snprintf(count_str, sizeof(count_str), "%d", count / 100);
|
||||
lv_label_set_text(count_label, count_str);
|
||||
}
|
||||
++count;
|
||||
}
|
||||
|
||||
void on_init()
|
||||
{
|
||||
char *text;
|
||||
|
||||
hello_world_label = lv_label_create(NULL, NULL);
|
||||
lv_label_set_text(hello_world_label, "Hello world!");
|
||||
text = lv_label_get_text(hello_world_label);
|
||||
printf("Label text %lu %s \n", strlen(text), text);
|
||||
lv_obj_align(hello_world_label, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0);
|
||||
|
||||
count_label = lv_label_create(NULL, NULL);
|
||||
lv_obj_align(count_label, NULL, LV_ALIGN_IN_TOP_MID, 0, 0);
|
||||
|
||||
btn1 = lv_btn_create(NULL, NULL); /*Create a button on the currently loaded screen*/
|
||||
lv_obj_set_event_cb(btn1, btn_event_cb); /*Set function to be called when the button is released*/
|
||||
lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, 0); /*Align below the label*/
|
||||
|
||||
/*Create a label on the button*/
|
||||
lv_obj_t *btn_label = lv_label_create(btn1, NULL);
|
||||
lv_label_set_text(btn_label, "Click ++");
|
||||
|
||||
label_count1 = lv_label_create(NULL, NULL);
|
||||
lv_label_set_text(label_count1, "1");
|
||||
lv_obj_align(label_count1, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
|
||||
|
||||
/* set up a timer */
|
||||
user_timer_t timer;
|
||||
timer = api_timer_create(10, true, false, timer1_update);
|
||||
if (timer)
|
||||
api_timer_restart(timer, 10);
|
||||
else
|
||||
printf("Fail to create timer.\n");
|
||||
}
|
||||
|
||||
static void btn_event_cb(lv_obj_t *btn, lv_event_t event)
|
||||
{
|
||||
if(event == LV_EVENT_RELEASED) {
|
||||
label_count1_value++;
|
||||
snprintf(label_count1_str, sizeof(label_count1_str),
|
||||
"%d", label_count1_value);
|
||||
lv_label_set_text(label_count1, label_count1_str);
|
||||
if (label_count1_value == 100)
|
||||
label_count1_value = 0;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "wasm_app.h"
|
||||
#include "wa-inc/wgl.h"
|
||||
#include "wa-inc/timer_wasm_app.h"
|
||||
|
||||
static void btn_event_cb(wgl_obj_t btn, wgl_event_t event);
|
||||
|
||||
uint32_t count = 0;
|
||||
char count_str[11] = { 0 };
|
||||
wgl_obj_t hello_world_label;
|
||||
wgl_obj_t count_label;
|
||||
wgl_obj_t btn1;
|
||||
wgl_obj_t label_count1;
|
||||
int label_count1_value = 0;
|
||||
char label_count1_str[11] = { 0 };
|
||||
|
||||
void timer1_update(user_timer_t timer1)
|
||||
{
|
||||
if ((count % 100) == 0) {
|
||||
snprintf(count_str, sizeof(count_str), "%d", count / 100);
|
||||
wgl_label_set_text(count_label, count_str);
|
||||
}
|
||||
++count;
|
||||
}
|
||||
|
||||
void on_init()
|
||||
{
|
||||
hello_world_label = wgl_label_create((wgl_obj_t)NULL, (wgl_obj_t)NULL);
|
||||
wgl_label_set_text(hello_world_label, "Hello world!");
|
||||
wgl_obj_align(hello_world_label, (wgl_obj_t)NULL, WGL_ALIGN_IN_TOP_LEFT, 0, 0);
|
||||
|
||||
count_label = wgl_label_create((wgl_obj_t)NULL, (wgl_obj_t)NULL);
|
||||
wgl_obj_align(count_label, (wgl_obj_t)NULL, WGL_ALIGN_IN_TOP_MID, 0, 0);
|
||||
|
||||
btn1 = wgl_btn_create((wgl_obj_t)NULL, (wgl_obj_t)NULL); /*Create a button on the currently loaded screen*/
|
||||
wgl_obj_set_event_cb(btn1, btn_event_cb); /*Set function to be called when the button is released*/
|
||||
wgl_obj_align(btn1, (wgl_obj_t)NULL, WGL_ALIGN_CENTER, 0, 0); /*Align below the label*/
|
||||
|
||||
/*Create a label on the button*/
|
||||
wgl_obj_t btn_label = wgl_label_create(btn1, (wgl_obj_t)NULL);
|
||||
wgl_label_set_text(btn_label, "Click ++");
|
||||
|
||||
label_count1 = wgl_label_create((wgl_obj_t)NULL, (wgl_obj_t)NULL);
|
||||
wgl_label_set_text(label_count1, "0");
|
||||
wgl_obj_align(label_count1, (wgl_obj_t)NULL, WGL_ALIGN_IN_BOTTOM_MID, 0, 0);
|
||||
|
||||
/* set up a timer */
|
||||
user_timer_t timer;
|
||||
timer = api_timer_create(10, true, false, timer1_update);
|
||||
if (timer)
|
||||
api_timer_restart(timer, 10);
|
||||
else
|
||||
printf("Fail to create timer.\n");
|
||||
}
|
||||
|
||||
static void btn_event_cb(wgl_obj_t btn, wgl_event_t event)
|
||||
{
|
||||
if(event == WGL_EVENT_RELEASED) {
|
||||
label_count1_value++;
|
||||
snprintf(label_count1_str, sizeof(label_count1_str),
|
||||
"%d", label_count1_value);
|
||||
wgl_label_set_text(label_count1, label_count1_str);
|
||||
|
||||
//wgl_cont_set_fit4(btn, WGL_FIT_FLOOD, WGL_FIT_FLOOD, WGL_FIT_FLOOD, WGL_FIT_FLOOD);
|
||||
//wgl_obj_clean(btn);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user