#include"WirelessRelay.h" #include #include volatile unsigned char *_port = &PORTB; unsigned char _pin = PB5; 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) ); } } 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::setValue(const uint8_t value) { lastValue = value; for(short z = 0; z<10; z++) { sendId(); sendBit(value); sendBit(!value); sync(); } } void WirelessRelay::resend() { setValue(lastValue); } WirelessRelay::WirelessRelay(const uint16_t idIn, char nameIn[]) { id = idIn; setName(nameIn); type = 0; } WirelessRelay::WirelessRelay(const Item& item) { Item::operator=(item); type = 0; }