mirror of
https://github.com/Show-maket/IR-protocol.git
synced 2025-05-04 15:20:16 +00:00
35 lines
851 B
C++
35 lines
851 B
C++
#include "IR_config.h"
|
|
|
|
void IR_FOX::setPin(uint8_t pin){
|
|
this->pin = pin;
|
|
port = digitalPinToPort(pin);
|
|
mask = digitalPinToBitMask(pin);
|
|
pinMode(pin, INPUT_PULLUP);
|
|
}
|
|
|
|
void IR_FOX::checkAddressRuleApply(uint16_t address, uint16_t id, bool &flag)
|
|
{
|
|
flag = false;
|
|
flag |= id == 0;
|
|
flag |= address == id;
|
|
flag |= address >= IR_Broadcast;
|
|
}
|
|
|
|
uint8_t IR_FOX::crc8(uint8_t *data, uint8_t start, uint8_t end, uint8_t poly)
|
|
{ // TODO: сделать возможность межбайтовой проверки
|
|
uint8_t crc = 0xff;
|
|
size_t i, j;
|
|
for (i = start; i < end; i++)
|
|
{
|
|
crc ^= data[i];
|
|
for (j = 0; j < 8; j++)
|
|
{
|
|
if ((crc & 0x80) != 0)
|
|
crc = (uint8_t)((crc << 1) ^ poly);
|
|
else
|
|
crc <<= 1;
|
|
}
|
|
}
|
|
return crc;
|
|
};
|