diff --git a/src_main/io/pispi.cpp b/src_main/io/pispi.cpp index 547966a4..80a9741d 100644 --- a/src_main/io/pispi.cpp +++ b/src_main/io/pispi.cpp @@ -24,6 +24,8 @@ PISPI::PISPI(const PIString & path, uint speed, PIIODevice::DeviceMode mode) : P setSpeed(speed); setBits(8); spi_mode = 0; + if (mode == ReadOnly) + piCoutObj << "error, SPI can't work in ReadOnly mode"; #ifndef WINDOWS PRIVATE->fd = 0; #endif @@ -111,10 +113,32 @@ int PISPI::writeDevice(const void * data, int max_size) { //piCoutObj << "write" << max_size << tx_buf.size(); ret = ioctl(PRIVATE->fd, SPI_IOC_MESSAGE(1), &PRIVATE->spi_ioc_tr); if (ret < 1) {piCoutObj << "can't send spi message" << ret; return -1;} - recv_buf.append(rx_buf); + if (canRead()) recv_buf.append(rx_buf); if (recv_buf.size_s() > threadedReadBufferSize()) recv_buf.resize(threadedReadBufferSize()); return max_size; } #endif return 0; } + + +PIString PISPI::constructFullPathDevice() const { + PIString ret; + ret << path() << ":" << int(speed()) << ":" << int(bits()) << ":" << (int)parameters(); + return ret; +} + + +void PISPI::configureFromFullPathDevice(const PIString & full_path) { + PIStringList pl = full_path.split(":"); + for (int i = 0; i < pl.size_s(); ++i) { + PIString p(pl[i]); + switch (i) { + case 0: setPath(p); break; + case 1: setSpeed(p.toInt()); break; + case 2: setBits(p.toInt()); break; + case 3: setParameters(p.toInt()); break; + default: break; + } + } +} diff --git a/src_main/io/pispi.h b/src_main/io/pispi.h index 4d5c21f5..fe74881f 100644 --- a/src_main/io/pispi.h +++ b/src_main/io/pispi.h @@ -42,6 +42,11 @@ protected: int readDevice(void * read_to, int max_size); int writeDevice(const void * data, int max_size); + PIString fullPathPrefix() const {return PIStringAscii("spi");} + PIString constructFullPathDevice() const; + void configureFromFullPathDevice(const PIString & full_path); + DeviceInfoFlags deviceInfoFlags() const {return PIIODevice::Sequential;} + private: uint spi_speed; uchar spi_mode;