From e88177d7858cfc06efed083eba6b8a60eb2556d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Mon, 17 Feb 2020 14:27:16 +0100 Subject: [PATCH] led_tm1637: minor, put spaces around operators --- lib/led_tm1637.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/led_tm1637.c b/lib/led_tm1637.c index 4bf1e4b..96174d7 100644 --- a/lib/led_tm1637.c +++ b/lib/led_tm1637.c @@ -199,7 +199,7 @@ static inline void led_tm1637_tick(void) static bool led_tm1637_write(const uint8_t* data, size_t length) { bool to_return = true; // return if write succeeded - if (data==NULL || length==0) { // verify there it data to be read + if (NULL == data || 0 == length) { // verify there it data to be read return false; } @@ -214,10 +214,10 @@ static bool led_tm1637_write(const uint8_t* data, size_t length) gpio_clear(GPIO_PORT(LED_TM1637_CLK_PIN), GPIO_PIN(LED_TM1637_CLK_PIN)); // put CLK low // send data bytes (MSb first) - for (size_t i=0; i=' '+LENGTH(ascii_7segments)) { + for (uint8_t i = 0; i < 4; 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 false; } } uint8_t write_data[] = { 0x40 }; // command: write data, automatic address adding, normal - uint8_t data[] = { 0xc0, ascii_7segments[(text[0]&0x7f)-' ']|(text[0]&0x80), ascii_7segments[(text[1]&0x7f)-' ']|(text[1]&0x80), ascii_7segments[(text[2]&0x7f)-' ']|(text[2]&0x80), ascii_7segments[(text[3]&0x7f)-' ']|(text[3]&0x80) }; // set address C0H and add data + uint8_t data[] = { 0xc0, ascii_7segments[(text[0] & 0x7f) - ' '] | (text[0] & 0x80), ascii_7segments[(text[1] & 0x7f) - ' ']|(text[1] & 0x80), ascii_7segments[(text[2] & 0x7f) - ' ']|(text[2] & 0x80), ascii_7segments[(text[3] & 0x7f) - ' ']|(text[3] & 0x80) }; // set address C0H and add data if (led_tm1637_write(write_data,LENGTH(write_data)) && led_tm1637_write(data,LENGTH(data))) { // send commands return true;