Subversion Repositories Projects

Rev

Rev 346 | Rev 379 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 346 Rev 349
Line 145... Line 145...
145
        while (pgm_read_byte(string) != 0x00)
145
        while (pgm_read_byte(string) != 0x00)
146
                write_ascii_char(((x++)+(y * 30)), pgm_read_byte(string++));
146
                write_ascii_char(((x++)+(y * 30)), pgm_read_byte(string++));
147
}
147
}
Line 148... Line 148...
148
 
148
 
149
/**
149
/**
150
 *  Write only the last three digits of a <number> at <x>/<y> to MAX7456
150
 * Write only some digits of a unsigned <number> at <x>/<y> to MAX7456 display memory
151
 *  display memory. takes full 16bit numbers as well for stuff
151
 * <num> represents the largest multiple of 10 that will still be displayable as
-
 
152
 * the first digit, so num = 10 will be 0-99 and so on
152
 *  like compass only taking three characters (values <= 999)
153
 * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of   7
153
 */
154
 */
-
 
155
void write_ndigit_number_u(uint8_t x, uint8_t y, uint16_t number, int16_t num, uint8_t pad) {
-
 
156
                // if number is largar than 99[..]9 we must decrease it
154
void write_3digit_number_u(uint8_t x, uint8_t y, uint16_t number) {
157
                while (number >= (num * 10)) {
-
 
158
                        number -= num * 10;
-
 
159
                }
155
    uint16_t num = 100;
160
 
156
    uint8_t started = 0;
161
                uint8_t started = 0;
157
 
162
 
158
    while (num > 0) {
163
                while (num > 0) {
159
        uint8_t b = number / num;
164
                        uint8_t b = number / num;
160
        if (b > 0 || started || num == 1) {
165
                        if (b > 0 || started || num == 1) {
161
            write_ascii_char((x++)+(y * 30), '0' + b);
166
                            write_ascii_char((x++)+(y * 30), '0' + b);
162
            started = 1;
167
                            started = 1;
-
 
168
                        } else {
163
        } else {
169
                                if (pad) write_ascii_char((x++)+(y * 30), '0');
164
            write_ascii_char((x++)+(y * 30), 0);
170
                                else write_ascii_char((x++)+(y * 30), 0);
165
        }
171
                        }
166
        number -= b * num;
172
                        number -= b * num;
167
 
173
 
168
        num /= 10;
174
                        num /= 10;
169
    }
175
                }
Line 170... Line 176...
170
}
176
}
171
 
177
 
172
/**
178
/**
173
 *  Write only the last two digits of a number at <x>/<y> to MAX7456
179
 * Write only some digits of a signed <number> at <x>/<y> to MAX7456 display memory
174
 *  display memory. takes full 16bit numbers as well for stuff
180
 * <num> represents the largest multiple of 10 that will still be displayable as
175
 *  like seconds only taking two characters (values <= 99)
-
 
176
 *  Since this is used for seconds only and it looks better, there
181
 * the first digit, so num = 10 will be 0-99 and so on
177
 *  is a trading 0 attached
182
 * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of   7
178
 */
183
 */
179
void write_2digit_number_u(uint8_t x, uint8_t y, uint16_t number) {
184
void write_ndigit_number_s(uint8_t x, uint8_t y, int16_t number, int16_t num, uint8_t pad) {
-
 
185
    if (((uint16_t) number) > 32767) {
180
    uint16_t num = 10;
186
        number = number - 65536;
181
    uint8_t started = 0;
-
 
182
 
-
 
183
    while (num > 0) {
-
 
184
        uint8_t b = number / num;
187
                num *= -1;
185
        if (b > 0 || started || num == 1) {
-
 
186
            write_ascii_char((x++)+(y * 30), '0' + b);
-
 
187
            started = 1;
-
 
188
        } else {
-
 
189
            write_ascii_char((x++)+(y * 30), '0');
188
 
190
        }
-
 
191
        number -= b * num;
189
                // if number is smaller than -99[..]9 we must increase it
192
 
-
 
193
        num /= 10;
190
                while (number <= (num * 10)) {
194
    }
191
                        number -= num * 10;
195
}
-
 
196
 
-
 
197
/**
-
 
198
 *  write a unsigned number as /10th at <x>/<y> to MAX7456 display memory
-
 
199
 */
-
 
200
void write_number_u_10th(uint8_t x, uint8_t y, uint16_t number) {
192
                }
201
    uint16_t num = 10000;
193
 
202
    uint8_t started = 0;
194
                uint8_t started = 0;
203
 
195
 
204
    while (num > 0) {
-
 
-
 
196
                while (num < 0) {
205
        uint8_t b = number / num;
197
                        uint8_t b = number / num;
206
 
198
                        if (pad) write_ascii_char((x)+(y * 30), '0');
207
        if (b > 0 || started || num == 1) {
199
                        if (b > 0 || started || num == 1) {
208
            if ((num / 10) == 0) write_char((x++)+(y * 30), 65);
200
                                if (!started) write_char((x - 1)+(y * 30), 0x49);
209
            write_ascii_char((x++)+(y * 30), '0' + b);
201
                            write_ascii_char((x++)+(y * 30), '0' + b);
210
            started = 1;
202
                            started = 1;
211
        } else {
203
                        } else {
212
            write_ascii_char((x++)+(y * 30), 0);
204
                                write_ascii_char((x++)+(y * 30), 0);
213
        }
205
                        }
214
        number -= b * num;
206
                        number -= b * num;
215
 
-
 
216
        num /= 10;
207
 
217
    }
-
 
218
}
-
 
219
 
-
 
220
/**
-
 
221
 *  write a unsigned number at <x>/<y> to MAX7456 display memory
-
 
222
 */
-
 
223
void write_number_u(uint8_t x, uint8_t y, uint16_t number) {
-
 
224
    uint16_t num = 10000;
-
 
225
    uint8_t started = 0;
-
 
226
 
-
 
227
    while (num > 0) {
-
 
228
        uint8_t b = number / num;
-
 
229
        if (b > 0 || started || num == 1) {
-
 
230
            write_ascii_char((x++)+(y * 30), '0' + b);
208
                        num /= 10;
231
            started = 1;
209
                }
232
        } else {
-
 
233
            write_ascii_char((x++)+(y * 30), 0);
210
        } else {
234
        }
-
 
235
        number -= b * num;
-
 
236
 
211
        write_char((x)+(y * 30), 0);
237
        num /= 10;
212
        write_ndigit_number_u(x, y, number, num, pad);
Line 238... Line 213...
238
    }
213
    }
-
 
214
}
-
 
215
 
-
 
216
/**
-
 
217
 * Write only some digits of a unsigned <number> at <x>/<y> to MAX7456 display memory
-
 
218
 * as /10th of the value
-
 
219
 * <num> represents the largest multiple of 10 that will still be displayable as
-
 
220
 * the first digit, so num = 10 will be 0-99 and so on
-
 
221
 * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of   7
-
 
222
 */
-
 
223
void write_ndigit_number_u_10th(uint8_t x, uint8_t y, uint16_t number, int16_t num, uint8_t pad) {
-
 
224
                // if number is largar than 99[..]9 we must decrease it
-
 
225
                while (number >= (num * 10)) {
-
 
226
                        number -= num * 10;
-
 
227
                }
-
 
228
               
-
 
229
 
-
 
230
                uint8_t started = 0;
-
 
231
                while (num > 0) {
-
 
232
                        uint8_t b = number / num;
-
 
233
                        if (b > 0 || started || num == 1) {
-
 
234
                                if ((num / 10) == 0) {
-
 
235
                                        if (!started) write_ascii_char((x - 1)+(y * 30), '0');
-
 
236
                                        write_char((x++)+(y * 30), 65); // decimal point
-
 
237
                                }
-
 
238
                                write_ascii_char((x++)+(y * 30), '0' + b);
-
 
239
                            started = 1;
-
 
240
                        } else {
-
 
241
                                if (pad) write_ascii_char((x++)+(y * 30), '0');
-
 
242
                                else write_ascii_char((x++)+(y * 30), ' ');
-
 
243
                        }
-
 
244
                        number -= b * num;
-
 
245
 
-
 
246
                        num /= 10;
-
 
247
                }
239
}
248
}
-
 
249
 
-
 
250
/**
-
 
251
 * Write only some digits of a signed <number> at <x>/<y> to MAX7456 display memory
-
 
252
 * as /10th of the value
240
 
253
 * <num> represents the largest multiple of 10 that will still be displayable as
241
/**
254
 * the first digit, so num = 10 will be 0-99 and so on
242
 *  write a signed number at <x>/<y> to MAX7456 display memory
255
 * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of   7
243
 */
256
 */
-
 
257
void write_ndigit_number_s_10th(uint8_t x, uint8_t y, int16_t number, int16_t num, uint8_t pad) {
244
void write_number_s(uint8_t x, uint8_t y, int16_t w) {
258
    if (((uint16_t) number) > 32767) {
-
 
259
        number = number - 65536;
245
    if (((uint16_t) w) > 32767) {
260
                num *= -1;
-
 
261
 
-
 
262
                // if number is smaller than -99[..]9 we must increase it
-
 
263
                while (number <= (num * 10)) {
246
        w = w - 65536;
264
                        number -= num * 10;
247
 
265
                }
248
        int16_t num = -10000;
266
 
249
        uint8_t started = 0;
267
                uint8_t started = 0;
-
 
268
 
250
 
269
                while (num < 0) {
-
 
270
                        uint8_t b = number / num;
-
 
271
                        if (pad) write_ascii_char((x)+(y * 30), '0');
-
 
272
                        if (b > 0 || started || num == 1) {
251
        while (num < 0) {
273
                                if ((num / 10) == 0) {
-
 
274
                                        if (!started) {
-
 
275
                                                write_ascii_char((x - 2)+(y * 30), '-');
-
 
276
                                                write_ascii_char((x - 1)+(y * 30), '0');
-
 
277
                                        }
-
 
278
                                        write_char((x++)+(y * 30), 65); // decimal point
252
            uint8_t b = w / num;
279
                                } else if (!started) {
253
            if (b > 0 || started || num == 1) {
280
                                        write_char((x - 1)+(y * 30), 0x49); // minus
254
                if (!started) write_char((x - 1)+(y * 30), 0x49);
281
                                }
255
                write_ascii_char((x++)+(y * 30), '0' + b);
282
                            write_ascii_char((x++)+(y * 30), '0' + b);
256
                started = 1;
283
                            started = 1;
257
            } else {
284
                        } else {
258
                write_ascii_char((x++)+(y * 30), 0);
285
                                write_ascii_char((x++)+(y * 30), 0);
259
            }
286
                        }
260
            w -= b * num;
287
                        number -= b * num;
261
 
288
 
262
            num /= 10;
289
                        num /= 10;
263
        }
290
                }
264
    } else {
291
        } else {
265
        write_char((x)+(y * 30), 0);
292
        write_char((x)+(y * 30), 0);
Line 266... Line 293...
266
        write_number_u(x, y, w);
293
        write_ndigit_number_u_10th(x, y, number, num, pad);
267
    }
294
    }
268
}
295
}
269
 
296
 
270
/**
297
/**
271
 *  write <seconds> as human readable time at <x>/<y> to MAX7456 display mem
298
 *  write <seconds> as human readable time at <x>/<y> to MAX7456 display mem
272
 */
299
 */
273
void write_time(uint8_t x, uint8_t y, uint16_t seconds) {
300
void write_time(uint8_t x, uint8_t y, uint16_t seconds) {
274
    uint16_t min = seconds / 60;
301
    uint16_t min = seconds / 60;
275
    seconds -= min * 60;
302
    seconds -= min * 60;
Line 276... Line 303...
276
    write_3digit_number_u(x, y, min);
303
    write_ndigit_number_u(x, y, min, 100, 0);
277
    write_char_xy(x + 3, y, 68);
304
    write_char_xy(x + 3, y, 68);
278
    write_2digit_number_u(x + 4, y, seconds);
305
    write_ndigit_number_u(x + 4, y, seconds, 10, 1);