export PICO_SDK_PATH="/home/lhj/pico-setup/pico/pico-sdk" && cmake -DLV_CONF_BUILD_DISABLE_EXAMPLES=1 -DLV_CONF_BUILD_DISABLE_DEMOS=1 ..
/*****************************************************************************
* | File : LCD_1in28_test.c
* | Author : Waveshare team
* | Function : 1.3inch LCD test demo
* | Info :
*----------------
* | This version: V1.0
* | Date : 2021-08-20
* | Info :
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documnetation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
******************************************************************************/
#include "LCD_Test.h"
#include "LCD_1in28.h"
#include "QMI8658.h"
#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/adc.h"
#include "draw.h"
#include "lvgl.h"
#include "lv_port_disp.h"
bool timer_callback(repeating_timer_t *rt)
{
lv_tick_inc(5);
///printf("%lld\r\n",time_us_64());
}
static void btn_event_cb(lv_event_t * e)
{
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t * btn = lv_event_get_target(e);
if(code == LV_EVENT_CLICKED) {
static uint8_t cnt = 0;
cnt++;
/*Get the first child of the button which is the label and change its text*/
lv_obj_t * label = lv_obj_get_child(btn, 0);
lv_label_set_text_fmt(label, "Button: %d", cnt);
}
}
/**
* Create a button with a label and react on click event.
*/
void lv_example_get_started_1(void)
{
lv_color_t color;
color.full=(uint16_t)0xF800;
lv_obj_t * btn = lv_btn_create(lv_scr_act()); /*Add a button the current screen*/
lv_obj_set_style_text_font(btn, &lv_font_montserrat_24 ,0);
lv_obj_set_style_text_color(btn,color,0);
lv_obj_set_pos(btn, 120-100, 120-50); /*Set its position*/
lv_obj_set_size(btn, 200, 100); /*Set its size*/
lv_obj_add_event_cb(btn, btn_event_cb, LV_EVENT_ALL, NULL); /*Assign a callback to the button*/
lv_obj_t * label = lv_label_create(btn); /*Add a label to the button*/
lv_label_set_text(label, "Hello LVGL"); /*Set the labels text*/
lv_obj_center(label);
}
lv_obj_t * chart;
lv_chart_series_t * ser1;
lv_chart_series_t * ser2;
lv_chart_series_t * ser3;
lv_chart_series_t * ser4;
lv_chart_series_t * ser5;
lv_chart_series_t * ser6;
int adc_chart_init(void)
{
lv_obj_set_style_bg_color(lv_scr_act(), lv_color_hex(0x343247), 0);
/*Create a chart*/
chart = lv_chart_create(lv_scr_act());
lv_chart_set_type(chart, LV_CHART_TYPE_LINE);
lv_chart_set_point_count(chart, 20u);
lv_chart_set_range(chart,LV_CHART_AXIS_PRIMARY_Y, 0, 240);
lv_chart_set_range(chart,LV_CHART_AXIS_SECONDARY_Y, 0, 240);
lv_chart_set_update_mode(chart, LV_CHART_UPDATE_MODE_SHIFT);
lv_chart_set_div_line_count(chart, 4, 8);
//lv_chart_set_zoom_x(lv_obj_t * obj, uint16_t zoom_x);
//lv_chart_set_zoom_y(lv_obj_t * obj, uint16_t zoom_y);
lv_chart_set_axis_tick(chart, LV_CHART_AXIS_PRIMARY_Y, 0, 0, 5, 1, true, 80);
lv_chart_set_axis_tick(chart, LV_CHART_AXIS_PRIMARY_X, 0, 0, 12, 1, true, 50);
lv_obj_set_size(chart, 240, 240);
lv_obj_align(chart, LV_ALIGN_CENTER, 0, 0);
/*Add two data series*/
ser1 = lv_chart_add_series(chart,lv_color_hex(0xFF0000),LV_CHART_AXIS_PRIMARY_Y);
ser2 = lv_chart_add_series(chart,lv_color_hex(0x00FF00),LV_CHART_AXIS_PRIMARY_Y);
ser3 = lv_chart_add_series(chart,lv_color_hex(0x0000FF),LV_CHART_AXIS_PRIMARY_Y);
ser4 = lv_chart_add_series(chart,lv_color_hex(0xFFFF00),LV_CHART_AXIS_PRIMARY_Y);
ser5 = lv_chart_add_series(chart,lv_color_hex(0x00FFFF),LV_CHART_AXIS_PRIMARY_Y);
ser6 = lv_chart_add_series(chart,lv_color_hex(0xFF00FF),LV_CHART_AXIS_PRIMARY_Y);
return 0;
}
int adc_chart_newdata(int index,int32_t newdata,int refresh)
{
if(index == 0)
{
lv_chart_set_next_value(chart, ser1, newdata);
}
if(index == 1)
{
lv_chart_set_next_value(chart, ser2, newdata);
}
if(index == 2)
{
lv_chart_set_next_value(chart, ser3, newdata);
}
if(index == 3)
{
lv_chart_set_next_value(chart, ser4, newdata);
}
if(index == 4)
{
lv_chart_set_next_value(chart, ser5, newdata);
}
else
{
lv_chart_set_next_value(chart, ser6, newdata);
}
if(refresh)
{
lv_chart_refresh(chart); /*Required after direct set*/
}
return 0;
}
struct repeating_timer timer;
int LCD_1in28_test(void)
{
if (DEV_Module_Init() != 0)
{
return -1;
}
adc_init();
adc_gpio_init(29);
adc_select_input(3);
LCD_1IN28_Init(VERTICAL);
LCD_1IN28_Clear(WHITE);
DEV_SET_PWM(60);
add_repeating_timer_ms(5,timer_callback,0,&timer);
///sleep_ms(5000);
lv_init();
lv_port_disp_init();
//lv_example_get_started_1();
float acc[3], gyro[3];
static int num = 0;
unsigned int tim_count=0;
adc_chart_init();
QMI8658_init();
while(1)
{
/* 读取采样值 */
num++;
QMI8658_read_xyz(acc, gyro, &tim_count);
adc_chart_newdata(0,acc[0]*240/1024+120,0);
adc_chart_newdata(1,acc[1]*240/1024+120,0);
adc_chart_newdata(2,acc[2]*240/1024+120,0);
adc_chart_newdata(3,gyro[0]*240/1024+120,0);
adc_chart_newdata(4,gyro[1]*240/1024+120,0);
if(num>=5)
{
num = 0;
adc_chart_newdata(5,gyro[2]*240/1024+120,1);
printf("acc_x = %4.3fmg , acc_y = %4.3fmg , acc_z = %4.3fmg\r\n", acc[0], acc[1], acc[2]);
printf("gyro_x = %4.3fdps, gyro_y = %4.3fdps, gyro_z = %4.3fdps\r\n", gyro[0], gyro[1], gyro[2]);
}
else
{
adc_chart_newdata(5,gyro[2],0);
}
sleep_us(1000); /* 必须又sleep 否则定时器不会回调 */
lv_task_handler();
}
DEV_Module_Exit();
return 0;
}
RP2040-LCD-1.28.zip
(28.11 MB, 下载次数: 1)