aboutsummaryrefslogtreecommitdiff
path: root/rmidevice
diff options
context:
space:
mode:
authorAndrew Duggan <aduggan@synaptics.com>2014-04-07 10:44:40 -0700
committerAndrew Duggan <aduggan@synaptics.com>2014-04-07 10:44:40 -0700
commit5d47750894ddaf019a016505f790c439e2eae3ac (patch)
tree3264ee4bddb24c9f8106c90799d6c6d5bdfe55e6 /rmidevice
parent65e5553ace01906e5c0ac3a810afd552a2820acd (diff)
downloadrmi4utils-5d47750894ddaf019a016505f790c439e2eae3ac.tar.gz
Move some functions from HIDDevice to RMIDevice to better support multiple transports update the Android builds.
Diffstat (limited to 'rmidevice')
-rw-r--r--rmidevice/hiddevice.h7
-rw-r--r--rmidevice/rmidevice.cpp52
-rw-r--r--rmidevice/rmidevice.h16
3 files changed, 50 insertions, 25 deletions
diff --git a/rmidevice/hiddevice.h b/rmidevice/hiddevice.h
index 59f32f9..d6ebd55 100644
--- a/rmidevice/hiddevice.h
+++ b/rmidevice/hiddevice.h
@@ -8,8 +8,7 @@ class HIDDevice : public RMIDevice
{
public:
HIDDevice(int bytesPerReadRequest = 0) : RMIDevice(bytesPerReadRequest), m_headIdx(0),
- m_tailIdx(0), m_deviceOpen(false), m_bCancel(false),
- m_attnQueueCount(0)
+ m_tailIdx(0), m_deviceOpen(false), m_attnQueueCount(0)
{}
virtual int Open(const char * filename);
virtual int Read(unsigned short addr, unsigned char *buf,
@@ -18,9 +17,8 @@ public:
unsigned short len);
virtual int SetMode(int mode);
virtual int WaitForAttention(struct timeval * timeout = NULL, int *sources = NULL);
- int GetAttentionReport(struct timeval * timeout, int *sources, unsigned char *buf, int *len);
+ virtual int GetAttentionReport(struct timeval * timeout, int *sources, unsigned char *buf, int *len);
virtual void Close();
- virtual void Cancel() { m_bCancel = true; }
~HIDDevice() { Close(); }
private:
@@ -43,7 +41,6 @@ private:
size_t m_featureReportSize;
bool m_deviceOpen;
- bool m_bCancel;
int m_attnQueueCount;
diff --git a/rmidevice/rmidevice.cpp b/rmidevice/rmidevice.cpp
index d955e81..920caf6 100644
--- a/rmidevice/rmidevice.cpp
+++ b/rmidevice/rmidevice.cpp
@@ -40,7 +40,18 @@
int RMIDevice::SetRMIPage(unsigned char page)
{
- return Write(RMI_DEVICE_PAGE_SELECT_REGISTER, &page, 1);
+ int rc;
+
+ if (m_page == page)
+ return 0;
+
+ m_page = page;
+ rc = Write(RMI_DEVICE_PAGE_SELECT_REGISTER, &page, 1);
+ if (rc < 0) {
+ m_page = -1;
+ return rc;
+ }
+ return 0;
}
int RMIDevice::QueryBasicProperties()
@@ -179,8 +190,6 @@ int RMIDevice::Reset()
{
int rc;
RMIFunction f01;
- struct timespec ts;
- struct timespec rem;
const unsigned char deviceReset = RMI_F01_CMD_DEVICE_RESET;
if (!GetFunction(f01, 1))
@@ -191,19 +200,9 @@ int RMIDevice::Reset()
if (rc < 0)
return rc;
- ts.tv_sec = RMI_F01_DEFAULT_RESET_DELAY_MS / 1000;
- ts.tv_nsec = (RMI_F01_DEFAULT_RESET_DELAY_MS % 1000) * 1000 * 1000;
- for (;;) {
- if (nanosleep(&ts, &rem) == 0) {
- break;
- } else {
- if (errno == EINTR) {
- ts = rem;
- continue;
- }
- return -1;
- }
- }
+ rc = Sleep(RMI_F01_DEFAULT_RESET_DELAY_MS);
+ if (rc < 0)
+ return -1;
fprintf(stdout, "Reset completed.\n");
return 0;
}
@@ -266,4 +265,25 @@ long long diff_time(struct timespec *start, struct timespec *end)
diff = (end->tv_sec - start->tv_sec) * 1000 * 1000;
diff += (end->tv_nsec - start->tv_nsec) / 1000;
return diff;
+}
+
+int Sleep(int ms)
+{
+ struct timespec ts;
+ struct timespec rem;
+
+ ts.tv_sec = ms / 1000;
+ ts.tv_nsec = (ms % 1000) * 1000 * 1000;
+ for (;;) {
+ if (nanosleep(&ts, &rem) == 0) {
+ break;
+ } else {
+ if (errno == EINTR) {
+ ts = rem;
+ continue;
+ }
+ return -1;
+ }
+ }
+ return 0;
} \ No newline at end of file
diff --git a/rmidevice/rmidevice.h b/rmidevice/rmidevice.h
index de17212..cc1f7ca 100644
--- a/rmidevice/rmidevice.h
+++ b/rmidevice/rmidevice.h
@@ -11,19 +11,23 @@
class RMIDevice
{
public:
- RMIDevice(int bytesPerReadRequest = 0) : m_bytesPerReadRequest(bytesPerReadRequest)
+ RMIDevice(int bytesPerReadRequest = 0) : m_bCancel(false),
+ m_bytesPerReadRequest(bytesPerReadRequest), m_page(-1)
{}
virtual int Open(const char * filename) = 0;
virtual int Read(unsigned short addr, unsigned char *data,
unsigned short len) = 0;
virtual int Write(unsigned short addr, const unsigned char *data,
unsigned short len) = 0;
- virtual int SetMode(int mode) = 0;
+ virtual int SetMode(int mode) { return -1; /* Unsupported */ }
virtual int WaitForAttention(struct timeval * timeout = NULL, int *sources = NULL) = 0;
+ virtual int GetAttentionReport(struct timeval * timeout, int *sources, unsigned char *buf,
+ int *len)
+ { return -1; /* Unsupported */ }
virtual void Close() = 0;
- virtual void Cancel() = 0;
+ virtual void Cancel() { m_bCancel = true; }
- virtual unsigned long GetFirmwareID() { return m_buildID; }
+ unsigned long GetFirmwareID() { return m_buildID; }
virtual int QueryBasicProperties();
int SetRMIPage(unsigned char page);
@@ -51,6 +55,7 @@ protected:
unsigned short m_packageRev;
unsigned long m_buildID;
unsigned char m_sensorID;
+ unsigned long m_boardID;
bool m_hasDS4Queries;
bool m_hasMultiPhysical;
@@ -60,9 +65,12 @@ protected:
bool m_hasPackageIDQuery;
bool m_hasBuildIDQuery;
+ bool m_bCancel;
int m_bytesPerReadRequest;
+ int m_page;
};
long long diff_time(struct timespec *start, struct timespec *end);
+int Sleep(int ms);
#endif /* _RMIDEVICE_H_ */ \ No newline at end of file