From d41e803bdec19a99809bc37bda803a0968c09a90 Mon Sep 17 00:00:00 2001 From: jesse Date: Thu, 17 Dec 2020 19:49:35 -0500 Subject: [PATCH] fixed errors and fromating --- include/tlc59711.h | 2 +- src/main.cpp | 5 ++++- src/spi.c | 2 +- src/tlc59711.c | 9 ++++++--- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/include/tlc59711.h b/include/tlc59711.h index 817cef7..14082af 100644 --- a/include/tlc59711.h +++ b/include/tlc59711.h @@ -2,6 +2,6 @@ #ifndef TLC59711_H #define TLC59711_H #include "spi.h" -extern void tlc59711_send(const uint16_t data[12]); +extern int tlc59711_send(const uint16_t data[12]); extern int tlc59711_init(const char *device); #endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 9f00f48..d302af4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,7 +7,10 @@ int main(int argc, char *argv[]) uint16_t test[12] = {0}; tlc59711_init("/dev/spidev1.1"); while(1){ - tlc59711_send(test); + int ret; + if((ret = tlc59711_send(test)) < 0 ){ + exit(ret); + } } return 0; } diff --git a/src/spi.c b/src/spi.c index cb9a7ed..2025fb9 100644 --- a/src/spi.c +++ b/src/spi.c @@ -35,7 +35,7 @@ extern int transfer(uint8_t tx[], uint8_t rx[],unsigned int size) ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr); if (ret < 1) - printf("can't send spi message"); + printf("can't send spi message\n"); return ret; } extern int spi_init(spiMode* modes,const char *device ) diff --git a/src/tlc59711.c b/src/tlc59711.c index fda856b..3cf7711 100644 --- a/src/tlc59711.c +++ b/src/tlc59711.c @@ -16,7 +16,7 @@ extern int tlc59711_init(const char *device) int fd = spi_init(&modes, device); return fd; } -extern void tlc59711_send(const uint16_t data[12]) +extern int tlc59711_send(const uint16_t data[12]) { uint8_t rx[24]; // throw away uint8_t tx[24]; @@ -25,7 +25,10 @@ extern void tlc59711_send(const uint16_t data[12]) tx[1] = command >> 16; tx[2] = command >> 8; tx[3] = command; - transfer(tx,rx,4); + int ret; + if((ret = transfer(tx,rx,4)) < 0){ + return ret; + } // 12 channels per TLC59711 @@ -36,7 +39,7 @@ extern void tlc59711_send(const uint16_t data[12]) //spiSend(data[c]); tx[c << 1] = 0xFF; } - transfer(tx,rx,24); + return transfer(tx,rx,24); } -- 2.42.0