Rev 346 | Rev 379 | Go to most recent revision | Show entire file | Regard 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 | */ |
154 | void write_3digit_number_u(uint8_t x, uint8_t y, uint16_t number) { |
- | |
155 | uint16_t num = 100; |
- | |
156 | uint8_t started = 0; |
- | |
157 | - | ||
158 | while (num > 0) { |
- | |
159 | uint8_t b = number / num; |
- | |
160 | if (b > 0 || started || num == 1) { |
155 | void write_ndigit_number_u(uint8_t x, uint8_t y, uint16_t number, int16_t num, uint8_t pad) { |
161 | write_ascii_char((x++)+(y * 30), '0' + b); |
- | |
162 | started = 1; |
- | |
163 | } else { |
- | |
164 | write_ascii_char((x++)+(y * 30), 0); |
- | |
165 | } |
156 | // if number is largar than 99[..]9 we must decrease it |
166 | number -= b * num; |
- | |
167 | 157 | while (number >= (num * 10)) { |
|
168 | num /= 10; |
- | |
169 | } |
158 | number -= num * 10; |
Line 170... | Line -... | ||
170 | } |
- | |
171 | - | ||
172 | /** |
- | |
173 | * Write only the last two digits of a number at <x>/<y> to MAX7456 |
- | |
174 | * display memory. takes full 16bit numbers as well for stuff |
- | |
175 | * like seconds only taking two characters (values <= 99) |
- | |
176 | * Since this is used for seconds only and it looks better, there |
- | |
177 | * is a trading 0 attached |
- | |
178 | */ |
- | |
179 | void write_2digit_number_u(uint8_t x, uint8_t y, uint16_t number) { |
159 | } |
Line 180... | Line 160... | ||
180 | uint16_t num = 10; |
160 | |
181 | uint8_t started = 0; |
161 | uint8_t started = 0; |
182 | 162 | ||
183 | while (num > 0) { |
163 | while (num > 0) { |
184 | uint8_t b = number / num; |
164 | uint8_t b = number / num; |
185 | if (b > 0 || started || num == 1) { |
165 | if (b > 0 || started || num == 1) { |
186 | write_ascii_char((x++)+(y * 30), '0' + b); |
166 | write_ascii_char((x++)+(y * 30), '0' + b); |
- | 167 | started = 1; |
|
187 | started = 1; |
168 | } else { |
188 | } else { |
169 | if (pad) write_ascii_char((x++)+(y * 30), '0'); |
Line 189... | Line 170... | ||
189 | write_ascii_char((x++)+(y * 30), '0'); |
170 | else write_ascii_char((x++)+(y * 30), 0); |
190 | } |
171 | } |
191 | number -= b * num; |
172 | number -= b * num; |
Line 192... | Line 173... | ||
192 | 173 | ||
193 | num /= 10; |
174 | num /= 10; |
- | 175 | } |
|
- | 176 | } |
|
- | 177 | ||
194 | } |
178 | /** |
195 | } |
179 | * Write only some digits of a signed <number> at <x>/<y> to MAX7456 display memory |
- | 180 | * <num> represents the largest multiple of 10 that will still be displayable as |
|
- | 181 | * the first digit, so num = 10 will be 0-99 and so on |
|
- | 182 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
|
- | 183 | */ |
|
- | 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) { |
|
196 | 186 | number = number - 65536; |
|
- | 187 | num *= -1; |
|
- | 188 | ||
197 | /** |
189 | // if number is smaller than -99[..]9 we must increase it |
Line 198... | Line 190... | ||
198 | * write a unsigned number as /10th at <x>/<y> to MAX7456 display memory |
190 | while (number <= (num * 10)) { |
199 | */ |
191 | number -= num * 10; |
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); |
Line 209... | Line 201... | ||
209 | write_ascii_char((x++)+(y * 30), '0' + b); |
201 | write_ascii_char((x++)+(y * 30), '0' + b); |
210 | started = 1; |
202 | started = 1; |
- | 203 | } else { |
|
- | 204 | write_ascii_char((x++)+(y * 30), 0); |
|
- | 205 | } |
|
- | 206 | number -= b * num; |
|
211 | } else { |
207 | |
Line 212... | Line 208... | ||
212 | write_ascii_char((x++)+(y * 30), 0); |
208 | num /= 10; |
213 | } |
209 | } |
- | 210 | } else { |
|
- | 211 | write_char((x)+(y * 30), 0); |
|
- | 212 | write_ndigit_number_u(x, y, number, num, pad); |
|
- | 213 | } |
|
214 | number -= b * num; |
214 | } |
215 | 215 | ||
- | 216 | /** |
|
216 | num /= 10; |
217 | * Write only some digits of a unsigned <number> at <x>/<y> to MAX7456 display memory |
217 | } |
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 |
|
Line -... | Line 221... | ||
- | 221 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
|
218 | } |
222 | */ |
219 | 223 | void write_ndigit_number_u_10th(uint8_t x, uint8_t y, uint16_t number, int16_t num, uint8_t pad) { |
|
220 | /** |
224 | // if number is largar than 99[..]9 we must decrease it |
- | 225 | while (number >= (num * 10)) { |
|
- | 226 | number -= num * 10; |
|
- | 227 | } |
|
- | 228 | ||
221 | * write a unsigned number at <x>/<y> to MAX7456 display memory |
229 | |
222 | */ |
230 | uint8_t started = 0; |
223 | void write_number_u(uint8_t x, uint8_t y, uint16_t number) { |
231 | while (num > 0) { |
224 | uint16_t num = 10000; |
232 | uint8_t b = number / num; |
- | 233 | if (b > 0 || started || num == 1) { |
|
225 | uint8_t started = 0; |
234 | if ((num / 10) == 0) { |
226 | 235 | if (!started) write_ascii_char((x - 1)+(y * 30), '0'); |
|
Line 227... | Line 236... | ||
227 | while (num > 0) { |
236 | write_char((x++)+(y * 30), 65); // decimal point |
228 | uint8_t b = number / num; |
237 | } |
229 | if (b > 0 || started || num == 1) { |
238 | write_ascii_char((x++)+(y * 30), '0' + b); |
Line 230... | Line 239... | ||
230 | write_ascii_char((x++)+(y * 30), '0' + b); |
239 | started = 1; |
231 | 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; |
|
232 | } else { |
245 | |
233 | write_ascii_char((x++)+(y * 30), 0); |
246 | num /= 10; |
234 | } |
247 | } |
235 | number -= b * num; |
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 |
|
- | 253 | * <num> represents the largest multiple of 10 that will still be displayable as |
|
- | 254 | * the first digit, so num = 10 will be 0-99 and so on |
|
Line 236... | Line -... | ||
236 | - | ||
237 | num /= 10; |
255 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
Line 238... | Line 256... | ||
238 | } |
256 | */ |
239 | } |
257 | void write_ndigit_number_s_10th(uint8_t x, uint8_t y, int16_t number, int16_t num, uint8_t pad) { |
- | 258 | if (((uint16_t) number) > 32767) { |
|
240 | 259 | number = number - 65536; |
|
- | 260 | num *= -1; |
|
- | 261 | ||
- | 262 | // if number is smaller than -99[..]9 we must increase it |
|
241 | /** |
263 | while (number <= (num * 10)) { |
- | 264 | number -= num * 10; |
|
- | 265 | } |
|
- | 266 | ||
- | 267 | uint8_t started = 0; |
|
- | 268 | ||
242 | * write a signed number at <x>/<y> to MAX7456 display memory |
269 | while (num < 0) { |
243 | */ |
270 | uint8_t b = number / num; |
244 | void write_number_s(uint8_t x, uint8_t y, int16_t w) { |
271 | if (pad) write_ascii_char((x)+(y * 30), '0'); |
245 | if (((uint16_t) w) > 32767) { |
272 | if (b > 0 || started || num == 1) { |
246 | w = w - 65536; |
273 | if ((num / 10) == 0) { |
247 | 274 | if (!started) { |
|
Line 248... | Line 275... | ||
248 | int16_t num = -10000; |
275 | write_ascii_char((x - 2)+(y * 30), '-'); |
249 | uint8_t started = 0; |
276 | write_ascii_char((x - 1)+(y * 30), '0'); |
250 | 277 | } |
|
251 | while (num < 0) { |
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 | } |
Line 255... | Line 282... | ||
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 { |
Line 265... | Line 292... | ||
265 | write_char((x)+(y * 30), 0); |
292 | write_char((x)+(y * 30), 0); |
266 | write_number_u(x, y, w); |
293 | write_ndigit_number_u_10th(x, y, number, num, pad); |
267 | } |
294 | } |