aboutsummaryrefslogtreecommitdiff
path: root/rmidevice/rmidevice.cpp
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/rmidevice.cpp
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/rmidevice.cpp')
-rw-r--r--rmidevice/rmidevice.cpp52
1 files changed, 36 insertions, 16 deletions
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