Subversion Repositories Projects

Rev

Rev 783 | Rev 835 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 783 Rev 800
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 "main.h"
21
#include <avr/io.h>
22
#include <avr/io.h>
22
#include <util/delay.h>
23
#include <util/delay.h>
23
#include <avr/pgmspace.h> 
24
#include <avr/pgmspace.h> 
24
#include <string.h>
25
#include <string.h>
25
#include <stdlib.h>
26
#include <stdlib.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
 
-
 
32
int pow(int a, int b) {
-
 
33
    if (b <= 0) return 1;
-
 
34
    int res = 1;
-
 
35
    while (b-- > 0) res *= a;
-
 
36
    return res;
-
 
37
}
31
 
38
 
32
/* ##########################################################################
39
/* ##########################################################################
33
 * MAX7456 SPI & Display stuff
40
 * MAX7456 SPI & Display stuff
34
 * ##########################################################################*/
41
 * ##########################################################################*/
35
 
42
 
36
/**
43
/**
37
 * Send a byte through SPI
44
 * Send a byte through SPI
38
 * inline because it increases the codesize currenlty 'only' by 110byte but saves
45
 * 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
46
 * 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 :)
47
 * (address and data byte), a significant speed-bost we do not want to miss :)
41
 */
48
 */
42
inline void spi_send(uint8_t byte) {
49
inline void spi_send(uint8_t byte) {
43
    for (int8_t i = 7; i >= 0; i--) {
50
    for (int8_t i = 7; i >= 0; i--) {
44
        if (((byte >> i) & 1)) {
51
        if (((byte >> i) & 1)) {
45
            MAX_SDIN_HIGH
52
            MAX_SDIN_HIGH
46
        } else {
53
        } else {
47
            MAX_SDIN_LOW
54
            MAX_SDIN_LOW
48
        }
55
        }
49
        MAX_SCLK_HIGH
56
        MAX_SCLK_HIGH
50
        MAX_SCLK_LOW
57
        MAX_SCLK_LOW
51
    }
58
    }
52
}
59
}
53
 
60
 
54
/**
61
/**
55
 *  Send <byte> to <address> of MAX7456
62
 *  Send <byte> to <address> of MAX7456
56
 */
63
 */
57
void spi_send_byte(uint8_t address, uint8_t byte) {
64
void spi_send_byte(uint8_t address, uint8_t byte) {
58
    // start sending
65
    // start sending
59
    MAX_CS_LOW
66
    MAX_CS_LOW
60
 
67
 
61
    spi_send(address);
68
    spi_send(address);
62
    spi_send(byte);
69
    spi_send(byte);
63
 
70
 
64
    // end sending
71
    // end sending
65
    MAX_CS_HIGH
72
    MAX_CS_HIGH
66
}
73
}
67
 
74
 
68
/**
75
/**
69
 *  write a <character> to <address> of MAX7456 display memory
76
 *  write a <character> to <address> of MAX7456 display memory
70
 */
77
 */
71
void write_char(uint16_t address, char character) {
78
void write_char(uint16_t address, char character) {
72
    spi_send_byte(0x05, (address & 0xFF00) >> 8); // DMAH
79
    spi_send_byte(0x05, (address & 0xFF00) >> 8); // DMAH
73
    spi_send_byte(0x06, (address & 0x00FF)); // DMAL
80
    spi_send_byte(0x06, (address & 0x00FF)); // DMAL
74
    spi_send_byte(0x07, character); // DMDI
81
    spi_send_byte(0x07, character); // DMDI
75
}
82
}
76
 
83
 
77
/**
84
/**
78
 *  clear display memory
85
 *  clear display memory
79
 *  (also sets 8bit mode)
86
 *  (also sets 8bit mode)
80
 */
87
 */
81
void clear(void) {
88
void clear(void) {
82
    /*uint16_t memory_address = 0;
89
    /*uint16_t memory_address = 0;
83
    for (unsigned int a = 0; a < 480; a++) {
90
    for (unsigned int a = 0; a < 480; a++) {
84
        write_char(memory_address++, 0);
91
        write_char(memory_address++, 0);
85
    }*/
92
    }*/
86
    // clear all display-mem (DMM)
93
    // clear all display-mem (DMM)
87
    spi_send_byte(0x04, 0b01000100);
94
    spi_send_byte(0x04, 0b01000100);
88
 
95
 
89
    // clearing takes 12uS according to maxim so lets wait longer
96
    // clearing takes 12uS according to maxim so lets wait longer
90
    _delay_us(20);
97
    _delay_us(20);
91
}
98
}
92
 
99
 
93
 
100
 
94
#if (ALLCHARSDEBUG|(WRITECHARS != -1))
101
#if (ALLCHARSDEBUG|(WRITECHARS != -1))
95
 
102
 
96
/**
103
/**
97
 * for testing write all chars to screen
104
 * for testing write all chars to screen
98
 */
105
 */
99
void write_all_chars() {
106
void write_all_chars() {
100
    uint16_t x = 3, y = 2, t = 0;
107
    uint16_t x = 3, y = 2, t = 0;
101
    while (t < 256) {
108
    while (t < 256) {
102
        write_char(x++ + y * 30, t++);
109
        write_char(x++ + y * 30, t++);
103
        if (x > 25) {
110
        if (x > 25) {
104
            y++;
111
            y++;
105
            x = 3;
112
            x = 3;
106
        }
113
        }
107
    }
114
    }
108
}
115
}
109
 
116
 
110
/**
117
/**
111
 * let the MAX7456 learn a new character at <number>
118
 * let the MAX7456 learn a new character at <number>
112
 * with <data>.
119
 * with <data>.
113
 */
120
 */
114
void learn_char(uint8_t number, unsigned char* data) {
121
void learn_char(uint8_t number, unsigned char* data) {
115
    // select character to write (CMAH)
122
    // select character to write (CMAH)
116
    spi_send_byte(0x09, number);
123
    spi_send_byte(0x09, number);
117
 
124
 
118
    for (uint8_t i = 0; i < 54; i++) {
125
    for (uint8_t i = 0; i < 54; i++) {
119
        // select 4pixel byte of char (CMAL)
126
        // select 4pixel byte of char (CMAL)
120
        spi_send_byte(0x0A, i);
127
        spi_send_byte(0x0A, i);
121
 
128
 
122
        // write 4pixel byte of char (CMDI)
129
        // write 4pixel byte of char (CMDI)
123
        spi_send_byte(0x0B, data[i]);
130
        spi_send_byte(0x0B, data[i]);
124
    }
131
    }
125
 
132
 
126
    // write to the NVM array from the shadow RAM (CMM)
133
    // write to the NVM array from the shadow RAM (CMM)
127
    spi_send_byte(0x08, 0b10100000);
134
    spi_send_byte(0x08, 0b10100000);
128
 
135
 
129
    // according to maxim writing to nvram takes about 12ms, lets wait longer
136
    // according to maxim writing to nvram takes about 12ms, lets wait longer
130
    _delay_ms(120);
137
    _delay_ms(120);
131
}
138
}
132
#endif
139
#endif
133
 
140
 
134
#if !(ALLCHARSDEBUG|(WRITECHARS != -1))
141
#if !(ALLCHARSDEBUG|(WRITECHARS != -1))
135
 
142
 
136
/**
143
/**
137
 *  write a character <attribute> to <address> of MAX7456 display memory
144
 *  write a character <attribute> to <address> of MAX7456 display memory
138
 */
145
 */
139
void write_char_att(uint16_t address, char attribute) {
146
void write_char_att(uint16_t address, char attribute) {
140
    // the only important part is that the DMAH[1] is set
147
    // the only important part is that the DMAH[1] is set
141
    // so we add 2 which binary is the 2nd lowest byte
148
    // so we add 2 which binary is the 2nd lowest byte
142
    spi_send_byte(0x05, ((address & 0xFF00) >> 8) | 2); // DMAH
149
    spi_send_byte(0x05, ((address & 0xFF00) >> 8) | 2); // DMAH
143
    spi_send_byte(0x06, (address & 0x00FF)); // DMAL
150
    spi_send_byte(0x06, (address & 0x00FF)); // DMAL
144
    spi_send_byte(0x07, attribute); // DMDI
151
    spi_send_byte(0x07, attribute); // DMDI
145
}
152
}
146
 
153
 
147
/**
154
/**
148
 *  write a <character> at <x>/<y> to MAX7456 display memory
155
 *  write a <character> at <x>/<y> to MAX7456 display memory
149
 */
156
 */
150
void write_char_xy(uint8_t x, uint8_t y, char character) {
157
void write_char_xy(uint8_t x, uint8_t y, char character) {
151
    uint16_t address = y * 30 + x;
158
    uint16_t address = y * 30 + x;
152
    write_char(address, character);
159
    write_char(address, character);
153
}
160
}
154
 
161
 
155
/**
162
/**
156
 *  write a  character <attribute> at <x>/<y> to MAX7456 display memory
163
 *  write a  character <attribute> at <x>/<y> to MAX7456 display memory
157
 */
164
 */
158
void write_char_att_xy(uint8_t x, uint8_t y, char attribute) {
165
void write_char_att_xy(uint8_t x, uint8_t y, char attribute) {
159
    uint16_t address = y * 30 + x;
166
    uint16_t address = y * 30 + x;
160
    write_char_att(address, attribute);
167
    write_char_att(address, attribute);
161
}
168
}
162
 
169
 
163
/**
170
/**
164
 *  write an ascii <character> to <address> of MAX7456 display memory
171
 *  write an ascii <character> to <address> of MAX7456 display memory
165
 */
172
 */
166
void write_ascii_char(uint16_t address, char c) {
173
void write_ascii_char(uint16_t address, char c) {
167
    if (c == 32) c = 0; // remap space
174
    if (c == 32) c = 0; // remap space
168
    else if (c > 48 && c <= 57) c -= 48; // remap numbers
175
    else if (c > 48 && c <= 57) c -= 48; // remap numbers
169
    else if (c == '0') c = 10; // remap zero
176
    else if (c == '0') c = 10; // remap zero
170
    else if (c >= 65 && c <= 90) c -= 54; // remap big letters
177
    else if (c >= 65 && c <= 90) c -= 54; // remap big letters
171
    else if (c >= 97 && c <= 122) c -= 60; // remap small letters
178
    else if (c >= 97 && c <= 122) c -= 60; // remap small letters
172
    else if (c == '(') c = 63; // remap
179
    else if (c == '(') c = 63; // remap
173
    else if (c == ')') c = 64; // remap
180
    else if (c == ')') c = 64; // remap
174
    else if (c == '.') c = 65; // remap
181
    else if (c == '.') c = 65; // remap
175
    else if (c == '-') c = 73; // remap minus
182
    else if (c == '-') c = 73; // remap minus
176
    else if (c == ';') c = 67; // remap
183
    else if (c == ';') c = 67; // remap
177
    else if (c == ':') c = 68; // remap
184
    else if (c == ':') c = 68; // remap
178
    else if (c == ',') c = 69; // remap
185
    else if (c == ',') c = 69; // remap
179
        //    else if (c == '?') c = 66; // remap
186
        //    else if (c == '?') c = 66; // remap
180
        //    else if (c == '\'') c = 70; // remap
187
        //    else if (c == '\'') c = 70; // remap
181
    else if (c == '/') c = 71; // remap
188
    else if (c == '/') c = 71; // remap
182
    //    else if (c == '"') c = 72; // remap
189
    //    else if (c == '"') c = 72; // remap
183
    //    else if (c == '<') c = 74; // remap
190
    //    else if (c == '<') c = 74; // remap
184
    //    else if (c == '>') c = 75; // remap
191
    //    else if (c == '>') c = 75; // remap
185
    //    else if (c == '@') c = 76; // remap
192
    //    else if (c == '@') c = 76; // remap
186
    write_char(address, c);
193
    write_char(address, c);
187
}
194
}
188
 
195
 
189
/**
196
/**
190
 *  write an ascii <string> at <x>/<y> to MAX7456 display memory
197
 *  write an ascii <string> at <x>/<y> to MAX7456 display memory
191
 */
198
 */
192
void write_ascii_string(uint8_t x, uint8_t y, char *string) {
199
void write_ascii_string(uint8_t x, uint8_t y, char *string) {
193
    while (*string) {
200
    while (*string) {
194
        write_ascii_char(((x++)+(y * 30)), *string);
201
        write_ascii_char(((x++)+(y * 30)), *string);
195
        string++;
202
        string++;
196
    }
203
    }
197
}
204
}
198
 
205
 
199
/**
206
/**
200
 *  write an ascii <string> with lenght <len> at <x>/<y> to MAX7456 display memory
207
 *  write an ascii <string> with lenght <len> at <x>/<y> to MAX7456 display memory
201
 */
208
 */
202
void write_ascii_string_len(uint8_t x, uint8_t y, char *string, uint8_t len) {
209
void write_ascii_string_len(uint8_t x, uint8_t y, char *string, uint8_t len) {
203
    while (len--) {
210
    while (len--) {
204
        write_ascii_char(((x++)+(y * 30)), *string);
211
        write_ascii_char(((x++)+(y * 30)), *string);
205
        string++;
212
        string++;
206
    }
213
    }
207
}
214
}
208
 
215
 
209
/**
216
/**
210
 *  write an ascii <string> from progmen at <x>/<y> to MAX7456 display memory
217
 *  write an ascii <string> from progmen at <x>/<y> to MAX7456 display memory
211
 */
218
 */
212
void write_ascii_string_pgm(uint8_t x, uint8_t y, const char *string) {
219
void write_ascii_string_pgm(uint8_t x, uint8_t y, const char *string) {
213
    while (pgm_read_byte(string) != 0x00)
220
    while (pgm_read_byte(string) != 0x00)
214
        write_ascii_char(((x++)+(y * 30)), pgm_read_byte(string++));
221
        write_ascii_char(((x++)+(y * 30)), pgm_read_byte(string++));
215
}
222
}
216
 
223
 
217
/**
224
/**
218
 *  write an <string> from progmen at <x>/<y> downwards to MAX7456 display memory
225
 *  write an <string> from progmen at <x>/<y> downwards to MAX7456 display memory
219
 */
226
 */
220
void write_string_pgm_down(uint8_t x, uint8_t y, const char *string, uint8_t length) {
227
void write_string_pgm_down(uint8_t x, uint8_t y, const char *string, uint8_t length) {
221
    while (length--)
228
    while (length--)
222
        write_char((x + (y++ * 30)), pgm_read_byte(string++));
229
        write_char((x + (y++ * 30)), pgm_read_byte(string++));
223
}
230
}
224
 
231
 
225
/**
232
/**
226
 * Write a unsigned <number> at <x>/<y> to MAX7456 display memory
233
 * Write a unsigned <number> at <x>/<y> to MAX7456 display memory
227
 * <length> represents the length to rightbound the number
234
 * <length> represents the length to rightbound the number
228
 * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of   7
235
 * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of   7
229
 */
236
 */
230
void write_ndigit_number_u(uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad) {
237
void write_ndigit_number_u(uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad) {
-
 
238
    if (number >= pow(10, length)) {
-
 
239
        number = pow(10, length) - 1;
-
 
240
    }
231
    itoa(number, conv_array, 10);
241
    itoa(number, conv_array, 10);
232
    for (uint8_t i = 0; i < length - strlen(conv_array); i++) {
242
    for (uint8_t i = 0; i < length - strlen(conv_array); i++) {
233
        if (pad) write_char((x++)+(y * 30), 10);
243
        if (pad) write_char((x++)+(y * 30), 10);
234
        else write_ascii_char((x++)+(y * 30), 0);
244
        else write_ascii_char((x++)+(y * 30), 0);
235
    }
245
    }
236
    write_ascii_string(x, y, conv_array);
246
    write_ascii_string(x, y, conv_array);
237
}
247
}
238
 
248
 
239
/**
249
/**
240
 * Write a signed <number> at <x>/<y> to MAX7456 display memory
250
 * Write a signed <number> at <x>/<y> to MAX7456 display memory
241
 * <length> represents the length to rightbound the number
251
 * <length> represents the length to rightbound the number
242
 * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of   7
252
 * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of   7
243
 */
253
 */
244
void write_ndigit_number_s(uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad) {
254
void write_ndigit_number_s(uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad) {
-
 
255
    if (number <= -pow(10, length)) {
-
 
256
        number = -pow(10, length) + 1;
-
 
257
    } else if (number >= pow(10, length)) {
-
 
258
        number = pow(10, length) - 1;
-
 
259
    }
-
 
260
 
245
    itoa(number, conv_array, 10);
261
    itoa(number, conv_array, 10);
-
 
262
    if (strlen(conv_array) < length) {
246
    for (uint8_t i = 0; i < length - strlen(conv_array); i++) {
263
        for (uint8_t i = 0; i < length - strlen(conv_array); i++) {
247
        if (pad) write_char((x++)+(y * 30), 10);
264
            if (pad) write_char((x++)+(y * 30), 10);
248
        else write_ascii_char((x++)+(y * 30), 0);
265
            else write_ascii_char((x++)+(y * 30), 0);
-
 
266
        }
249
    }
267
    }
250
    write_ascii_string(x, y, conv_array);
268
    write_ascii_string(x, y, conv_array);
251
}
269
}
252
 
270
 
253
/**
271
/**
254
 * Write a unsigned <number> at <x>/<y> to MAX7456 display memory as /10th of value
272
 * Write a unsigned <number> at <x>/<y> to MAX7456 display memory as /10th of value
255
 * <length> represents the length to rightbound the number
273
 * <length> represents the length to rightbound the number
256
 * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of   7
274
 * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of   7
257
 */
275
 */
258
void write_ndigit_number_u_10th(uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad) {
276
void write_ndigit_number_u_10th(uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad) {
-
 
277
    if (number >= pow(10, length)) {
-
 
278
        number = pow(10, length) - 1;
-
 
279
    }
259
    itoa(number, conv_array, 10);
280
    itoa(number, conv_array, 10);
260
    uint8_t len = strlen(conv_array);
281
    uint8_t len = strlen(conv_array);
261
    for (uint8_t i = 0; i < length - len; i++) {
282
    for (uint8_t i = 0; i < length - len; i++) {
262
        if (pad) write_char((x++)+(y * 30), 10); //  zero
283
        if (pad) write_char((x++)+(y * 30), 10); //  zero
263
        else write_char((x++)+(y * 30), 0); // blank
284
        else write_char((x++)+(y * 30), 0); // blank
264
    }
285
    }
265
    char rest = conv_array[len - 1];
286
    char rest = conv_array[len - 1];
266
    conv_array[len - 1] = 0;
287
    conv_array[len - 1] = 0;
267
    if (len == 1) {
288
    if (len == 1) {
268
        write_char((x - 1)+(y * 30), 10); // zero
289
        write_char((x - 1)+(y * 30), 10); // zero
269
    } else if (len == 2 && conv_array[0] == '-') {
290
    } else if (len == 2 && conv_array[0] == '-') {
270
        write_char((x - 1)+(y * 30), 0x49); // minus
291
        write_char((x - 1)+(y * 30), 0x49); // minus
271
        write_char((x)+(y * 30), 10); // zero
292
        write_char((x)+(y * 30), 10); // zero
272
    } else {
293
    } else {
273
        write_ascii_string(x, y, conv_array);
294
        write_ascii_string(x, y, conv_array);
274
    }
295
    }
275
    x += len - 1;
296
    x += len - 1;
276
    write_char((x++)+(y * 30), 65); // decimal point
297
    write_char((x++)+(y * 30), 65); // decimal point
277
    write_ascii_char((x++)+(y * 30), rest); // after dot
298
    write_ascii_char((x++)+(y * 30), rest); // after dot
278
}
299
}
279
 
300
 
280
/**
301
/**
281
 * Write a signed <number> at <x>/<y> to MAX7456 display memory as /10th of value
302
 * Write a signed <number> at <x>/<y> to MAX7456 display memory as /10th of value
282
 * <length> represents the length to rightbound the number
303
 * <length> represents the length to rightbound the number
283
 * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of   7
304
 * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of   7
284
 */
305
 */
285
void write_ndigit_number_s_10th(uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad) {
306
void write_ndigit_number_s_10th(uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad) {
-
 
307
    if (number >= pow(10, length)) {
-
 
308
        number = pow(10, length) - 1;
-
 
309
    }
286
    itoa(number, conv_array, 10);
310
    itoa(number, conv_array, 10);
287
    uint8_t len = strlen(conv_array);
311
    uint8_t len = strlen(conv_array);
288
    for (uint8_t i = 0; i < length - len; i++) {
312
    for (uint8_t i = 0; i < length - len; i++) {
289
        if (pad) write_char((x++)+(y * 30), 10); //  zero
313
        if (pad) write_char((x++)+(y * 30), 10); //  zero
290
        else write_char((x++)+(y * 30), 0); // blank
314
        else write_char((x++)+(y * 30), 0); // blank
291
    }
315
    }
292
    char rest = conv_array[len - 1];
316
    char rest = conv_array[len - 1];
293
    conv_array[len - 1] = 0;
317
    conv_array[len - 1] = 0;
294
    if (len == 1) {
318
    if (len == 1) {
295
        write_char((x - 1)+(y * 30), 10); // zero
319
        write_char((x - 1)+(y * 30), 10); // zero
296
    } else if (len == 2 && conv_array[0] == '-') {
320
    } else if (len == 2 && conv_array[0] == '-') {
297
        write_char((x - 1)+(y * 30), 0x49); // minus
321
        write_char((x - 1)+(y * 30), 0x49); // minus
298
        write_char((x)+(y * 30), 10); // zero
322
        write_char((x)+(y * 30), 10); // zero
299
    } else {
323
    } else {
300
        write_ascii_string(x, y, conv_array);
324
        write_ascii_string(x, y, conv_array);
301
    }
325
    }
302
    x += len - 1;
326
    x += len - 1;
303
    write_char((x++)+(y * 30), 65); // decimal point
327
    write_char((x++)+(y * 30), 65); // decimal point
304
    write_ascii_char((x++)+(y * 30), rest); // after dot
328
    write_ascii_char((x++)+(y * 30), rest); // after dot
305
}
329
}
306
 
330
 
307
/**
331
/**
308
 *  write <seconds> as human readable time at <x>/<y> to MAX7456 display mem
332
 *  write <seconds> as human readable time at <x>/<y> to MAX7456 display mem
309
 */
333
 */
310
void write_time(uint8_t x, uint8_t y, uint16_t seconds) {
334
void write_time(uint8_t x, uint8_t y, uint16_t seconds) {
311
    uint16_t min = seconds / 60;
335
    uint16_t min = seconds / 60;
312
    seconds -= min * 60;
336
    seconds -= min * 60;
313
    write_ndigit_number_u(x, y, min, 3, 0);
337
    write_ndigit_number_u(x, y, min, 3, 0);
314
    write_char_xy(x + 3, y, 68);
338
    write_char_xy(x + 3, y, 68);
315
    write_ndigit_number_u(x + 4, y, seconds, 2, 1);
339
    write_ndigit_number_u(x + 4, y, seconds, 2, 1);
316
}
340
}
317
 
341
 
318
/**
342
/**
319
 * wirte a <position> at <x>/<y> assuming it is a gps position for long-/latitude
343
 * wirte a <position> at <x>/<y> assuming it is a gps position for long-/latitude
320
 */
344
 */
321
void write_gps_pos(uint8_t x, uint8_t y, int32_t position) {
345
void write_gps_pos(uint8_t x, uint8_t y, int32_t position) {
322
    if (position < 0) {
346
    if (position < 0) {
323
        position ^= ~0;
347
        position ^= ~0;
324
        position++;
348
        position++;
325
        write_char_xy(x++, y, 0x49); // minus
349
        write_char_xy(x++, y, 0x49); // minus
326
    } else {
350
    } else {
327
        write_char_xy(x++, y, 0); // clear ('+' would be nice, maybe later)
351
        write_char_xy(x++, y, 0); // clear ('+' would be nice, maybe later)
328
    }
352
    }
329
    write_ndigit_number_u(x, y, (uint16_t)(position / (int32_t)10000000), 3, 1);
353
    write_ndigit_number_u(x, y, (uint16_t)(position / (int32_t)10000000), 3, 1);
330
    write_char_xy(x + 3, y, 65); // decimal point
354
    write_char_xy(x + 3, y, 65); // decimal point
331
    position = position - ((position / (int32_t)10000000) * (int32_t)10000000);
355
    position = position - ((position / (int32_t)10000000) * (int32_t)10000000);
332
    write_ndigit_number_u(x + 4, y, (uint16_t)(position / (int32_t)1000), 4, 1);
356
    write_ndigit_number_u(x + 4, y, (uint16_t)(position / (int32_t)1000), 4, 1);
333
    position = position - ((uint16_t)(position / (int32_t)1000) * (int32_t)1000);
357
    position = position - ((uint16_t)(position / (int32_t)1000) * (int32_t)1000);
334
    write_ndigit_number_u(x + 8, y, (uint16_t)position, 3, 1);
358
    write_ndigit_number_u(x + 8, y, (uint16_t)position, 3, 1);
335
    write_char_xy(x + 11, y, 0xD0); // degree symbol
359
    write_char_xy(x + 11, y, 0xD0); // degree symbol
336
}
360
}
337
 
361
 
338
#endif
362
#endif
339
 
363