Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: LCD_DISCO_F746NG GRecorder BSP_DISCO_F746NG
Diff: main.cpp
- Revision:
- 0:10c4b83c458d
- Child:
- 1:627f26953c53
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Mon Dec 02 19:28:26 2019 +0000
@@ -0,0 +1,78 @@
+//#pragma -O0
+#include "mbed.h"
+#include "lvgl/lvgl.h"
+#include "lv_port_disp.h"
+#include "lv_port_indev.h"
+#include "demo.h" //Comment/uncomment will switch between LittlevGL demo and Hello word example
+
+#define LVGL_TICK 5 //Time tick value for lvgl in ms (1-10msa)
+#define TICKER_TIME 0.001 * LVGL_TICK //modified to miliseconds
+#define WAIT_TIME 1000 * LVGL_TICK //modified to microseconds
+
+Ticker ticker; //Ticker for lvgl
+
+//Callback function for lvgl timing.
+void lv_ticker_func(){
+
+ lv_tick_inc(LVGL_TICK);
+ //Call lv_tick_inc(x) every x milliseconds in a Timer or Task (x should be between 1 and 10).
+ //It is required for the internal timing of LittlevGL.
+ lv_task_handler();
+ //Call lv_task_handler() periodically every few milliseconds.
+ //It will redraw the screen if required, handle input devices etc.
+}
+
+//lvgl button object event handler
+void event_handler(lv_obj_t * obj, lv_event_t event){
+ if(event == LV_EVENT_CLICKED) {
+ printf("Clicked\n");
+ }
+ else if(event == LV_EVENT_VALUE_CHANGED) {
+ printf("Toggled\n");
+ }
+}
+
+int main()
+{
+ printf("LittlevGL GUI-");
+ lv_init(); //Initialize the LittlevGL
+ lv_port_disp_init(); //Initialize diplay
+ lv_port_indev_init(); //Initialize touchpad
+ ticker.attach(callback(&lv_ticker_func),TICKER_TIME); //Attach callback to ticker
+
+#ifndef DEMO_H
+ printf("Hello word\n");
+ lv_obj_t * label_h = lv_label_create(lv_scr_act(), NULL);
+ static lv_style_t st;
+ lv_style_copy( &st, &lv_style_plain );
+ st.text.font = &lv_font_roboto_28;
+ lv_obj_set_style( label_h, &st );
+ lv_obj_set_size(label_h, 50, 30);
+ lv_label_set_recolor(label_h, true);
+ lv_label_set_text(label_h, "#ff0000 Hello word#");
+ lv_obj_align(label_h, NULL, LV_ALIGN_IN_TOP_MID, 0, 0);
+
+ lv_obj_t * label;
+ lv_obj_t * btn1 = lv_btn_create(lv_scr_act(), NULL);
+ lv_obj_set_event_cb(btn1, event_handler);
+ lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, -40);
+ label = lv_label_create(btn1, NULL);
+ lv_label_set_text(label, "Button");
+ lv_obj_t *btn2 = lv_btn_create(lv_scr_act(), NULL);
+ lv_obj_set_event_cb(btn2, event_handler);
+ lv_obj_align(btn2, NULL, LV_ALIGN_CENTER, 0, 40);
+ lv_btn_set_toggle(btn2, true);
+ lv_btn_toggle(btn2);
+ lv_btn_set_fit2(btn2, LV_FIT_NONE, LV_FIT_TIGHT);
+ label = lv_label_create(btn2, NULL);
+ lv_label_set_text(label, "Toggled");
+#else
+ printf("Demo\n");
+ demo_create(); // Demo from lv_examples
+#endif
+
+ while(1) {
+ //something
+ //wait_us(WAIT_TIME);
+ }
+}