mirror of
https://github.com/esphome/esphome.git
synced 2026-10-21 13:34:12 +00:00
[yashima][remote_base] Send IR frame bytes with item_bytes, including most significant bit first (#21171)
This commit is contained in:
@@ -13,6 +13,15 @@ static const int32_t BIT_ONE_SPACE_US = 3 * TICK_US;
|
||||
static const int32_t BIT_ZERO_SPACE_US = 1 * TICK_US;
|
||||
static const int32_t FOOTER_MARK_US = 1 * TICK_US;
|
||||
static const int32_t FOOTER_SPACE_US = 10 * TICK_US;
|
||||
static constexpr BitTimings BIT_TIMINGS{.bit_mark = BIT_MARK_US,
|
||||
.one_space = BIT_ONE_SPACE_US,
|
||||
.zero_space = BIT_ZERO_SPACE_US,
|
||||
.bit_order = BitOrder::BIT_ORDER_MSB_FIRST};
|
||||
// The second copy of the frame is sent inverted
|
||||
static constexpr BitTimings INVERTED_BIT_TIMINGS{.bit_mark = BIT_MARK_US,
|
||||
.one_space = BIT_ZERO_SPACE_US,
|
||||
.zero_space = BIT_ONE_SPACE_US,
|
||||
.bit_order = BitOrder::BIT_ORDER_MSB_FIRST};
|
||||
|
||||
uint8_t MideaData::calc_cs_() const {
|
||||
uint8_t cs = 0;
|
||||
@@ -30,34 +39,15 @@ void MideaProtocol::encode(RemoteTransmitData *dst, const MideaData &src) {
|
||||
dst->set_carrier_frequency(38000);
|
||||
dst->reserve(2 + 48 * 2 + 2 + 2 + 48 * 2 + 1);
|
||||
dst->item(HEADER_MARK_US, HEADER_SPACE_US);
|
||||
for (unsigned idx = 0; idx < 6; idx++) {
|
||||
for (uint8_t mask = 1 << 7; mask; mask >>= 1)
|
||||
dst->item(BIT_MARK_US, (src[idx] & mask) ? BIT_ONE_SPACE_US : BIT_ZERO_SPACE_US);
|
||||
}
|
||||
dst->item_bytes<BIT_TIMINGS>(src.data(), src.size());
|
||||
dst->item(FOOTER_MARK_US, FOOTER_SPACE_US);
|
||||
dst->item(HEADER_MARK_US, HEADER_SPACE_US);
|
||||
for (unsigned idx = 0; idx < 6; idx++) {
|
||||
for (uint8_t mask = 1 << 7; mask; mask >>= 1)
|
||||
dst->item(BIT_MARK_US, (src[idx] & mask) ? BIT_ZERO_SPACE_US : BIT_ONE_SPACE_US);
|
||||
}
|
||||
dst->item_bytes<INVERTED_BIT_TIMINGS>(src.data(), src.size());
|
||||
dst->mark(FOOTER_MARK_US);
|
||||
}
|
||||
|
||||
static bool decode_data(RemoteReceiveData &src, MideaData &dst) {
|
||||
for (unsigned idx = 0; idx < 6; idx++) {
|
||||
uint8_t data = 0;
|
||||
for (uint8_t mask = 1 << 7; mask; mask >>= 1) {
|
||||
if (!src.expect_mark(BIT_MARK_US))
|
||||
return false;
|
||||
if (src.expect_space(BIT_ONE_SPACE_US)) {
|
||||
data |= mask;
|
||||
} else if (!src.expect_space(BIT_ZERO_SPACE_US)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
dst[idx] = data;
|
||||
}
|
||||
return true;
|
||||
return src.expect_bytes<BIT_TIMINGS>(dst.data(), dst.size());
|
||||
}
|
||||
|
||||
optional<MideaData> MideaProtocol::decode(RemoteReceiveData src) {
|
||||
|
||||
@@ -75,6 +75,10 @@ const uint16_t YASHIMA_BIT_MARK = 667;
|
||||
const uint16_t YASHIMA_ONE_SPACE = 517;
|
||||
const uint16_t YASHIMA_ZERO_SPACE = 1543;
|
||||
const uint32_t YASHIMA_GAP = YASHIMA_HEADER_SPACE;
|
||||
static constexpr remote_base::BitTimings YASHIMA_BIT_TIMINGS{.bit_mark = YASHIMA_BIT_MARK,
|
||||
.one_space = YASHIMA_ONE_SPACE,
|
||||
.zero_space = YASHIMA_ZERO_SPACE,
|
||||
.bit_order = remote_base::BitOrder::BIT_ORDER_MSB_FIRST};
|
||||
|
||||
const uint32_t YASHIMA_CARRIER_FREQUENCY = 38000;
|
||||
|
||||
@@ -181,14 +185,7 @@ void YashimaClimate::transmit_state_() {
|
||||
// Header
|
||||
data->mark(YASHIMA_HEADER_MARK);
|
||||
data->space(YASHIMA_HEADER_SPACE);
|
||||
// Data (sent from the MSB to the LSB)
|
||||
for (uint8_t i : remote_state) {
|
||||
for (int8_t j = 7; j >= 0; j--) {
|
||||
data->mark(YASHIMA_BIT_MARK);
|
||||
bool bit = i & (1 << j);
|
||||
data->space(bit ? YASHIMA_ONE_SPACE : YASHIMA_ZERO_SPACE);
|
||||
}
|
||||
}
|
||||
data->item_bytes<YASHIMA_BIT_TIMINGS>(remote_state, YASHIMA_STATE_LENGTH);
|
||||
// Footer
|
||||
data->mark(YASHIMA_BIT_MARK);
|
||||
data->space(YASHIMA_GAP);
|
||||
|
||||
Reference in New Issue
Block a user