U8log的使用(hal库)

移植U8G2库和测试可以参考这篇文章

基于STM32移植U8g2图形库——OLED显示(HAL库)_stm32 u8g2-CSDN博客icon-default.png?t=N7T8https://blog.csdn.net/black_sneak/article/details/126312657

U8log的使用

U8log的使用配合U8G2

将U8G2整个屏幕给U8log用

只需将数据打印到U8log即可。刷新 屏幕由U8log自动处理。

初始化

u8log_t u8log;
#define u8log_weith  32
#define u8log_heigh  4
uint8_t u8log_buffer[u8log_weith*u8log_heigh]={0};
u8log_Init(&u8log,u8log_weith,u8log_heigh,u8log_buffer);
//初始化u8log
//参数u8log_weith和u8log_heigh是横向和纵向能够容纳多少个字符
//u8log_buffer是u8log_heigh*u8log_weith大小的uin8_t或者char类型的数组
u8log_SetLineHeightOffset(&u8log,0);
//设置字符间距
u8log_SetRedrawMode(&u8log,0);
//设置清屏模式
u8log_SetCallback(&u8log, u8log_u8g2_cb, &u8g2);
//将u8log与u8g2相连接,从而能够显示在u8g2对象上面
//字符输出时,
//\n是换行并回到开始位置
//\r是回到开始位置
//\f是回到屏幕左上角
//u8log_WriteString等u8log的打印函数自带刷新功能,不需要额外刷新,
//并且u8g2的刷新函数不会把u8log的内容刷新掉
//

运行

    char buff[20];
    while(1)
    {
        //u8g2_ClearBuffer(&u8g2); 
        sprintf(buff,"hello:\t%04d\n",HAL_GetTick()%999);
        u8log_WriteString(&u8log,buff);
        //u8g2_DrawRFrame(&u8g2,16,40,80,10,4);
        //u8g2_SendBuffer(&u8g2);
        HAL_Delay(500);
    }

将U8G2与u8log一同使用U8G2刷新,u8log显示区域可以任意设置,大小也是。

大小体现在u8log_weith和u8log_heigh,而位置体现在

此时u8log的更新依赖于u8g2的更新。

初始化

u8log_t u8log;
#define u8log_weith  15
#define u8log_heigh  2
uint8_t u8log_buffer[u8log_weith*u8log_heigh]={0};
u8log_Init(&u8log,u8log_weith,u8log_heigh,u8log_buffer);
//初始化u8log

运行

    char buff[20];
    while(1)
    {
        u8g2_ClearBuffer(&u8g2); 
        sprintf(buff,"hello:\t%04d\n",HAL_GetTick()%999);
        u8log_WriteString(&u8log,buff);
        u8g2_DrawLog(&u8g2,30,HAL_GetTick()%60,&u8log);
        u8g2_SendBuffer(&u8g2);
        HAL_Delay(500);
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值