How’d you get on with this John? I’ve just bought one of these boards, and I’m struggling too. After a lot of frustration, I’ve managed to draw a static picture on the LCD, by hacking some of the examples and using the Waveshare_ST7262_LVGL library. It did take me ages to work out how to use this library due to a complete lack of documentation, but eventually realised my issue was that I was overcomplicating it. Here is my code, that is a hack of the LVGL example clock:-
#include "img_hand.h"
#include <lvgl.h>
#include <Waveshare_ST7262_LVGL.h>
static const uint16_t screenWidth = 800;
static const uint16_t screenHeight = 480;
static lv_disp_draw_buf_t draw_buf;
static lv_color_t buf[screenWidth * screenHeight / 10];
// Global pointers for the meter indicators (the clock hands)
static lv_obj_t * meter;
static lv_meter_indicator_t * indic_hour;
static lv_meter_indicator_t * indic_min;
static lv_meter_indicator_t * indic_sec;
// Simulated track time variables
static int current_hour = 10;
static int current_min = 10;
static int current_sec = 0;
static void set_value(void * indic, int32_t v)
{
Serial.println("Start set_value"); // Print start message for RGB LCD example
lv_meter_set_indicator_end_value(meter, (lv_meter_indicator_t*)indic, v);
Serial.println("End set_value"); // Print start message for RGB LCD example
}
// UI Generation function
void create_analogue_clock() {
meter = lv_meter_create(lv_scr_act());
lv_obj_set_size(meter, 400, 400);
lv_obj_center(meter);
/*Create a scale for the minutes*/
/*61 ticks in a 360 degrees range (the last and the first line overlaps)*/
lv_meter_scale_t * scale_min = lv_meter_add_scale(meter);
lv_meter_set_scale_ticks(meter, scale_min, 61, 1, 10, lv_palette_main(LV_PALETTE_GREY));
lv_meter_set_scale_range(meter, scale_min, 0, 60, 360, 270);
/*Create an other scale for the hours. It's only visual and contains only major ticks*/
lv_meter_scale_t * scale_hour = lv_meter_add_scale(meter);
lv_meter_set_scale_ticks(meter, scale_hour, 12, 0, 0, lv_palette_main(LV_PALETTE_GREY)); /*12 ticks*/
lv_meter_set_scale_major_ticks(meter, scale_hour, 1, 2, 20, lv_color_black(), 10); /*Every tick is major*/
lv_meter_set_scale_range(meter, scale_hour, 1, 12, 330, 300); /*[1..12] values in an almost full circle*/
LV_IMG_DECLARE(img_hand)
/*Add a the hands from images*/
lv_meter_indicator_t * indic_min = lv_meter_add_needle_img(meter, scale_min, &img_hand, 5, 5);
lv_meter_indicator_t * indic_hour = lv_meter_add_needle_img(meter, scale_min, &img_hand, 5, 5);
// 3. Second Hand (Thin, long, distinct red color)
lv_meter_indicator_t * indic_sec = lv_meter_add_needle_line(meter, scale_min, 2, lv_palette_main(LV_PALETTE_RED), -10);
// lv_meter_indicator_t * indic_sec = lv_meter_add_needle_img(meter, scale_min, &img_hand, 5, 5);
/*Create an animation to set the value*/
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_exec_cb(&a, set_value);
lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
a.start_value = 12;
lv_anim_set_values(&a, 0, 60);
lv_anim_set_time(&a, 1000 * 60); /* 60 sec for 1 turn of the second hand */
lv_anim_set_var(&a, indic_sec);
lv_anim_start(&a);
a.start_value = 5;
lv_anim_set_values(&a, 0, 60);
lv_anim_set_time(&a, 3600*1000); /*3600 sec for 1 turn of the minute hand (1 hour)*/
lv_anim_set_var(&a, indic_min);
lv_anim_start(&a);
a.start_value = 20;
lv_anim_set_var(&a, indic_hour);
lv_anim_set_time(&a, 12*3600*1000); /*12 hour for 1 turn of the hour hand*/
lv_anim_set_values(&a, 0, 60);
lv_anim_start(&a);
}
void setup() {
Serial.begin(115200);
Serial.println("Clock example start"); // Print start message for RGB LCD example
lvgl_port_lock(-1);
// init lvl for our panel
lcd_init ();
// Render our UI components
create_analogue_clock();
lvgl_port_unlock();
Serial.println("Clock example end"); // Print start message for RGB LCD example
}
void loop() {
// Drive the LVGL graphics pipeline engine
Serial.println("IDLE loop"); // Print idle loop message
lv_timer_handler();
delay(1);
}
For the life of me, I can’t get the hands to animate. The loop() function seems to repeat about 30 odd times, then exit. Given that that’s equivalent to about 30ms, it doesn’t give the second hand a change to advance at all.
If anyone out there has enough experience with these boards to shed some light on this, I’d be enterally grateful.
Cheers,
Garrick