76 lines
1.5 KiB
C++
76 lines
1.5 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();
|
|
}
|
|
}
|
|
|
|
WirelessRelay::WirelessRelay( volatile unsigned char *port, const unsigned char pin, const uint16_t id):_id(id), _port(port), _pin(pin){}
|