update lvgl 2

This commit is contained in:
gemu2015 2021-04-24 12:31:14 +02:00
parent 7b83e5d1e6
commit 0f7ec3cb77
5 changed files with 236 additions and 41 deletions

View File

@ -153,6 +153,13 @@ void Renderer::DrawStringAt(int16_t x, int16_t y, const char* text, uint16_t col
int refcolumn = x;
sFONT *xfont = selected_font;
/*
if (font == 5 && !drawmode) {
// clear bckground
int16_t x1,y1;
uint16_t w,h;
Adafruit_GFX::getTextBounds(text, 0, 0, &x1, &y1, &w, &h);
}*/
#ifndef USE_EPD_FONTS
font=0;
#endif
@ -297,13 +304,15 @@ void Renderer::setTextFont(uint8_t f) {
void Renderer::SetRamfont(uint8_t *font) {
ramfont = (GFXfont*)font;
if (font) {
uint32_t bitmap_offset = (uint32_t)ramfont->bitmap;
uint32_t glyph_offset = (uint32_t)ramfont->glyph;
ramfont->bitmap = (uint8_t*)((uint32_t)font + bitmap_offset);
ramfont->glyph = (GFXglyph*)((uint32_t)font + glyph_offset);
}
setFont(ramfont);
}
@ -588,6 +597,33 @@ void Renderer::scrollTo(uint16_t y) {
}
void Renderer::SetPwrCB(pwr_cb cb) {
}
void Renderer::SetDimCB(dim_cb cb) {
}
uint16_t Renderer::fgcol(void) {
return 0;
}
uint16_t Renderer::bgcol(void) {
return 0;
}
int8_t Renderer::color_type(void) {
return 0;
}
void Renderer::Splash(void) {
}
const char dname[1] = {0};
char *Renderer::devname(void) {
return (char*)dname;
}
void VButton::xdrawButton(bool inverted) {
wr_redir=1;
drawButton(inverted);

View File

@ -16,6 +16,8 @@
// a. in class GFX setCursor,setTextSize => virtual
// b. textcolor,textbgcolor => public;
typedef void (*pwr_cb)(uint8_t);
typedef void (*dim_cb)(uint8_t);
class Renderer : public Adafruit_GFX {
//Paint(unsigned char* image, int width, int height);
@ -42,12 +44,21 @@ public:
virtual void setScrollMargins(uint16_t top, uint16_t bottom);
virtual void scrollTo(uint16_t y);
virtual void TS_RotConvert(int16_t *x, int16_t *y);
virtual void SetPwrCB(pwr_cb cb);
virtual void SetDimCB(dim_cb cb);
virtual uint16_t fgcol(void);
virtual uint16_t bgcol(void);
virtual int8_t color_type(void);
virtual void Splash(void);
virtual char *devname(void);
void setDrawMode(uint8_t mode);
uint8_t drawmode;
virtual void FastString(uint16_t x,uint16_t y,uint16_t tcolor, const char* str);
void setTextSize(uint8_t s);
virtual uint8_t *allocate_framebuffer(uint32_t size);
pwr_cb pwr_cbp = 0;
dim_cb dim_cbp = 0;
private:
void DrawCharAt(int16_t x, int16_t y, char ascii_char,int16_t colored);
inline void drawFastVLineInternal(int16_t x, int16_t y, int16_t h, uint16_t color) __attribute__((always_inline));

View File

@ -2621,6 +2621,15 @@ chknext:
tind->bits.is_string = 0;
return lp + len;
}
#ifdef USE_LVGL
if (!strncmp(vname, "lvgl(", 5)) {
lp = GetNumericArgument(lp + 5, OPER_EQU, &fvar, gv);
fvar = lvgl_test(fvar);
lp++;
len = 0;
goto exit;
}
#endif
break;
case 'm':
if (!strncmp(vname, "med(", 4)) {
@ -7704,6 +7713,137 @@ void cpy2lf(char *dst, uint32_t dstlen, char *src) {
}
}
#ifdef USE_LVGL
#include <renderer.h>
#include "lvgl.h"
const char ili9342[] PROGMEM =
":H,ILI9342,320,240,16,SPI,1,*,*,*,*,*,*,*,40\n"
":S,2,1,3,0,100,100\n"
":I\n"
"EF,3,03,80,02\n"
"CF,3,00,C1,30\n"
"ED,4,64,03,12,81\n"
"E8,3,85,00,78\n"
"CB,5,39,2C,00,34,02\n"
"F7,1,20\n"
"EA,2,00,00\n"
"C0,1,23\n"
"C1,1,10\n"
"C5,2,3e,28\n"
"C7,1,86\n"
"36,1,48\n"
"37,1,00\n"
"3A,1,55\n"
"B1,2,00,18\n"
"B6,3,08,82,27\n"
"F2,1,00\n"
"26,1,01\n"
"E0,0F,0F,31,2B,0C,0E,08,4E,F1,37,07,10,03,0E,09,00\n"
"E1,0F,00,0E,14,03,11,07,31,C1,48,08,0F,0C,31,36,0F\n"
"21,80\n"
"11,80\n"
"29,80\n"
":o,28\n"
":O,29\n"
":A,2A,2B,2C,16\n"
":R,36\n"
":0,08,00,00,00\n"
":1,A8,00,00,01\n"
":2,C8,00,00,02\n"
":3,68,00,00,03\n"
":i,21,20\n"
":TI2,38,22,21\n"
"#\n";
void start_lvgl(const char * uconfig);
int32_t lvgl_test(int32_t p) {
start_lvgl(ili9342);
lv_obj_clean(lv_scr_act());
lv_obj_t *label1 = lv_label_create(lv_scr_act(), NULL);
/*Modify the Label's text*/
lv_label_set_text(label1, "Hello world!");
/* Align the Label to the center
* NULL means align on parent (which is the screen now)
* 0, 0 at the end means an x, y offset after alignment*/
lv_obj_align(label1, NULL, LV_ALIGN_CENTER, 0, 0);
/*Add a button*/
lv_obj_t *btn1 = lv_btn_create(lv_scr_act(), NULL); /*Add to the active screen*/
lv_obj_set_pos(btn1, 2, 2); /*Adjust the position*/
lv_obj_set_size(btn1, 96, 30); /* set size of button */
// lv_btn_set_action(btn1, LV_BTN_ACTION_CLICK, my_click_action); /*Assign a callback for clicking*/
/*Add text*/
lv_obj_t *label = lv_label_create(btn1, NULL); /*Put on 'btn1'*/
lv_label_set_text(label, "Click");
return 0;
}
/*
lv_obj_t * myButton;
lv_obj_t * myButtonLabel;
lv_obj_t * myLabel;
lv_style_t myButtonStyleREL; //relesed style
lv_style_t myButtonStylePR; //pressed style
static lv_res_t btn_click_action(lv_obj_t * btn) {
uint8_t id = lv_obj_get_free_num(btn); //id usefull when there are multiple buttons
if(id == 0)
{
char buffer[100];
sprintf(buffer, "button was clicked %i milliseconds from start", pros::millis());
lv_label_set_text(myLabel, buffer);
}
return LV_RES_OK;
}
#define LV_COLOR_MAKE lv_color_make
void initialize() {
lv_style_copy(&myButtonStyleREL, &lv_style_plain);
myButtonStyleREL.body.main_color = LV_COLOR_MAKE(150, 0, 0);
myButtonStyleREL.body.grad_color = LV_COLOR_MAKE(0, 0, 150);
myButtonStyleREL.body.radius = 0;
myButtonStyleREL.text.color = LV_COLOR_MAKE(255, 255, 255);
lv_style_copy(&myButtonStylePR, &lv_style_plain);
myButtonStylePR.body.main_color = LV_COLOR_MAKE(255, 0, 0);
myButtonStylePR.body.grad_color = LV_COLOR_MAKE(0, 0, 255);
myButtonStylePR.body.radius = 0;
myButtonStylePR.text.color = LV_COLOR_MAKE(255, 255, 255);
myButton = lv_btn_create(lv_scr_act(), NULL); //create button, lv_scr_act() is deafult screen object
lv_obj_set_free_num(myButton, 0); //set button is to 0
lv_btn_set_action(myButton, LV_BTN_ACTION_CLICK, btn_click_action); //set function to be called on button click
lv_btn_set_style(myButton, LV_BTN_STYLE_REL, &myButtonStyleREL); //set the relesed style
lv_btn_set_style(myButton, LV_BTN_STYLE_PR, &myButtonStylePR); //set the pressed style
lv_obj_set_size(myButton, 200, 50); //set the button size
lv_obj_align(myButton, NULL, LV_ALIGN_IN_TOP_LEFT, 10, 10); //set the position to top mid
myButtonLabel = lv_label_create(myButton, NULL); //create label and puts it inside of the button
lv_label_set_text(myButtonLabel, "Click the Button"); //sets label text
myLabel = lv_label_create(lv_scr_act(), NULL); //create label and puts it on the screen
lv_label_set_text(myLabel, "Button has not been clicked yet"); //sets label text
lv_obj_align(myLabel, NULL, LV_ALIGN_LEFT_MID, 10, 0); //set the position to center
}
*/
#endif
/*********************************************************************************************\
* Interface

View File

@ -824,6 +824,14 @@ extern FS *ffsp;
char fname[32];
*ep = 0;
ep++;
if (*cp == '-' && *(cp + 1) == 0) {
if (ram_font) {
free (ram_font);
ram_font = 0;
if (renderer) renderer->SetRamfont(0);
}
cp = ep;
} else {
if (*cp != '/') {
fname[0] = '/';
fname[1] = 0;
@ -847,6 +855,7 @@ extern FS *ffsp;
//Serial.printf("Font loaded: %s\n",fname );
}
}
}
cp = ep;
}
}

View File

@ -20,7 +20,7 @@
#ifdef USE_LVGL
#include <uDisplay_lvgl.h>
#include <renderer.h>
#include "lvgl.h"
#define XDRV_54 54
@ -37,7 +37,7 @@
* you should lock on the very same semaphore! */
SemaphoreHandle_t xGuiSemaphore;
uDisplay_lvgl * udisp = nullptr;
//uDisplay * udisp = nullptr;
// necessary for compilation
uint8_t color_type_lvgl = 0;
@ -243,6 +243,8 @@ static lv_fs_res_t lvbe_fs_remove(lv_fs_drv_t * drv, const char *path) {
* display ecosystem.
************************************************************/
Renderer *Init_uDisplay(const char *desc, int8_t cs);
void start_lvgl(const char * uconfig);
void start_lvgl(const char * uconfig) {
@ -251,25 +253,18 @@ void start_lvgl(const char * uconfig) {
return;
}
if (udisp == nullptr) {
udisp = new uDisplay_lvgl((char*)uconfig);
if (uconfig && !renderer) {
renderer = Init_uDisplay((char*)uconfig, -1);
if (!renderer) return;
}
udisp->Init();
// Settings.display_width = udisp->width();
// Settings.display_height = udisp->height();
udisp->DisplayInit(0 /* DISPLAY_INIT_MODE */, Settings.display_size, Settings.display_rotate, Settings.display_font);
udisp->dim(Settings.display_dimmer);
// **************************************************
// Initialize the glue between Adafruit and LVGL
// **************************************************
glue = new Adafruit_LvGL_Glue();
// Initialize glue, passing in address of display & touchscreen
LvGLStatus status = glue->begin(udisp);
LvGLStatus status = glue->begin(renderer);
if (status != LVGL_OK) {
AddLog(LOG_LEVEL_ERROR, PSTR("Glue error %d"), status);
return;
@ -277,8 +272,10 @@ void start_lvgl(const char * uconfig) {
// Set the default background color of the display
// This is normally overriden by an opaque screen on top
#ifdef USE_BERRY
lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_from_uint32(USE_LVGL_BG_DEFAULT));
lv_obj_set_style_local_bg_opa(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_COVER);
#endif
#if LV_USE_LOG
lv_log_register_print_cb(lvbe_debug);
@ -319,6 +316,8 @@ void start_lvgl(const char * uconfig) {
* Otherwise there can be problem such as memory corruption and so on.
* NOTE: When not using Wi-Fi nor Bluetooth you can pin the guiTask to core 0 */
xTaskCreatePinnedToCore(guiTask, "gui", 4096*2, NULL, 0, NULL, 1);
AddLog(LOG_LEVEL_INFO, PSTR("LVGL initialized"));
}
/*********************************************************************************************\