return false on input error

This commit is contained in:
King Kévin 2017-03-08 10:59:09 +01:00
parent d0a713a98e
commit 8e65cff24d
2 changed files with 5 additions and 3 deletions

View File

@ -221,15 +221,16 @@ void led_max7219_intensity(uint8_t intensity)
led_max7219_write(0x0A00+intensity); // set brightness
}
void led_max7219_text(char* text)
bool led_max7219_text(char* text)
{
for (uint8_t i=0; i<8; i++) { // input text should only contain printable character (8th bit is used for dots)
if ((text[i]&0x7f)<' ' || (text[i]&0x7f)>=' '+LENGTH(ascii_7segments)) {
return;
return false;
}
}
led_max7219_write(0x0900); // disable BCD decoding on all 7 digits
for (uint8_t i=0; i<8; i++) { // display text
led_max7219_write(((i+1)<<8)+(ascii_7segments[(text[7-i]&0x7f)-' '])+(text[7-i]&0x80)); // send digit (in reverse order)
}
return true;
}

View File

@ -41,6 +41,7 @@ void led_max7219_intensity(uint8_t intensity);
/** display text
* @param[in] text text to display (8 characters)
* @note use first bit of each character to enable dot
* @return false if string has unsupported characters
*/
void led_max7219_text(char* text);
bool led_max7219_text(char* text);