Files
RGBController/WirelessRelay.cpp
2017-05-19 09:48:19 +02:00

94 lines
1.8 KiB
C++

#include"WirelessRelay.h"
void WirelessRelay::sendId()
{
writePin(_port,_pin,true);
_delay_us(SMALL_TIME);
writePin(_port,_pin,false);
_delay_us(LARGE_TIME);
for(short i = 0; i<10; i++)
{
sendBit( _id & 1 << (15 - i) ? true : false );
}
}
void WirelessRelay::sendBit(const bool in)
{
switch(in)
{
case true:
//Der Code fuer '0'
writePin(_port,_pin,true);
_delay_us(SMALL_TIME);
writePin(_port,_pin,false);
_delay_us(LARGE_TIME);
writePin(_port,_pin,true);
_delay_us(SMALL_TIME);
writePin(_port,_pin,false);
_delay_us(LARGE_TIME);
break;
case false:
//Der Code fuer '1'
writePin(_port,_pin,true);
_delay_us(LARGE_TIME);
writePin(_port,_pin,false);
_delay_us(SMALL_TIME);
writePin(_port,_pin,true);
_delay_us(SMALL_TIME);
writePin(_port,_pin,false);
_delay_us(LARGE_TIME);
break;
}
}
void WirelessRelay::sync()
{
writePin(_port,_pin,false);
_delay_us(SMALL_TIME*31);
}
void WirelessRelay::on()
{
for(short z = 0; z<10; z++)
{
sendId();
sendBit(true);
sendBit(false);
sync();
}
}
void WirelessRelay::off()
{
for(short z = 0; z<10; z++)
{
sendId();
sendBit(false);
sendBit(true);
sync();
}
}
uint16_t WirelessRelay::getId()
{
return _id;
}
void WirelessRelay::init( volatile unsigned char *port, const unsigned char pin, const uint16_t id)
{
_port=port;
_id=id;
_pin=pin;
}
WirelessRelay::WirelessRelay( volatile unsigned char *port, const unsigned char pin, const uint16_t id)
{
init( port, pin, id);
}
WirelessRelay::WirelessRelay(){}