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

DynamicKeyboardLibrary/DynamicKeyboardLibrary/DynamicKeyboardController.cpp
DynamicKeyboardLibrary/DynamicKeyboardLibrary/DynamicKeyboardController.h

index 384b007829646983d4e2d3dc2a8ab03faddd26f2..333a0a08a8aebd50d16582981f4d4c0ccc12220e 100644 (file)
@@ -1,6 +1,11 @@
 #include "DynamicKeyboardController.h"\r
 \r
+\r
+#ifdef __MACOSX__\r
+#include <SerialMac.hpp>\r
+#else\r
 #include <ArduinoSerial\SerialWindows.hpp>\r
+#endif\r
 \r
 #include <cstdio>\r
 \r
@@ -8,7 +13,11 @@ DynamicKeyboardController::DynamicKeyboardController(char *port, int baudrate)
 {\r
        try\r
        {\r
+#ifdef WIN32\r
                _comPort = new SerialWindows(port, baudrate);\r
+#elif  __MACOSX__\r
+               _comPort = new SerialMac(port, baudrate);\r
+#endif\r
        }\r
        catch (...)\r
        {\r
@@ -84,9 +93,12 @@ bool DynamicKeyboardController::getState(UINT16 &solenoids, UINT8 &minDutyCycle,
 {\r
        if (!_comPort)\r
                return false;\r
-       _comPort->WriteData("I",1);\r
+       _comPort->WriteData((void *)("I"),1);\r
+#ifdef WIN32\r
        Sleep(1000);\r
-\r
+#else\r
+    sleep(1000);\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
index 483abb286cd4a1ed467c1aea506f674b37a8df26..4cc73cc52f7015699b4d5ff3ea3656fef44bf6a8 100644 (file)
@@ -1,7 +1,13 @@
 #ifndef __DYNAMICKEYBOARDCONTROLLER__\r
 #define __DYNAMICKEYBOARDCONTROLLER__\r
 \r
+#ifdef __MACOSX__\r
+#include <Serial.hpp>\r
+#define EXPORTED\r
+#else\r
 #include <ArduinoSerial\Serial.hpp>\r
+#define EXPORTED __declspec(dllexport)\r
+#endif\r
 \r
 #include <iostream>\r
 \r
@@ -16,23 +22,24 @@ class DynamicKeyboardController
                        port is the COM port for the communication with the Arduino Board\r
                        baudrate is the baudrate for the communication, the default value may be sufficient\r
                */\r
-               __declspec(dllexport) DynamicKeyboardController(char *port, int baudrate = 115200);\r
+\r
+        EXPORTED DynamicKeyboardController(char *port, int baudrate = 115200);\r
 \r
                /* sets a configuration on keys\r
            XY is the configuration. Here 1 represent a raised key, \r
            0 a lowered key.\r
                */\r
-               __declspec(dllexport) void setConfiguration(UINT16 config);\r
+               EXPORTED void setConfiguration(UINT16 config);\r
                /*\r
                        raise the specified keys\r
                        1 raises a key, 0 does not change its state\r
                */\r
-               __declspec(dllexport) void raiseKeys(UINT16 config);\r
+               EXPORTED void raiseKeys(UINT16 config);\r
                /*\r
                        lowers the specified keys\r
                        1 lowers a key, 0 does not change its state\r
                */\r
-               __declspec(dllexport) void lowerKeys(UINT16 config);\r
+               EXPORTED void lowerKeys(UINT16 config);\r
 \r
                /*\r
                        higher duty cycle values results to higher voltage\r
@@ -41,25 +48,25 @@ class DynamicKeyboardController
                        the values are choosen with empirical tests, \r
                        depending on the solenoids and the power supply\r
                */\r
-               __declspec(dllexport) void setMaximumDutyCycle(UINT8 val) const;\r
-               __declspec(dllexport) void setMinimumDutyCycle(UINT8 val) const;\r
+               EXPORTED void setMaximumDutyCycle(UINT8 val) const;\r
+               EXPORTED void setMinimumDutyCycle(UINT8 val) const;\r
 \r
                /*\r
                        The shorter the boost mode the better since it goes beyond the standards\r
                        The longer the boost mode is, the longer we should wait before changing \r
                        the keys state again.\r
                */\r
-               __declspec(dllexport) void setBoostDuration(UINT16) const;\r
+               EXPORTED void setBoostDuration(UINT16) const;\r
 \r
                /*\r
                        returns the state of the solenoids, the max and min duty cycle and the boost duration\r
                */\r
-               __declspec(dllexport) bool getState(UINT16 &solenoids, UINT8 &minDutyCycle, UINT8 &maxDutyCycle, UINT16 &boostDuration) const;\r
+               EXPORTED bool getState(UINT16 &solenoids, UINT8 &minDutyCycle, UINT8 &maxDutyCycle, UINT16 &boostDuration) const;\r
 \r
                /*\r
                        returns on the stream the state of the solenoids, the max and min duty cycle and the boost duration\r
                */\r
-               __declspec(dllexport) friend std::ostream& operator<< (std::ostream& stream, const DynamicKeyboardController& controller);\r
+               EXPORTED friend std::ostream& operator<< (std::ostream& stream, const DynamicKeyboardController& controller);\r
 \r
        protected:\r
                Serial *_comPort;\r