Implement 2D graphic API (#87)

* Implement 2D graphic library based on LittlevGL

* Add lvgl license file
This commit is contained in:
Weining
2019-08-01 16:57:54 +08:00
committed by wenyongh
parent 1db5a2f697
commit 9aa9cbde77
86 changed files with 8675 additions and 10 deletions

View File

@ -48,6 +48,29 @@ set(WASM_DIR ${WAMR_ROOT_DIR}/core/iwasm)
set(APP_MGR_DIR ${WAMR_ROOT_DIR}/core/app-mgr)
set(SHARED_DIR ${WAMR_ROOT_DIR}/core/shared-lib)
set (lv_drivers_name lv_drivers)
set (lv_name lvgl)
set (LV_DRIVERS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/${lv_drivers_name})
set (LVGL_DIR ${WASM_DIR}/lib/3rdparty/${lv_name})
if ((NOT EXISTS ${LVGL_DIR}) OR (NOT EXISTS ${LV_DRIVERS_DIR}))
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt.in ${CMAKE_CURRENT_BINARY_DIR}/download_lvgl_drivers/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/download_lvgl_drivers )
if(result)
message(FATAL_ERROR "CMake step for lvgl drivers failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/download_lvgl_drivers )
if(result)
message(FATAL_ERROR "Build step for lvgl drivers failed: ${result}")
endif()
endif()
file(GLOB_RECURSE LV_DRIVERS_SOURCES "${LV_DRIVERS_DIR}/*.c" )
enable_language (ASM)
@ -57,6 +80,7 @@ include (${WASM_DIR}/runtime/vmcore-wasm/vmcore.cmake)
include (${WASM_DIR}/lib/native/base/wasm_lib_base.cmake)
include (${WASM_DIR}/lib/native/libc/wasm_libc.cmake)
include (${WASM_DIR}/lib/native/extension/sensor/wasm_lib_sensor.cmake)
include (${WASM_DIR}/lib/native/extension/gui/wasm_lib_gui.cmake)
include (${WASM_DIR}/lib/native/extension/connection/wasm_lib_conn.cmake)
include (${WASM_DIR}/lib/native/extension/connection/${TARGET_PLATFORM}/connection_mgr.cmake)
include (${WASM_DIR}/lib/native-interface/native_interface.cmake)
@ -85,6 +109,7 @@ add_library (vmlib
${WASM_LIB_BASE_SOURCE}
${WASM_LIB_EXT_SOURCE}
${WASM_LIB_SENSOR_SOURCE}
${WASM_LIB_GUI_SOURCE}
${WASM_LIB_CONN_SOURCE}
${WASM_LIB_CONN_MGR_SOURCE}
${PLATFORM_SHARED_SOURCE}
@ -93,7 +118,7 @@ add_library (vmlib
${NATIVE_INTERFACE_SOURCE}
)
add_executable (simple src/main.c src/iwasm_main.c src/ext_lib_export.c)
add_executable (simple src/main.c src/iwasm_main.c src/ext_lib_export.c ${LV_DRIVERS_SOURCES})
target_link_libraries (simple vmlib -lm -ldl -lpthread)
target_link_libraries (simple vmlib -lm -ldl -lpthread -lSDL2)

View File

@ -0,0 +1,41 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cmake_minimum_required(VERSION 2.8.2)
project(lvgl_download NONE)
include(ExternalProject)
ExternalProject_Add(${lv_name}
GIT_REPOSITORY https://github.com/littlevgl/lvgl.git
GIT_TAG ""
BINARY_DIR ""
SOURCE_DIR "${LVGL_DIR}"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
ExternalProject_Add(${lv_drivers_name}
GIT_REPOSITORY https://github.com/littlevgl/lv_drivers.git
GIT_TAG ""
BINARY_DIR ""
SOURCE_DIR "${LV_DRIVERS_DIR}"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)

View File

@ -19,6 +19,7 @@ simple/
├── connection.c
├── event_publisher.c
├── event_subscriber.c
├── gui.c
├── request_handler.c
├── request_sender.c
├── sensor.c
@ -63,6 +64,20 @@ The `host_init_func` is called when the application manager starts up. And `host
- wasm-apps<br/>
Source files of sample wasm applications.
Install required SDK and libraries
==============
- 32 bit SDL(simple directmedia layer)
Use apt-get</br>
`sudo apt-get install libsdl2-dev:i386`</br>
Or download source from www.libsdl.org</br>
`./configure C_FLAGS=-m32 CXX_FLAGS=-m32 LD_FLAGS=-m32`</br>
`make`</br>
`sudo make install`</br>
- Install EMSDK
<pre>
https://emscripten.org/docs/tools_reference/emsdk.html
</pre>
Build all binaries
==============
Execute the build.sh script then all binaries including wasm application files would be generated in 'out' directory.
@ -78,6 +93,7 @@ out/
├── connection.wasm
├── event_publisher.wasm
├── event_subscriber.wasm
├── gui.wasm
├── request_handler.wasm
├── request_sender.wasm
├── sensor.wasm
@ -102,6 +118,8 @@ out/
This application shows the sub/pub programming model. The pub application publishes the event "alert/overheat" by calling api_publish_event() API. The subscriber could be host_tool or other wasm application.
+ event_subscriber.wasm<br/>
This application shows the sub/pub programming model. The sub application subscribes the "alert/overheat" event by calling api_subscribe_event() API so that it is able to receive the event once generated and published by the pub application. To make the process clear to interpret, the sub application dumps the event when receiving it.
+ gui.wasm<br/>
This application shows the built-in 2D graphical user interface API with which various widgets could be created.
+ request_handler.wasm<br/>
This application shows the request/response programming model. The request handler application registers 2 resources(/url1 and /url2) by calling api_register_resource_handler() API. The request sender could be host_tool or other wasm application.
+ request_sender.wasm<br/>

View File

@ -8,7 +8,7 @@ BUILD_DIR=${PWD}/build
IWASM_ROOT=${PWD}/../../core/iwasm
APP_LIBS=${IWASM_ROOT}/lib/app-libs
NATIVE_LIBS=${IWASM_ROOT}/lib/native-interface
APP_LIB_SRC="${APP_LIBS}/base/*.c ${APP_LIBS}/extension/sensor/*.c ${APP_LIBS}/extension/connection/*.c ${NATIVE_LIBS}/*.c"
APP_LIB_SRC="${APP_LIBS}/base/*.c ${APP_LIBS}/extension/sensor/*.c ${APP_LIBS}/extension/connection/*.c ${APP_LIBS}/extension/gui/src/*.c ${NATIVE_LIBS}/*.c"
WASM_APPS=${PWD}/wasm-apps
rm -rf ${OUT_DIR}
@ -57,10 +57,11 @@ APP_SRC="$i ${APP_LIB_SRC}"
OUT_FILE=${i%.*}.wasm
emcc -O3 -I${APP_LIBS}/base -I${APP_LIBS}/extension/sensor -I${NATIVE_LIBS} \
-I${APP_LIBS}/extension/connection \
-I${APP_LIBS}/extension/gui \
-s WASM=1 -s SIDE_MODULE=1 -s ASSERTIONS=1 -s STACK_OVERFLOW_CHECK=2 \
-s TOTAL_MEMORY=65536 -s TOTAL_STACK=4096 \
-s "EXPORTED_FUNCTIONS=['_on_init', '_on_destroy', '_on_request', '_on_response', \
'_on_sensor_event', '_on_timer_callback', '_on_connection_data']" \
'_on_sensor_event', '_on_timer_callback', '_on_connection_data', '_on_widget_event']" \
-o ${OUT_DIR}/wasm-apps/${OUT_FILE} ${APP_SRC}
if [ -f ${OUT_DIR}/wasm-apps/${OUT_FILE} ]; then
echo "build ${OUT_FILE} success"

View File

@ -1,10 +1,12 @@
#include "lib_export.h"
#include "sensor_api.h"
#include "connection_api.h"
#include "gui_api.h"
static NativeSymbol extended_native_symbol_defs[] = {
#include "runtime_sensor.inl"
#include "connection.inl"
#include "wamr_gui.inl"
};
#include "ext_lib_export.h"

View File

@ -32,6 +32,10 @@
#include "attr_container.h"
#include "module_wasm_app.h"
#include "wasm_export.h"
#include "lv_drivers/display/monitor.h"
#include "lv_drivers/indev/mouse.h"
#define MAX 2048
#ifndef CONNECTION_UART
@ -47,6 +51,7 @@ extern void * thread_timer_check(void *);
extern void init_sensor_framework();
extern int aee_host_msg_callback(void *msg, uint16_t msg_len);
extern bool init_connection_framework();
extern void wgl_init();
#ifndef CONNECTION_UART
int listenfd = -1;
@ -425,6 +430,37 @@ static bool parse_args(int argc, char *argv[])
return true;
}
/**
* 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[480*10];
lv_disp_buf_init(&disp_buf1, buf1_1, NULL, 480*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;
// 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);
}
// Driver function
int iwasm_main(int argc, char *argv[])
{
@ -448,6 +484,8 @@ int iwasm_main(int argc, char *argv[])
goto fail1;
}
wgl_init();
hal_init();
init_sensor_framework();
// timer manager

View File

@ -0,0 +1,310 @@
/**
* @file lv_drv_conf.h
*
*/
/*
* COPY THIS FILE AS lv_drv_conf.h
*/
#if 1 /*Set it to "1" to enable the content*/
#ifndef LV_DRV_CONF_H
#define LV_DRV_CONF_H
#include "lv_conf.h"
/*********************
* DELAY INTERFACE
*********************/
#define LV_DRV_DELAY_INCLUDE <stdint.h> /*Dummy include by default*/
#define LV_DRV_DELAY_US(us) /*delay_us(us)*/ /*Delay the given number of microseconds*/
#define LV_DRV_DELAY_MS(ms) /*delay_ms(ms)*/ /*Delay the given number of milliseconds*/
/*********************
* DISPLAY INTERFACE
*********************/
/*------------
* Common
*------------*/
#define LV_DRV_DISP_INCLUDE <stdint.h> /*Dummy include by default*/
#define LV_DRV_DISP_CMD_DATA(val) /*pin_x_set(val)*/ /*Set the command/data pin to 'val'*/
#define LV_DRV_DISP_RST(val) /*pin_x_set(val)*/ /*Set the reset pin to 'val'*/
/*---------
* SPI
*---------*/
#define LV_DRV_DISP_SPI_CS(val) /*spi_cs_set(val)*/ /*Set the SPI's Chip select to 'val'*/
#define LV_DRV_DISP_SPI_WR_BYTE(data) /*spi_wr(data)*/ /*Write a byte the SPI bus*/
#define LV_DRV_DISP_SPI_WR_ARRAY(adr, n) /*spi_wr_mem(adr, n)*/ /*Write 'n' bytes to SPI bus from 'adr'*/
/*------------------
* Parallel port
*-----------------*/
#define LV_DRV_DISP_PAR_CS(val) /*par_cs_set(val)*/ /*Set the Parallel port's Chip select to 'val'*/
#define LV_DRV_DISP_PAR_SLOW /*par_slow()*/ /*Set low speed on the parallel port*/
#define LV_DRV_DISP_PAR_FAST /*par_fast()*/ /*Set high speed on the parallel port*/
#define LV_DRV_DISP_PAR_WR_WORD(data) /*par_wr(data)*/ /*Write a word to the parallel port*/
#define LV_DRV_DISP_PAR_WR_ARRAY(adr, n) /*par_wr_mem(adr,n)*/ /*Write 'n' bytes to Parallel ports from 'adr'*/
/***************************
* INPUT DEVICE INTERFACE
***************************/
/*----------
* Common
*----------*/
#define LV_DRV_INDEV_INCLUDE <stdint.h> /*Dummy include by default*/
#define LV_DRV_INDEV_RST(val) /*pin_x_set(val)*/ /*Set the reset pin to 'val'*/
#define LV_DRV_INDEV_IRQ_READ 0 /*pn_x_read()*/ /*Read the IRQ pin*/
/*---------
* SPI
*---------*/
#define LV_DRV_INDEV_SPI_CS(val) /*spi_cs_set(val)*/ /*Set the SPI's Chip select to 'val'*/
#define LV_DRV_INDEV_SPI_XCHG_BYTE(data) 0 /*spi_xchg(val)*/ /*Write 'val' to SPI and give the read value*/
/*---------
* I2C
*---------*/
#define LV_DRV_INDEV_I2C_START /*i2c_start()*/ /*Make an I2C start*/
#define LV_DRV_INDEV_I2C_STOP /*i2c_stop()*/ /*Make an I2C stop*/
#define LV_DRV_INDEV_I2C_RESTART /*i2c_restart()*/ /*Make an I2C restart*/
#define LV_DRV_INDEV_I2C_WR(data) /*i2c_wr(data)*/ /*Write a byte to the I1C bus*/
#define LV_DRV_INDEV_I2C_READ(last_read) 0 /*i2c_rd()*/ /*Read a byte from the I2C bud*/
/*********************
* DISPLAY DRIVERS
*********************/
/*-------------------
* Monitor of PC
*-------------------*/
#ifndef USE_MONITOR
# define USE_MONITOR 1
#endif
#if USE_MONITOR
# define MONITOR_HOR_RES LV_HOR_RES_MAX
# define MONITOR_VER_RES LV_VER_RES_MAX
/* Scale window by this factor (useful when simulating small screens) */
# define MONITOR_ZOOM 1
/* Used to test true double buffering with only address changing.
* Set LV_VDB_SIZE = (LV_HOR_RES * LV_VER_RES) and LV_VDB_DOUBLE = 1 and LV_COLOR_DEPTH = 32" */
# define MONITOR_DOUBLE_BUFFERED 0
/*Eclipse: <SDL2/SDL.h> Visual Studio: <SDL.h>*/
# define MONITOR_SDL_INCLUDE_PATH <SDL2/SDL.h>
/*Different rendering might be used if running in a Virtual machine*/
# define MONITOR_VIRTUAL_MACHINE 0
/*Open two windows to test multi display support*/
# define MONITOR_DUAL 0
#endif
/*-----------------------------------
* Native Windows (including mouse)
*----------------------------------*/
#ifndef USE_WINDOWS
# define USE_WINDOWS 0
#endif
#define USE_WINDOWS 0
#if USE_WINDOWS
# define WINDOW_HOR_RES 480
# define WINDOW_VER_RES 320
#endif
/*----------------
* SSD1963
*--------------*/
#ifndef USE_SSD1963
# define USE_SSD1963 0
#endif
#if USE_SSD1963
# define SSD1963_HOR_RES LV_HOR_RES
# define SSD1963_VER_RES LV_VER_RES
# define SSD1963_HT 531
# define SSD1963_HPS 43
# define SSD1963_LPS 8
# define SSD1963_HPW 10
# define SSD1963_VT 288
# define SSD1963_VPS 12
# define SSD1963_FPS 4
# define SSD1963_VPW 10
# define SSD1963_HS_NEG 0 /*Negative hsync*/
# define SSD1963_VS_NEG 0 /*Negative vsync*/
# define SSD1963_ORI 0 /*0, 90, 180, 270*/
# define SSD1963_COLOR_DEPTH 16
#endif
/*----------------
* R61581
*--------------*/
#ifndef USE_R61581
# define USE_R61581 0
#endif
#if USE_R61581
# define R61581_HOR_RES LV_HOR_RES
# define R61581_VER_RES LV_VER_RES
# define R61581_HSPL 0 /*HSYNC signal polarity*/
# define R61581_HSL 10 /*HSYNC length (Not Implemented)*/
# define R61581_HFP 10 /*Horitontal Front poarch (Not Implemented)*/
# define R61581_HBP 10 /*Horitontal Back poarch (Not Implemented */
# define R61581_VSPL 0 /*VSYNC signal polarity*/
# define R61581_VSL 10 /*VSYNC length (Not Implemented)*/
# define R61581_VFP 8 /*Vertical Front poarch*/
# define R61581_VBP 8 /*Vertical Back poarch */
# define R61581_DPL 0 /*DCLK signal polarity*/
# define R61581_EPL 1 /*ENABLE signal polarity*/
# define R61581_ORI 0 /*0, 180*/
# define R61581_LV_COLOR_DEPTH 16 /*Fix 16 bit*/
#endif
/*------------------------------
* ST7565 (Monochrome, low res.)
*-----------------------------*/
#ifndef USE_ST7565
# define USE_ST7565 0
#endif
#if USE_ST7565
/*No settings*/
#endif /*USE_ST7565*/
/*-----------------------------------------
* Linux frame buffer device (/dev/fbx)
*-----------------------------------------*/
#ifndef USE_FBDEV
# define USE_FBDEV 1
#endif
#if USE_FBDEV
# define FBDEV_PATH "/dev/fb0"
#endif
/*********************
* INPUT DEVICES
*********************/
/*--------------
* XPT2046
*--------------*/
#ifndef USE_XPT2046
# define USE_XPT2046 0
#endif
#if USE_XPT2046
# define XPT2046_HOR_RES 480
# define XPT2046_VER_RES 320
# define XPT2046_X_MIN 200
# define XPT2046_Y_MIN 200
# define XPT2046_X_MAX 3800
# define XPT2046_Y_MAX 3800
# define XPT2046_AVG 4
# define XPT2046_INV 0
#endif
/*-----------------
* FT5406EE8
*-----------------*/
#ifndef USE_FT5406EE8
# define USE_FT5406EE8 0
#endif
#if USE_FT5406EE8
# define FT5406EE8_I2C_ADR 0x38 /*7 bit address*/
#endif
/*---------------
* AD TOUCH
*--------------*/
#ifndef USE_AD_TOUCH
# define USE_AD_TOUCH 0
#endif
#if USE_AD_TOUCH
/*No settings*/
#endif
/*---------------------------------------
* Mouse or touchpad on PC (using SDL)
*-------------------------------------*/
#ifndef USE_MOUSE
# define USE_MOUSE 1
#endif
#if USE_MOUSE
/*No settings*/
#endif
/*-------------------------------------------
* Mousewheel as encoder on PC (using SDL)
*------------------------------------------*/
#ifndef USE_MOUSEWHEEL
# define USE_MOUSEWHEEL 1
#endif
#if USE_MOUSEWHEEL
/*No settings*/
#endif
/*-------------------------------------------------
* Touchscreen as libinput interface (for Linux based systems)
*------------------------------------------------*/
#ifndef USE_LIBINPUT
# define USE_LIBINPUT 0
#endif
#if USE_LIBINPUT
# define LIBINPUT_NAME "/dev/input/event0" /*You can use the "evtest" Linux tool to get the list of devices and test them*/
#endif /*USE_LIBINPUT*/
/*-------------------------------------------------
* Mouse or touchpad as evdev interface (for Linux based systems)
*------------------------------------------------*/
#ifndef USE_EVDEV
# define USE_EVDEV 0
#endif
#if USE_EVDEV
# define EVDEV_NAME "/dev/input/event0" /*You can use the "evtest" Linux tool to get the list of devices and test them*/
# define EVDEV_SWAP_AXES 0 /*Swap the x and y axes of the touchscreen*/
# define EVDEV_SCALE 0 /* Scale input, e.g. if touchscreen resolution does not match display resolution */
# if EVDEV_SCALE
# define EVDEV_SCALE_HOR_RES (4096) /* Horizontal resolution of touchscreen */
# define EVDEV_SCALE_VER_RES (4096) /* Vertical resolution of touchscreen */
# endif /*EVDEV_SCALE*/
# define EVDEV_CALIBRATE 0 /*Scale and offset the touchscreen coordinates by using maximum and minimum values for each axis*/
# if EVDEV_CALIBRATE
# define EVDEV_HOR_MIN 3800 /*If EVDEV_XXX_MIN > EVDEV_XXX_MAX the XXX axis is automatically inverted*/
# define EVDEV_HOR_MAX 200
# define EVDEV_VER_MIN 200
# define EVDEV_VER_MAX 3800
# endif /*EVDEV_SCALE*/
#endif /*USE_EVDEV*/
/*-------------------------------
* Keyboard of a PC (using SDL)
*------------------------------*/
#ifndef USE_KEYBOARD
# define USE_KEYBOARD 1
#endif
#if USE_KEYBOARD
/*No settings*/
#endif
#endif /*LV_DRV_CONF_H*/
#endif /*End of "Content enable"*/

View File

@ -0,0 +1,80 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdlib.h>
#include <unistd.h>
#include "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) {
sprintf(count_str, "%d", count / 100);
wgl_label_set_text(count_label, count_str);
}
++count;
}
void on_init()
{
char text[32] = {0};
hello_world_label = wgl_label_create((wgl_obj_t)NULL, (wgl_obj_t)NULL);
wgl_label_set_text(hello_world_label, "Hello world!");
wgl_label_get_text(hello_world_label, text, sizeof(text));
printf("Label text %d %s \n", wgl_label_get_text_length(hello_world_label), text);
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);
api_timer_restart(timer, 10);
}
static void btn_event_cb(wgl_obj_t btn, wgl_event_t event)
{
if(event == WGL_EVENT_RELEASED) {
label_count1_value++;
sprintf(label_count1_str, "%d", label_count1_value);
wgl_label_set_text(label_count1, label_count1_str);
}
}

View File

@ -0,0 +1,82 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdlib.h>
#include <unistd.h>
#include "wasm_app.h"
#include "lvgl.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 = 0;
char label_count1_str[11] = { 0 };
void timer1_update(user_timer_t timer1)
{
if ((count % 100) == 0) {
sprintf(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, "0");
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);
api_timer_restart(timer, 10);
}
static void btn_event_cb(lv_obj_t *btn, lv_event_t event)
{
if(event == LV_EVENT_RELEASED) {
label_count1_value++;
sprintf(label_count1_str, "%d", label_count1_value);
lv_label_set_text(label_count1, label_count1_str);
}
}