git-svn-id: svn://db.shs.com.ru/pip@585 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -24,6 +24,8 @@ PISPI::PISPI(const PIString & path, uint speed, PIIODevice::DeviceMode mode) : P
|
|||||||
setSpeed(speed);
|
setSpeed(speed);
|
||||||
setBits(8);
|
setBits(8);
|
||||||
spi_mode = 0;
|
spi_mode = 0;
|
||||||
|
if (mode == ReadOnly)
|
||||||
|
piCoutObj << "error, SPI can't work in ReadOnly mode";
|
||||||
#ifndef WINDOWS
|
#ifndef WINDOWS
|
||||||
PRIVATE->fd = 0;
|
PRIVATE->fd = 0;
|
||||||
#endif
|
#endif
|
||||||
@@ -111,10 +113,32 @@ int PISPI::writeDevice(const void * data, int max_size) {
|
|||||||
//piCoutObj << "write" << max_size << tx_buf.size();
|
//piCoutObj << "write" << max_size << tx_buf.size();
|
||||||
ret = ioctl(PRIVATE->fd, SPI_IOC_MESSAGE(1), &PRIVATE->spi_ioc_tr);
|
ret = ioctl(PRIVATE->fd, SPI_IOC_MESSAGE(1), &PRIVATE->spi_ioc_tr);
|
||||||
if (ret < 1) {piCoutObj << "can't send spi message" << ret; return -1;}
|
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());
|
if (recv_buf.size_s() > threadedReadBufferSize()) recv_buf.resize(threadedReadBufferSize());
|
||||||
return max_size;
|
return max_size;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -42,6 +42,11 @@ protected:
|
|||||||
int readDevice(void * read_to, int max_size);
|
int readDevice(void * read_to, int max_size);
|
||||||
int writeDevice(const void * data, 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:
|
private:
|
||||||
uint spi_speed;
|
uint spi_speed;
|
||||||
uchar spi_mode;
|
uchar spi_mode;
|
||||||
|
|||||||
Reference in New Issue
Block a user