Skip to content
This repository has been archived by the owner on Dec 28, 2018. It is now read-only.

Commit

Permalink
chnage folder structure
Browse files Browse the repository at this point in the history
  • Loading branch information
lexruee committed Jan 28, 2015
1 parent e80f352 commit 54ac5ab
Show file tree
Hide file tree
Showing 29 changed files with 2,460 additions and 59 deletions.
File renamed without changes.
54 changes: 0 additions & 54 deletions pi_switch/README.md

This file was deleted.

1 change: 1 addition & 0 deletions pi_switch/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from pi_switch_wrapper import *
1 change: 0 additions & 1 deletion pi_switch/pi_switch
Submodule pi_switch deleted from 4a4401
458 changes: 458 additions & 0 deletions pi_switch/wrapper/LICENSE.txt

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pi_switch/wrapper/RCSwitch/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.o
14 changes: 14 additions & 0 deletions pi_switch/wrapper/RCSwitch/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
CC=g++
CFLAGS=-Wall -c
LDFLAGS=-lwiringPi -lpthread

all: PiSwitch.o

PiSwitch.o:
$(CC) $(CFLAGS) PiSwitch.cpp -o PiSwitch.o $(LDFLAGS)

test: test.cpp
$(CC) test.cpp -o test.o $(LDFLAGS)

clean:
rm *.o
245 changes: 245 additions & 0 deletions pi_switch/wrapper/RCSwitch/PiSwitch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
/*
PiSwitch - RaspberryPi library for remote control outlet switches
Copyright (c) 2015 Alexander Rueedlinger. All right reserved.
Project home: https://github.com/lexruee/pi_switch
This library is a port of the RCSwitch - Arduino library.
Project home: http://code.google.com/p/rc-switch/
The RCSwitch team did a great job for providing us such a great
library! So thanks to all RCSwitch contributors:
- Suat Özgür
- Andre Koehler
- Gordeev Andrey Vladimirovich
- Skineffect
- Dominik Fischer
- Frank Oltmanns
- Andreas Steinel
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "PiSwitch.h"
#include "RCSwitch.cpp"

/*
* This file provides Proxy classes for all available RCSwitch types:
* - Type A with 10 pole DIP switches
* - Type B with two rotary/sliding switches
* - Type C Intertechno
* - Type D REV
*
* Besides that a RCSwitchSender class is provided to
* create new switch types in a more OOP way.
*/


/*
* RCSwitchSender implementation.
*/

RCSwitchSender::RCSwitchSender() {
this->rcSwitch = new RCSwitch;
}

RCSwitchSender::~RCSwitchSender() {
delete rcSwitch;
}

void RCSwitchSender::sendTriState(std::string Code) {
char *cCode = new char[Code.length()+1];
std::strcpy(cCode, Code.c_str());
rcSwitch->sendTriState(cCode);
delete[] cCode;
}

void RCSwitchSender::send(unsigned long Code, unsigned int length) {
rcSwitch->send(Code, length);
}

void RCSwitchSender::send(std::string Code) {
char *cCode = new char[Code.length()+1];
std::strcpy(cCode, Code.c_str());
rcSwitch->send(cCode);
delete[] cCode;
}

void RCSwitchSender::enableTransmit(int nTransmitterPin) {
rcSwitch->enableTransmit(nTransmitterPin);
}

void RCSwitchSender::disableTransmit() {
rcSwitch->disableTransmit();
}

void RCSwitchSender::setPulseLength(int nPulseLength) {
rcSwitch->setPulseLength(nPulseLength);
}

void RCSwitchSender::setRepeatTransmit(int nRepeatTransmit) {
rcSwitch->setRepeatTransmit(nRepeatTransmit);
}

void RCSwitchSender::setProtocol(int nProtocol) {
rcSwitch->setProtocol(nProtocol);
}

void RCSwitchSender::setProtocol(int nProtocol, int nPulseLength) {
rcSwitch->setProtocol(nProtocol, nPulseLength);
}


/*
* RCSwitchProxy implementation.
*/
void RCSwitchProxy::init() {
this->rcSwitch = new RCSwitch;
}

void RCSwitchProxy::enableTransmit(int pin) {
rcSwitch->enableTransmit(pin);
}


void RCSwitchProxy::disableTransmit() {
rcSwitch->disableTransmit();
}

void RCSwitchProxy::destroy(){
delete rcSwitch;
}


/*
* RCSwitch type A implementation.
*/
class RCSwitchA: public RCSwitchProxy {
public:
RCSwitchA(std::string groupCode, std::string deviceCode){
cDeviceCode = new char[deviceCode.length()+1];
cGroupCode = new char[groupCode.length()+1];
std::strcpy(cDeviceCode, deviceCode.c_str());
std::strcpy(cGroupCode, groupCode.c_str());
this->init();
}

void switchOn(){
rcSwitch->switchOn(cGroupCode, cDeviceCode);
}

void switchOff(){
rcSwitch->switchOff(cGroupCode, cDeviceCode);
}

~RCSwitchA(){
this->destroy();
delete[] cGroupCode;
delete[] cDeviceCode;
}

private:
char *cGroupCode;
char *cDeviceCode;
};


/*
* RCSwitch type B implementation.
*/
class RCSwitchB: public RCSwitchProxy {
public:
RCSwitchB(int addressCode, int channelCode) {
this->addressCode = addressCode;
this->channelCode = channelCode;
this->init();
}

void switchOn(){
rcSwitch->switchOn(addressCode, channelCode);
}

void switchOff(){
rcSwitch->switchOff(addressCode, channelCode);
}

~RCSwitchB(){
this->destroy();
}

private:
int addressCode;
int channelCode;
};


/*
* RCSwitch type C implementation.
*/
class RCSwitchC: public RCSwitchProxy {
public:
RCSwitchC(std::string family, int groupCode, int deviceCode) {
this->family = family;
this->deviceCode = deviceCode;
this->groupCode = groupCode;
this->init();
}

void switchOn(){
rcSwitch->switchOn(family[0], groupCode, deviceCode);
}

void switchOff(){
rcSwitch->switchOff(family[0], groupCode, deviceCode);
}

~RCSwitchC(){
this->destroy();
}

private:
std::string family;
int groupCode;
int deviceCode;
};


/*
* RCSwitch type D implementation.
*/
class RCSwitchD: public RCSwitchProxy {
public:
RCSwitchD(std::string groupCode, int deviceCode) {
this->groupCode = groupCode;
this->deviceCode = deviceCode;
this->init();
}

void switchOn(){
rcSwitch->switchOn(groupCode[0], deviceCode);
}

void switchOff(){
rcSwitch->switchOff(groupCode[0], deviceCode);
}

~RCSwitchD(){
this->destroy();
}

private:
std::string groupCode;
int deviceCode;
};
Loading

0 comments on commit 54ac5ab

Please sign in to comment.