Added protocol SilvanChip. Right now it only work with a TellStick Duo.

This commit is contained in:
Micke Prag 2010-09-29 12:46:10 +00:00
parent 6ace9fb071
commit a049d60090
4 changed files with 173 additions and 0 deletions

View file

@ -16,6 +16,7 @@ SET( telldus-core_SRCS
DeviceFuhaote.cpp
DeviceGroup.cpp
DeviceIkea.cpp
DeviceSilvanChip.cpp
DeviceNexa.cpp
DeviceRisingSun.cpp
DeviceSartano.cpp

View file

@ -0,0 +1,137 @@
#include "DeviceSilvanChip.h"
#include <string>
using namespace TelldusCore;
/*
* Constructor
*/
DeviceSilvanChip::DeviceSilvanChip(int id, const std::string &model, const std::string &name)
:Device(id, model, name)
{
}
DeviceSilvanChip::~DeviceSilvanChip(void)
{
}
bool DeviceSilvanChip::setHouse(const std::string &strNewHouse) {
intHouse = atoi(strNewHouse.c_str());
return true;
}
bool DeviceSilvanChip::setDeviceParameter(const std::string &strName, const std::string &strValue) {
if (strName.compare("house") == 0) {
return setHouse(strValue);
}
return false;
}
/*
* Turn on this device
*/
int DeviceSilvanChip::turnOn(Controller *controller){
std::string strCode = getStringCode(controller, TELLSTICK_TURNON);
return controller->send(strCode);
}
/*
* Turn off this device
*/
int DeviceSilvanChip::turnOff(Controller *controller){
std::string strCode = getStringCode(controller, TELLSTICK_TURNOFF);
return controller->send(strCode);
}
int DeviceSilvanChip::learn(Controller *controller) {
std::string strCode = getStringCode(controller, TELLSTICK_LEARN);
return controller->send(strCode);
}
bool DeviceSilvanChip::parameterMatches( const std::string &name, const std::string &value ) const {
return false;
}
/*
* Has the device got the method?
*/
int DeviceSilvanChip::methods(){
return (TELLSTICK_TURNON | TELLSTICK_TURNOFF | TELLSTICK_LEARN);
}
std::string DeviceSilvanChip::getStringCode(Controller *controller, int method){
const unsigned char S = 100;
const unsigned char L = 255;
const std::string LONG = "\255\1\200";
const std::string ONE = LONG + "\100";
const std::string ZERO = "\100" + LONG;
std::string strReturn = "R\1S";
strReturn.append(1, S);
strReturn.append(1, L);
strReturn.append(1, 1);
strReturn.append(1, L);
strReturn.append(1, 1);
strReturn.append(1, L);
strReturn.append(1, 1);
strReturn.append(1, L);
strReturn.append(1, 1);
strReturn.append(1, L);
strReturn.append(1, 1);
strReturn.append(1, L);
strReturn.append(1, 1);
strReturn.append(1, L);
strReturn.append(1, 1);
strReturn.append(1, L);
strReturn.append(1, 1);
strReturn.append(1, L);
strReturn.append(1, 1);
strReturn.append(1, L);
strReturn.append(1, 1);
strReturn.append(1, L);
strReturn.append(1, 1);
strReturn.append(1, L);
strReturn.append(1, 1);
strReturn.append(1, S);
for( int i = 19; i >= 0; --i ) {
if (intHouse & (1 << i)) {
strReturn.append(ONE);
} else {
strReturn.append(ZERO);
}
}
if (method == TELLSTICK_TURNON) {
strReturn.append(ZERO);
strReturn.append(ZERO);
strReturn.append(ONE);
strReturn.append(ZERO);
} else if (method == TELLSTICK_LEARN) {
strReturn.append(ZERO);
strReturn.append(ZERO);
strReturn.append(ZERO);
strReturn.append(ONE);
} else {
strReturn.append(ONE);
strReturn.append(ZERO);
strReturn.append(ZERO);
strReturn.append(ZERO);
}
strReturn.append(ZERO);
strReturn.append("+");
return strReturn;
}
std::string DeviceSilvanChip::getProtocol() const {
return "silvanchip";
}

View file

@ -0,0 +1,30 @@
#pragma once
#include "Device.h"
#include <string>
namespace TelldusCore {
class DeviceSilvanChip : public Device
{
public:
DeviceSilvanChip(int id, const std::string &model, const std::string &name);
virtual ~DeviceSilvanChip(void);
virtual int methods();
virtual std::string getProtocol() const;
virtual bool parameterMatches( const std::string &name, const std::string &value ) const;
bool setHouse(const std::string &strNewHouse);
protected:
virtual bool setDeviceParameter(const std::string &strName, const std::string &strValue);
virtual int turnOn(Controller *controller);
virtual int turnOff(Controller *controller);
virtual int learn(Controller *controller);
std::string getStringCode(Controller *controller, int method);
int intHouse;
};
}

View file

@ -16,6 +16,7 @@
#include "DeviceEverflourish.h"
#include "DeviceFuhaote.h"
#include "DeviceGroup.h"
#include "DeviceSilvanChip.h"
#include "DeviceNexa.h"
#include "DeviceRisingSun.h"
#include "DeviceWaveman.h"
@ -105,6 +106,10 @@ Device *Manager::getDevice(int intDeviceId){
dev = new DeviceFuhaote(intDeviceId, strModel, strName);
((DeviceFuhaote*)dev)->setCode(settings.getDeviceParameter(intDeviceId, "code"));
} else if (strcasecmp(protocol.c_str(), "silvanchip") == 0) {
dev = new DeviceSilvanChip(intDeviceId, strModel, strName);
((DeviceSilvanChip*)dev)->setHouse(settings.getDeviceParameter(intDeviceId, "house"));
} else if (strcasecmp(protocol.c_str(), "group") == 0) {
dev = new DeviceGroup(intDeviceId, strModel, strName);
((DeviceGroup*)dev)->setDevices(settings.getDeviceParameter(intDeviceId, "devices"));