led_tm1637: minor, put spaces around operators

This commit is contained in:
King Kévin 2020-02-17 14:27:16 +01:00
parent 2896185e45
commit e88177d785
1 changed files with 12 additions and 12 deletions

View File

@ -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; i++) { // send all bytes
for (size_t i = 0; i < length; i++) { // send all bytes
uint8_t byte = data[i];
for (uint8_t b=0; b<8; b++) { // send all bits
if (byte&0x1) { // send a 1
for (uint8_t b = 0; b < 8; b++) { // send all bits
if (byte & 0x1) { // send a 1
gpio_set(GPIO_PORT(LED_TM1637_DIO_PIN), GPIO_PIN(LED_TM1637_DIO_PIN)); // put DIO high
} else {
gpio_clear(GPIO_PORT(LED_TM1637_DIO_PIN), GPIO_PIN(LED_TM1637_DIO_PIN)); // put DIO low
@ -253,7 +253,7 @@ static bool led_tm1637_write(const uint8_t* data, size_t length)
bool led_tm1637_on(void)
{
uint8_t data[] = { 0x88+display_brightness }; // command to turn display on (use set brightness)
uint8_t data[] = { 0x88 + display_brightness }; // command to turn display on (use set brightness)
bool to_return = false; // result to return
if (led_tm1637_write(data,LENGTH(data))) { // send command
display_on = true; // remember display is on
@ -264,7 +264,7 @@ bool led_tm1637_on(void)
bool led_tm1637_off(void)
{
uint8_t data[] = { 0x80+display_brightness }; // command to turn display off (use set brightness)
uint8_t data[] = { 0x80 + display_brightness }; // command to turn display off (use set brightness)
if (led_tm1637_write(data,LENGTH(data))) { // send command
display_on = false; // remember display is off
return true; // command succeeded
@ -286,7 +286,7 @@ bool led_tm1637_brightness(enum led_tm1637_brightness_t brightness)
bool led_tm1637_number(uint16_t number)
{
uint8_t write_data[] = { 0x40 }; // command: write data, automatic address adding, normal
uint8_t data[] = { 0xc0, ascii_7segments[((number/1000)%10)+'0'-' '], ascii_7segments[((number/100)%10)+'0'-' '], ascii_7segments[((number/10)%10)+'0'-' '], ascii_7segments[((number/1)%10)+'0'-' '] }; // set address C0H and add data
uint8_t data[] = { 0xc0, ascii_7segments[((number / 1000) % 10) + '0' - ' '], ascii_7segments[((number / 100) % 10) + '0' - ' '], ascii_7segments[((number / 10) % 10) + '0' - ' '], ascii_7segments[((number / 1) % 10) + '0' - ' '] }; // 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;
@ -297,7 +297,7 @@ bool led_tm1637_number(uint16_t number)
bool led_tm1637_time(uint8_t hours, uint8_t minutes)
{
uint8_t write_data[] = { 0x40 }; // command: write data, automatic address adding, normal
uint8_t data[] = { 0xc0, ascii_7segments[((hours/10)%10)+'0'-' '], ascii_7segments[((hours/1)%10)+'0'-' ']|0x80, ascii_7segments[((minutes/10)%10)+'0'-' '], ascii_7segments[((minutes/1)%10)+'0'-' '] }; // set address C0H and add data
uint8_t data[] = { 0xc0, ascii_7segments[((hours / 10) % 10) + '0' - ' '], ascii_7segments[((hours / 1) % 10) + '0' - ' '] | 0x80, ascii_7segments[((minutes / 10) % 10) + '0' - ' '], ascii_7segments[((minutes / 1) % 10) + '0' - ' '] }; // 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;
@ -307,16 +307,16 @@ bool led_tm1637_time(uint8_t hours, uint8_t minutes)
bool led_tm1637_text(char* text)
{
if (strlen(text)!=4) { // input text should have exactly 4 characters
if (strlen(text) != 4) { // input text should have exactly 4 characters
return false;
}
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)) {
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;