1
0
mirror of https://github.com/esphome/esphome.git synced 2025-03-15 15:18:16 +00:00

bugfix clang/tidy

This commit is contained in:
aanban 2025-02-24 17:12:30 +01:00
parent a2407455e9
commit e3072e2078

View File

@ -28,13 +28,13 @@ constexpr uint32_t N_BITS = 1 + 8 + 8;
constexpr uint32_t N_SYM = 2 + ((3 + 17 + 1) * 2u); // + 2 = 44 constexpr uint32_t N_SYM = 2 + ((3 + 17 + 1) * 2u); // + 2 = 44
// states finite-state-machine decoder // states finite-state-machine decoder
enum class rxSt { Idle, Data, Stop }; enum class RxSt {RX_IDLE, RX_DATA, RX_STOP};
void Beo4Protocol::encode(RemoteTransmitData *dst, const Beo4Data &data) { void Beo4Protocol::encode(RemoteTransmitData *dst, const Beo4Data &data) {
uint32_t beoCode = ((uint32_t) data.source << 8) + (uint32_t) data.command; uint32_t beo_code = ((uint32_t) data.source << 8) + (uint32_t) data.command;
uint32_t jc = 0, ic = 0; // loop counters uint32_t jc = 0, ic = 0; // loop counters
uint32_t curBit = 0; // current bit uint32_t cur_bit = 0; // current bit
uint32_t preBit = 0; // previous bit to compare uint32_t pre_bit = 0; // previous bit to compare
dst->set_carrier_frequency(455000); dst->set_carrier_frequency(455000);
dst->reserve(N_SYM); dst->reserve(N_SYM);
@ -51,14 +51,15 @@ void Beo4Protocol::encode(RemoteTransmitData *dst, const Beo4Data &data) {
// to right, then comparing current with previous bit // to right, then comparing current with previous bit
// and set pulse to "same" "one" or "zero" // and set pulse to "same" "one" or "zero"
for (jc = 15, ic = 0; ic < 16; ic++, jc--) { for (jc = 15, ic = 0; ic < 16; ic++, jc--) {
curBit = ((beoCode) >> jc) & 1; cur_bit = ((beo_code) >> jc) & 1;
if (curBit == preBit) if (cur_bit == pre_bit) {
dst->item(PW_CARR_US, PW_SAME_US); dst->item(PW_CARR_US, PW_SAME_US);
else if (1 == curBit) } else if (1 == cur_bit) {
dst->item(PW_CARR_US, PW_ONE_US); dst->item(PW_CARR_US, PW_ONE_US);
else } else {
dst->item(PW_CARR_US, PW_ZERO_US); dst->item(PW_CARR_US, PW_ZERO_US);
preBit = curBit; }
pre_bit = cur_bit;
} }
// complete the frame with stop-symbol and final carrier pulse // complete the frame with stop-symbol and final carrier pulse
dst->item(PW_CARR_US, PW_STOP_US); dst->item(PW_CARR_US, PW_STOP_US);
@ -74,62 +75,63 @@ optional<Beo4Data> Beo4Protocol::decode(RemoteReceiveData src) {
.repeats = 0, .repeats = 0,
}; };
if (n_sym > 42) { // suppress dummy codes (TSO7000 hiccups) if (n_sym > 42) { // suppress dummy codes (TSO7000 hiccups)
static uint32_t beoCode = 0; // decoded beoCode static uint32_t beo_code = 0; // decoded beo_code
rxSt rxFSM = rxSt::Idle; // begin in idle state RxSt fsm = RxSt::RX_IDLE; // begin in IDLE state
int32_t ic = 0, jc = 0; int32_t ic = 0;
uint32_t preBit = 0; // previous bit int32_t jc = 0;
uint32_t cntBit = 0; // bit counter uint32_t pre_bit = 0; // previous bit
uint32_t cnt_bit = 0; // bit counter
ESP_LOGD(TAG, "Beo4: n_sym=%d ", n_sym); ESP_LOGD(TAG, "Beo4: n_sym=%d ", n_sym);
for (jc = 0, ic = 0; ic < (n_sym - 1); ic += 2, jc++) { for (jc = 0, ic = 0; ic < (n_sym - 1); ic += 2, jc++) {
int32_t pulseWidth = src[ic] - src[ic + 1]; int32_t pulse_width = src[ic] - src[ic + 1];
if (pulseWidth > 1500) { // suppress TSOP7000 (dummy pulses) if (pulse_width > 1500) { // suppress TSOP7000 (dummy pulses)
int32_t pulseCode = (pulseWidth + 1560) / 3125; int32_t pulse_code = (pulse_width + 1560) / 3125;
switch (rxFSM) { switch (fsm) {
case rxSt::Idle: { // waiting until start-code case RxSt::RX_IDLE: { // waiting for start-code
beoCode = 0; beo_code = 0;
cntBit = 0; cnt_bit = 0;
preBit = 0; pre_bit = 0;
if (PC_START == pulseCode) { if (PC_START == pulse_code) {
rxFSM = rxSt::Data; // next--> collect data fsm = RxSt::RX_DATA; // next--> collecting data
} }
break; break;
} }
case rxSt::Data: { // collecting data case RxSt::RX_DATA: { // collecting data
uint32_t curBit = 0; uint32_t cur_bit = 0;
switch (pulseCode) { switch (pulse_code) {
case PC_ZERO: { case PC_ZERO: {
curBit = preBit = 0; cur_bit = pre_bit = 0;
break; break;
} }
case PC_SAME: { case PC_SAME: {
curBit = preBit; cur_bit = pre_bit;
break; break;
} }
case PC_ONE: { case PC_ONE: {
curBit = preBit = 1; cur_bit = pre_bit = 1;
break; break;
} }
default: { default: {
rxFSM = rxSt::Idle; // frame is faulty, reset and.. fsm = RxSt::RX_IDLE; // frame is faulty, reset and..
break; // ..process further symbols break; // ..process further symbols
} }
} }
beoCode = (beoCode << 1) + curBit; beo_code = (beo_code << 1) + cur_bit;
if (++cntBit == N_BITS) { // beoCode is complete if (++cnt_bit == N_BITS) { // beo_code is complete
rxFSM = rxSt::Stop; // next--> validate stop-code fsm = RxSt::RX_STOP; // next--> validate stop-code
} }
break; break;
} }
case rxSt::Stop: { // validate stop code case RxSt::RX_STOP: { // validating stop code
if (PC_STOP == pulseCode) { // stop code valid if (PC_STOP == pulse_code) { // stop code valid
data.source = (uint8_t) ((beoCode >> 8) & 0xff); data.source = (uint8_t) ((beo_code >> 8) & 0xff);
data.command = (uint8_t) ((beoCode) &0xff); data.command = (uint8_t) ((beo_code) &0xff);
data.repeats++; // update counter data.repeats++; // count repeats
} }
if ((n_sym - ic) < 42) { if ((n_sym - ic) < 42) {
return data; // no more frames, so return here return data; // no more frames, so return here
} else { } else {
rxFSM = rxSt::Idle; // process further symbols fsm = RxSt::RX_IDLE; // process further symbols
} }
break; break;
} }