2021-07-08 21:20:13 +03:00
|
|
|
#include "furi/check.h"
|
2022-02-25 18:22:58 +03:00
|
|
|
#include "common/infrared_common_i.h"
|
2021-05-18 13:51:00 +03:00
|
|
|
#include <stdint.h>
|
2022-02-25 18:22:58 +03:00
|
|
|
#include "../infrared_i.h"
|
|
|
|
#include "infrared_protocol_defs_i.h"
|
2021-07-08 21:20:13 +03:00
|
|
|
#include <furi.h>
|
2021-05-18 13:51:00 +03:00
|
|
|
|
2021-07-08 21:20:13 +03:00
|
|
|
static const uint32_t repeat_timings[] = {
|
2022-02-25 18:22:58 +03:00
|
|
|
INFRARED_SAMSUNG_REPEAT_PAUSE2,
|
|
|
|
INFRARED_SAMSUNG_REPEAT_MARK,
|
|
|
|
INFRARED_SAMSUNG_REPEAT_SPACE,
|
|
|
|
INFRARED_SAMSUNG_BIT1_MARK,
|
|
|
|
INFRARED_SAMSUNG_BIT1_SPACE,
|
|
|
|
INFRARED_SAMSUNG_BIT1_MARK,
|
2021-05-18 13:51:00 +03:00
|
|
|
};
|
|
|
|
|
2022-02-25 18:22:58 +03:00
|
|
|
void infrared_encoder_samsung32_reset(void* encoder_ptr, const InfraredMessage* message) {
|
2021-07-08 21:20:13 +03:00
|
|
|
furi_assert(encoder_ptr);
|
|
|
|
|
2022-02-25 18:22:58 +03:00
|
|
|
InfraredCommonEncoder* encoder = encoder_ptr;
|
|
|
|
infrared_common_encoder_reset(encoder);
|
2021-05-18 13:51:00 +03:00
|
|
|
|
2021-07-08 21:20:13 +03:00
|
|
|
uint8_t address = message->address;
|
|
|
|
uint8_t command = message->command;
|
|
|
|
uint8_t command_inverse = ~command;
|
|
|
|
|
2022-01-05 19:10:18 +03:00
|
|
|
uint32_t* data = (void*)encoder->data;
|
2021-07-08 21:20:13 +03:00
|
|
|
*data |= address;
|
|
|
|
*data |= address << 8;
|
|
|
|
*data |= command << 16;
|
|
|
|
*data |= command_inverse << 24;
|
2021-09-15 20:22:58 +03:00
|
|
|
|
|
|
|
encoder->bits_to_encode = encoder->protocol->databit_len[0];
|
2021-05-18 13:51:00 +03:00
|
|
|
}
|
|
|
|
|
2022-02-25 18:22:58 +03:00
|
|
|
InfraredStatus infrared_encoder_samsung32_encode_repeat(
|
|
|
|
InfraredCommonEncoder* encoder,
|
2022-01-05 19:10:18 +03:00
|
|
|
uint32_t* duration,
|
|
|
|
bool* level) {
|
2021-07-08 21:20:13 +03:00
|
|
|
furi_assert(encoder);
|
|
|
|
|
|
|
|
/* space + 2 timings preambule + payload + stop bit */
|
2021-09-15 20:22:58 +03:00
|
|
|
uint32_t timings_encoded_up_to_repeat = 1 + 2 + encoder->bits_encoded * 2 + 1;
|
2021-07-08 21:20:13 +03:00
|
|
|
uint32_t repeat_cnt = encoder->timings_encoded - timings_encoded_up_to_repeat;
|
|
|
|
|
|
|
|
furi_assert(encoder->timings_encoded >= timings_encoded_up_to_repeat);
|
|
|
|
|
2022-01-05 19:10:18 +03:00
|
|
|
if(repeat_cnt > 0)
|
2021-07-08 21:20:13 +03:00
|
|
|
*duration = repeat_timings[repeat_cnt % COUNT_OF(repeat_timings)];
|
|
|
|
else
|
2022-02-25 18:22:58 +03:00
|
|
|
*duration = INFRARED_SAMSUNG_REPEAT_PAUSE1;
|
2021-07-08 21:20:13 +03:00
|
|
|
|
|
|
|
*level = repeat_cnt % 2;
|
|
|
|
++encoder->timings_encoded;
|
|
|
|
bool done = (!((repeat_cnt + 1) % COUNT_OF(repeat_timings)));
|
|
|
|
|
2022-02-25 18:22:58 +03:00
|
|
|
return done ? InfraredStatusDone : InfraredStatusOk;
|
2021-07-08 21:20:13 +03:00
|
|
|
}
|
|
|
|
|
2022-02-25 18:22:58 +03:00
|
|
|
void* infrared_encoder_samsung32_alloc(void) {
|
|
|
|
return infrared_common_encoder_alloc(&protocol_samsung32);
|
2021-05-18 13:51:00 +03:00
|
|
|
}
|
|
|
|
|
2022-02-25 18:22:58 +03:00
|
|
|
void infrared_encoder_samsung32_free(void* encoder_ptr) {
|
|
|
|
infrared_common_encoder_free(encoder_ptr);
|
2021-05-18 13:51:00 +03:00
|
|
|
}
|
|
|
|
|
2022-02-25 18:22:58 +03:00
|
|
|
InfraredStatus
|
|
|
|
infrared_encoder_samsung32_encode(void* encoder_ptr, uint32_t* duration, bool* level) {
|
|
|
|
return infrared_common_encode(encoder_ptr, duration, level);
|
2021-07-08 21:20:13 +03:00
|
|
|
}
|