increased reciver time tolerance
This commit is contained in:
@ -31,7 +31,7 @@ set(CMAKE_LINKER /usr/bin/avr-ld)
|
|||||||
|
|
||||||
# Compiler flags
|
# Compiler flags
|
||||||
add_definitions(-mmcu=${MCU} -DF_CPU=${CPU_SPEED})
|
add_definitions(-mmcu=${MCU} -DF_CPU=${CPU_SPEED})
|
||||||
add_definitions(-s -c -g -Os -Wall -std=c++17 )
|
add_definitions(-s -c -g -Os -flto -Wall -std=c++17 )
|
||||||
add_definitions(-fno-exceptions -ffunction-sections -fdata-sections)
|
add_definitions(-fno-exceptions -ffunction-sections -fdata-sections)
|
||||||
|
|
||||||
# Linker flags
|
# Linker flags
|
||||||
|
@ -29,18 +29,18 @@ int8_t W433DataReciver::reciveBit(uint8_t index)
|
|||||||
{
|
{
|
||||||
if(
|
if(
|
||||||
timesBuffer[index] < 0 &&
|
timesBuffer[index] < 0 &&
|
||||||
isTime(timesBuffer[index+1], SMALL_TIME, true) &&
|
isTime(timesBuffer[index+1], SMALL_TIME, true, SMALL_TIME_TOLERANCE) &&
|
||||||
isTime(timesBuffer[index+2], LARGE_TIME, false) &&
|
isTime(timesBuffer[index+2], LARGE_TIME, false, LARGE_TIME_TOLERANCE) &&
|
||||||
isTime(timesBuffer[index+3], SMALL_TIME, true)
|
isTime(timesBuffer[index+3], SMALL_TIME, true, SMALL_TIME_TOLERANCE)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else if(
|
else if(
|
||||||
timesBuffer[index] < 0 &&
|
timesBuffer[index] < 0 &&
|
||||||
isTime(timesBuffer[index+1], LARGE_TIME, true) &&
|
isTime(timesBuffer[index+1], LARGE_TIME, true, LARGE_TIME_TOLERANCE) &&
|
||||||
isTime(timesBuffer[index+2], SMALL_TIME, false) &&
|
isTime(timesBuffer[index+2], SMALL_TIME, false, SMALL_TIME_TOLERANCE) &&
|
||||||
isTime(timesBuffer[index+3], SMALL_TIME, true)
|
isTime(timesBuffer[index+3], SMALL_TIME, true, SMALL_TIME_TOLERANCE)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
@ -58,7 +58,7 @@ bool W433DataReciver::isTime(int16_t input, const uint16_t time, const bool stat
|
|||||||
|
|
||||||
bool W433DataReciver::reciveSync(const uint16_t elapsedTime)
|
bool W433DataReciver::reciveSync(const uint16_t elapsedTime)
|
||||||
{
|
{
|
||||||
if(elapsedTime < SYNC_TIME+50 && elapsedTime > SYNC_TIME-50)
|
if(elapsedTime < SYNC_TIME+SYNC_TIME_TOLERANCE && elapsedTime > SYNC_TIME-SYNC_TIME_TOLERANCE)
|
||||||
{
|
{
|
||||||
++syncCount;
|
++syncCount;
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,9 @@ private:
|
|||||||
static constexpr uint16_t SYNC_TIME = 800;
|
static constexpr uint16_t SYNC_TIME = 800;
|
||||||
static constexpr uint16_t LARGE_TIME = 2000;
|
static constexpr uint16_t LARGE_TIME = 2000;
|
||||||
static constexpr uint16_t SMALL_TIME = 500;
|
static constexpr uint16_t SMALL_TIME = 500;
|
||||||
|
static constexpr uint8_t SYNC_TIME_TOLERANCE = SYNC_TIME*0.15;
|
||||||
|
static constexpr uint8_t LARGE_TIME_TOLERANCE = LARGE_TIME*0.15;
|
||||||
|
static constexpr uint8_t SMALL_TIME_TOLERANCE = SMALL_TIME*0.15;
|
||||||
static constexpr uint16_t TICKS_PER_US = (F_CPU) / (1000000*CLOCK_DEVIDER) ;
|
static constexpr uint16_t TICKS_PER_US = (F_CPU) / (1000000*CLOCK_DEVIDER) ;
|
||||||
static constexpr uint8_t signature = 0xA5;
|
static constexpr uint8_t signature = 0xA5;
|
||||||
|
|
||||||
@ -59,7 +62,7 @@ private:
|
|||||||
inline bool recivedByte(const uint16_t elapsedTime);
|
inline bool recivedByte(const uint16_t elapsedTime);
|
||||||
inline bool reciveSync(const uint16_t elapsedTime);
|
inline bool reciveSync(const uint16_t elapsedTime);
|
||||||
|
|
||||||
static inline bool isTime(int16_t input, const uint16_t time, const bool state = true, const uint16_t tollerance = 50);
|
static inline bool isTime(int16_t input, const uint16_t time, const bool state = true, const uint16_t tollerance = 100);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
45
main.cpp
45
main.cpp
@ -13,7 +13,7 @@
|
|||||||
#include "W433DataReciver.h"
|
#include "W433DataReciver.h"
|
||||||
|
|
||||||
#define COMMAND_BUFFER_SIZE 64
|
#define COMMAND_BUFFER_SIZE 64
|
||||||
#define SNPRINTF_BUFFER_SIZE 64
|
#define SNPRINTF_BUFFER_SIZE 96
|
||||||
|
|
||||||
#define MAX_RELAYS 32
|
#define MAX_RELAYS 32
|
||||||
#define RELAY_VECTOR_EEPROM_ADDR 32
|
#define RELAY_VECTOR_EEPROM_ADDR 32
|
||||||
@ -49,7 +49,6 @@ inline static void printHelp(Serial* serial)
|
|||||||
rgb pattern [id] : RGB pattern.\n\
|
rgb pattern [id] : RGB pattern.\n\
|
||||||
rgb preset [id] : set preset color.\n\
|
rgb preset [id] : set preset color.\n\
|
||||||
rgb fade [on/off] : turn Colorfade on or off.\n\
|
rgb fade [on/off] : turn Colorfade on or off.\n\
|
||||||
aux [on/off] : Turn on/off PWM Channel.\n\
|
|
||||||
aux set [VAL] : Set PWM value.\n"));
|
aux set [VAL] : Set PWM value.\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,6 +57,11 @@ void save()
|
|||||||
EEPROM_write_class< SVector<WirelessRelay, MAX_RELAYS> > (RELAY_VECTOR_EEPROM_ADDR, relays);
|
EEPROM_write_class< SVector<WirelessRelay, MAX_RELAYS> > (RELAY_VECTOR_EEPROM_ADDR, relays);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void loadRGB(RgbLed* rgbled)
|
||||||
|
{
|
||||||
|
rgbled->setSolidColor(EEPROM_read_char(1), EEPROM_read_char(2), EEPROM_read_char(3));
|
||||||
|
}
|
||||||
|
|
||||||
void load()
|
void load()
|
||||||
{
|
{
|
||||||
EEPROM_read_class< SVector<WirelessRelay, MAX_RELAYS> > (RELAY_VECTOR_EEPROM_ADDR, &relays);
|
EEPROM_read_class< SVector<WirelessRelay, MAX_RELAYS> > (RELAY_VECTOR_EEPROM_ADDR, &relays);
|
||||||
@ -66,12 +70,12 @@ void load()
|
|||||||
void writeRelayState(Serial* serial, WirelessRelay* relay, uint8_t number)
|
void writeRelayState(Serial* serial, WirelessRelay* relay, uint8_t number)
|
||||||
{
|
{
|
||||||
uint16_t id = relay->getId();
|
uint16_t id = relay->getId();
|
||||||
snprintf(buffer, SNPRINTF_BUFFER_SIZE, "RELAY NUMBER: %u ID: %s%s%s NAME: %s STATE: %u\n", number,
|
snprintf(buffer, SNPRINTF_BUFFER_SIZE, "RELAY NUMBER: %u ID: %s%s%s STATE: %u NAME: %s\n", number,
|
||||||
bit_rep[ id >> 12],
|
bit_rep[ id >> 12],
|
||||||
bit_rep[(id & 0x0F00) >> 8 ],
|
bit_rep[(id & 0x0F00) >> 8 ],
|
||||||
bit_rep[(id & 0x00F0) >> 4 ],
|
bit_rep[(id & 0x00F0) >> 4 ],
|
||||||
relay->getName(),
|
relay->getExpectedState(),
|
||||||
relay->getExpectedState()
|
relay->getName()
|
||||||
);
|
);
|
||||||
serial->write(buffer, SNPRINTF_BUFFER_SIZE);
|
serial->write(buffer, SNPRINTF_BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
@ -176,7 +180,13 @@ void rgbDispatch(RgbLed* rgbled, char* token, Serial* serial)
|
|||||||
char* bToken = strtok(NULL, " \n");
|
char* bToken = strtok(NULL, " \n");
|
||||||
if(rToken != NULL && gToken != NULL && bToken != NULL)
|
if(rToken != NULL && gToken != NULL && bToken != NULL)
|
||||||
{
|
{
|
||||||
rgbled->setSolidColor(atoi(rToken), atoi(gToken), atoi(bToken));
|
uint8_t r = atoi(rToken);
|
||||||
|
uint8_t g = atoi(gToken);
|
||||||
|
uint8_t b = atoi(bToken);
|
||||||
|
rgbled->setSolidColor(r,g,b);
|
||||||
|
EEPROM_write_char(1, r);
|
||||||
|
EEPROM_write_char(2, g);
|
||||||
|
EEPROM_write_char(3, b);
|
||||||
serial->write_p(PSTR("Set RGB values\n"));
|
serial->write_p(PSTR("Set RGB values\n"));
|
||||||
}
|
}
|
||||||
else serial->write_p(PSTR("Usage: rgb set [RRR] [GGG] [BBB]\n"));
|
else serial->write_p(PSTR("Usage: rgb set [RRR] [GGG] [BBB]\n"));
|
||||||
@ -228,21 +238,13 @@ void rgbDispatch(RgbLed* rgbled, char* token, Serial* serial)
|
|||||||
|
|
||||||
void auxDispatch(Pwm16b* auxPwm, char* token, Serial* serial)
|
void auxDispatch(Pwm16b* auxPwm, char* token, Serial* serial)
|
||||||
{
|
{
|
||||||
if(strcmp(token, "on") == 0 )
|
if(strcmp(token, "set") == 0 )
|
||||||
{
|
|
||||||
auxPwm->on();
|
|
||||||
serial->write_p(PSTR("Aux pwm on\n"));
|
|
||||||
}
|
|
||||||
else if(strcmp(token, "off") == 0 )
|
|
||||||
{
|
|
||||||
auxPwm->off();
|
|
||||||
serial->write_p(PSTR("Aux pwm off\n"));
|
|
||||||
}
|
|
||||||
else if(strcmp(token, "set") == 0 )
|
|
||||||
{
|
{
|
||||||
token = strtok(NULL, " \n");
|
token = strtok(NULL, " \n");
|
||||||
if(token != NULL)
|
if(token != NULL)
|
||||||
{
|
{
|
||||||
|
if(atoi(token) == 0) auxPwm->off();
|
||||||
|
else auxPwm->on();
|
||||||
auxPwm->setDutyA(atoi(token) << 8);
|
auxPwm->setDutyA(atoi(token) << 8);
|
||||||
serial->write_p(PSTR("Set PWM value\n"));
|
serial->write_p(PSTR("Set PWM value\n"));
|
||||||
}
|
}
|
||||||
@ -251,7 +253,7 @@ void auxDispatch(Pwm16b* auxPwm, char* token, Serial* serial)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
serial->write(token, COMMAND_BUFFER_SIZE-4);
|
serial->write(token, COMMAND_BUFFER_SIZE-4);
|
||||||
serial->write_p(PSTR(" is not a valid subcommand: aux [on/off/set]\n"));
|
serial->write_p(PSTR(" is not a valid subcommand: aux set [value]\n"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,7 +266,7 @@ void serialDispatch(Serial* serial, SVector<WirelessRelay, MAX_RELAYS>* relays,
|
|||||||
unsigned int length = serial->getString(buffer, COMMAND_BUFFER_SIZE);
|
unsigned int length = serial->getString(buffer, COMMAND_BUFFER_SIZE);
|
||||||
if(length > 2)
|
if(length > 2)
|
||||||
{
|
{
|
||||||
cli();
|
setBit(&PCICR, PCIE1, false);
|
||||||
char* token = strtok(buffer, " \n");
|
char* token = strtok(buffer, " \n");
|
||||||
if(strcmp(token, "relay") == 0)
|
if(strcmp(token, "relay") == 0)
|
||||||
{
|
{
|
||||||
@ -294,6 +296,7 @@ void serialDispatch(Serial* serial, SVector<WirelessRelay, MAX_RELAYS>* relays,
|
|||||||
for(uint8_t i = 0; i < relays->count(); i++)
|
for(uint8_t i = 0; i < relays->count(); i++)
|
||||||
{
|
{
|
||||||
writeRelayState(serial, &relays->at(i), i);
|
writeRelayState(serial, &relays->at(i), i);
|
||||||
|
//serial->putChar('\n');
|
||||||
}
|
}
|
||||||
serial->write_p(PSTR("EOL\n"));
|
serial->write_p(PSTR("EOL\n"));
|
||||||
}
|
}
|
||||||
@ -320,7 +323,7 @@ void serialDispatch(Serial* serial, SVector<WirelessRelay, MAX_RELAYS>* relays,
|
|||||||
{
|
{
|
||||||
serial->write_p(PSTR("Not a valid command\n"));
|
serial->write_p(PSTR("Not a valid command\n"));
|
||||||
}
|
}
|
||||||
sei();
|
setBit(&PCICR, PCIE1, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -369,6 +372,7 @@ int main()
|
|||||||
pwmTc2.off();
|
pwmTc2.off();
|
||||||
|
|
||||||
RgbLed rgbled( &pwmTc0, &pwmTc2 );
|
RgbLed rgbled( &pwmTc0, &pwmTc2 );
|
||||||
|
loadRGB(&rgbled);
|
||||||
|
|
||||||
Pwm16b pwmTc1 ( &TCCR1A, &TCCR1B, &OCR1A, &OCR1B, &ICR1, 0b00000001, true, false);
|
Pwm16b pwmTc1 ( &TCCR1A, &TCCR1B, &OCR1A, &OCR1B, &ICR1, 0b00000001, true, false);
|
||||||
|
|
||||||
@ -423,3 +427,4 @@ int main()
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ void RgbLed::setSolidColor( const uint8_t r, const uint8_t g, const uint8_t b)
|
|||||||
_targetR = r;
|
_targetR = r;
|
||||||
_targetG = g;
|
_targetG = g;
|
||||||
_targetB = b;
|
_targetB = b;
|
||||||
(!_fade && r+b+g == 0) ? off() : on();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RgbLed::setPreset( const uint8_t preset)
|
void RgbLed::setPreset( const uint8_t preset)
|
||||||
@ -148,7 +147,7 @@ void RgbLed::patternStep()
|
|||||||
if(_counter<65530) _counter++;
|
if(_counter<65530) _counter++;
|
||||||
else _pwmB->setDutyB(140);
|
else _pwmB->setDutyB(140);
|
||||||
|
|
||||||
_delay_ms(18); //honey dose this make me look slow?
|
_delay_ms(18);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,13 +184,13 @@ void RgbLed::logic()
|
|||||||
|
|
||||||
uint8_t RgbLed::getR()
|
uint8_t RgbLed::getR()
|
||||||
{
|
{
|
||||||
return OCR0B;
|
return _pwmA->getValueB();
|
||||||
}
|
}
|
||||||
uint8_t RgbLed::getB()
|
uint8_t RgbLed::getB()
|
||||||
{
|
{
|
||||||
return OCR2B;
|
return _pwmB->getValueB();
|
||||||
}
|
}
|
||||||
uint8_t RgbLed::getG()
|
uint8_t RgbLed::getG()
|
||||||
{
|
{
|
||||||
return OCR0A;
|
return _pwmA->getValueA();
|
||||||
}
|
}
|
||||||
|
4
rgbled.h
4
rgbled.h
@ -7,6 +7,10 @@ private:
|
|||||||
Pwm8b* _pwmA;
|
Pwm8b* _pwmA;
|
||||||
Pwm8b* _pwmB;
|
Pwm8b* _pwmB;
|
||||||
|
|
||||||
|
static constexpr uint16_t calBlue[] = {1000, 1000, 1000};
|
||||||
|
static constexpr uint16_t calGreen[] = {1000, 1000, 1000};
|
||||||
|
static constexpr uint16_t calRed[] = {1000, 1000, 1000};
|
||||||
|
|
||||||
uint8_t _pattern = 0;
|
uint8_t _pattern = 0;
|
||||||
|
|
||||||
uint16_t _counter = 0;
|
uint16_t _counter = 0;
|
||||||
|
Reference in New Issue
Block a user