UP BMP脚本
This commit is contained in:
@@ -18,7 +18,7 @@ extern "C" {
|
||||
#define PIX_COLOR_SIZE 1
|
||||
|
||||
// 启用单行刷新
|
||||
#define LINE_FAST_SHOW
|
||||
//#define LINE_FAST_SHOW
|
||||
|
||||
typedef struct Font Font_f_t;
|
||||
typedef void (*Font_Show_t)(Font_f_t *font, uint8_t *data, size_t len);
|
||||
|
@@ -61,10 +61,10 @@ Chinese_t Hzk[] = {
|
||||
},
|
||||
};
|
||||
|
||||
Chinese_t *find_chinese_data(uint8_t unicode_high, uint8_t unicode_low) {
|
||||
uint16_t find_chinese_data(uint8_t unicode_high, uint8_t unicode_low) {
|
||||
for (int i = 0; i < sizeof(Hzk) / sizeof(Chinese_t); ++i) {
|
||||
if (Hzk[i].unicode[0] == unicode_high && Hzk[i].unicode[1] == unicode_low) {
|
||||
return &Hzk[i];
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
|
@@ -108,7 +108,7 @@ void draw_letter_normal(Font_f_t *fd, uint16_t pos_x, uint16_t pos_y, lv_font_gl
|
||||
uint8_t fd_buf[fd->dev_w / 2];
|
||||
#endif
|
||||
#if PIX_COLOR_SIZE == 16
|
||||
uint16_t fd_buf[fd->dev_w / 8];
|
||||
uint16_t fd_buf[fd->dev_w / 2];
|
||||
#endif
|
||||
int32_t mask_p = 0;
|
||||
|
||||
|
@@ -207,30 +207,41 @@ void OLED_ShowChar(OLED_T *dev, uint8_t x, uint8_t y, uint8_t chr, uint8_t size1
|
||||
}
|
||||
}
|
||||
|
||||
void OLED_ShowString(OLED_T *dev, uint8_t x, uint8_t y, uint8_t *chr, uint8_t size1) {
|
||||
while ((*chr >= ' ') && (*chr <= '~'))//判断是不是非法字符!
|
||||
void OLED_ShowString(OLED_T *dev, uint8_t x, uint8_t y, uint8_t *str, uint8_t size1) {
|
||||
while ((*str >= ' ') && (*str <= '~'))//判断是不是非法字符!
|
||||
{
|
||||
OLED_ShowChar(dev, x, y, *chr, size1);
|
||||
OLED_ShowChar(dev, x, y, *str, size1);
|
||||
x += size1 / 2;
|
||||
if (x > dev->width - size1) //换行
|
||||
{
|
||||
x = 0;
|
||||
y += 2;
|
||||
}
|
||||
chr++;
|
||||
str++;
|
||||
}
|
||||
}
|
||||
|
||||
#define GET_LOW_BYTE0(x) ((x >> 0) & 0x000000ff) /* 获取第0个字节 */
|
||||
#define GET_LOW_BYTE1(x) ((x >> 8) & 0x000000ff) /* 获取第1个字节 */
|
||||
#define GET_LOW_BYTE2(x) ((x >> 16) & 0x000000ff) /* 获取第2个字节 */
|
||||
#define GET_LOW_BYTE3(x) ((x >> 24) & 0x000000ff) /* 获取第3个字节 */
|
||||
|
||||
void OLED_ShowCHString(OLED_T *dev, uint8_t x, uint8_t y, uint8_t *str) {
|
||||
uint8_t i, temp, size2, ys = y, xs = x, c = x;
|
||||
uint16_t index;
|
||||
size2 = Hzk_size * Hzk_size / 8; //得到字体一个字符对应点阵集所占的字节数
|
||||
while (*str) {
|
||||
// Hzk_size=12;
|
||||
// size2 = Hzk_size * Hzk_size / 8; //得到字体一个字符对应点阵集所占的字节数
|
||||
size2 = Hzk_size * ((Hzk_size + 7) / 8 * 8) / 8;
|
||||
uint8_t test[24] = {0x00, 0x00, 0x2E, 0x18, 0xF7, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0xD0, 0xFC, 0x5F, 0x0D,
|
||||
0xC6, 0x00, 0x00, 0x00};
|
||||
while (*str != '\0') {
|
||||
for (index = 0; index < sizeof(Hzk) / sizeof(Chinese_t); index++) {
|
||||
if (Hzk[index].unicode[0] == str[0] && Hzk[index].unicode[1] == str[1])//对比汉字区码位码
|
||||
{
|
||||
for (i = 0; i < size2; i++) {
|
||||
temp = Hzk[index].data[i];
|
||||
// temp = test[i];
|
||||
OLED_BSet(dev, xs, ys, temp);
|
||||
xs++;
|
||||
if (xs - c == Hzk_size) {
|
||||
@@ -240,10 +251,19 @@ void OLED_ShowCHString(OLED_T *dev, uint8_t x, uint8_t y, uint8_t *str) {
|
||||
}
|
||||
}
|
||||
ys = y;
|
||||
x += Hzk_size;
|
||||
str++;
|
||||
str++;
|
||||
} else {
|
||||
return;
|
||||
OLED_ShowChar(dev, x, y, *str, 16);
|
||||
x += 16 / 2;
|
||||
if (x > dev->width - 16) //换行
|
||||
{
|
||||
x = 0;
|
||||
y += 2;
|
||||
}
|
||||
str++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -264,6 +284,7 @@ void draw_rect(Font_f_t *fd, uint8_t *data, size_t len) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
void OLED_DisplayString(OLED_T *dev, const lv_font_t *font, uint8_t *s, uint16_t x, uint16_t y) {
|
||||
uint32_t unicode_letter;
|
||||
@@ -272,10 +293,10 @@ void OLED_DisplayString(OLED_T *dev, const lv_font_t *font, uint8_t *s, uint16_t
|
||||
if (font) {
|
||||
s += Font_utf8_to_unicode(s, &unicode_letter);
|
||||
x += Font_draw_letter(font, &fd, unicode_letter, x, y);
|
||||
x += 2; //字间距
|
||||
x += 0; //字间距
|
||||
} else {
|
||||
OLED_ShowChar(dev, x, y, *s, 12);
|
||||
x += 6;
|
||||
x += 12;
|
||||
s++;
|
||||
}
|
||||
}
|
||||
@@ -301,14 +322,23 @@ void OLED_ShowNum(OLED_T *dev, uint8_t x, uint8_t y, uint32_t num, uint8_t len,
|
||||
}
|
||||
}
|
||||
|
||||
void OLED_ShowPic(OLED_T *dev, uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t *bmp) {
|
||||
uint8_t y = 0;
|
||||
if (y % 8 == 0)y = 0;
|
||||
else y += 1;
|
||||
for (y = y0; y < y1; y++) {
|
||||
OLED_SPos(dev, x0, y);
|
||||
dev->data(bmp + y * (x1 - x0), x1 - x0);
|
||||
void OLED_ShowPic(OLED_T *dev, uint8_t x0, uint8_t y0, uint8_t w, uint8_t h, uint8_t *bmp) {
|
||||
size_t index;
|
||||
uint16_t x = x0, y = y0;
|
||||
for (index = 0; index < (w * h) / 8; index++) {
|
||||
OLED_BSet(dev, x, y, bmp[index]);
|
||||
if ((x - x0) == w) {
|
||||
y += 8;
|
||||
x = x0;
|
||||
}
|
||||
}
|
||||
// uint8_t y = 0;
|
||||
// if (y % 8 == 0)y = 0;
|
||||
// else y += 1;
|
||||
// for (y = y0; y < y1; y++) {
|
||||
// OLED_SPos(dev, x0, y);
|
||||
// dev->data(bmp + y * (x1 - x0), x1 - x0);
|
||||
// }
|
||||
}
|
||||
|
||||
void OLED_Fill(OLED_T *dev, uint8_t data) {
|
||||
|
@@ -4,6 +4,7 @@
|
||||
#include <stdio.h>
|
||||
#include <ctime>
|
||||
#include <stdint.h>
|
||||
#include <cstdlib>
|
||||
#include "tool.h"
|
||||
|
||||
float Mapping(float val, float I_Min, float I_Max, float O_Min, float O_Max) {
|
||||
@@ -46,16 +47,6 @@ void BufPrint(char *name, void *buf, Type_t type, unsigned int len, unsigned cha
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
uint8_t UTF8ToUnicode(uint8_t *dataArea, uint8_t dataAreaLength, uint8_t *uniDA) {
|
||||
uint8_t len = dataAreaLength * 2 / 3;
|
||||
// uint8_t uniDA[len];
|
||||
for (int i = 0; i < dataAreaLength / 3; i++) {
|
||||
uniDA[i * 2] = ((dataArea[i * 3] & 0xF) << 4) + ((dataArea[i * 3 + 1] >> 2) & 0xF);
|
||||
uniDA[i * 2 + 1] = ((dataArea[i * 3 + 1] & 0x3) << 6) + (dataArea[i * 3 + 2] & 0x3F);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
float Str2Float(char *str) {
|
||||
int integer = 0;
|
||||
double decimal = 0;
|
||||
|
Reference in New Issue
Block a user