Somfy Telis - Custom buttons + Prog mode

This commit is contained in:
MX
2023-02-28 00:02:30 +03:00
parent 568176d775
commit 2c95a7cba4
10 changed files with 153 additions and 13 deletions

View File

@@ -73,6 +73,25 @@ const SubGhzProtocol subghz_protocol_somfy_telis = {
.encoder = &subghz_protocol_somfy_telis_encoder,
};
static uint8_t st_btn_temp_id;
static uint8_t st_btn_temp_id_original;
void somfy_telis_set_btn(uint8_t b) {
st_btn_temp_id = b;
}
uint8_t somfy_telis_get_original_btn() {
return st_btn_temp_id_original;
}
uint8_t somfy_telis_get_custom_btn() {
return st_btn_temp_id;
}
void somfy_telis_reset_original_btn() {
st_btn_temp_id_original = 0;
}
void* subghz_protocol_encoder_somfy_telis_alloc(SubGhzEnvironment* environment) {
UNUSED(environment);
SubGhzProtocolEncoderSomfyTelis* instance = malloc(sizeof(SubGhzProtocolEncoderSomfyTelis));
@@ -95,13 +114,86 @@ void subghz_protocol_encoder_somfy_telis_free(void* context) {
free(instance);
}
static bool
subghz_protocol_somfy_telis_gen_data(SubGhzProtocolEncoderSomfyTelis* instance, uint8_t btn) {
UNUSED(btn);
static bool subghz_protocol_somfy_telis_gen_data(
SubGhzProtocolEncoderSomfyTelis* instance,
uint8_t btn,
bool new_remote) {
// If we doing a clone we will use its data
uint64_t data = instance->generic.data ^ (instance->generic.data >> 8);
instance->generic.btn = (data >> 44) & 0xF; // ctrl
instance->generic.cnt = (data >> 24) & 0xFFFF; // rolling code
instance->generic.serial = data & 0xFFFFFF; // address
if(!new_remote) {
instance->generic.btn = (data >> 44) & 0xF; // ctrl
btn = instance->generic.btn;
instance->generic.cnt = (data >> 24) & 0xFFFF; // rolling code
instance->generic.serial = data & 0xFFFFFF; // address
}
// Save original button for later use
if(st_btn_temp_id_original == 0) {
st_btn_temp_id_original = btn;
}
// Set custom button
if(st_btn_temp_id == 1) {
switch(st_btn_temp_id_original) {
case 0x1:
btn = 0x2;
break;
case 0x2:
btn = 0x1;
break;
case 0x4:
btn = 0x1;
break;
case 0x8:
btn = 0x1;
break;
default:
break;
}
}
if(st_btn_temp_id == 2) {
switch(st_btn_temp_id_original) {
case 0x1:
btn = 0x4;
break;
case 0x2:
btn = 0x4;
break;
case 0x4:
btn = 0x2;
break;
case 0x8:
btn = 0x4;
break;
default:
break;
}
}
if(st_btn_temp_id == 3) {
switch(st_btn_temp_id_original) {
case 0x1:
btn = 0x8;
break;
case 0x2:
btn = 0x8;
break;
case 0x4:
btn = 0x8;
break;
case 0x8:
btn = 0x2;
break;
default:
break;
}
}
if((st_btn_temp_id == 0) && (st_btn_temp_id_original != 0)) {
btn = st_btn_temp_id_original;
}
if(instance->generic.cnt < 0xFFFF) {
if((instance->generic.cnt + furi_hal_subghz_get_rolling_counter_mult()) >= 0xFFFF) {
@@ -114,8 +206,12 @@ static bool
}
uint8_t frame[7];
frame[0] = data >> 48;
frame[1] = instance->generic.btn << 4;
if(!new_remote) {
frame[0] = data >> 48;
} else {
frame[0] = 0xA7;
}
frame[1] = btn << 4;
frame[2] = instance->generic.cnt >> 8;
frame[3] = instance->generic.cnt;
frame[4] = instance->generic.serial >> 16;
@@ -154,7 +250,7 @@ bool subghz_protocol_somfy_telis_create_data(
instance->generic.serial = serial;
instance->generic.cnt = cnt;
instance->generic.data_count_bit = 56;
bool res = subghz_protocol_somfy_telis_gen_data(instance, btn);
bool res = subghz_protocol_somfy_telis_gen_data(instance, btn, true);
if(res) {
res = subghz_block_generic_serialize(&instance->generic, flipper_format, preset);
}
@@ -172,7 +268,7 @@ static bool subghz_protocol_encoder_somfy_telis_get_upload(
furi_assert(instance);
//gen new key
if(subghz_protocol_somfy_telis_gen_data(instance, btn)) {
if(subghz_protocol_somfy_telis_gen_data(instance, btn, false)) {
//ToDo if you need to add a callback to automatically update the data on the display
} else {
return false;
@@ -583,6 +679,11 @@ static void subghz_protocol_somfy_telis_check_remote_controller(SubGhzBlockGener
instance->btn = (data >> 44) & 0xF; // ctrl
instance->cnt = (data >> 24) & 0xFFFF; // rolling code
instance->serial = data & 0xFFFFFF; // address
// Save original button for later use
if(st_btn_temp_id_original == 0) {
st_btn_temp_id_original = instance->btn;
}
}
/**