Started refactoring Device into Controllers
This commit is contained in:
parent
72cc92b5af
commit
c688af38c4
5 changed files with 129 additions and 6 deletions
|
@ -22,6 +22,7 @@ SET( telldus-core_SRCS
|
||||||
Controller.cpp
|
Controller.cpp
|
||||||
Manager.cpp
|
Manager.cpp
|
||||||
Settings.cpp
|
Settings.cpp
|
||||||
|
TellStick.cpp
|
||||||
telldus-core.cpp
|
telldus-core.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -21,13 +21,13 @@
|
||||||
namespace TelldusCore {
|
namespace TelldusCore {
|
||||||
class Controller {
|
class Controller {
|
||||||
public:
|
public:
|
||||||
Controller();
|
|
||||||
|
|
||||||
virtual ~Controller();
|
virtual ~Controller();
|
||||||
|
|
||||||
virtual int firmwareVersion() = 0;
|
virtual int firmwareVersion() = 0;
|
||||||
virtual int send( const std::string &message ) = 0;
|
virtual int send( const std::string &message ) = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Controller();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
#include "Controller.h"
|
#include "Controller.h"
|
||||||
#ifdef TELLSTICK_DUO
|
#ifdef TELLSTICK_DUO
|
||||||
#include "TellStickDuo.h"
|
#include "TellStick.h"
|
||||||
#endif
|
#endif
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
|
@ -46,8 +46,10 @@ Manager::Manager()
|
||||||
: lastCallbackId(0)
|
: lastCallbackId(0)
|
||||||
{
|
{
|
||||||
#ifdef TELLSTICK_DUO
|
#ifdef TELLSTICK_DUO
|
||||||
Controller *controller = new TellStickDuo("TSQVB5HU");
|
/* Controller *controller = TellStick::findFirstDevice();
|
||||||
|
if (controller) {
|
||||||
controllers[1] = controller;
|
controllers[1] = controller;
|
||||||
|
}*/
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
85
driver/libtelldus-core/TellStick.cpp
Normal file
85
driver/libtelldus-core/TellStick.cpp
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
//
|
||||||
|
// C++ Implementation: TellStick
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Author: Micke Prag <micke.prag@telldus.se>, (C) 2009
|
||||||
|
//
|
||||||
|
// Copyright: See COPYING file that comes with this distribution
|
||||||
|
//
|
||||||
|
//
|
||||||
|
#include "TellStick.h"
|
||||||
|
#include "ftd2xx.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
|
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 "";
|
||||||
|
}
|
35
driver/libtelldus-core/TellStick.h
Normal file
35
driver/libtelldus-core/TellStick.h
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
//
|
||||||
|
// C++ Interface: TellStick
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Author: Micke Prag <micke.prag@telldus.se>, (C) 2009
|
||||||
|
//
|
||||||
|
// Copyright: See COPYING file that comes with this distribution
|
||||||
|
//
|
||||||
|
//
|
||||||
|
#ifndef TELLSTICK_H
|
||||||
|
#define TELLSTICK_H
|
||||||
|
|
||||||
|
#include "controller.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
@author Micke Prag <micke.prag@telldus.se>
|
||||||
|
*/
|
||||||
|
namespace TelldusCore {
|
||||||
|
class TellStick : public Controller {
|
||||||
|
public:
|
||||||
|
virtual ~TellStick();
|
||||||
|
|
||||||
|
static int findFirstDevice();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
TellStick();
|
||||||
|
|
||||||
|
private:
|
||||||
|
static std::string findByVIDPID( int vid, int pid );
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Add table
Add a link
Reference in a new issue