1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
/*
* graphics_adapter.c
*
* Created on: Sep 24, 2017
* Author: Roy
*/
#include <stdbool.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "graphics_adapter.h"
#include "grlib/grlib.h"
#include "drivers/frame.h"
#include "drivers/kentec320x240x16_ssd2119.h"
#define LINE_HEIGHT 12
#define MAX_POSITION 240
int current_position = 0;
char current_line[100];
void init_graphics(uint32_t ui32SysClock)
{
// Initialize the display driver.
Kentec320x240x16_SSD2119Init(ui32SysClock);
// Initialize the graphics context.
GrContextInit(&g_sContext, &g_sKentec320x240x16_SSD2119);
}
void draw_image(uint8_t* data)
{
GrImageDraw(&g_sContext, data, 0, 0);
}
void draw_string(char* data, size_t length)
{
tRectangle backRect;
backRect.i16XMin = 100;
backRect.i16XMax = 300;
backRect.i16YMin = 100;
backRect.i16YMax = 80;
GrContextForegroundSet(&g_sContext, ClrBlack);
GrRectFill(&g_sContext, &backRect);
GrStringDraw(&g_sContext, data, length, 0, 0, true);
}
void writeLine(char* text)
{
if (current_position >= MAX_POSITION)
{
clear();
}
strcpy(current_line, text);
GrStringDraw(&g_sContext, current_line, strlen(current_line), 0, current_position, true);
current_position += LINE_HEIGHT;
}
void writeFloat(float num)
{
char num_buf[10];
ltoa(num, num_buf);
strcat(current_line, num_buf);
GrStringDraw(&g_sContext, current_line, strlen(current_line), 0, current_position - LINE_HEIGHT, true);
}
void writeString(char* text)
{
strcat(current_line,text);
GrStringDraw(&g_sContext, current_line, strlen(current_line), 0, current_position - LINE_HEIGHT, true);
}
void clear()
{
tRectangle backRect;
backRect.i16XMin = 0;
backRect.i16XMax = 340;
backRect.i16YMin = 240;
backRect.i16YMax = 0;
GrContextForegroundSet(&g_sContext, ClrBlack);
GrRectFill(&g_sContext, &backRect);
GrContextFontSet(&g_sContext, TEXT_FONT);
GrContextForegroundSet(&g_sContext, ClrWhite);
current_position = 0;
}
|