Fix MAC port
authorThomas Pietrzak <thomas.pietrzak@gmail.com>
Fri, 16 Mar 2012 14:16:53 +0000 (14:16 +0000)
committerThomas Pietrzak <thomas.pietrzak@gmail.com>
Fri, 16 Mar 2012 14:16:53 +0000 (14:16 +0000)
git-svn-id: svn+ssh://thomaspietrzak.com/var/svn/rep@67 47cf9a05-e0a8-4ed5-9e9b-101a649bc004

DynamicKeyboardLibrary/DynamicKeyboardLibrary/DynamicKeyboardController.cpp

index 333a0a08a8aebd50d16582981f4d4c0ccc12220e..c7e8419b98c824281cf8d1c283e4b480c7c8af96 100644 (file)
@@ -3,7 +3,7 @@
 \r
 #ifdef __MACOSX__\r
 #include <SerialMac.hpp>\r
-#else\r
+#elif defined WIN32\r
 #include <ArduinoSerial\SerialWindows.hpp>\r
 #endif\r
 \r
@@ -15,7 +15,7 @@ DynamicKeyboardController::DynamicKeyboardController(char *port, int baudrate)
        {\r
 #ifdef WIN32\r
                _comPort = new SerialWindows(port, baudrate);\r
-#elif  __MACOSX__\r
+#elif defined  __MACOSX__\r
                _comPort = new SerialMac(port, baudrate);\r
 #endif\r
        }\r
@@ -91,20 +91,21 @@ void DynamicKeyboardController::setBoostDuration(UINT16 val) const
 \r
 bool DynamicKeyboardController::getState(UINT16 &solenoids, UINT8 &minDutyCycle, UINT8 &maxDutyCycle, UINT16 &boostDuration) const\r
 {\r
-       if (!_comPort)\r
-               return false;\r
-       _comPort->WriteData((void *)("I"),1);\r
+    char comm = 'I';\r
+    if (!_comPort || !_comPort->WriteData(&comm,1))\r
+        return false;\r
 #ifdef WIN32\r
        Sleep(1000);\r
 #else\r
-    sleep(1000);\r
+    sleep(1);\r
 #endif\r
        /*\r
                we currently receive 2 bytes for 16 keys states, max DC, min DC and boost duration\r
                We may receive more bytes in the future if we handle more keys\r
        */\r
        unsigned char buffer[6];\r
-       _comPort->ReadData(buffer, 6);\r
+    if (_comPort->ReadData(buffer, 6) <= 0)\r
+        return false;\r
        solenoids = (UINT16(buffer[0]) << 8) | buffer[1];\r
        maxDutyCycle = buffer[2];\r
        minDutyCycle = buffer[3];\r