initial commit
This commit is contained in:
243
examples/LVGL_Arduino/Display_ST7789.cpp
Normal file
243
examples/LVGL_Arduino/Display_ST7789.cpp
Normal file
@@ -0,0 +1,243 @@
|
||||
#include "Display_ST7789.h"
|
||||
|
||||
#define SPI_WRITE(_dat) SPI.transfer(_dat)
|
||||
#define SPI_WRITE_Word(_dat) SPI.transfer16(_dat)
|
||||
void SPI_Init()
|
||||
{
|
||||
SPI.begin(EXAMPLE_PIN_NUM_SCLK,EXAMPLE_PIN_NUM_MISO,EXAMPLE_PIN_NUM_MOSI);
|
||||
}
|
||||
|
||||
void LCD_WriteCommand(uint8_t Cmd)
|
||||
{
|
||||
SPI.beginTransaction(SPISettings(SPIFreq, MSBFIRST, SPI_MODE0));
|
||||
digitalWrite(EXAMPLE_PIN_NUM_LCD_CS, LOW);
|
||||
digitalWrite(EXAMPLE_PIN_NUM_LCD_DC, LOW);
|
||||
SPI_WRITE(Cmd);
|
||||
digitalWrite(EXAMPLE_PIN_NUM_LCD_CS, HIGH);
|
||||
SPI.endTransaction();
|
||||
}
|
||||
void LCD_WriteData(uint8_t Data)
|
||||
{
|
||||
SPI.beginTransaction(SPISettings(SPIFreq, MSBFIRST, SPI_MODE0));
|
||||
digitalWrite(EXAMPLE_PIN_NUM_LCD_CS, LOW);
|
||||
digitalWrite(EXAMPLE_PIN_NUM_LCD_DC, HIGH);
|
||||
SPI_WRITE(Data);
|
||||
digitalWrite(EXAMPLE_PIN_NUM_LCD_CS, HIGH);
|
||||
SPI.endTransaction();
|
||||
}
|
||||
void LCD_WriteData_Word(uint16_t Data)
|
||||
{
|
||||
SPI.beginTransaction(SPISettings(SPIFreq, MSBFIRST, SPI_MODE0));
|
||||
digitalWrite(EXAMPLE_PIN_NUM_LCD_CS, LOW);
|
||||
digitalWrite(EXAMPLE_PIN_NUM_LCD_DC, HIGH);
|
||||
SPI_WRITE_Word(Data);
|
||||
digitalWrite(EXAMPLE_PIN_NUM_LCD_CS, HIGH);
|
||||
SPI.endTransaction();
|
||||
}
|
||||
void LCD_WriteData_nbyte(uint8_t* SetData,uint8_t* ReadData,uint32_t Size)
|
||||
{
|
||||
SPI.beginTransaction(SPISettings(SPIFreq, MSBFIRST, SPI_MODE0));
|
||||
digitalWrite(EXAMPLE_PIN_NUM_LCD_CS, LOW);
|
||||
digitalWrite(EXAMPLE_PIN_NUM_LCD_DC, HIGH);
|
||||
SPI.transferBytes(SetData, ReadData, Size);
|
||||
digitalWrite(EXAMPLE_PIN_NUM_LCD_CS, HIGH);
|
||||
SPI.endTransaction();
|
||||
}
|
||||
|
||||
void LCD_Reset(void)
|
||||
{
|
||||
digitalWrite(EXAMPLE_PIN_NUM_LCD_CS, LOW);
|
||||
delay(50);
|
||||
digitalWrite(EXAMPLE_PIN_NUM_LCD_RST, LOW);
|
||||
delay(50);
|
||||
digitalWrite(EXAMPLE_PIN_NUM_LCD_RST, HIGH);
|
||||
delay(50);
|
||||
}
|
||||
void LCD_Init(void)
|
||||
{
|
||||
pinMode(EXAMPLE_PIN_NUM_LCD_CS, OUTPUT);
|
||||
pinMode(EXAMPLE_PIN_NUM_LCD_DC, OUTPUT);
|
||||
pinMode(EXAMPLE_PIN_NUM_LCD_RST, OUTPUT);
|
||||
Backlight_Init();
|
||||
SPI_Init();
|
||||
|
||||
LCD_Reset();
|
||||
//************* Start Initial Sequence **********//
|
||||
LCD_WriteCommand(0x11);
|
||||
delay(120);
|
||||
LCD_WriteCommand(0x36);
|
||||
if (HORIZONTAL)
|
||||
LCD_WriteData(0x00);
|
||||
else
|
||||
LCD_WriteData(0x70);
|
||||
|
||||
LCD_WriteCommand(0x3A);
|
||||
LCD_WriteData(0x05);
|
||||
|
||||
LCD_WriteCommand(0xB0);
|
||||
LCD_WriteData(0x00);
|
||||
LCD_WriteData(0xE8);
|
||||
|
||||
LCD_WriteCommand(0xB2);
|
||||
LCD_WriteData(0x0C);
|
||||
LCD_WriteData(0x0C);
|
||||
LCD_WriteData(0x00);
|
||||
LCD_WriteData(0x33);
|
||||
LCD_WriteData(0x33);
|
||||
|
||||
LCD_WriteCommand(0xB7);
|
||||
LCD_WriteData(0x35);
|
||||
|
||||
LCD_WriteCommand(0xBB);
|
||||
LCD_WriteData(0x35);
|
||||
|
||||
LCD_WriteCommand(0xC0);
|
||||
LCD_WriteData(0x2C);
|
||||
|
||||
LCD_WriteCommand(0xC2);
|
||||
LCD_WriteData(0x01);
|
||||
|
||||
LCD_WriteCommand(0xC3);
|
||||
LCD_WriteData(0x13);
|
||||
|
||||
LCD_WriteCommand(0xC4);
|
||||
LCD_WriteData(0x20);
|
||||
|
||||
LCD_WriteCommand(0xC6);
|
||||
LCD_WriteData(0x0F);
|
||||
|
||||
LCD_WriteCommand(0xD0);
|
||||
LCD_WriteData(0xA4);
|
||||
LCD_WriteData(0xA1);
|
||||
|
||||
LCD_WriteCommand(0xD6);
|
||||
LCD_WriteData(0xA1);
|
||||
|
||||
LCD_WriteCommand(0xE0);
|
||||
LCD_WriteData(0xF0);
|
||||
LCD_WriteData(0x00);
|
||||
LCD_WriteData(0x04);
|
||||
LCD_WriteData(0x04);
|
||||
LCD_WriteData(0x04);
|
||||
LCD_WriteData(0x05);
|
||||
LCD_WriteData(0x29);
|
||||
LCD_WriteData(0x33);
|
||||
LCD_WriteData(0x3E);
|
||||
LCD_WriteData(0x38);
|
||||
LCD_WriteData(0x12);
|
||||
LCD_WriteData(0x12);
|
||||
LCD_WriteData(0x28);
|
||||
LCD_WriteData(0x30);
|
||||
|
||||
LCD_WriteCommand(0xE1);
|
||||
LCD_WriteData(0xF0);
|
||||
LCD_WriteData(0x07);
|
||||
LCD_WriteData(0x0A);
|
||||
LCD_WriteData(0x0D);
|
||||
LCD_WriteData(0x0B);
|
||||
LCD_WriteData(0x07);
|
||||
LCD_WriteData(0x28);
|
||||
LCD_WriteData(0x33);
|
||||
LCD_WriteData(0x3E);
|
||||
LCD_WriteData(0x36);
|
||||
LCD_WriteData(0x14);
|
||||
LCD_WriteData(0x14);
|
||||
LCD_WriteData(0x29);
|
||||
LCD_WriteData(0x32);
|
||||
|
||||
LCD_WriteCommand(0x21);
|
||||
|
||||
LCD_WriteCommand(0x11);
|
||||
delay(120);
|
||||
LCD_WriteCommand(0x29);
|
||||
}
|
||||
/******************************************************************************
|
||||
function: Set the cursor position
|
||||
parameter :
|
||||
Xstart: Start uint16_t x coordinate
|
||||
Ystart: Start uint16_t y coordinate
|
||||
Xend : End uint16_t coordinates
|
||||
Yend : End uint16_t coordinatesen
|
||||
******************************************************************************/
|
||||
void LCD_SetCursor(uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend)
|
||||
{
|
||||
if (HORIZONTAL) {
|
||||
// set the X coordinates
|
||||
LCD_WriteCommand(0x2A);
|
||||
LCD_WriteData(Xstart >> 8);
|
||||
LCD_WriteData(Xstart + Offset_X);
|
||||
LCD_WriteData(Xend >> 8);
|
||||
LCD_WriteData(Xend + Offset_X);
|
||||
|
||||
// set the Y coordinates
|
||||
LCD_WriteCommand(0x2B);
|
||||
LCD_WriteData(Ystart >> 8);
|
||||
LCD_WriteData(Ystart + Offset_Y);
|
||||
LCD_WriteData(Yend >> 8);
|
||||
LCD_WriteData(Yend + Offset_Y);
|
||||
}
|
||||
else {
|
||||
// set the X coordinates
|
||||
LCD_WriteCommand(0x2A);
|
||||
LCD_WriteData(Ystart >> 8);
|
||||
LCD_WriteData(Ystart + Offset_Y);
|
||||
LCD_WriteData(Yend >> 8);
|
||||
LCD_WriteData(Yend + Offset_Y);
|
||||
// set the Y coordinates
|
||||
LCD_WriteCommand(0x2B);
|
||||
LCD_WriteData(Xstart >> 8);
|
||||
LCD_WriteData(Xstart + Offset_X);
|
||||
LCD_WriteData(Xend >> 8);
|
||||
LCD_WriteData(Xend + Offset_X);
|
||||
}
|
||||
LCD_WriteCommand(0x2C);
|
||||
}
|
||||
/******************************************************************************
|
||||
function: Refresh the image in an area
|
||||
parameter :
|
||||
Xstart: Start uint16_t x coordinate
|
||||
Ystart: Start uint16_t y coordinate
|
||||
Xend : End uint16_t coordinates
|
||||
Yend : End uint16_t coordinates
|
||||
color : Set the color
|
||||
******************************************************************************/
|
||||
void LCD_addWindow(uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend,uint16_t* color)
|
||||
{
|
||||
// uint16_t i,j;
|
||||
// LCD_SetCursor(Xstart, Ystart, Xend,Yend);
|
||||
// uint16_t Show_Width = Xend - Xstart + 1;
|
||||
// uint16_t Show_Height = Yend - Ystart + 1;
|
||||
// for(i = 0; i < Show_Height; i++){
|
||||
// for(j = 0; j < Show_Width; j++){
|
||||
// LCD_WriteData_Word(color[(i*(Show_Width))+j]);
|
||||
// }
|
||||
// }
|
||||
uint16_t Show_Width = Xend - Xstart + 1;
|
||||
uint16_t Show_Height = Yend - Ystart + 1;
|
||||
uint32_t numBytes = Show_Width * Show_Height * sizeof(uint16_t);
|
||||
uint8_t Read_D[numBytes];
|
||||
LCD_SetCursor(Xstart, Ystart, Xend, Yend);
|
||||
LCD_WriteData_nbyte((uint8_t*)color, Read_D, numBytes);
|
||||
}
|
||||
// backlight
|
||||
void Backlight_Init(void)
|
||||
{
|
||||
ledcAttach(EXAMPLE_PIN_NUM_BK_LIGHT, Frequency, Resolution);
|
||||
ledcWrite(EXAMPLE_PIN_NUM_BK_LIGHT, 100);
|
||||
}
|
||||
|
||||
void Set_Backlight(uint8_t Light) //
|
||||
{
|
||||
|
||||
if(Light > 100 || Light < 0)
|
||||
printf("Set Backlight parameters in the range of 0 to 100 \r\n");
|
||||
else{
|
||||
uint32_t Backlight = Light*10;
|
||||
ledcWrite(EXAMPLE_PIN_NUM_BK_LIGHT, Backlight);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
32
examples/LVGL_Arduino/Display_ST7789.h
Normal file
32
examples/LVGL_Arduino/Display_ST7789.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include <SPI.h>
|
||||
#define LCD_WIDTH 172 //LCD width
|
||||
#define LCD_HEIGHT 320 //LCD height
|
||||
|
||||
#define SPIFreq 80000000
|
||||
#define EXAMPLE_PIN_NUM_MISO 5
|
||||
#define EXAMPLE_PIN_NUM_MOSI 6
|
||||
#define EXAMPLE_PIN_NUM_SCLK 7
|
||||
#define EXAMPLE_PIN_NUM_LCD_CS 14
|
||||
#define EXAMPLE_PIN_NUM_LCD_DC 15
|
||||
#define EXAMPLE_PIN_NUM_LCD_RST 21
|
||||
#define EXAMPLE_PIN_NUM_BK_LIGHT 22
|
||||
#define Frequency 1000
|
||||
#define Resolution 10
|
||||
|
||||
#define VERTICAL 0
|
||||
#define HORIZONTAL 1
|
||||
|
||||
#define Offset_X 34
|
||||
#define Offset_Y 0
|
||||
|
||||
|
||||
void LCD_SetCursor(uint16_t x1, uint16_t y1, uint16_t x2,uint16_t y2);
|
||||
|
||||
void LCD_Init(void);
|
||||
void LCD_SetCursor(uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend);
|
||||
void LCD_addWindow(uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend,uint16_t* color);
|
||||
|
||||
void Backlight_Init(void);
|
||||
void Set_Backlight(uint8_t Light);
|
||||
26
examples/LVGL_Arduino/LVGL_Arduino.ino
Normal file
26
examples/LVGL_Arduino/LVGL_Arduino.ino
Normal file
@@ -0,0 +1,26 @@
|
||||
#include "SD_Card.h"
|
||||
#include "Display_ST7789.h"
|
||||
#include "LVGL_Driver.h"
|
||||
#include "LVGL_Example.h"
|
||||
void setup()
|
||||
{
|
||||
Flash_test();
|
||||
LCD_Init();
|
||||
Lvgl_Init();
|
||||
SD_Init();
|
||||
|
||||
Lvgl_Example1();
|
||||
// lv_demo_widgets();
|
||||
// lv_demo_benchmark();
|
||||
// lv_demo_keypad_encoder();
|
||||
// lv_demo_music();
|
||||
// lv_demo_stress();
|
||||
|
||||
Wireless_Test2();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Timer_Loop();
|
||||
delay(5);
|
||||
}
|
||||
84
examples/LVGL_Arduino/LVGL_Driver.cpp
Normal file
84
examples/LVGL_Arduino/LVGL_Driver.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
/*****************************************************************************
|
||||
| File : LVGL_Driver.c
|
||||
|
||||
| help :
|
||||
The provided LVGL library file must be installed first
|
||||
******************************************************************************/
|
||||
#include "LVGL_Driver.h"
|
||||
|
||||
static lv_disp_draw_buf_t draw_buf;
|
||||
static lv_color_t buf1[ LVGL_BUF_LEN ];
|
||||
static lv_color_t buf2[ LVGL_BUF_LEN ];
|
||||
// static lv_color_t* buf1 = (lv_color_t*) heap_caps_malloc(LVGL_BUF_LEN, MALLOC_CAP_SPIRAM);
|
||||
// static lv_color_t* buf2 = (lv_color_t*) heap_caps_malloc(LVGL_BUF_LEN, MALLOC_CAP_SPIRAM);
|
||||
|
||||
|
||||
|
||||
/* Serial debugging */
|
||||
void Lvgl_print(const char * buf)
|
||||
{
|
||||
// Serial.printf(buf);
|
||||
// Serial.flush();
|
||||
}
|
||||
|
||||
/* Display flushing
|
||||
Displays LVGL content on the LCD
|
||||
This function implements associating LVGL data to the LCD screen
|
||||
*/
|
||||
void Lvgl_Display_LCD( lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p )
|
||||
{
|
||||
LCD_addWindow(area->x1, area->y1, area->x2, area->y2, ( uint16_t *)&color_p->full);
|
||||
lv_disp_flush_ready( disp_drv );
|
||||
}
|
||||
/*Read the touchpad*/
|
||||
void Lvgl_Touchpad_Read( lv_indev_drv_t * indev_drv, lv_indev_data_t * data )
|
||||
{
|
||||
// NULL
|
||||
}
|
||||
void example_increase_lvgl_tick(void *arg)
|
||||
{
|
||||
/* Tell LVGL how many milliseconds has elapsed */
|
||||
lv_tick_inc(EXAMPLE_LVGL_TICK_PERIOD_MS);
|
||||
}
|
||||
void Lvgl_Init(void)
|
||||
{
|
||||
lv_init();
|
||||
lv_disp_draw_buf_init( &draw_buf, buf1, buf2, LVGL_BUF_LEN);
|
||||
|
||||
/*Initialize the display*/
|
||||
static lv_disp_drv_t disp_drv;
|
||||
lv_disp_drv_init( &disp_drv );
|
||||
/*Change the following line to your display resolution*/
|
||||
disp_drv.hor_res = LVGL_WIDTH;
|
||||
disp_drv.ver_res = LVGL_HEIGHT;
|
||||
disp_drv.flush_cb = Lvgl_Display_LCD;
|
||||
disp_drv.full_refresh = 1; /**< 1: Always make the whole screen redrawn*/
|
||||
disp_drv.draw_buf = &draw_buf;
|
||||
lv_disp_drv_register( &disp_drv );
|
||||
|
||||
/*Initialize the (dummy) input device driver*/
|
||||
static lv_indev_drv_t indev_drv;
|
||||
lv_indev_drv_init( &indev_drv );
|
||||
indev_drv.type = LV_INDEV_TYPE_POINTER;
|
||||
indev_drv.read_cb = Lvgl_Touchpad_Read;
|
||||
lv_indev_drv_register( &indev_drv );
|
||||
|
||||
/* Create simple label */
|
||||
lv_obj_t *label = lv_label_create( lv_scr_act() );
|
||||
lv_label_set_text( label, "Hello Ardino and LVGL!");
|
||||
lv_obj_align( label, LV_ALIGN_CENTER, 0, 0 );
|
||||
|
||||
const esp_timer_create_args_t lvgl_tick_timer_args = {
|
||||
.callback = &example_increase_lvgl_tick,
|
||||
.name = "lvgl_tick"
|
||||
};
|
||||
esp_timer_handle_t lvgl_tick_timer = NULL;
|
||||
esp_timer_create(&lvgl_tick_timer_args, &lvgl_tick_timer);
|
||||
esp_timer_start_periodic(lvgl_tick_timer, EXAMPLE_LVGL_TICK_PERIOD_MS * 1000);
|
||||
|
||||
}
|
||||
void Timer_Loop(void)
|
||||
{
|
||||
lv_timer_handler(); /* let the GUI do its work */
|
||||
// delay( 5 );
|
||||
}
|
||||
22
examples/LVGL_Arduino/LVGL_Driver.h
Normal file
22
examples/LVGL_Arduino/LVGL_Driver.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <lvgl.h>
|
||||
#include <lv_conf.h>
|
||||
#include <demos/lv_demos.h>
|
||||
#include <esp_heap_caps.h>
|
||||
#include "Display_ST7789.h"
|
||||
|
||||
#define LVGL_WIDTH (LCD_WIDTH )
|
||||
#define LVGL_HEIGHT LCD_HEIGHT
|
||||
#define LVGL_BUF_LEN (LVGL_WIDTH * LVGL_HEIGHT / 20)
|
||||
|
||||
#define EXAMPLE_LVGL_TICK_PERIOD_MS 5
|
||||
|
||||
|
||||
void Lvgl_print(const char * buf);
|
||||
void Lvgl_Display_LCD( lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p ); // Displays LVGL content on the LCD. This function implements associating LVGL data to the LCD screen
|
||||
void Lvgl_Touchpad_Read( lv_indev_drv_t * indev_drv, lv_indev_data_t * data ); // Read the touchpad
|
||||
void example_increase_lvgl_tick(void *arg);
|
||||
|
||||
void Lvgl_Init(void);
|
||||
void Timer_Loop(void);
|
||||
440
examples/LVGL_Arduino/LVGL_Example.cpp
Normal file
440
examples/LVGL_Arduino/LVGL_Example.cpp
Normal file
@@ -0,0 +1,440 @@
|
||||
#include "LVGL_Example.h"
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
typedef enum {
|
||||
DISP_SMALL,
|
||||
DISP_MEDIUM,
|
||||
DISP_LARGE,
|
||||
} disp_size_t;
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static void Onboard_create(lv_obj_t * parent);
|
||||
static void color_changer_create(lv_obj_t * parent);
|
||||
|
||||
static void color_changer_event_cb(lv_event_t * e);
|
||||
static void color_event_cb(lv_event_t * e);
|
||||
static void ta_event_cb(lv_event_t * e);
|
||||
static void birthday_event_cb(lv_event_t * e);
|
||||
static void calendar_event_cb(lv_event_t * e);
|
||||
void IRAM_ATTR example1_increase_lvgl_tick(lv_timer_t * t);
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static disp_size_t disp_size;
|
||||
|
||||
static lv_obj_t * tv;
|
||||
static lv_obj_t * calendar;
|
||||
lv_style_t style_text_muted;
|
||||
lv_style_t style_title;
|
||||
static lv_style_t style_icon;
|
||||
static lv_style_t style_bullet;
|
||||
|
||||
static lv_obj_t * chart1;
|
||||
static lv_obj_t * chart2;
|
||||
static lv_obj_t * chart3;
|
||||
|
||||
static lv_chart_series_t * ser1;
|
||||
static lv_chart_series_t * ser2;
|
||||
static lv_chart_series_t * ser3;
|
||||
static lv_chart_series_t * ser4;
|
||||
|
||||
static const lv_font_t * font_large;
|
||||
static const lv_font_t * font_normal;
|
||||
|
||||
static lv_timer_t * auto_step_timer;
|
||||
static lv_color_t original_screen_bg_color;
|
||||
|
||||
static lv_timer_t * meter2_timer;
|
||||
|
||||
lv_obj_t * SD_Size;
|
||||
lv_obj_t * FlashSize;
|
||||
lv_obj_t * Board_angle;
|
||||
lv_obj_t * RTC_Time;
|
||||
lv_obj_t * Wireless_Scan;
|
||||
|
||||
|
||||
|
||||
void IRAM_ATTR auto_switch(lv_timer_t * t)
|
||||
{
|
||||
uint16_t page = lv_tabview_get_tab_act(tv);
|
||||
|
||||
if (page == 0) {
|
||||
lv_tabview_set_act(tv, 1, LV_ANIM_ON);
|
||||
} else if (page == 3) {
|
||||
lv_tabview_set_act(tv, 2, LV_ANIM_ON);
|
||||
}
|
||||
}
|
||||
void Lvgl_Example1(void){
|
||||
|
||||
disp_size = DISP_SMALL;
|
||||
|
||||
font_large = LV_FONT_DEFAULT;
|
||||
font_normal = LV_FONT_DEFAULT;
|
||||
|
||||
lv_coord_t tab_h;
|
||||
tab_h = 45;
|
||||
#if LV_FONT_MONTSERRAT_18
|
||||
font_large = &lv_font_montserrat_18;
|
||||
#else
|
||||
LV_LOG_WARN("LV_FONT_MONTSERRAT_18 is not enabled for the widgets demo. Using LV_FONT_DEFAULT instead.");
|
||||
#endif
|
||||
#if LV_FONT_MONTSERRAT_12
|
||||
font_normal = &lv_font_montserrat_12;
|
||||
#else
|
||||
LV_LOG_WARN("LV_FONT_MONTSERRAT_12 is not enabled for the widgets demo. Using LV_FONT_DEFAULT instead.");
|
||||
#endif
|
||||
|
||||
lv_style_init(&style_text_muted);
|
||||
lv_style_set_text_opa(&style_text_muted, LV_OPA_90);
|
||||
|
||||
lv_style_init(&style_title);
|
||||
lv_style_set_text_font(&style_title, font_large);
|
||||
|
||||
lv_style_init(&style_icon);
|
||||
lv_style_set_text_color(&style_icon, lv_theme_get_color_primary(NULL));
|
||||
lv_style_set_text_font(&style_icon, font_large);
|
||||
|
||||
lv_style_init(&style_bullet);
|
||||
lv_style_set_border_width(&style_bullet, 0);
|
||||
lv_style_set_radius(&style_bullet, LV_RADIUS_CIRCLE);
|
||||
|
||||
tv = lv_tabview_create(lv_scr_act(), LV_DIR_TOP, tab_h);
|
||||
|
||||
lv_obj_set_style_text_font(lv_scr_act(), font_normal, 0);
|
||||
|
||||
|
||||
lv_obj_t * t1 = lv_tabview_add_tab(tv, "Onboard");
|
||||
|
||||
|
||||
Onboard_create(t1);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Lvgl_Example1_close(void)
|
||||
{
|
||||
/*Delete all animation*/
|
||||
lv_anim_del(NULL, NULL);
|
||||
|
||||
lv_timer_del(meter2_timer);
|
||||
meter2_timer = NULL;
|
||||
|
||||
lv_obj_clean(lv_scr_act());
|
||||
|
||||
lv_style_reset(&style_text_muted);
|
||||
lv_style_reset(&style_title);
|
||||
lv_style_reset(&style_icon);
|
||||
lv_style_reset(&style_bullet);
|
||||
}
|
||||
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
static void Onboard_create(lv_obj_t * parent)
|
||||
{
|
||||
|
||||
/*Create a panel*/
|
||||
lv_obj_t * panel1 = lv_obj_create(parent);
|
||||
lv_obj_set_height(panel1, LV_SIZE_CONTENT);
|
||||
|
||||
lv_obj_t * panel1_title = lv_label_create(panel1);
|
||||
lv_label_set_text(panel1_title, "Onboard parameter");
|
||||
lv_obj_add_style(panel1_title, &style_title, 0);
|
||||
|
||||
lv_obj_t * SD_label = lv_label_create(panel1);
|
||||
lv_label_set_text(SD_label, "SD Card");
|
||||
lv_obj_add_style(SD_label, &style_text_muted, 0);
|
||||
|
||||
SD_Size = lv_textarea_create(panel1);
|
||||
lv_textarea_set_one_line(SD_Size, true);
|
||||
lv_textarea_set_placeholder_text(SD_Size, "SD Size");
|
||||
lv_obj_add_event_cb(SD_Size, ta_event_cb, LV_EVENT_ALL, NULL);
|
||||
|
||||
lv_obj_t * Flash_label = lv_label_create(panel1);
|
||||
lv_label_set_text(Flash_label, "Flash Size");
|
||||
lv_obj_add_style(Flash_label, &style_text_muted, 0);
|
||||
|
||||
FlashSize = lv_textarea_create(panel1);
|
||||
lv_textarea_set_one_line(FlashSize, true);
|
||||
lv_textarea_set_placeholder_text(FlashSize, "Flash Size");
|
||||
lv_obj_add_event_cb(FlashSize, ta_event_cb, LV_EVENT_ALL, NULL);
|
||||
|
||||
lv_obj_t * Wireless_label = lv_label_create(panel1);
|
||||
lv_label_set_text(Wireless_label, "Wireless scan");
|
||||
lv_obj_add_style(Wireless_label, &style_text_muted, 0);
|
||||
|
||||
Wireless_Scan = lv_textarea_create(panel1);
|
||||
lv_textarea_set_one_line(Wireless_Scan, true);
|
||||
lv_textarea_set_placeholder_text(Wireless_Scan, "Wireless number");
|
||||
lv_obj_add_event_cb(Wireless_Scan, ta_event_cb, LV_EVENT_ALL, NULL);
|
||||
|
||||
// 器件布局
|
||||
static lv_coord_t grid_main_col_dsc[] = {LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST};
|
||||
static lv_coord_t grid_main_row_dsc[] = {LV_GRID_CONTENT, LV_GRID_CONTENT, LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST};
|
||||
lv_obj_set_grid_dsc_array(parent, grid_main_col_dsc, grid_main_row_dsc);
|
||||
|
||||
|
||||
/*Create the top panel*/
|
||||
static lv_coord_t grid_1_col_dsc[] = {LV_GRID_CONTENT, LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST};
|
||||
static lv_coord_t grid_1_row_dsc[] = {LV_GRID_CONTENT, /*Avatar*/
|
||||
LV_GRID_CONTENT, /*Name*/
|
||||
LV_GRID_CONTENT, /*Description*/
|
||||
LV_GRID_CONTENT, /*Email*/
|
||||
LV_GRID_CONTENT, /*Phone number*/
|
||||
LV_GRID_CONTENT, /*Button1*/
|
||||
LV_GRID_CONTENT, /*Button2*/
|
||||
LV_GRID_TEMPLATE_LAST
|
||||
};
|
||||
|
||||
lv_obj_set_grid_dsc_array(panel1, grid_1_col_dsc, grid_1_row_dsc);
|
||||
|
||||
|
||||
static lv_coord_t grid_2_col_dsc[] = {LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST};
|
||||
static lv_coord_t grid_2_row_dsc[] = {
|
||||
LV_GRID_CONTENT, /*Title*/
|
||||
5, /*Separator*/
|
||||
LV_GRID_CONTENT, /*Box title*/
|
||||
40, /*Box*/
|
||||
LV_GRID_CONTENT, /*Box title*/
|
||||
40, /*Box*/
|
||||
LV_GRID_CONTENT, /*Box title*/
|
||||
40, /*Box*/
|
||||
LV_GRID_CONTENT, /*Box title*/
|
||||
40, /*Box*/
|
||||
LV_GRID_CONTENT, /*Box title*/
|
||||
40, /*Box*/
|
||||
LV_GRID_CONTENT, /*Box title*/
|
||||
40, /*Box*/
|
||||
LV_GRID_TEMPLATE_LAST
|
||||
};
|
||||
|
||||
// lv_obj_set_grid_dsc_array(panel2, grid_2_col_dsc, grid_2_row_dsc);
|
||||
// lv_obj_set_grid_dsc_array(panel3, grid_2_col_dsc, grid_2_row_dsc);
|
||||
|
||||
lv_obj_set_grid_cell(panel1, LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_START, 0, 1);
|
||||
lv_obj_set_grid_dsc_array(panel1, grid_2_col_dsc, grid_2_row_dsc);
|
||||
lv_obj_set_grid_cell(panel1_title, LV_GRID_ALIGN_START, 0, 1, LV_GRID_ALIGN_CENTER, 0, 1);
|
||||
lv_obj_set_grid_cell(SD_label, LV_GRID_ALIGN_START, 0, 1, LV_GRID_ALIGN_START, 2, 1);
|
||||
lv_obj_set_grid_cell(SD_Size, LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_CENTER, 3, 1);
|
||||
lv_obj_set_grid_cell(Flash_label, LV_GRID_ALIGN_START, 0, 1, LV_GRID_ALIGN_START, 4, 1);
|
||||
lv_obj_set_grid_cell(FlashSize, LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_CENTER, 5, 1);
|
||||
lv_obj_set_grid_cell(Wireless_label, LV_GRID_ALIGN_START, 0, 1, LV_GRID_ALIGN_START, 6, 1);
|
||||
lv_obj_set_grid_cell(Wireless_Scan, LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_CENTER, 7, 1);
|
||||
|
||||
// 器件布局 END
|
||||
|
||||
auto_step_timer = lv_timer_create(example1_increase_lvgl_tick, 100, NULL);
|
||||
}
|
||||
|
||||
void IRAM_ATTR example1_increase_lvgl_tick(lv_timer_t * t)
|
||||
{
|
||||
char buf[100]={0};
|
||||
|
||||
snprintf(buf, sizeof(buf), "%d MB\r\n", SDCard_Size);
|
||||
lv_textarea_set_placeholder_text(SD_Size, buf);
|
||||
snprintf(buf, sizeof(buf), "%d MB\r\n", Flash_Size);
|
||||
lv_textarea_set_placeholder_text(FlashSize, buf);
|
||||
if(Scan_finish)
|
||||
snprintf(buf, sizeof(buf), "W: %d B: %d OK.\r\n",WIFI_NUM,BLE_NUM);
|
||||
// snprintf(buf, sizeof(buf), "WIFI: %d ..OK.\r\n",WIFI_NUM);
|
||||
else
|
||||
snprintf(buf, sizeof(buf), "W: %d B: %d\r\n",WIFI_NUM,BLE_NUM);
|
||||
// snprintf(buf, sizeof(buf), "WIFI: %d \r\n",WIFI_NUM);
|
||||
lv_textarea_set_placeholder_text(Wireless_Scan, buf);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
static void color_changer_create(lv_obj_t * parent)
|
||||
{
|
||||
static lv_palette_t palette[] = {
|
||||
LV_PALETTE_BLUE, LV_PALETTE_GREEN, LV_PALETTE_BLUE_GREY, LV_PALETTE_ORANGE,
|
||||
LV_PALETTE_RED, LV_PALETTE_PURPLE, LV_PALETTE_TEAL, _LV_PALETTE_LAST
|
||||
};
|
||||
|
||||
lv_obj_t * color_cont = lv_obj_create(parent);
|
||||
lv_obj_remove_style_all(color_cont);
|
||||
lv_obj_set_flex_flow(color_cont, LV_FLEX_FLOW_ROW);
|
||||
lv_obj_set_flex_align(color_cont, LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
||||
lv_obj_add_flag(color_cont, LV_OBJ_FLAG_FLOATING);
|
||||
|
||||
lv_obj_set_style_bg_color(color_cont, lv_color_white(), 0);
|
||||
lv_obj_set_style_pad_right(color_cont, disp_size == DISP_SMALL ? LV_DPX(47) : LV_DPX(55), 0);
|
||||
lv_obj_set_style_bg_opa(color_cont, LV_OPA_COVER, 0);
|
||||
lv_obj_set_style_radius(color_cont, LV_RADIUS_CIRCLE, 0);
|
||||
|
||||
if(disp_size == DISP_SMALL) lv_obj_set_size(color_cont, LV_DPX(52), LV_DPX(52));
|
||||
else lv_obj_set_size(color_cont, LV_DPX(60), LV_DPX(60));
|
||||
|
||||
lv_obj_align(color_cont, LV_ALIGN_BOTTOM_RIGHT, - LV_DPX(10), - LV_DPX(10));
|
||||
|
||||
uint32_t i;
|
||||
for(i = 0; palette[i] != _LV_PALETTE_LAST; i++) {
|
||||
lv_obj_t * c = lv_btn_create(color_cont);
|
||||
lv_obj_set_style_bg_color(c, lv_palette_main(palette[i]), 0);
|
||||
lv_obj_set_style_radius(c, LV_RADIUS_CIRCLE, 0);
|
||||
lv_obj_set_style_opa(c, LV_OPA_TRANSP, 0);
|
||||
lv_obj_set_size(c, 20, 20);
|
||||
lv_obj_add_event_cb(c, color_event_cb, LV_EVENT_ALL, &palette[i]);
|
||||
lv_obj_clear_flag(c, LV_OBJ_FLAG_SCROLL_ON_FOCUS);
|
||||
}
|
||||
|
||||
lv_obj_t * btn = lv_btn_create(parent);
|
||||
lv_obj_add_flag(btn, LV_OBJ_FLAG_FLOATING | LV_OBJ_FLAG_CLICKABLE);
|
||||
lv_obj_set_style_bg_color(btn, lv_color_white(), LV_STATE_CHECKED);
|
||||
lv_obj_set_style_pad_all(btn, 10, 0);
|
||||
lv_obj_set_style_radius(btn, LV_RADIUS_CIRCLE, 0);
|
||||
lv_obj_add_event_cb(btn, color_changer_event_cb, LV_EVENT_ALL, color_cont);
|
||||
lv_obj_set_style_shadow_width(btn, 0, 0);
|
||||
lv_obj_set_style_bg_img_src(btn, LV_SYMBOL_TINT, 0);
|
||||
|
||||
if(disp_size == DISP_SMALL) {
|
||||
lv_obj_set_size(btn, LV_DPX(42), LV_DPX(42));
|
||||
lv_obj_align(btn, LV_ALIGN_BOTTOM_RIGHT, -LV_DPX(15), -LV_DPX(15));
|
||||
}
|
||||
else {
|
||||
lv_obj_set_size(btn, LV_DPX(50), LV_DPX(50));
|
||||
lv_obj_align(btn, LV_ALIGN_BOTTOM_RIGHT, -LV_DPX(15), -LV_DPX(15));
|
||||
}
|
||||
}
|
||||
|
||||
static void color_changer_anim_cb(void * var, int32_t v)
|
||||
{
|
||||
lv_obj_t * obj =(lv_obj_t *) var;
|
||||
lv_coord_t max_w = lv_obj_get_width(lv_obj_get_parent(obj)) - LV_DPX(20);
|
||||
lv_coord_t w;
|
||||
|
||||
if(disp_size == DISP_SMALL) {
|
||||
w = lv_map(v, 0, 256, LV_DPX(52), max_w);
|
||||
lv_obj_set_width(obj, w);
|
||||
lv_obj_align(obj, LV_ALIGN_BOTTOM_RIGHT, - LV_DPX(10), - LV_DPX(10));
|
||||
}
|
||||
else {
|
||||
w = lv_map(v, 0, 256, LV_DPX(60), max_w);
|
||||
lv_obj_set_width(obj, w);
|
||||
lv_obj_align(obj, LV_ALIGN_BOTTOM_RIGHT, - LV_DPX(10), - LV_DPX(10));
|
||||
}
|
||||
|
||||
if(v > LV_OPA_COVER) v = LV_OPA_COVER;
|
||||
|
||||
uint32_t i;
|
||||
for(i = 0; i < lv_obj_get_child_cnt(obj); i++) {
|
||||
lv_obj_set_style_opa(lv_obj_get_child(obj, i), v, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void color_changer_event_cb(lv_event_t * e)
|
||||
{
|
||||
if(lv_event_get_code(e) == LV_EVENT_CLICKED) {
|
||||
lv_obj_t * color_cont = (lv_obj_t *)lv_event_get_user_data(e);
|
||||
if(lv_obj_get_width(color_cont) < LV_HOR_RES / 2) {
|
||||
lv_anim_t a;
|
||||
lv_anim_init(&a);
|
||||
lv_anim_set_var(&a, color_cont);
|
||||
lv_anim_set_exec_cb(&a, color_changer_anim_cb);
|
||||
lv_anim_set_values(&a, 0, 256);
|
||||
lv_anim_set_time(&a, 200);
|
||||
lv_anim_start(&a);
|
||||
}
|
||||
else {
|
||||
lv_anim_t a;
|
||||
lv_anim_init(&a);
|
||||
lv_anim_set_var(&a, color_cont);
|
||||
lv_anim_set_exec_cb(&a, color_changer_anim_cb);
|
||||
lv_anim_set_values(&a, 256, 0);
|
||||
lv_anim_set_time(&a, 200);
|
||||
lv_anim_start(&a);
|
||||
}
|
||||
}
|
||||
}
|
||||
static void color_event_cb(lv_event_t * e)
|
||||
{
|
||||
lv_event_code_t code = lv_event_get_code(e);
|
||||
lv_obj_t * obj = lv_event_get_target(e);
|
||||
|
||||
if(code == LV_EVENT_FOCUSED) {
|
||||
lv_obj_t * color_cont = lv_obj_get_parent(obj);
|
||||
if(lv_obj_get_width(color_cont) < LV_HOR_RES / 2) {
|
||||
lv_anim_t a;
|
||||
lv_anim_init(&a);
|
||||
lv_anim_set_var(&a, color_cont);
|
||||
lv_anim_set_exec_cb(&a, color_changer_anim_cb);
|
||||
lv_anim_set_values(&a, 0, 256);
|
||||
lv_anim_set_time(&a, 200);
|
||||
lv_anim_start(&a);
|
||||
}
|
||||
}
|
||||
else if(code == LV_EVENT_CLICKED) {
|
||||
lv_palette_t * palette_primary = (lv_palette_t *)lv_event_get_user_data(e);
|
||||
lv_palette_t palette_secondary =(lv_palette_t) ((*palette_primary) + 3); /*Use another palette as secondary*/
|
||||
if(palette_secondary >= _LV_PALETTE_LAST) palette_secondary =(lv_palette_t)(0);
|
||||
#if LV_USE_THEME_DEFAULT
|
||||
lv_theme_default_init(NULL, lv_palette_main(*palette_primary), lv_palette_main(palette_secondary),
|
||||
LV_THEME_DEFAULT_DARK, font_normal);
|
||||
#endif
|
||||
lv_color_t color = lv_palette_main(*palette_primary);
|
||||
lv_style_set_text_color(&style_icon, color);
|
||||
lv_chart_set_series_color(chart1, ser1, color);
|
||||
lv_chart_set_series_color(chart2, ser3, color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void ta_event_cb(lv_event_t * e)
|
||||
{
|
||||
}
|
||||
|
||||
static void birthday_event_cb(lv_event_t * e)
|
||||
{
|
||||
lv_event_code_t code = lv_event_get_code(e);
|
||||
lv_obj_t * ta = lv_event_get_target(e);
|
||||
|
||||
if(code == LV_EVENT_FOCUSED) {
|
||||
if(lv_indev_get_type(lv_indev_get_act()) == LV_INDEV_TYPE_POINTER) {
|
||||
if(calendar == NULL) {
|
||||
lv_obj_add_flag(lv_layer_top(), LV_OBJ_FLAG_CLICKABLE);
|
||||
calendar = lv_calendar_create(lv_layer_top());
|
||||
lv_obj_set_style_bg_opa(lv_layer_top(), LV_OPA_50, 0);
|
||||
lv_obj_set_style_bg_color(lv_layer_top(), lv_palette_main(LV_PALETTE_GREY), 0);
|
||||
if(disp_size == DISP_SMALL) lv_obj_set_size(calendar, 180, 200);
|
||||
else if(disp_size == DISP_MEDIUM) lv_obj_set_size(calendar, 200, 220);
|
||||
else lv_obj_set_size(calendar, 300, 330);
|
||||
lv_calendar_set_showed_date(calendar, 1990, 01);
|
||||
lv_obj_align(calendar, LV_ALIGN_CENTER, 0, 30);
|
||||
lv_obj_add_event_cb(calendar, calendar_event_cb, LV_EVENT_ALL, ta);
|
||||
|
||||
lv_calendar_header_dropdown_create(calendar);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void calendar_event_cb(lv_event_t * e)
|
||||
{
|
||||
lv_event_code_t code = lv_event_get_code(e);
|
||||
lv_obj_t * ta = (lv_obj_t *)lv_event_get_user_data(e);
|
||||
lv_obj_t * obj = (lv_obj_t *)lv_event_get_current_target(e);
|
||||
if(code == LV_EVENT_VALUE_CHANGED) {
|
||||
lv_calendar_date_t d;
|
||||
lv_calendar_get_pressed_date(obj, &d);
|
||||
char buf[32];
|
||||
lv_snprintf(buf, sizeof(buf), "%02d.%02d.%d", d.day, d.month, d.year);
|
||||
lv_textarea_set_text(ta, buf);
|
||||
|
||||
lv_obj_del(calendar);
|
||||
calendar = NULL;
|
||||
lv_obj_clear_flag(lv_layer_top(), LV_OBJ_FLAG_CLICKABLE);
|
||||
lv_obj_set_style_bg_opa(lv_layer_top(), LV_OPA_TRANSP, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
10
examples/LVGL_Arduino/LVGL_Example.h
Normal file
10
examples/LVGL_Arduino/LVGL_Example.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "LVGL_Driver.h"
|
||||
#include "SD_Card.h"
|
||||
#include "Wireless.h"
|
||||
|
||||
#define EXAMPLE1_LVGL_TICK_PERIOD_MS 1000
|
||||
|
||||
|
||||
void Lvgl_Example1(void);
|
||||
116
examples/LVGL_Arduino/SD_Card.cpp
Normal file
116
examples/LVGL_Arduino/SD_Card.cpp
Normal file
@@ -0,0 +1,116 @@
|
||||
#include "SD_Card.h"
|
||||
|
||||
uint16_t SDCard_Size;
|
||||
uint16_t Flash_Size;
|
||||
|
||||
bool SD_Init() {
|
||||
// SD
|
||||
pinMode(SD_CS, OUTPUT);
|
||||
digitalWrite(SD_CS, HIGH);
|
||||
if (SD.begin(SD_CS, SPI)) {
|
||||
printf("SD card initialization successful!\r\n");
|
||||
} else {
|
||||
printf("SD card initialization failed!\r\n");
|
||||
}
|
||||
uint8_t cardType = SD.cardType();
|
||||
if(cardType == CARD_NONE){
|
||||
printf("No SD card attached\r\n");
|
||||
return false;
|
||||
}
|
||||
else{
|
||||
printf("SD Card Type: ");
|
||||
if(cardType == CARD_MMC){
|
||||
printf("MMC\r\n");
|
||||
} else if(cardType == CARD_SD){
|
||||
printf("SDSC\r\n");
|
||||
} else if(cardType == CARD_SDHC){
|
||||
printf("SDHC\r\n");
|
||||
} else {
|
||||
printf("UNKNOWN\r\n");
|
||||
}
|
||||
uint64_t totalBytes = SD.totalBytes();
|
||||
uint64_t usedBytes = SD.usedBytes();
|
||||
SDCard_Size = totalBytes/(1024*1024);
|
||||
printf("Total space: %llu\n", totalBytes);
|
||||
printf("Used space: %llu\n", usedBytes);
|
||||
printf("Free space: %llu\n", totalBytes - usedBytes);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool File_Search(const char* directory, const char* fileName)
|
||||
{
|
||||
File Path = SD.open(directory);
|
||||
if (!Path) {
|
||||
printf("Path: <%s> does not exist\r\n",directory);
|
||||
return false;
|
||||
}
|
||||
File file = Path.openNextFile();
|
||||
while (file) {
|
||||
if (strcmp(file.name(), fileName) == 0) {
|
||||
if (strcmp(directory, "/") == 0)
|
||||
printf("File '%s%s' found in root directory.\r\n",directory,fileName);
|
||||
else
|
||||
printf("File '%s/%s' found in root directory.\r\n",directory,fileName);
|
||||
Path.close();
|
||||
return true;
|
||||
}
|
||||
file = Path.openNextFile();
|
||||
}
|
||||
if (strcmp(directory, "/") == 0)
|
||||
printf("File '%s%s' not found in root directory.\r\n",directory,fileName);
|
||||
else
|
||||
printf("File '%s/%s' not found in root directory.\r\n",directory,fileName);
|
||||
Path.close();
|
||||
return false;
|
||||
}
|
||||
uint16_t Folder_retrieval(const char* directory, const char* fileExtension, char File_Name[][100],uint16_t maxFiles)
|
||||
{
|
||||
File Path = SD.open(directory);
|
||||
if (!Path) {
|
||||
printf("Path: <%s> does not exist\r\n",directory);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint16_t fileCount = 0;
|
||||
char filePath[100];
|
||||
File file = Path.openNextFile();
|
||||
while (file && fileCount < maxFiles) {
|
||||
if (!file.isDirectory() && strstr(file.name(), fileExtension)) {
|
||||
strncpy(File_Name[fileCount], file.name(), sizeof(File_Name[fileCount]));
|
||||
if (strcmp(directory, "/") == 0) {
|
||||
snprintf(filePath, 100, "%s%s", directory, file.name());
|
||||
} else {
|
||||
snprintf(filePath, 100, "%s/%s", directory, file.name());
|
||||
}
|
||||
printf("File found: %s\r\n", filePath);
|
||||
fileCount++;
|
||||
}
|
||||
file = Path.openNextFile();
|
||||
}
|
||||
Path.close();
|
||||
if (fileCount > 0) {
|
||||
printf(" %d <%s> files were retrieved\r\n",fileCount,fileExtension);
|
||||
return fileCount;
|
||||
} else {
|
||||
printf("No files with extension '%s' found in directory: %s\r\n", fileExtension, directory);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void remove_file_extension(char *file_name) {
|
||||
char *last_dot = strrchr(file_name, '.');
|
||||
if (last_dot != NULL) {
|
||||
*last_dot = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
void Flash_test()
|
||||
{
|
||||
printf("/********** RAM Test**********/\r\n");
|
||||
// Get Flash size
|
||||
uint32_t flashSize = ESP.getFlashChipSize();
|
||||
Flash_Size = flashSize/1024/1024;
|
||||
printf("Flash size: %d MB \r\n", flashSize/1024/1024);
|
||||
|
||||
printf("/******* RAM Test Over********/\r\n\r\n");
|
||||
}
|
||||
19
examples/LVGL_Arduino/SD_Card.h
Normal file
19
examples/LVGL_Arduino/SD_Card.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
#include "Arduino.h"
|
||||
#include <cstring>
|
||||
#include "Display_ST7789.h"
|
||||
#include "SD.h"
|
||||
#include "FS.h"
|
||||
|
||||
// Digital I/O used
|
||||
#define SD_CS 4 // SD_D3:
|
||||
|
||||
extern uint16_t SDCard_Size;
|
||||
extern uint16_t Flash_Size;
|
||||
|
||||
bool SD_Init();
|
||||
void Flash_test();
|
||||
|
||||
bool File_Search(const char* directory, const char* fileName);
|
||||
uint16_t Folder_retrieval(const char* directory, const char* fileExtension, char File_Name[][100],uint16_t maxFiles);
|
||||
void remove_file_extension(char *file_name);
|
||||
79
examples/LVGL_Arduino/Wireless.cpp
Normal file
79
examples/LVGL_Arduino/Wireless.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
#include "Wireless.h"
|
||||
|
||||
|
||||
bool WIFI_Connection = 0;
|
||||
uint8_t WIFI_NUM = 0;
|
||||
uint8_t BLE_NUM = 0;
|
||||
bool Scan_finish = 0;
|
||||
int wifi_scan_number()
|
||||
{
|
||||
printf("/**********WiFi Test**********/\r\n");
|
||||
// Set WiFi to station mode and disconnect from an AP if it was previously connected.
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.setSleep(true);
|
||||
// WiFi.scanNetworks will return the number of networks found.
|
||||
int count = WiFi.scanNetworks();
|
||||
if (count == 0)
|
||||
{
|
||||
printf("No WIFI device was scanned\r\n");
|
||||
}
|
||||
else{
|
||||
printf("Scanned %d Wi-Fi devices\r\n",count);
|
||||
}
|
||||
|
||||
// Delete the scan result to free memory for code below.
|
||||
WiFi.disconnect(true);
|
||||
WiFi.scanDelete();
|
||||
WiFi.mode(WIFI_OFF);
|
||||
vTaskDelay(100);
|
||||
printf("/*******WiFi Test Over********/\r\n\r\n");
|
||||
return count;
|
||||
}
|
||||
int ble_scan_number()
|
||||
{
|
||||
printf("/**********BLE Test**********/\r\n");
|
||||
BLEDevice::init("ESP32");
|
||||
BLEScan* pBLEScan = BLEDevice::getScan();
|
||||
pBLEScan->setActiveScan(true);
|
||||
|
||||
BLEScanResults* foundDevices = pBLEScan->start(5);
|
||||
int count = foundDevices->getCount();
|
||||
if (count == 0)
|
||||
{
|
||||
printf("No Bluetooth device was scanned\r\n");
|
||||
}
|
||||
else{
|
||||
printf("Scanned %d Bluetooth devices\r\n",count);
|
||||
}
|
||||
pBLEScan->stop();
|
||||
pBLEScan->clearResults();
|
||||
BLEDevice::deinit(true);
|
||||
vTaskDelay(100);
|
||||
printf("/**********BLE Test Over**********/\r\n\r\n");
|
||||
return count;
|
||||
}
|
||||
extern char buffer[128]; /* Make sure buffer is enough for `sprintf` */
|
||||
void Wireless_Test1(){
|
||||
BLE_NUM = ble_scan_number(); // !!! Please note that continuing to use Bluetooth will result in allocation failure due to RAM usage, so pay attention to RAM usage when Bluetooth is turned on
|
||||
WIFI_NUM = wifi_scan_number();
|
||||
Scan_finish = 1;
|
||||
}
|
||||
|
||||
void WirelessScanTask(void *parameter) {
|
||||
BLE_NUM = ble_scan_number(); // !!! Please note that continuing to use Bluetooth will result in allocation failure due to RAM usage, so pay attention to RAM usage when Bluetooth is turned on
|
||||
WIFI_NUM = wifi_scan_number();
|
||||
Scan_finish = 1;
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
void Wireless_Test2(){
|
||||
xTaskCreatePinnedToCore(
|
||||
WirelessScanTask,
|
||||
"WirelessScanTask",
|
||||
4096,
|
||||
NULL,
|
||||
2,
|
||||
NULL,
|
||||
0
|
||||
);
|
||||
}
|
||||
14
examples/LVGL_Arduino/Wireless.h
Normal file
14
examples/LVGL_Arduino/Wireless.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
#include "WiFi.h"
|
||||
#include <BLEDevice.h>
|
||||
#include <BLEScan.h>
|
||||
|
||||
extern bool WIFI_Connection;
|
||||
extern uint8_t WIFI_NUM;
|
||||
extern uint8_t BLE_NUM;
|
||||
extern bool Scan_finish;
|
||||
|
||||
int wifi_scan_number();
|
||||
int ble_scan_number();
|
||||
void Wireless_Test1();
|
||||
void Wireless_Test2();
|
||||
Reference in New Issue
Block a user