Skip to content

Commit

Permalink
Removing duplicate code in subghz scnes.
Browse files Browse the repository at this point in the history
  • Loading branch information
gid9798 committed Dec 15, 2022
1 parent 03153b4 commit f43fd7a
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 224 deletions.
9 changes: 3 additions & 6 deletions applications/main/subghz/scenes/subghz_scene_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@ ADD_SCENE(subghz, test_static, TestStatic)
ADD_SCENE(subghz, test_packet, TestPacket)
#endif
ADD_SCENE(subghz, set_type, SetType)
ADD_SCENE(subghz, set_fix_faac_868, SetFixFaac868)
ADD_SCENE(subghz, set_cnt_faac_868, SetCntFaac868)
ADD_SCENE(subghz, set_seed_faac_868, SetSeedFaac868)
ADD_SCENE(subghz, set_fix_faac_433, SetFixFaac433)
ADD_SCENE(subghz, set_cnt_faac_433, SetCntFaac433)
ADD_SCENE(subghz, set_seed_faac_433, SetSeedFaac433)
ADD_SCENE(subghz, set_fix_faac, SetFixFaac)
ADD_SCENE(subghz, set_cnt_faac, SetCntFaac)
ADD_SCENE(subghz, set_seed_faac, SetSeedFaac)
ADD_SCENE(subghz, set_fix_bft, SetFixBft)
ADD_SCENE(subghz, set_cnt_bft, SetCntBft)
ADD_SCENE(subghz, set_seed_bft, SetSeedBft)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
#include "../subghz_i.h"

#define TAG "SubGhzSetCntFaac433"
#define TAG "SubGhzSetCntFaac"

void subghz_scene_set_cnt_faac_433_byte_input_callback(void* context) {
void subghz_scene_set_cnt_faac_byte_input_callback(void* context) {
SubGhz* subghz = context;

view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventByteInputDone);
}

void subghz_scene_set_cnt_faac_433_on_enter(void* context) {
void subghz_scene_set_cnt_faac_on_enter(void* context) {
SubGhz* subghz = context;

// Setup view
ByteInput* byte_input = subghz->byte_input;
byte_input_set_header_text(byte_input, "Enter COUNTER in hex, 20bits");
byte_input_set_result_callback(
byte_input,
subghz_scene_set_cnt_faac_433_byte_input_callback,
subghz_scene_set_cnt_faac_byte_input_callback,
NULL,
subghz,
subghz->txrx->secure_data->cnt,
3);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdByteInput);
}

bool subghz_scene_set_cnt_faac_433_on_event(void* context, SceneManagerEvent event) {
bool subghz_scene_set_cnt_faac_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
bool consumed = false;

if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubGhzCustomEventByteInputDone) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSetSeedFaac433);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSetSeedFaac);
consumed = true;
}
}
return consumed;
}

void subghz_scene_set_cnt_faac_433_on_exit(void* context) {
void subghz_scene_set_cnt_faac_on_exit(void* context) {
SubGhz* subghz = context;

// Clear view
Expand Down
46 changes: 0 additions & 46 deletions applications/main/subghz/scenes/subghz_scene_set_cnt_faac_868.c

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
#include "../subghz_i.h"

#define TAG "SubGhzSetFixFaac433"
#define TAG "SubGhzSetFixFaac"

void subghz_scene_set_fix_faac_433_byte_input_callback(void* context) {
void subghz_scene_set_fix_faac_byte_input_callback(void* context) {
SubGhz* subghz = context;

view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventByteInputDone);
}

void subghz_scene_set_fix_faac_433_on_enter(void* context) {
void subghz_scene_set_fix_faac_on_enter(void* context) {
SubGhz* subghz = context;

// Setup view
ByteInput* byte_input = subghz->byte_input;
byte_input_set_header_text(byte_input, "Enter FIX in hex");
byte_input_set_result_callback(
byte_input,
subghz_scene_set_fix_faac_433_byte_input_callback,
subghz_scene_set_fix_faac_byte_input_callback,
NULL,
subghz,
subghz->txrx->secure_data->fix,
4);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdByteInput);
}

bool subghz_scene_set_fix_faac_433_on_event(void* context, SceneManagerEvent event) {
bool subghz_scene_set_fix_faac_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
bool consumed = false;

if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubGhzCustomEventByteInputDone) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSetCntFaac433);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSetCntFaac);
consumed = true;
}
}
return consumed;
}

void subghz_scene_set_fix_faac_433_on_exit(void* context) {
void subghz_scene_set_fix_faac_on_exit(void* context) {
SubGhz* subghz = context;

// Clear view
Expand Down
46 changes: 0 additions & 46 deletions applications/main/subghz/scenes/subghz_scene_set_fix_faac_868.c

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@
#include <dolphin/dolphin.h>
#include <lib/subghz/protocols/faac_slh.h>

#define TAG "SubGhzSetSeedFaac433"
#define TAG "SubGhzSetSeedFaac"

void subghz_scene_set_seed_faac_433_byte_input_callback(void* context) {
void subghz_scene_set_seed_faac_byte_input_callback(void* context) {
SubGhz* subghz = context;

view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventByteInputDone);
}

void subghz_scene_set_seed_faac_433_on_enter(void* context) {
void subghz_scene_set_seed_faac_on_enter(void* context) {
SubGhz* subghz = context;

// Setup view
ByteInput* byte_input = subghz->byte_input;
byte_input_set_header_text(byte_input, "Enter SEED in hex");
byte_input_set_result_callback(
byte_input,
subghz_scene_set_seed_faac_433_byte_input_callback,
subghz_scene_set_seed_faac_byte_input_callback,
NULL,
subghz,
subghz->txrx->secure_data->seed,
4);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdByteInput);
}

bool subghz_scene_set_seed_faac_433_on_event(void* context, SceneManagerEvent event) {
bool subghz_scene_set_seed_faac_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
bool consumed = false;
bool generated_protocol = false;
Expand All @@ -48,7 +48,14 @@ bool subghz_scene_set_seed_faac_433_on_event(void* context, SceneManagerEvent ev
subghz->txrx->transmitter =
subghz_transmitter_alloc_init(subghz->txrx->environment, "Faac SLH");
if(subghz->txrx->transmitter) {
subghz_preset_init(subghz, "AM650", 433920000, NULL, 0);
SubGhzCustomEvent state =
scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneSetType);

if(state == SubmenuIndexFaacSLH_433) {
subghz_preset_init(subghz, "AM650", 433920000, NULL, 0);
} else if(state == SubmenuIndexFaacSLH_868) {
subghz_preset_init(subghz, "AM650", 868350000, NULL, 0);
}
subghz_protocol_faac_slh_create_data(
subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter),
subghz->txrx->fff_data,
Expand Down Expand Up @@ -94,7 +101,7 @@ bool subghz_scene_set_seed_faac_433_on_event(void* context, SceneManagerEvent ev
return consumed;
}

void subghz_scene_set_seed_faac_433_on_exit(void* context) {
void subghz_scene_set_seed_faac_on_exit(void* context) {
SubGhz* subghz = context;

// Clear view
Expand Down
103 changes: 0 additions & 103 deletions applications/main/subghz/scenes/subghz_scene_set_seed_faac_868.c

This file was deleted.

4 changes: 2 additions & 2 deletions applications/main/subghz/scenes/subghz_scene_set_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) {
uint32_t key = subghz_random_serial();
switch(event.event) {
case SubmenuIndexFaacSLH_868:
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSetFixFaac868);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSetFixFaac);
break;
case SubmenuIndexFaacSLH_433:
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSetFixFaac433);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSetFixFaac);
break;
case SubmenuIndexBFT:
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSetFixBft);
Expand Down

0 comments on commit f43fd7a

Please sign in to comment.