fix extra zero

This commit is contained in:
DashyFox 2024-01-24 18:24:46 +03:00
parent d629b24864
commit fdcb22b1a1
2 changed files with 18 additions and 11 deletions

View File

@ -24,31 +24,38 @@ void IR_Decoder::writeToBuffer(bool bit) {
if (bufBitPos == nextControlBit) {
nextControlBit += (isData ? syncBits : bitPerByte);
isData = !isData;
i_syncBit = 0;
Serial.print(" ");
}
Serial.print(bit);
if (isData) { // Запись битов в dataBuffer
dataBuffer[(i_dataBuffer / 8)] |= bit << (7 - i_dataBuffer%8);
if (i_dataBuffer % 8 == 7) {
Serial.print("+");
}
dataBuffer[(i_dataBuffer / 8)] |= bit << (7 - i_dataBuffer % 8);
i_dataBuffer++;
bufBitPos++;
i_syncBit = 0;
} else { // Проверка контрольных sync битов
if (i_syncBit == 0) { // Первый бит синхронизации
if (bit != dataBuffer[((i_dataBuffer - 1) / 8)] & 1 << (7 - ((i_dataBuffer - 1) & ~(~0 << 3)))) {
Serial.print("~");
if (bit != (dataBuffer[((i_dataBuffer - 1) / 8)] & 1 << (7 - (i_dataBuffer - 1) % 8) & 1)) {
bufBitPos++;
i_syncBit++;
} else {
i_syncBit = 0;
errorCounter++;
Serial.print("E");
// Serial.print("bit: ");Serial.println(bit);
// Serial.print("dataBuffer: ");Serial.println(dataBuffer[((i_dataBuffer - 1) / 8)] & 1 << (7 - ((i_dataBuffer - 1) & ~(~0 << 3))));
// Serial.print("bit: "); Serial.println(bit);
// Serial.print("dataBuffer: "); Serial.println(dataBuffer[((i_dataBuffer - 1) / 8)] & 1 << (7 - ((i_dataBuffer - 1) & ~(~0 << 3))));
}
} else { // Последующие биты синхронизации
Serial.print("`");
bufBitPos++;
}
i_syncBit++;
}
}
Serial.print(bit);
// if (bufBitPos >= bufferRawSize * 8 - 1) { isBufferOverflow = true; }

View File

@ -21,7 +21,7 @@
#define aroundRise(t) (riseTimeMin < t && t < riseTimeMax)
#define IR_timeout ((riseTimeMax * 8) + syncBits +1) // us // таймаут в 8 data + 3 sync + 1
#define subBufferSize 15 //Буфер для складирования фронтов, пока их не обработают
#define subBufferSize 5 //Буфер для складирования фронтов, пока их не обработают
class IR_Encoder;
class IR_Decoder : private IR_FOX {