-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomChar.c
182 lines (170 loc) · 3.47 KB
/
CustomChar.c
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
//hex presentation of all the custom chars
unsigned char halfBar[8] = {
0x03,
0x03,
0x03,
0x03,
0x03,
0x03,
0x03,
0x03
};
unsigned char cTwo[8] = {
0x00,
0x00,
0x09,
0x15,
0x13,
0x00,
0x00,
0x00
};
unsigned char cFour[8] = {
0x00,
0x00,
0x1F,
0x04,
0x1C,
0x00,
0x00,
0x00
};
unsigned char cFive[8] = {
0x00,
0x00,
0x16,
0x15,
0x1D,
0x00,
0x00,
0x00
};
unsigned char cSix[8] = {
0x00,
0x00,
0x13,
0x15,
0x0F,
0x00,
0x00,
0x00
};
unsigned char cSeven[8] = {
0x00,
0x00,
0x18,
0x14,
0x13,
0x00,
0x00,
0x00
};
unsigned char cEight[8] = {
0x00,
0x00,
0x1F,
0x15,
0x1F,
0x00,
0x00,
0x00
};
unsigned char cNine[8] = {
0x00,
0x00,
0x1E,
0x15,
0x1D,
0x00,
0x00,
0x00
};
unsigned char empty[8] = {
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00
};
/*
* Iterates the saved character pattern to given array
* TODO should be changed to pass only pointer
*/
int iterateArray(unsigned char numberPattern[], unsigned char pattern[]) {
for(int i = 0; i< 9; i++) {
numberPattern[i] = pattern[i];
}
return 0;
}
// maps the given index (lcd memory addres) to corrseponding character pattern
int getCustomCharPattern(int number, unsigned char pattern[]) {
switch (number) {
case 0:
iterateArray(pattern, halfBar);
return 0;
case 2:
iterateArray(pattern, cTwo);
return 0;
case 4:
iterateArray(pattern, cFour);
return 0;
case 5:
iterateArray(pattern, cFive);
return 0;
case 6:
iterateArray(pattern, cSix);
return 0;
case 7:
iterateArray(pattern, cSeven);
return 0;
case 8:
iterateArray(pattern, cEight);
return 0;
case 9:
iterateArray(pattern, cNine);
return 0;
default:
iterateArray(pattern, empty);
return 1;
}
};
// returns lcd character that resemble the given character sideways
// 0, 1, 3 are reused preset symbols
unsigned char getRemappedChar(char key) {
switch (key) {
case 'B':
return (unsigned char) 0x00; // B is just a placeholder key, currently not in use
case '0':
return (unsigned char) 0x6F; // "o" symbol
case '1':
return (unsigned char) 0x2D; // "-" symbol
case '2':
return (unsigned char) 0x01; // Address of the custom 2 symbol in lcd memory
case '3':
return (unsigned char) 0x6D; // "similar looking to w"
case '4':
return (unsigned char) 0x02; // Address of the custom 4 symbol in lcd memory
case '5':
return (unsigned char) 0x03; //...
case '6':
return (unsigned char) 0x04;
case '7':
return (unsigned char) 0x05;
case '8':
return (unsigned char) 0x06;
case '9':
return (unsigned char) 0x07;
default:
return (unsigned char) 0xFF; //returns a filled square
}
}
// remaps given char array to the sideways symbols
int remapText(char inputText[], unsigned char mappedText[]) {
for (int i = 0; i < 2; i++) {
mappedText[i] = getRemappedChar(inputText[i]);
}
return 0;
}