📄 graph.c
字号:
/*
* test.c --- Primary header file for
* LCD Device Driver with Framebuffer
* (C)opyright 2004 Bit 920 Labs
*
* Written by: Tangliting <dawn@bit.edu.cn>
* Created on: Sat. Mar 7 14:33:45 GMT +8:00 2004
*/
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <string.h>
#include <linux/fb.h>
#include <linux/kd.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <termios.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include "lcd.c"
#include "ascii.lib"
FILE *hzkFile = NULL;
void DrawCharEN(short x, short y, unsigned char c, ColorType color)
{
unsigned char codes[16];
short i;
for (i = 0; i < 16; i++)
codes[i] = ascii_codes[c][i];
fb_Text_8x16(x, y, codes, color);
}
void DrawCharCHS(int x, int y, unsigned char c[2], ColorType color)
{
unsigned char codes[32];
short i;
unsigned char ch, cl;
unsigned long offset;
if (hzkFile == NULL)
{
printf("No Chinese Character Library opened.\n");
exit(1);
}
ch = c[0];
cl = c[1];
offset = ((ch - 0xa1) * 94L + (cl - 0xa1)) * 32L;
fseek(hzkFile, offset, SEEK_SET);
fread(codes, 32, 1, hzkFile);
fb_Text_16x16(x, y, codes, color);
}
int main()
{
short x, y;
short i;
ColorType color = SYS_WHITE;
short colorPage;
short endFlag;
unsigned char * ascTxt = "Beijing Institute of Technology";
unsigned char * chsTxt = "北京理工大学计算机学院";
unsigned char bufferTxt[2];
short x_max, y_max;
ColorType color_max;
if (fb_Init() == -1)
{
printf("Initialize Framebuffer LCD failed.\n");
exit(1);
}
x_max = fb_GetScreenWidth() - 1;
y_max = fb_GetScreenHeight() - 1;
color_max = fb_GetScreenColors() - 1;
fb_Clear(SYS_BLACK);
fb_DrawLine_H(10, x_max, 100, SYS_WHITE);
fb_DrawLine_V(10, 10, y_max,GREEN );
fb_DrawRect(30, 30, 100, 100, GREEN);
fb_FillRect(100, 100, 200, 300, BLUE);
fb_DrawEllipse(100, 100, 50, 50, CYAN);
fb_DrawEllipse(300, 400, 50, 60, YELLOW);
fb_FillEllipse( 200, 200, 20, 25, ORANGE);
fb_FillEllipse( 300, 300, 50, 15, PURPLE);
x = 320, y = 240;
for (i = 0; i < strlen(ascTxt); i++)
{
DrawCharEN(x, y, ascTxt[i], SYS_WHITE);
x += 8;
}
printf("Test text_16x16:\t");
hzkFile = fopen("./hzk", "rb"); //change from hz16 to hzk
x = 340, y = 260;
for (i = 0; i < strlen(chsTxt); i += 2)
{
bufferTxt[0] = chsTxt[i];
bufferTxt[1] = chsTxt[i + 1];
DrawCharCHS(x, y, bufferTxt, CYAN);
x += 16;
}
fclose(hzkFile);
printf("\nFinished Test. Press any key to exit.\n");
getchar();
fb_Release();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -