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
main.cpp
- Committer:
- JohnnyK
- Date:
- 2020-04-07
- Revision:
- 2:afc050526249
- Parent:
- 1:627f26953c53
- Child:
- 3:4f5dc253eb7b
File content as of revision 2:afc050526249:
//Notebook page https://os.mbed.com/users/JohnnyK/notebook/how-start-with-the-littlevgl/
#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.
}
#ifndef DEMO_H
//lvgl buttons object event handler
static void event_handler(lv_obj_t * obj, lv_event_t event){
switch(event) {
case LV_EVENT_PRESSED:
printf("Pressed\n");
break;
case LV_EVENT_SHORT_CLICKED:
printf("Short clicked\n");
break;
case LV_EVENT_CLICKED:
printf("Clicked\n");
break;
case LV_EVENT_VALUE_CHANGED:
printf("Toggled\n");
break;
case LV_EVENT_LONG_PRESSED:
printf("Long press\n");
break;
case LV_EVENT_LONG_PRESSED_REPEAT:
printf("Long press repeat\n");
break;
case LV_EVENT_RELEASED:
printf("Released\n");
break;
}
}
#endif
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) {
//do something
//thread_sleep_for(WAIT_TIME);
}
}