Subversion Repositories Projects

Rev

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

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