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)
#if defined (RF24_LINUX)
SPI();
#if defined (MRAA)
GPIO();
gpio.begin(ce_pin,csn_pin);
......
......@@ -13,8 +13,7 @@
#include <pthread.h>
static pthread_mutex_t spiMutex;
SPI::SPI() {
SPI::SPI():fd(-1) {
}
void SPI::begin(int busNo){
......@@ -51,14 +50,16 @@ void SPI::init()
{
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);
}
if (this->fd < 0)
{
perror("can't open device");
abort();
}
if (this->fd < 0)
{
perror("can't open device");
abort();
}
}
/*
* spi mode
......@@ -206,6 +207,7 @@ void SPI::transfern(char* buf, uint32_t len)
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