From: Thomas Pietrzak Date: Wed, 14 Mar 2012 13:23:54 +0000 (+0000) Subject: MAC port X-Git-Url: https://git.thomaspietrzak.com/?a=commitdiff_plain;h=077a33f516164a5be52e72757778a4eadd7468b4;p=DynamicKeyboardLib.git MAC port git-svn-id: svn+ssh://thomaspietrzak.com/var/svn/rep@61 47cf9a05-e0a8-4ed5-9e9b-101a649bc004 --- diff --git a/DynamicKeyboardLibrary/DynamicKeyboardLibrary/DynamicKeyboardController.cpp b/DynamicKeyboardLibrary/DynamicKeyboardLibrary/DynamicKeyboardController.cpp index 384b007..333a0a0 100644 --- a/DynamicKeyboardLibrary/DynamicKeyboardLibrary/DynamicKeyboardController.cpp +++ b/DynamicKeyboardLibrary/DynamicKeyboardLibrary/DynamicKeyboardController.cpp @@ -1,6 +1,11 @@ #include "DynamicKeyboardController.h" + +#ifdef __MACOSX__ +#include +#else #include +#endif #include @@ -8,7 +13,11 @@ DynamicKeyboardController::DynamicKeyboardController(char *port, int baudrate) { try { +#ifdef WIN32 _comPort = new SerialWindows(port, baudrate); +#elif __MACOSX__ + _comPort = new SerialMac(port, baudrate); +#endif } catch (...) { @@ -84,9 +93,12 @@ bool DynamicKeyboardController::getState(UINT16 &solenoids, UINT8 &minDutyCycle, { if (!_comPort) return false; - _comPort->WriteData("I",1); + _comPort->WriteData((void *)("I"),1); +#ifdef WIN32 Sleep(1000); - +#else + sleep(1000); +#endif /* we currently receive 2 bytes for 16 keys states, max DC, min DC and boost duration We may receive more bytes in the future if we handle more keys diff --git a/DynamicKeyboardLibrary/DynamicKeyboardLibrary/DynamicKeyboardController.h b/DynamicKeyboardLibrary/DynamicKeyboardLibrary/DynamicKeyboardController.h index 483abb2..4cc73cc 100644 --- a/DynamicKeyboardLibrary/DynamicKeyboardLibrary/DynamicKeyboardController.h +++ b/DynamicKeyboardLibrary/DynamicKeyboardLibrary/DynamicKeyboardController.h @@ -1,7 +1,13 @@ #ifndef __DYNAMICKEYBOARDCONTROLLER__ #define __DYNAMICKEYBOARDCONTROLLER__ +#ifdef __MACOSX__ +#include +#define EXPORTED +#else #include +#define EXPORTED __declspec(dllexport) +#endif #include @@ -16,23 +22,24 @@ class DynamicKeyboardController port is the COM port for the communication with the Arduino Board baudrate is the baudrate for the communication, the default value may be sufficient */ - __declspec(dllexport) DynamicKeyboardController(char *port, int baudrate = 115200); + + EXPORTED DynamicKeyboardController(char *port, int baudrate = 115200); /* sets a configuration on keys XY is the configuration. Here 1 represent a raised key, 0 a lowered key. */ - __declspec(dllexport) void setConfiguration(UINT16 config); + EXPORTED void setConfiguration(UINT16 config); /* raise the specified keys 1 raises a key, 0 does not change its state */ - __declspec(dllexport) void raiseKeys(UINT16 config); + EXPORTED void raiseKeys(UINT16 config); /* lowers the specified keys 1 lowers a key, 0 does not change its state */ - __declspec(dllexport) void lowerKeys(UINT16 config); + EXPORTED void lowerKeys(UINT16 config); /* higher duty cycle values results to higher voltage @@ -41,25 +48,25 @@ class DynamicKeyboardController the values are choosen with empirical tests, depending on the solenoids and the power supply */ - __declspec(dllexport) void setMaximumDutyCycle(UINT8 val) const; - __declspec(dllexport) void setMinimumDutyCycle(UINT8 val) const; + EXPORTED void setMaximumDutyCycle(UINT8 val) const; + EXPORTED void setMinimumDutyCycle(UINT8 val) const; /* The shorter the boost mode the better since it goes beyond the standards The longer the boost mode is, the longer we should wait before changing the keys state again. */ - __declspec(dllexport) void setBoostDuration(UINT16) const; + EXPORTED void setBoostDuration(UINT16) const; /* returns the state of the solenoids, the max and min duty cycle and the boost duration */ - __declspec(dllexport) bool getState(UINT16 &solenoids, UINT8 &minDutyCycle, UINT8 &maxDutyCycle, UINT16 &boostDuration) const; + EXPORTED bool getState(UINT16 &solenoids, UINT8 &minDutyCycle, UINT8 &maxDutyCycle, UINT16 &boostDuration) const; /* returns on the stream the state of the solenoids, the max and min duty cycle and the boost duration */ - __declspec(dllexport) friend std::ostream& operator<< (std::ostream& stream, const DynamicKeyboardController& controller); + EXPORTED friend std::ostream& operator<< (std::ostream& stream, const DynamicKeyboardController& controller); protected: Serial *_comPort;