147,123 → 147,150 |
} |
|
/** |
* Write only the last three digits of a <number> at <x>/<y> to MAX7456 |
* display memory. takes full 16bit numbers as well for stuff |
* like compass only taking three characters (values <= 999) |
* Write only some digits of a unsigned <number> at <x>/<y> to MAX7456 display memory |
* <num> represents the largest multiple of 10 that will still be displayable as |
* the first digit, so num = 10 will be 0-99 and so on |
* <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
*/ |
void write_3digit_number_u(uint8_t x, uint8_t y, uint16_t number) { |
uint16_t num = 100; |
uint8_t started = 0; |
void write_ndigit_number_u(uint8_t x, uint8_t y, uint16_t number, int16_t num, uint8_t pad) { |
// if number is largar than 99[..]9 we must decrease it |
while (number >= (num * 10)) { |
number -= num * 10; |
} |
|
while (num > 0) { |
uint8_t b = number / num; |
if (b > 0 || started || num == 1) { |
write_ascii_char((x++)+(y * 30), '0' + b); |
started = 1; |
} else { |
write_ascii_char((x++)+(y * 30), 0); |
} |
number -= b * num; |
uint8_t started = 0; |
|
num /= 10; |
} |
while (num > 0) { |
uint8_t b = number / num; |
if (b > 0 || started || num == 1) { |
write_ascii_char((x++)+(y * 30), '0' + b); |
started = 1; |
} else { |
if (pad) write_ascii_char((x++)+(y * 30), '0'); |
else write_ascii_char((x++)+(y * 30), 0); |
} |
number -= b * num; |
|
num /= 10; |
} |
} |
|
/** |
* Write only the last two digits of a number at <x>/<y> to MAX7456 |
* display memory. takes full 16bit numbers as well for stuff |
* like seconds only taking two characters (values <= 99) |
* Since this is used for seconds only and it looks better, there |
* is a trading 0 attached |
* Write only some digits of a signed <number> at <x>/<y> to MAX7456 display memory |
* <num> represents the largest multiple of 10 that will still be displayable as |
* the first digit, so num = 10 will be 0-99 and so on |
* <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
*/ |
void write_2digit_number_u(uint8_t x, uint8_t y, uint16_t number) { |
uint16_t num = 10; |
uint8_t started = 0; |
void write_ndigit_number_s(uint8_t x, uint8_t y, int16_t number, int16_t num, uint8_t pad) { |
if (((uint16_t) number) > 32767) { |
number = number - 65536; |
num *= -1; |
|
while (num > 0) { |
uint8_t b = number / num; |
if (b > 0 || started || num == 1) { |
write_ascii_char((x++)+(y * 30), '0' + b); |
started = 1; |
} else { |
write_ascii_char((x++)+(y * 30), '0'); |
} |
number -= b * num; |
// if number is smaller than -99[..]9 we must increase it |
while (number <= (num * 10)) { |
number -= num * 10; |
} |
|
num /= 10; |
} |
} |
uint8_t started = 0; |
|
/** |
* write a unsigned number as /10th at <x>/<y> to MAX7456 display memory |
*/ |
void write_number_u_10th(uint8_t x, uint8_t y, uint16_t number) { |
uint16_t num = 10000; |
uint8_t started = 0; |
while (num < 0) { |
uint8_t b = number / num; |
if (pad) write_ascii_char((x)+(y * 30), '0'); |
if (b > 0 || started || num == 1) { |
if (!started) write_char((x - 1)+(y * 30), 0x49); |
write_ascii_char((x++)+(y * 30), '0' + b); |
started = 1; |
} else { |
write_ascii_char((x++)+(y * 30), 0); |
} |
number -= b * num; |
|
while (num > 0) { |
uint8_t b = number / num; |
|
if (b > 0 || started || num == 1) { |
if ((num / 10) == 0) write_char((x++)+(y * 30), 65); |
write_ascii_char((x++)+(y * 30), '0' + b); |
started = 1; |
} else { |
write_ascii_char((x++)+(y * 30), 0); |
} |
number -= b * num; |
|
num /= 10; |
num /= 10; |
} |
} else { |
write_char((x)+(y * 30), 0); |
write_ndigit_number_u(x, y, number, num, pad); |
} |
} |
|
/** |
* write a unsigned number at <x>/<y> to MAX7456 display memory |
* Write only some digits of a unsigned <number> at <x>/<y> to MAX7456 display memory |
* as /10th of the value |
* <num> represents the largest multiple of 10 that will still be displayable as |
* the first digit, so num = 10 will be 0-99 and so on |
* <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
*/ |
void write_number_u(uint8_t x, uint8_t y, uint16_t number) { |
uint16_t num = 10000; |
uint8_t started = 0; |
void write_ndigit_number_u_10th(uint8_t x, uint8_t y, uint16_t number, int16_t num, uint8_t pad) { |
// if number is largar than 99[..]9 we must decrease it |
while (number >= (num * 10)) { |
number -= num * 10; |
} |
|
|
while (num > 0) { |
uint8_t b = number / num; |
if (b > 0 || started || num == 1) { |
write_ascii_char((x++)+(y * 30), '0' + b); |
started = 1; |
} else { |
write_ascii_char((x++)+(y * 30), 0); |
} |
number -= b * num; |
uint8_t started = 0; |
while (num > 0) { |
uint8_t b = number / num; |
if (b > 0 || started || num == 1) { |
if ((num / 10) == 0) { |
if (!started) write_ascii_char((x - 1)+(y * 30), '0'); |
write_char((x++)+(y * 30), 65); // decimal point |
} |
write_ascii_char((x++)+(y * 30), '0' + b); |
started = 1; |
} else { |
if (pad) write_ascii_char((x++)+(y * 30), '0'); |
else write_ascii_char((x++)+(y * 30), ' '); |
} |
number -= b * num; |
|
num /= 10; |
} |
num /= 10; |
} |
} |
|
/** |
* write a signed number at <x>/<y> to MAX7456 display memory |
* Write only some digits of a signed <number> at <x>/<y> to MAX7456 display memory |
* as /10th of the value |
* <num> represents the largest multiple of 10 that will still be displayable as |
* the first digit, so num = 10 will be 0-99 and so on |
* <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
*/ |
void write_number_s(uint8_t x, uint8_t y, int16_t w) { |
if (((uint16_t) w) > 32767) { |
w = w - 65536; |
void write_ndigit_number_s_10th(uint8_t x, uint8_t y, int16_t number, int16_t num, uint8_t pad) { |
if (((uint16_t) number) > 32767) { |
number = number - 65536; |
num *= -1; |
|
int16_t num = -10000; |
uint8_t started = 0; |
// if number is smaller than -99[..]9 we must increase it |
while (number <= (num * 10)) { |
number -= num * 10; |
} |
|
while (num < 0) { |
uint8_t b = w / num; |
if (b > 0 || started || num == 1) { |
if (!started) write_char((x - 1)+(y * 30), 0x49); |
write_ascii_char((x++)+(y * 30), '0' + b); |
started = 1; |
} else { |
write_ascii_char((x++)+(y * 30), 0); |
} |
w -= b * num; |
uint8_t started = 0; |
|
num /= 10; |
} |
} else { |
while (num < 0) { |
uint8_t b = number / num; |
if (pad) write_ascii_char((x)+(y * 30), '0'); |
if (b > 0 || started || num == 1) { |
if ((num / 10) == 0) { |
if (!started) { |
write_ascii_char((x - 2)+(y * 30), '-'); |
write_ascii_char((x - 1)+(y * 30), '0'); |
} |
write_char((x++)+(y * 30), 65); // decimal point |
} else if (!started) { |
write_char((x - 1)+(y * 30), 0x49); // minus |
} |
write_ascii_char((x++)+(y * 30), '0' + b); |
started = 1; |
} else { |
write_ascii_char((x++)+(y * 30), 0); |
} |
number -= b * num; |
|
num /= 10; |
} |
} else { |
write_char((x)+(y * 30), 0); |
write_number_u(x, y, w); |
write_ndigit_number_u_10th(x, y, number, num, pad); |
} |
} |
|
273,9 → 300,9 |
void write_time(uint8_t x, uint8_t y, uint16_t seconds) { |
uint16_t min = seconds / 60; |
seconds -= min * 60; |
write_3digit_number_u(x, y, min); |
write_ndigit_number_u(x, y, min, 100, 0); |
write_char_xy(x + 3, y, 68); |
write_2digit_number_u(x + 4, y, seconds); |
write_ndigit_number_u(x + 4, y, seconds, 10, 1); |
} |
|
/** |