Commit 137031e1 authored by mz-fuzzy's avatar mz-fuzzy

spidev fix: don't close spidev if not open before

Signed-off-by: default avatarmz-fuzzy <mzfuzzy800@gmail.com>
parent b364215e
...@@ -573,8 +573,6 @@ bool RF24::begin(void) ...@@ -573,8 +573,6 @@ bool RF24::begin(void)
#if defined (RF24_LINUX) #if defined (RF24_LINUX)
SPI();
#if defined (MRAA) #if defined (MRAA)
GPIO(); GPIO();
gpio.begin(ce_pin,csn_pin); gpio.begin(ce_pin,csn_pin);
......
...@@ -13,8 +13,7 @@ ...@@ -13,8 +13,7 @@
#include <pthread.h> #include <pthread.h>
static pthread_mutex_t spiMutex; static pthread_mutex_t spiMutex;
SPI::SPI() { SPI::SPI():fd(-1) {
} }
void SPI::begin(int busNo){ void SPI::begin(int busNo){
...@@ -51,14 +50,16 @@ void SPI::init() ...@@ -51,14 +50,16 @@ void SPI::init()
{ {
int ret; int ret;
if( !(this->fd > 0)){ if (this->fd < 0) // check whether spi is already open
{
this->fd = open(this->device.c_str(), O_RDWR); this->fd = open(this->device.c_str(), O_RDWR);
}
if (this->fd < 0) if (this->fd < 0)
{ {
perror("can't open device"); perror("can't open device");
abort(); abort();
} }
}
/* /*
* spi mode * spi mode
...@@ -206,6 +207,7 @@ void SPI::transfern(char* buf, uint32_t len) ...@@ -206,6 +207,7 @@ void SPI::transfern(char* buf, uint32_t len)
SPI::~SPI() { SPI::~SPI() {
close(this->fd); if (!(this->fd < 0))
close(this->fd);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment