SubGhz: remove direct reading (hopper_state)

This commit is contained in:
gid9798 2023-05-06 17:02:32 +03:00
parent cb8c77ee2c
commit c98e76f31e
6 changed files with 39 additions and 17 deletions

View file

@ -215,7 +215,7 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
// Stop CC1101 Rx
subghz->state_notifications = SubGhzNotificationStateIDLE;
subghz_txrx_stop(subghz);
subghz->txrx->hopper_state = SubGhzHopperStateOFF;
subghz_hopper_set_state(subghz, SubGhzHopperStateOFF);
subghz->txrx->idx_menu_chosen = 0;
subghz_receiver_set_rx_callback(subghz->txrx->receiver, NULL, subghz);
@ -269,7 +269,7 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
break;
}
} else if(event.type == SceneManagerEventTypeTick) {
if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) {
if(subghz_hopper_get_state(subghz) != SubGhzHopperStateOFF) {
subghz_hopper_update(subghz);
subghz_scene_receiver_update_statusbar(subghz);
}

View file

@ -143,7 +143,7 @@ static void subghz_scene_receiver_config_set_frequency(VariableItem* item) {
SubGhz* subghz = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
if(subghz->txrx->hopper_state == SubGhzHopperStateOFF) {
if(subghz_hopper_get_state(subghz) == SubGhzHopperStateOFF) {
char text_buf[10] = {0};
snprintf(
text_buf,
@ -209,7 +209,7 @@ static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item)
subghz_setting_get_frequency_default_index(subghz->setting));
}
subghz->txrx->hopper_state = hopping_value[index];
subghz_hopper_set_state(subghz, hopping_value[index]);
}
static void subghz_scene_receiver_config_set_speaker(VariableItem* item) {
@ -317,7 +317,7 @@ void subghz_scene_receiver_config_on_enter(void* context) {
subghz_scene_receiver_config_set_hopping_running,
subghz);
value_index = subghz_scene_receiver_config_hopper_value_index(
subghz->txrx->hopper_state, hopping_value, HOPPING_COUNT, subghz);
subghz_hopper_get_state(subghz), hopping_value, HOPPING_COUNT, subghz);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, hopping_text[value_index]);
}

View file

@ -122,9 +122,7 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event)
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubGhzCustomEventSceneReceiverInfoTxStart) {
//CC1101 Stop RX -> Start TX
if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) {
subghz->txrx->hopper_state = SubGhzHopperStatePause;
}
subghz_subghz_hopper_set_pause(subghz);
subghz_txrx_stop(subghz);
@ -142,9 +140,7 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event)
subghz_setting_get_preset_data_by_name(
subghz->setting, furi_string_get_cstr(subghz->txrx->preset->name)));
subghz_rx(subghz, subghz->txrx->preset->frequency);
if(subghz->txrx->hopper_state == SubGhzHopperStatePause) {
subghz->txrx->hopper_state = SubGhzHopperStateRunning;
}
subghz_hopper_remove_pause(subghz);
subghz->state_notifications = SubGhzNotificationStateRx;
} else {
subghz->state_notifications = SubGhzNotificationStateTx;
@ -165,16 +161,14 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event)
subghz->setting, furi_string_get_cstr(subghz->txrx->preset->name)));
subghz_rx(subghz, subghz->txrx->preset->frequency);
if(subghz->txrx->hopper_state == SubGhzHopperStatePause) {
subghz->txrx->hopper_state = SubGhzHopperStateRunning;
}
subghz_hopper_remove_pause(subghz);
subghz->state_notifications = SubGhzNotificationStateRx;
}
return true;
} else if(event.event == SubGhzCustomEventSceneReceiverInfoSave) {
//CC1101 Stop RX -> Save
subghz->state_notifications = SubGhzNotificationStateIDLE;
subghz->txrx->hopper_state = SubGhzHopperStateOFF;
subghz_hopper_set_state(subghz, SubGhzHopperStateOFF);
subghz_txrx_stop(subghz);
if(!subghz_scene_receiver_info_update_parser(subghz)) {
@ -193,7 +187,7 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event)
return true;
}
} else if(event.type == SceneManagerEventTypeTick) {
if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) {
if(subghz_hopper_get_state(subghz) != SubGhzHopperStateOFF) {
subghz_hopper_update(subghz);
}
switch(subghz->state_notifications) {

View file

@ -271,7 +271,7 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) {
subghz, "AM650", subghz_setting_get_default_frequency(subghz->setting), NULL, 0);
}
subghz->txrx->txrx_state = SubGhzTxRxStateSleep;
subghz->txrx->hopper_state = SubGhzHopperStateOFF;
subghz_hopper_set_state(subghz, SubGhzHopperStateOFF);
subghz->txrx->speaker_state = SubGhzSpeakerStateDisable;
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
subghz->txrx->debug_pin_state = false;

View file

@ -629,6 +629,30 @@ void subghz_hopper_update(SubGhz* subghz) {
}
}
SubGhzHopperState subghz_hopper_get_state(SubGhz* subghz) {
furi_assert(subghz);
return subghz->txrx->hopper_state;
}
void subghz_hopper_set_state(SubGhz* subghz, SubGhzHopperState state) {
furi_assert(subghz);
subghz->txrx->hopper_state = state;
}
void subghz_hopper_remove_pause(SubGhz* subghz) {
furi_assert(subghz);
if(subghz->txrx->hopper_state == SubGhzHopperStatePause) {
subghz->txrx->hopper_state = SubGhzHopperStateRunning;
}
}
void subghz_subghz_hopper_set_pause(SubGhz* subghz) {
furi_assert(subghz);
if(subghz->txrx->hopper_state == SubGhzHopperStateOFF) {
subghz->txrx->hopper_state = SubGhzHopperStatePause;
}
}
void subghz_speaker_on(SubGhz* subghz) {
if(subghz->txrx->debug_pin_state) {
furi_hal_subghz_set_async_mirror_pin(&gpio_ibutton);

View file

@ -180,6 +180,10 @@ void subghz_speaker_unmute(SubGhz* subghz);
void subghz_txrx_stop(SubGhz* subghz);
SubGhzTxRxState subghz_txrx_get_state(SubGhz* subghz);
SubGhzHopperState subghz_hopper_get_state(SubGhz* subghz);
void subghz_hopper_set_state(SubGhz* subghz, SubGhzHopperState state);
void subghz_hopper_remove_pause(SubGhz* subghz);
void subghz_subghz_hopper_set_pause(SubGhz* subghz);
extern const NotificationSequence subghz_sequence_rx;
extern const NotificationSequence subghz_sequence_rx_locked;