add utf8
This commit is contained in:
parent
f635c4a0b8
commit
5b84f4cfad
41
MikuOled.cpp
41
MikuOled.cpp
@ -1,7 +1,8 @@
|
||||
|
||||
#include "MikuDuino.h"
|
||||
#include "Wire.h"
|
||||
#include "MikuOled.h"
|
||||
#include <iconv.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* MikuPi.cpp:
|
||||
@ -14,6 +15,23 @@
|
||||
*
|
||||
*/
|
||||
|
||||
int UTF8toGB2312(char *sourcebuf,char *destbuf)
|
||||
{
|
||||
iconv_t cd;
|
||||
size_t sourcelen,destlen;
|
||||
sourcelen=strlen(sourcebuf)+1;
|
||||
destlen=sourcelen*4;
|
||||
if ((cd = iconv_open("gb2312","utf-8")) ==0)
|
||||
return -1;
|
||||
if(-1 == iconv(cd,&sourcebuf,&sourcelen,&destbuf,&destlen))
|
||||
{
|
||||
perror("iconv");
|
||||
return -2;
|
||||
}
|
||||
iconv_close(cd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8 Miku_Oled::buf[OLED_BUFFER_LENGTH+1];
|
||||
|
||||
const char logo[]={
|
||||
@ -98,6 +116,7 @@ Miku_Oled::Miku_Oled()
|
||||
{
|
||||
buffer=buf+1;
|
||||
buf[0]=0x40;
|
||||
encoding=GB2312;
|
||||
showLogo();
|
||||
}
|
||||
|
||||
@ -106,6 +125,11 @@ void Miku_Oled::oled_sendCommand(int c)
|
||||
Wire.write((uint8)0,(uint8)c);
|
||||
}
|
||||
|
||||
void Miku_Oled::setEncoding(uint8 code)
|
||||
{
|
||||
encoding=code;
|
||||
}
|
||||
|
||||
void Miku_Oled::begin()
|
||||
{
|
||||
Wire.begin();
|
||||
@ -185,15 +209,22 @@ void Miku_Oled::drawPoint(uint8 x,uint8 y,uint8 c)
|
||||
buffer[p]|=(uint8)(1<<m);
|
||||
}
|
||||
|
||||
void Miku_Oled::drawText(const char* txt)
|
||||
void Miku_Oled::drawText(char* txt)
|
||||
{
|
||||
char mytxt[256];
|
||||
|
||||
if (encoding==UTF8)
|
||||
UTF8toGB2312(txt,mytxt);
|
||||
else
|
||||
memcpy(mytxt, txt, strlen(txt)+1);
|
||||
|
||||
FILE *fphzk;
|
||||
fphzk=fopen("/usr/share/fonts/mikupi.font","rb");
|
||||
int i,r,rr;
|
||||
uint8 out[32];
|
||||
for(i=0;i<strlen(txt);i++)
|
||||
for(i=0;i<strlen(mytxt);i++)
|
||||
{
|
||||
uint8 x=*(txt+i);
|
||||
uint8 x=*(mytxt+i);
|
||||
if (x<161)
|
||||
{
|
||||
if (x==10)
|
||||
@ -231,7 +262,7 @@ void Miku_Oled::drawText(const char* txt)
|
||||
ypos+=16;
|
||||
}
|
||||
|
||||
long p=(((*(txt+i))-161)*94+(*(txt+i+1))-161)*32+4096;
|
||||
long p=(((*(mytxt+i))-161)*94+(*(mytxt+i+1))-161)*32+4096;
|
||||
i++;
|
||||
fseek(fphzk, p, SEEK_SET);
|
||||
r=fread(out,1,32,fphzk);
|
||||
|
||||
@ -76,12 +76,14 @@ class Miku_Oled {
|
||||
void showBMP(uint8*);
|
||||
void setPos(uint8,uint8);
|
||||
void drawPoint(uint8,uint8,uint8);
|
||||
void drawText(const char*);
|
||||
void drawText(char*);
|
||||
void setEncoding(uint8);
|
||||
private:
|
||||
void oled_sendCommand(int);
|
||||
static uint8 buf[];
|
||||
uint8 *buffer;
|
||||
uint8 xpos,ypos;
|
||||
uint8 encoding;
|
||||
};
|
||||
|
||||
|
||||
|
||||
2
MikuPi.h
2
MikuPi.h
@ -18,6 +18,8 @@
|
||||
#define INPUT_PULLUP (2)
|
||||
#define OUTPUT (1)
|
||||
|
||||
#define GB2312 (0)
|
||||
#define UTF8 (1)
|
||||
|
||||
#define PI_MODEL_UNKNOWN 0
|
||||
#define PI_MODEL_M1 1
|
||||
|
||||
@ -25,6 +25,7 @@ void setup()
|
||||
{
|
||||
sayHello();
|
||||
oled.begin();
|
||||
oled.setEncoding(UTF8);
|
||||
oled.clearDisplay();
|
||||
int i;
|
||||
for(i=1;i<lu_argc;i++){
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user