Rev 761 | Rev 800 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 761 | Rev 783 | ||
---|---|---|---|
1 | /**************************************************************************** |
1 | /**************************************************************************** |
2 | * Copyright (C) 2009-2010 by Claas Anders "CaScAdE" Rathje * |
2 | * Copyright (C) 2009-2010 by Claas Anders "CaScAdE" Rathje * |
3 | * admiralcascade@gmail.com * |
3 | * admiralcascade@gmail.com * |
4 | * Project-URL: http://www.mylifesucks.de/oss/c-osd/ * |
4 | * Project-URL: http://www.mylifesucks.de/oss/c-osd/ * |
5 | * * |
5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * |
6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License as published by * |
7 | * it under the terms of the GNU General Public License as published by * |
8 | * the Free Software Foundation; either version 2 of the License. * |
8 | * the Free Software Foundation; either version 2 of the License. * |
9 | * * |
9 | * * |
10 | * This program is distributed in the hope that it will be useful, * |
10 | * This program is distributed in the hope that it will be useful, * |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
13 | * GNU General Public License for more details. * |
13 | * GNU General Public License for more details. * |
14 | * * |
14 | * * |
15 | * You should have received a copy of the GNU General Public License * |
15 | * You should have received a copy of the GNU General Public License * |
16 | * along with this program; if not, write to the * |
16 | * along with this program; if not, write to the * |
17 | * Free Software Foundation, Inc., * |
17 | * Free Software Foundation, Inc., * |
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
19 | ****************************************************************************/ |
19 | ****************************************************************************/ |
20 | 20 | ||
21 | #include <avr/io.h> |
21 | #include <avr/io.h> |
22 | #include <util/delay.h> |
22 | #include <util/delay.h> |
23 | #include <avr/pgmspace.h> |
23 | #include <avr/pgmspace.h> |
24 | #include <string.h> |
24 | #include <string.h> |
25 | #include <stdlib.h> |
25 | #include <stdlib.h> |
26 | #include "main.h" |
26 | #include "main.h" |
27 | #include "max7456_software_spi.h" |
27 | #include "max7456_software_spi.h" |
28 | 28 | ||
29 | 29 | ||
30 | char conv_array[7]; // general array for number -> char conversation |
30 | char conv_array[7]; // general array for number -> char conversation |
31 | 31 | ||
32 | /* ########################################################################## |
32 | /* ########################################################################## |
33 | * MAX7456 SPI & Display stuff |
33 | * MAX7456 SPI & Display stuff |
34 | * ##########################################################################*/ |
34 | * ##########################################################################*/ |
35 | 35 | ||
36 | /** |
36 | /** |
37 | * Send a byte through SPI |
37 | * Send a byte through SPI |
38 | * inline because it increases the codesize currenlty 'only' by 110byte but saves |
38 | * inline because it increases the codesize currenlty 'only' by 110byte but saves |
39 | * the context-change on every char and attribute which is at least done twice |
39 | * the context-change on every char and attribute which is at least done twice |
40 | * (address and data byte), a significant speed-bost we do not want to miss :) |
40 | * (address and data byte), a significant speed-bost we do not want to miss :) |
41 | */ |
41 | */ |
42 | inline void spi_send(uint8_t byte) { |
42 | inline void spi_send(uint8_t byte) { |
43 | for (int8_t i = 7; i >= 0; i--) { |
43 | for (int8_t i = 7; i >= 0; i--) { |
44 | if (((byte >> i) & 1)) { |
44 | if (((byte >> i) & 1)) { |
45 | MAX_SDIN_HIGH |
45 | MAX_SDIN_HIGH |
46 | } else { |
46 | } else { |
47 | MAX_SDIN_LOW |
47 | MAX_SDIN_LOW |
48 | } |
48 | } |
49 | MAX_SCLK_HIGH |
49 | MAX_SCLK_HIGH |
50 | MAX_SCLK_LOW |
50 | MAX_SCLK_LOW |
51 | } |
51 | } |
52 | } |
52 | } |
53 | 53 | ||
54 | /** |
54 | /** |
55 | * Send <byte> to <address> of MAX7456 |
55 | * Send <byte> to <address> of MAX7456 |
56 | */ |
56 | */ |
57 | void spi_send_byte(uint8_t address, uint8_t byte) { |
57 | void spi_send_byte(uint8_t address, uint8_t byte) { |
58 | // start sending |
58 | // start sending |
59 | MAX_CS_LOW |
59 | MAX_CS_LOW |
60 | 60 | ||
61 | spi_send(address); |
61 | spi_send(address); |
62 | spi_send(byte); |
62 | spi_send(byte); |
63 | 63 | ||
64 | // end sending |
64 | // end sending |
65 | MAX_CS_HIGH |
65 | MAX_CS_HIGH |
66 | } |
66 | } |
67 | 67 | ||
68 | /** |
68 | /** |
69 | * write a <character> to <address> of MAX7456 display memory |
69 | * write a <character> to <address> of MAX7456 display memory |
70 | */ |
70 | */ |
71 | void write_char(uint16_t address, char character) { |
71 | void write_char(uint16_t address, char character) { |
72 | spi_send_byte(0x05, (address & 0xFF00) >> 8); // DMAH |
72 | spi_send_byte(0x05, (address & 0xFF00) >> 8); // DMAH |
73 | spi_send_byte(0x06, (address & 0x00FF)); // DMAL |
73 | spi_send_byte(0x06, (address & 0x00FF)); // DMAL |
74 | spi_send_byte(0x07, character); // DMDI |
74 | spi_send_byte(0x07, character); // DMDI |
75 | } |
75 | } |
76 | 76 | ||
77 | /** |
77 | /** |
78 | * clear display memory |
78 | * clear display memory |
79 | * (also sets 8bit mode) |
79 | * (also sets 8bit mode) |
80 | */ |
80 | */ |
81 | void clear(void) { |
81 | void clear(void) { |
82 | /*uint16_t memory_address = 0; |
82 | /*uint16_t memory_address = 0; |
83 | for (unsigned int a = 0; a < 480; a++) { |
83 | for (unsigned int a = 0; a < 480; a++) { |
84 | write_char(memory_address++, 0); |
84 | write_char(memory_address++, 0); |
85 | }*/ |
85 | }*/ |
86 | // clear all display-mem (DMM) |
86 | // clear all display-mem (DMM) |
87 | spi_send_byte(0x04, 0b01000100); |
87 | spi_send_byte(0x04, 0b01000100); |
88 | 88 | ||
89 | // clearing takes 12uS according to maxim so lets wait longer |
89 | // clearing takes 12uS according to maxim so lets wait longer |
90 | _delay_us(20); |
90 | _delay_us(20); |
91 | } |
91 | } |
92 | 92 | ||
93 | 93 | ||
94 | #if (ALLCHARSDEBUG|(WRITECHARS != -1)) |
94 | #if (ALLCHARSDEBUG|(WRITECHARS != -1)) |
95 | 95 | ||
96 | /** |
96 | /** |
97 | * for testing write all chars to screen |
97 | * for testing write all chars to screen |
98 | */ |
98 | */ |
99 | void write_all_chars() { |
99 | void write_all_chars() { |
100 | uint16_t x = 3, y = 2, t = 0; |
100 | uint16_t x = 3, y = 2, t = 0; |
101 | while (t < 256) { |
101 | while (t < 256) { |
102 | write_char(x++ + y * 30, t++); |
102 | write_char(x++ + y * 30, t++); |
103 | if (x > 25) { |
103 | if (x > 25) { |
104 | y++; |
104 | y++; |
105 | x = 3; |
105 | x = 3; |
106 | } |
106 | } |
107 | } |
107 | } |
108 | } |
108 | } |
109 | 109 | ||
110 | /** |
110 | /** |
111 | * let the MAX7456 learn a new character at <number> |
111 | * let the MAX7456 learn a new character at <number> |
112 | * with <data>. |
112 | * with <data>. |
113 | */ |
113 | */ |
114 | void learn_char(uint8_t number, unsigned char* data) { |
114 | void learn_char(uint8_t number, unsigned char* data) { |
115 | // select character to write (CMAH) |
115 | // select character to write (CMAH) |
116 | spi_send_byte(0x09, number); |
116 | spi_send_byte(0x09, number); |
117 | 117 | ||
118 | for (uint8_t i = 0; i < 54; i++) { |
118 | for (uint8_t i = 0; i < 54; i++) { |
119 | // select 4pixel byte of char (CMAL) |
119 | // select 4pixel byte of char (CMAL) |
120 | spi_send_byte(0x0A, i); |
120 | spi_send_byte(0x0A, i); |
121 | 121 | ||
122 | // write 4pixel byte of char (CMDI) |
122 | // write 4pixel byte of char (CMDI) |
123 | spi_send_byte(0x0B, data[i]); |
123 | spi_send_byte(0x0B, data[i]); |
124 | } |
124 | } |
125 | 125 | ||
126 | // write to the NVM array from the shadow RAM (CMM) |
126 | // write to the NVM array from the shadow RAM (CMM) |
127 | spi_send_byte(0x08, 0b10100000); |
127 | spi_send_byte(0x08, 0b10100000); |
128 | 128 | ||
129 | // according to maxim writing to nvram takes about 12ms, lets wait longer |
129 | // according to maxim writing to nvram takes about 12ms, lets wait longer |
130 | _delay_ms(120); |
130 | _delay_ms(120); |
131 | } |
131 | } |
132 | #endif |
132 | #endif |
133 | 133 | ||
134 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
134 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
135 | 135 | ||
136 | /** |
136 | /** |
137 | * write a character <attribute> to <address> of MAX7456 display memory |
137 | * write a character <attribute> to <address> of MAX7456 display memory |
138 | */ |
138 | */ |
139 | void write_char_att(uint16_t address, char attribute) { |
139 | void write_char_att(uint16_t address, char attribute) { |
140 | // the only important part is that the DMAH[1] is set |
140 | // the only important part is that the DMAH[1] is set |
141 | // so we add 2 which binary is the 2nd lowest byte |
141 | // so we add 2 which binary is the 2nd lowest byte |
142 | spi_send_byte(0x05, ((address & 0xFF00) >> 8) | 2); // DMAH |
142 | spi_send_byte(0x05, ((address & 0xFF00) >> 8) | 2); // DMAH |
143 | spi_send_byte(0x06, (address & 0x00FF)); // DMAL |
143 | spi_send_byte(0x06, (address & 0x00FF)); // DMAL |
144 | spi_send_byte(0x07, attribute); // DMDI |
144 | spi_send_byte(0x07, attribute); // DMDI |
145 | } |
145 | } |
146 | 146 | ||
147 | /** |
147 | /** |
148 | * write a <character> at <x>/<y> to MAX7456 display memory |
148 | * write a <character> at <x>/<y> to MAX7456 display memory |
149 | */ |
149 | */ |
150 | void write_char_xy(uint8_t x, uint8_t y, char character) { |
150 | void write_char_xy(uint8_t x, uint8_t y, char character) { |
151 | uint16_t address = y * 30 + x; |
151 | uint16_t address = y * 30 + x; |
152 | write_char(address, character); |
152 | write_char(address, character); |
153 | } |
153 | } |
154 | 154 | ||
155 | /** |
155 | /** |
156 | * write a character <attribute> at <x>/<y> to MAX7456 display memory |
156 | * write a character <attribute> at <x>/<y> to MAX7456 display memory |
157 | */ |
157 | */ |
158 | void write_char_att_xy(uint8_t x, uint8_t y, char attribute) { |
158 | void write_char_att_xy(uint8_t x, uint8_t y, char attribute) { |
159 | uint16_t address = y * 30 + x; |
159 | uint16_t address = y * 30 + x; |
160 | write_char_att(address, attribute); |
160 | write_char_att(address, attribute); |
161 | } |
161 | } |
162 | 162 | ||
163 | /** |
163 | /** |
164 | * write an ascii <character> to <address> of MAX7456 display memory |
164 | * write an ascii <character> to <address> of MAX7456 display memory |
165 | */ |
165 | */ |
166 | void write_ascii_char(uint16_t address, char c) { |
166 | void write_ascii_char(uint16_t address, char c) { |
167 | if (c == 32) c = 0; // remap space |
167 | if (c == 32) c = 0; // remap space |
168 | else if (c > 48 && c <= 57) c -= 48; // remap numbers |
168 | else if (c > 48 && c <= 57) c -= 48; // remap numbers |
169 | else if (c == '0') c = 10; // remap zero |
169 | else if (c == '0') c = 10; // remap zero |
170 | else if (c >= 65 && c <= 90) c -= 54; // remap big letters |
170 | else if (c >= 65 && c <= 90) c -= 54; // remap big letters |
171 | else if (c >= 97 && c <= 122) c -= 60; // remap small letters |
171 | else if (c >= 97 && c <= 122) c -= 60; // remap small letters |
172 | else if (c == '(') c = 63; // remap |
172 | else if (c == '(') c = 63; // remap |
173 | else if (c == ')') c = 64; // remap |
173 | else if (c == ')') c = 64; // remap |
174 | else if (c == '.') c = 65; // remap |
174 | else if (c == '.') c = 65; // remap |
175 | else if (c == '-') c = 73; // remap minus |
175 | else if (c == '-') c = 73; // remap minus |
176 | else if (c == ';') c = 67; // remap |
176 | else if (c == ';') c = 67; // remap |
177 | else if (c == ':') c = 68; // remap |
177 | else if (c == ':') c = 68; // remap |
178 | else if (c == ',') c = 69; // remap |
178 | else if (c == ',') c = 69; // remap |
179 | // else if (c == '?') c = 66; // remap |
179 | // else if (c == '?') c = 66; // remap |
180 | // else if (c == '\'') c = 70; // remap |
180 | // else if (c == '\'') c = 70; // remap |
181 | else if (c == '/') c = 71; // remap |
181 | else if (c == '/') c = 71; // remap |
182 | // else if (c == '"') c = 72; // remap |
182 | // else if (c == '"') c = 72; // remap |
183 | // else if (c == '<') c = 74; // remap |
183 | // else if (c == '<') c = 74; // remap |
184 | // else if (c == '>') c = 75; // remap |
184 | // else if (c == '>') c = 75; // remap |
185 | // else if (c == '@') c = 76; // remap |
185 | // else if (c == '@') c = 76; // remap |
186 | write_char(address, c); |
186 | write_char(address, c); |
187 | } |
187 | } |
188 | 188 | ||
189 | /** |
189 | /** |
190 | * write an ascii <string> at <x>/<y> to MAX7456 display memory |
190 | * write an ascii <string> at <x>/<y> to MAX7456 display memory |
191 | */ |
191 | */ |
192 | void write_ascii_string(uint8_t x, uint8_t y, char *string) { |
192 | void write_ascii_string(uint8_t x, uint8_t y, char *string) { |
193 | while (*string) { |
193 | while (*string) { |
194 | write_ascii_char(((x++)+(y * 30)), *string); |
194 | write_ascii_char(((x++)+(y * 30)), *string); |
195 | string++; |
195 | string++; |
196 | } |
196 | } |
197 | } |
197 | } |
198 | 198 | ||
199 | /** |
199 | /** |
- | 200 | * write an ascii <string> with lenght <len> at <x>/<y> to MAX7456 display memory |
|
- | 201 | */ |
|
- | 202 | void write_ascii_string_len(uint8_t x, uint8_t y, char *string, uint8_t len) { |
|
- | 203 | while (len--) { |
|
- | 204 | write_ascii_char(((x++)+(y * 30)), *string); |
|
- | 205 | string++; |
|
- | 206 | } |
|
- | 207 | } |
|
- | 208 | ||
- | 209 | /** |
|
200 | * write an ascii <string> from progmen at <x>/<y> to MAX7456 display memory |
210 | * write an ascii <string> from progmen at <x>/<y> to MAX7456 display memory |
201 | */ |
211 | */ |
202 | void write_ascii_string_pgm(uint8_t x, uint8_t y, const char *string) { |
212 | void write_ascii_string_pgm(uint8_t x, uint8_t y, const char *string) { |
203 | while (pgm_read_byte(string) != 0x00) |
213 | while (pgm_read_byte(string) != 0x00) |
204 | write_ascii_char(((x++)+(y * 30)), pgm_read_byte(string++)); |
214 | write_ascii_char(((x++)+(y * 30)), pgm_read_byte(string++)); |
205 | } |
215 | } |
206 | 216 | ||
207 | /** |
217 | /** |
208 | * write an <string> from progmen at <x>/<y> downwards to MAX7456 display memory |
218 | * write an <string> from progmen at <x>/<y> downwards to MAX7456 display memory |
209 | */ |
219 | */ |
210 | void write_string_pgm_down(uint8_t x, uint8_t y, const char *string, uint8_t length) { |
220 | void write_string_pgm_down(uint8_t x, uint8_t y, const char *string, uint8_t length) { |
211 | while (length--) |
221 | while (length--) |
212 | write_char((x + (y++ * 30)), pgm_read_byte(string++)); |
222 | write_char((x + (y++ * 30)), pgm_read_byte(string++)); |
213 | } |
223 | } |
214 | 224 | ||
215 | /** |
225 | /** |
216 | * Write a unsigned <number> at <x>/<y> to MAX7456 display memory |
226 | * Write a unsigned <number> at <x>/<y> to MAX7456 display memory |
217 | * <length> represents the length to rightbound the number |
227 | * <length> represents the length to rightbound the number |
218 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
228 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
219 | */ |
229 | */ |
220 | void write_ndigit_number_u(uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad) { |
230 | void write_ndigit_number_u(uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad) { |
221 | itoa(number, conv_array, 10); |
231 | itoa(number, conv_array, 10); |
222 | for (uint8_t i = 0; i < length - strlen(conv_array); i++) { |
232 | for (uint8_t i = 0; i < length - strlen(conv_array); i++) { |
223 | if (pad) write_char((x++)+(y * 30), 10); |
233 | if (pad) write_char((x++)+(y * 30), 10); |
224 | else write_ascii_char((x++)+(y * 30), 0); |
234 | else write_ascii_char((x++)+(y * 30), 0); |
225 | } |
235 | } |
226 | write_ascii_string(x, y, conv_array); |
236 | write_ascii_string(x, y, conv_array); |
227 | } |
237 | } |
228 | 238 | ||
229 | /** |
239 | /** |
230 | * Write a signed <number> at <x>/<y> to MAX7456 display memory |
240 | * Write a signed <number> at <x>/<y> to MAX7456 display memory |
231 | * <length> represents the length to rightbound the number |
241 | * <length> represents the length to rightbound the number |
232 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
242 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
233 | */ |
243 | */ |
234 | void write_ndigit_number_s(uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad) { |
244 | void write_ndigit_number_s(uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad) { |
235 | itoa(number, conv_array, 10); |
245 | itoa(number, conv_array, 10); |
236 | for (uint8_t i = 0; i < length - strlen(conv_array); i++) { |
246 | for (uint8_t i = 0; i < length - strlen(conv_array); i++) { |
237 | if (pad) write_char((x++)+(y * 30), 10); |
247 | if (pad) write_char((x++)+(y * 30), 10); |
238 | else write_ascii_char((x++)+(y * 30), 0); |
248 | else write_ascii_char((x++)+(y * 30), 0); |
239 | } |
249 | } |
240 | write_ascii_string(x, y, conv_array); |
250 | write_ascii_string(x, y, conv_array); |
241 | } |
251 | } |
242 | 252 | ||
243 | /** |
253 | /** |
244 | * Write a unsigned <number> at <x>/<y> to MAX7456 display memory as /10th of value |
254 | * Write a unsigned <number> at <x>/<y> to MAX7456 display memory as /10th of value |
245 | * <length> represents the length to rightbound the number |
255 | * <length> represents the length to rightbound the number |
246 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
256 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
247 | */ |
257 | */ |
248 | void write_ndigit_number_u_10th(uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad) { |
258 | void write_ndigit_number_u_10th(uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad) { |
249 | itoa(number, conv_array, 10); |
259 | itoa(number, conv_array, 10); |
250 | uint8_t len = strlen(conv_array); |
260 | uint8_t len = strlen(conv_array); |
251 | for (uint8_t i = 0; i < length - len; i++) { |
261 | for (uint8_t i = 0; i < length - len; i++) { |
252 | if (pad) write_char((x++)+(y * 30), 10); // zero |
262 | if (pad) write_char((x++)+(y * 30), 10); // zero |
253 | else write_char((x++)+(y * 30), 0); // blank |
263 | else write_char((x++)+(y * 30), 0); // blank |
254 | } |
264 | } |
255 | char rest = conv_array[len - 1]; |
265 | char rest = conv_array[len - 1]; |
256 | conv_array[len - 1] = 0; |
266 | conv_array[len - 1] = 0; |
257 | if (len == 1) { |
267 | if (len == 1) { |
258 | write_char((x - 1)+(y * 30), 10); // zero |
268 | write_char((x - 1)+(y * 30), 10); // zero |
259 | } else if (len == 2 && conv_array[0] == '-') { |
269 | } else if (len == 2 && conv_array[0] == '-') { |
260 | write_char((x - 1)+(y * 30), 0x49); // minus |
270 | write_char((x - 1)+(y * 30), 0x49); // minus |
261 | write_char((x)+(y * 30), 10); // zero |
271 | write_char((x)+(y * 30), 10); // zero |
262 | } else { |
272 | } else { |
263 | write_ascii_string(x, y, conv_array); |
273 | write_ascii_string(x, y, conv_array); |
264 | } |
274 | } |
265 | x += len - 1; |
275 | x += len - 1; |
266 | write_char((x++)+(y * 30), 65); // decimal point |
276 | write_char((x++)+(y * 30), 65); // decimal point |
267 | write_ascii_char((x++)+(y * 30), rest); // after dot |
277 | write_ascii_char((x++)+(y * 30), rest); // after dot |
268 | } |
278 | } |
269 | 279 | ||
270 | /** |
280 | /** |
271 | * Write a signed <number> at <x>/<y> to MAX7456 display memory as /10th of value |
281 | * Write a signed <number> at <x>/<y> to MAX7456 display memory as /10th of value |
272 | * <length> represents the length to rightbound the number |
282 | * <length> represents the length to rightbound the number |
273 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
283 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
274 | */ |
284 | */ |
275 | void write_ndigit_number_s_10th(uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad) { |
285 | void write_ndigit_number_s_10th(uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad) { |
276 | itoa(number, conv_array, 10); |
286 | itoa(number, conv_array, 10); |
277 | uint8_t len = strlen(conv_array); |
287 | uint8_t len = strlen(conv_array); |
278 | for (uint8_t i = 0; i < length - len; i++) { |
288 | for (uint8_t i = 0; i < length - len; i++) { |
279 | if (pad) write_char((x++)+(y * 30), 10); // zero |
289 | if (pad) write_char((x++)+(y * 30), 10); // zero |
280 | else write_char((x++)+(y * 30), 0); // blank |
290 | else write_char((x++)+(y * 30), 0); // blank |
281 | } |
291 | } |
282 | char rest = conv_array[len - 1]; |
292 | char rest = conv_array[len - 1]; |
283 | conv_array[len - 1] = 0; |
293 | conv_array[len - 1] = 0; |
284 | if (len == 1) { |
294 | if (len == 1) { |
285 | write_char((x - 1)+(y * 30), 10); // zero |
295 | write_char((x - 1)+(y * 30), 10); // zero |
286 | } else if (len == 2 && conv_array[0] == '-') { |
296 | } else if (len == 2 && conv_array[0] == '-') { |
287 | write_char((x - 1)+(y * 30), 0x49); // minus |
297 | write_char((x - 1)+(y * 30), 0x49); // minus |
288 | write_char((x)+(y * 30), 10); // zero |
298 | write_char((x)+(y * 30), 10); // zero |
289 | } else { |
299 | } else { |
290 | write_ascii_string(x, y, conv_array); |
300 | write_ascii_string(x, y, conv_array); |
291 | } |
301 | } |
292 | x += len - 1; |
302 | x += len - 1; |
293 | write_char((x++)+(y * 30), 65); // decimal point |
303 | write_char((x++)+(y * 30), 65); // decimal point |
294 | write_ascii_char((x++)+(y * 30), rest); // after dot |
304 | write_ascii_char((x++)+(y * 30), rest); // after dot |
295 | } |
305 | } |
296 | 306 | ||
297 | /** |
307 | /** |
298 | * write <seconds> as human readable time at <x>/<y> to MAX7456 display mem |
308 | * write <seconds> as human readable time at <x>/<y> to MAX7456 display mem |
299 | */ |
309 | */ |
300 | void write_time(uint8_t x, uint8_t y, uint16_t seconds) { |
310 | void write_time(uint8_t x, uint8_t y, uint16_t seconds) { |
301 | uint16_t min = seconds / 60; |
311 | uint16_t min = seconds / 60; |
302 | seconds -= min * 60; |
312 | seconds -= min * 60; |
303 | write_ndigit_number_u(x, y, min, 3, 0); |
313 | write_ndigit_number_u(x, y, min, 3, 0); |
304 | write_char_xy(x + 3, y, 68); |
314 | write_char_xy(x + 3, y, 68); |
305 | write_ndigit_number_u(x + 4, y, seconds, 2, 1); |
315 | write_ndigit_number_u(x + 4, y, seconds, 2, 1); |
306 | } |
316 | } |
307 | 317 | ||
308 | /** |
318 | /** |
309 | * wirte a <position> at <x>/<y> assuming it is a gps position for long-/latitude |
319 | * wirte a <position> at <x>/<y> assuming it is a gps position for long-/latitude |
310 | */ |
320 | */ |
311 | void write_gps_pos(uint8_t x, uint8_t y, int32_t position) { |
321 | void write_gps_pos(uint8_t x, uint8_t y, int32_t position) { |
312 | if (position < 0) { |
322 | if (position < 0) { |
313 | position ^= ~0; |
323 | position ^= ~0; |
314 | position++; |
324 | position++; |
315 | write_char_xy(x++, y, 0x49); // minus |
325 | write_char_xy(x++, y, 0x49); // minus |
316 | } else { |
326 | } else { |
317 | write_char_xy(x++, y, 0); // clear ('+' would be nice, maybe later) |
327 | write_char_xy(x++, y, 0); // clear ('+' would be nice, maybe later) |
318 | } |
328 | } |
319 | write_ndigit_number_u(x, y, (uint16_t)(position / (int32_t)10000000), 3, 1); |
329 | write_ndigit_number_u(x, y, (uint16_t)(position / (int32_t)10000000), 3, 1); |
320 | write_char_xy(x + 3, y, 65); // decimal point |
330 | write_char_xy(x + 3, y, 65); // decimal point |
321 | position = position - ((position / (int32_t)10000000) * (int32_t)10000000); |
331 | position = position - ((position / (int32_t)10000000) * (int32_t)10000000); |
322 | write_ndigit_number_u(x + 4, y, (uint16_t)(position / (int32_t)1000), 4, 1); |
332 | write_ndigit_number_u(x + 4, y, (uint16_t)(position / (int32_t)1000), 4, 1); |
323 | position = position - ((uint16_t)(position / (int32_t)1000) * (int32_t)1000); |
333 | position = position - ((uint16_t)(position / (int32_t)1000) * (int32_t)1000); |
324 | write_ndigit_number_u(x + 8, y, (uint16_t)position, 3, 1); |
334 | write_ndigit_number_u(x + 8, y, (uint16_t)position, 3, 1); |
325 | write_char_xy(x + 11, y, 0xD0); // degree symbol |
335 | write_char_xy(x + 11, y, 0xD0); // degree symbol |
326 | } |
336 | } |
327 | 337 | ||
328 | #endif |
338 | #endif |
329 | 339 |