【平头哥RVB2601创意应用开发】串口接收字符并在oled屏幕上显示
[复制链接]
本帖最后由 serialworld 于 2022-3-26 09:03 编辑
实现了串口接收字符并在oled屏幕上显示的功能,具体代码如下:/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
/*********************
* INCLUDES
*********************/
#define _DEFAULT_SOURCE /* needed for usleep() */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <aos/aos.h>
#include "aos/cli.h"
#include "app_init.h"
#include "lvgl.h"
#include "lv_label.h"
#include "oled.h"
#include "myled.h"
#include "console_uart.h"
/*********************
* DEFINES
*********************/
#define TAG "app"
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
// GUI
//static void gui_lvgl_task(void *arg);
//
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
#define N 80
volatile uint32_t g_debug = 0;
volatile uint32_t g_debug_v = 0;
volatile char c;
char myinput[N];
static lv_obj_t *p;
static void gui_lvgl_task(void *arg);
static void led_task(void *arg);
static void ch_input_task(void *arg);
void fun(char *str);
#include "csi_core.h"
/**
* main
*/
int main(void)
{
board_yoc_init();
myled_init();
aos_task_new("gui", gui_lvgl_task, NULL, 10 * 1024);
aos_task_new("led", led_task, NULL, 10 * 1024);
aos_task_new("getchar", ch_input_task, NULL, 10 * 1024);
return 0;
}
static void gui_label_create(void)
{
p = lv_label_create(lv_scr_act(), NULL);
lv_label_set_long_mode(p, LV_LABEL_LONG_BREAK);
lv_label_set_align(p, LV_LABEL_ALIGN_LEFT);
lv_obj_set_pos(p, 0, 4);
lv_obj_set_size(p, 128, 60);
lv_label_set_text(p, "Hello\n world!\n");
// lv_label_set_long_mode(p, LV_LABEL_LONG_SROLL_CIRC);
}
static void gui_lvgl_task(void *arg)
{
lv_init();
/*Initialize for LittlevGL*/
oled_init();
/*Select display 1*/
// demo_create();
gui_label_create();
// extern static lv_obj_t *p;
while (1) {
/* Periodically call the lv_task handler.
* It could be done in a timer interrupt or an OS task too.*/
lv_task_handler();
// LOGD(TAG, "hello world!");
aos_msleep(5);
lv_label_set_text(p, myinput);
lv_tick_inc(1);
}
}
static void led_task(void *arg){
while(1){
myled_test();
}
}
static void ch_input_task(void *arg){
while(1){
fun(myinput);
printf("%s",myinput);
aos_msleep(5);
}
}
void fun(char * str){
for (int i=0,ch ='\0';ch != '\n';++i){
ch= uart_getc();
if(i>=N){
continue;
}
if(ch == '\n' ||i == N-1){
str = '\0';
continue;
}
str =ch;
}
|