From: Thomas Pietrzak Date: Fri, 16 Mar 2012 14:16:53 +0000 (+0000) Subject: Fix MAC port X-Git-Url: https://git.thomaspietrzak.com/?a=commitdiff_plain;h=757b9be2dde547a2a8741d3a1bd9f9abe245aeee;p=DynamicKeyboardLib.git Fix MAC port git-svn-id: svn+ssh://thomaspietrzak.com/var/svn/rep@67 47cf9a05-e0a8-4ed5-9e9b-101a649bc004 --- diff --git a/DynamicKeyboardLibrary/DynamicKeyboardLibrary/DynamicKeyboardController.cpp b/DynamicKeyboardLibrary/DynamicKeyboardLibrary/DynamicKeyboardController.cpp index 333a0a0..c7e8419 100644 --- a/DynamicKeyboardLibrary/DynamicKeyboardLibrary/DynamicKeyboardController.cpp +++ b/DynamicKeyboardLibrary/DynamicKeyboardLibrary/DynamicKeyboardController.cpp @@ -3,7 +3,7 @@ #ifdef __MACOSX__ #include -#else +#elif defined WIN32 #include #endif @@ -15,7 +15,7 @@ DynamicKeyboardController::DynamicKeyboardController(char *port, int baudrate) { #ifdef WIN32 _comPort = new SerialWindows(port, baudrate); -#elif __MACOSX__ +#elif defined __MACOSX__ _comPort = new SerialMac(port, baudrate); #endif } @@ -91,20 +91,21 @@ void DynamicKeyboardController::setBoostDuration(UINT16 val) const bool DynamicKeyboardController::getState(UINT16 &solenoids, UINT8 &minDutyCycle, UINT8 &maxDutyCycle, UINT16 &boostDuration) const { - if (!_comPort) - return false; - _comPort->WriteData((void *)("I"),1); + char comm = 'I'; + if (!_comPort || !_comPort->WriteData(&comm,1)) + return false; #ifdef WIN32 Sleep(1000); #else - sleep(1000); + sleep(1); #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 */ unsigned char buffer[6]; - _comPort->ReadData(buffer, 6); + if (_comPort->ReadData(buffer, 6) <= 0) + return false; solenoids = (UINT16(buffer[0]) << 8) | buffer[1]; maxDutyCycle = buffer[2]; minDutyCycle = buffer[3];