diff --git a/driver/libtelldus-core/CMakeLists.txt b/driver/libtelldus-core/CMakeLists.txt index 3a5de92b..f3017373 100644 --- a/driver/libtelldus-core/CMakeLists.txt +++ b/driver/libtelldus-core/CMakeLists.txt @@ -22,6 +22,7 @@ SET( telldus-core_SRCS Controller.cpp Manager.cpp Settings.cpp + TellStick.cpp telldus-core.cpp ) diff --git a/driver/libtelldus-core/Controller.h b/driver/libtelldus-core/Controller.h index 8001a770..f7d32c37 100644 --- a/driver/libtelldus-core/Controller.h +++ b/driver/libtelldus-core/Controller.h @@ -20,14 +20,14 @@ */ namespace TelldusCore { class Controller { - public: - Controller(); - + public: virtual ~Controller(); virtual int firmwareVersion() = 0; virtual int send( const std::string &message ) = 0; + protected: + Controller(); }; } diff --git a/driver/libtelldus-core/Manager.cpp b/driver/libtelldus-core/Manager.cpp index 90e96568..8caa985c 100644 --- a/driver/libtelldus-core/Manager.cpp +++ b/driver/libtelldus-core/Manager.cpp @@ -25,7 +25,7 @@ #include "Controller.h" #ifdef TELLSTICK_DUO -#include "TellStickDuo.h" +#include "TellStick.h" #endif #include "common.h" @@ -46,8 +46,10 @@ Manager::Manager() : lastCallbackId(0) { #ifdef TELLSTICK_DUO - Controller *controller = new TellStickDuo("TSQVB5HU"); - controllers[1] = controller; +/* Controller *controller = TellStick::findFirstDevice(); + if (controller) { + controllers[1] = controller; + }*/ #endif } diff --git a/driver/libtelldus-core/TellStick.cpp b/driver/libtelldus-core/TellStick.cpp new file mode 100644 index 00000000..c422b9e0 --- /dev/null +++ b/driver/libtelldus-core/TellStick.cpp @@ -0,0 +1,85 @@ +// +// C++ Implementation: TellStick +// +// Description: +// +// +// Author: Micke Prag , (C) 2009 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "TellStick.h" +#include "ftd2xx.h" +#include + + +using namespace TelldusCore; + +TellStick::TellStick() { +} + + +TellStick::~TellStick() { +} + + +int TellStick::findFirstDevice() { + //TellStick + std::string serial = findByVIDPID(0x1781, 0x0C30); + if (serial.length() > 0) { + return 1; + } + //TellStick Duo + serial = findByVIDPID(0x1781, 0x0C31); + if (serial.length() > 0) { + return 2; + } + return 0; +} + +std::string TellStick::findByVIDPID( int vid, int pid ) { + FT_HANDLE fthHandle = 0; + FT_STATUS ftStatus = FT_OK; + + try{ + DWORD dwNumberOfDevices = 0; + +#ifndef _WINDOWS + FT_SetVIDPID(vid, pid); +#endif + ftStatus = FT_CreateDeviceInfoList(&dwNumberOfDevices); + if (ftStatus == FT_OK) { + for (int i = 0; i < (int)dwNumberOfDevices; i++) { + + FT_PROGRAM_DATA pData; + char ManufacturerBuf[32]; + char ManufacturerIdBuf[16]; + char DescriptionBuf[64]; + char SerialNumberBuf[16]; + + pData.Signature1 = 0x00000000; + pData.Signature2 = 0xffffffff; + pData.Version = 0x00000002; // EEPROM structure with FT232R extensions + pData.Manufacturer = ManufacturerBuf; + pData.ManufacturerId = ManufacturerIdBuf; + pData.Description = DescriptionBuf; + pData.SerialNumber = SerialNumberBuf; + + ftStatus = FT_Open(i, &fthHandle); + ftStatus = FT_EE_Read(fthHandle, &pData); + if(ftStatus == FT_OK){ + if(pData.VendorId == vid && pData.ProductId == pid){ + ftStatus = FT_Close(fthHandle); + return pData.SerialNumber; + } + } + ftStatus = FT_Close(fthHandle); + } + } + } + catch(...){ + throw; + } + return ""; +} diff --git a/driver/libtelldus-core/TellStick.h b/driver/libtelldus-core/TellStick.h new file mode 100644 index 00000000..c399f998 --- /dev/null +++ b/driver/libtelldus-core/TellStick.h @@ -0,0 +1,35 @@ +// +// C++ Interface: TellStick +// +// Description: +// +// +// Author: Micke Prag , (C) 2009 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef TELLSTICK_H +#define TELLSTICK_H + +#include "controller.h" + +/** + @author Micke Prag +*/ +namespace TelldusCore { + class TellStick : public Controller { + public: + virtual ~TellStick(); + + static int findFirstDevice(); + + protected: + TellStick(); + + private: + static std::string findByVIDPID( int vid, int pid ); + }; +} + +#endif