add missing files, support display blanking
This commit is contained in:
85
WirelessRelay.cpp
Normal file
85
WirelessRelay.cpp
Normal file
@ -0,0 +1,85 @@
|
||||
#include"WirelessRelay.h"
|
||||
#include <avr/io.h>
|
||||
#include <string.h>
|
||||
|
||||
volatile unsigned char *_port = &PORTD;
|
||||
unsigned char _pin = PD2;
|
||||
|
||||
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;
|
||||
}
|
Reference in New Issue
Block a user