Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/flipperzero-firmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSkorpionm <85568270+Skorpionm@users.noreply.github.com>2022-07-03 19:03:36 +0300
committerGitHub <noreply@github.com>2022-07-03 19:03:36 +0300
commitfea2bfa82215a0b71464177aec5dc21be39f0ee9 (patch)
treec0c33f9c55443c79c7060abbf418fbcb72a0973a
parent09ec3832c8a9ff67f620536ffe2905592438c195 (diff)
[FL-2610] SubGhz: add keypad lock SubGhz -> Read (#1343)
* [FL-2610] SubGhz: add keypad lock SubGhz -> Read * SubGhz: fix multiple clicks on the back button * SubGhz: turn on the backlight when receiving with the keypad locked. key processing delay when exiting Locked mode * SubGhz: chanage lock variable and enums names * SubGhz: replace direct return with consumed Co-authored-by: あく <alleteam@gmail.com>
-rw-r--r--applications/subghz/helpers/subghz_custom_event.h3
-rw-r--r--applications/subghz/helpers/subghz_types.h69
-rw-r--r--applications/subghz/scenes/subghz_scene_read_raw.c23
-rw-r--r--applications/subghz/scenes/subghz_scene_receiver.c45
-rw-r--r--applications/subghz/scenes/subghz_scene_receiver_config.c38
-rw-r--r--applications/subghz/subghz.c3
-rw-r--r--applications/subghz/subghz_i.h64
-rw-r--r--applications/subghz/views/receiver.c136
-rw-r--r--applications/subghz/views/receiver.h3
9 files changed, 287 insertions, 97 deletions
diff --git a/applications/subghz/helpers/subghz_custom_event.h b/applications/subghz/helpers/subghz_custom_event.h
index a2e5ee3e..05f0f492 100644
--- a/applications/subghz/helpers/subghz_custom_event.h
+++ b/applications/subghz/helpers/subghz_custom_event.h
@@ -41,6 +41,7 @@ typedef enum {
SubGhzCustomEventSceneShowOnlyRX,
SubGhzCustomEventSceneAnalyzerLock,
SubGhzCustomEventSceneAnalyzerUnlock,
+ SubGhzCustomEventSceneSettingLock,
SubGhzCustomEventSceneExit,
SubGhzCustomEventSceneStay,
@@ -48,6 +49,8 @@ typedef enum {
SubGhzCustomEventViewReceiverOK,
SubGhzCustomEventViewReceiverConfig,
SubGhzCustomEventViewReceiverBack,
+ SubGhzCustomEventViewReceiverOffDisplay,
+ SubGhzCustomEventViewReceiverUnlock,
SubGhzCustomEventViewReadRAWBack,
SubGhzCustomEventViewReadRAWIDLE,
diff --git a/applications/subghz/helpers/subghz_types.h b/applications/subghz/helpers/subghz_types.h
new file mode 100644
index 00000000..8d2dcf17
--- /dev/null
+++ b/applications/subghz/helpers/subghz_types.h
@@ -0,0 +1,69 @@
+#pragma once
+
+/** SubGhzNotification state */
+typedef enum {
+ SubGhzNotificationStateStarting,
+ SubGhzNotificationStateIDLE,
+ SubGhzNotificationStateTx,
+ SubGhzNotificationStateRx,
+ SubGhzNotificationStateRxDone,
+} SubGhzNotificationState;
+
+/** SubGhzTxRx state */
+typedef enum {
+ SubGhzTxRxStateIDLE,
+ SubGhzTxRxStateRx,
+ SubGhzTxRxStateTx,
+ SubGhzTxRxStateSleep,
+} SubGhzTxRxState;
+
+/** SubGhzHopperState state */
+typedef enum {
+ SubGhzHopperStateOFF,
+ SubGhzHopperStateRunnig,
+ SubGhzHopperStatePause,
+ SubGhzHopperStateRSSITimeOut,
+} SubGhzHopperState;
+
+/** SubGhzRxKeyState state */
+typedef enum {
+ SubGhzRxKeyStateIDLE,
+ SubGhzRxKeyStateNoSave,
+ SubGhzRxKeyStateNeedSave,
+ SubGhzRxKeyStateBack,
+ SubGhzRxKeyStateStart,
+ SubGhzRxKeyStateAddKey,
+ SubGhzRxKeyStateExit,
+ SubGhzRxKeyStateRAWLoad,
+ SubGhzRxKeyStateRAWSave,
+} SubGhzRxKeyState;
+
+/** SubGhzLoadKeyState state */
+typedef enum {
+ SubGhzLoadKeyStateUnknown,
+ SubGhzLoadKeyStateOK,
+ SubGhzLoadKeyStateParseErr,
+ SubGhzLoadKeyStateOnlyRx,
+} SubGhzLoadKeyState;
+
+/** SubGhzLock */
+typedef enum {
+ SubGhzLockOff,
+ SubGhzLockOn,
+} SubGhzLock;
+
+typedef enum {
+ SubGhzViewIdMenu,
+ SubGhzViewIdReceiver,
+ SubGhzViewIdPopup,
+ SubGhzViewIdTextInput,
+ SubGhzViewIdWidget,
+ SubGhzViewIdTransmitter,
+ SubGhzViewIdVariableItemList,
+ SubGhzViewIdFrequencyAnalyzer,
+ SubGhzViewIdReadRAW,
+
+ SubGhzViewIdStatic,
+ SubGhzViewIdTestCarrier,
+ SubGhzViewIdTestPacket,
+} SubGhzViewId;
diff --git a/applications/subghz/scenes/subghz_scene_read_raw.c b/applications/subghz/scenes/subghz_scene_read_raw.c
index 45bb8a50..598f235e 100644
--- a/applications/subghz/scenes/subghz_scene_read_raw.c
+++ b/applications/subghz/scenes/subghz_scene_read_raw.c
@@ -106,6 +106,7 @@ void subghz_scene_read_raw_on_enter(void* context) {
bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
+ bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
switch(event.event) {
case SubGhzCustomEventViewReadRAWBack:
@@ -141,7 +142,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
}
}
}
- return true;
+ consumed = true;
break;
case SubGhzCustomEventViewReadRAWTXRXStop:
@@ -156,14 +157,14 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
subghz_sleep(subghz);
};
subghz->state_notifications = SubGhzNotificationStateIDLE;
- return true;
+ consumed = true;
break;
case SubGhzCustomEventViewReadRAWConfig:
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerSet);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverConfig);
- return true;
+ consumed = true;
break;
case SubGhzCustomEventViewReadRAWErase:
@@ -175,7 +176,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
}
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
notification_message(subghz->notifications, &sequence_reset_rgb);
- return true;
+ consumed = true;
break;
case SubGhzCustomEventViewReadRAWMore:
@@ -184,7 +185,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerSet);
subghz->txrx->rx_key_state = SubGhzRxKeyStateRAWLoad;
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneMoreRAW);
- return true;
+ consumed = true;
} else {
furi_crash("SubGhz: RAW file name update error.");
}
@@ -214,7 +215,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
}
}
}
- return true;
+ consumed = true;
break;
case SubGhzCustomEventViewReadRAWSendStop:
@@ -224,7 +225,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
subghz_sleep(subghz);
}
subghz_read_raw_stop_send(subghz->subghz_read_raw);
- return true;
+ consumed = true;
break;
case SubGhzCustomEventViewReadRAWIDLE:
@@ -255,7 +256,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
subghz->state_notifications = SubGhzNotificationStateIDLE;
subghz->txrx->rx_key_state = SubGhzRxKeyStateAddKey;
- return true;
+ consumed = true;
break;
case SubGhzCustomEventViewReadRAWREC:
@@ -281,7 +282,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError);
}
}
- return true;
+ consumed = true;
break;
case SubGhzCustomEventViewReadRAWSave:
@@ -291,7 +292,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
subghz->txrx->rx_key_state = SubGhzRxKeyStateBack;
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveName);
}
- return true;
+ consumed = true;
break;
default:
@@ -315,7 +316,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
break;
}
}
- return false;
+ return consumed;
}
void subghz_scene_read_raw_on_exit(void* context) {
diff --git a/applications/subghz/scenes/subghz_scene_receiver.c b/applications/subghz/scenes/subghz_scene_receiver.c
index 01005148..55302b01 100644
--- a/applications/subghz/scenes/subghz_scene_receiver.c
+++ b/applications/subghz/scenes/subghz_scene_receiver.c
@@ -14,6 +14,23 @@ static const NotificationSequence subghs_sequence_rx = {
NULL,
};
+static const NotificationSequence subghs_sequence_rx_locked = {
+ &message_green_255,
+
+ &message_display_backlight_on,
+
+ &message_vibro_on,
+ &message_note_c6,
+ &message_delay_50,
+ &message_sound_off,
+ &message_vibro_off,
+
+ &message_delay_500,
+
+ &message_display_backlight_off,
+ NULL,
+};
+
static void subghz_scene_receiver_update_statusbar(void* context) {
SubGhz* subghz = context;
string_t history_stat_str;
@@ -92,6 +109,8 @@ void subghz_scene_receiver_on_enter(void* context) {
subghz->txrx->rx_key_state = SubGhzRxKeyStateStart;
}
+ subghz_view_receiver_set_lock(subghz->subghz_receiver, subghz->lock);
+
//Load history to receiver
subghz_view_receiver_exit(subghz->subghz_receiver);
for(uint8_t i = 0; i < subghz_history_get_item(subghz->txrx->history); i++) {
@@ -126,11 +145,10 @@ void subghz_scene_receiver_on_enter(void* context) {
bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
-
+ bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
switch(event.event) {
case SubGhzCustomEventViewReceiverBack:
-
// Stop CC1101 Rx
subghz->state_notifications = SubGhzNotificationStateIDLE;
if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
@@ -151,20 +169,28 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneStart);
}
- return true;
+ consumed = true;
break;
case SubGhzCustomEventViewReceiverOK:
subghz->txrx->idx_menu_chosen =
subghz_view_receiver_get_idx_menu(subghz->subghz_receiver);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverInfo);
- return true;
+ consumed = true;
break;
case SubGhzCustomEventViewReceiverConfig:
subghz->state_notifications = SubGhzNotificationStateIDLE;
subghz->txrx->idx_menu_chosen =
subghz_view_receiver_get_idx_menu(subghz->subghz_receiver);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverConfig);
- return true;
+ consumed = true;
+ break;
+ case SubGhzCustomEventViewReceiverOffDisplay:
+ notification_message(subghz->notifications, &sequence_display_backlight_off);
+ consumed = true;
+ break;
+ case SubGhzCustomEventViewReceiverUnlock:
+ subghz->lock = SubGhzLockOff;
+ consumed = true;
break;
default:
break;
@@ -174,20 +200,23 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
subghz_hopper_update(subghz);
subghz_scene_receiver_update_statusbar(subghz);
}
-
switch(subghz->state_notifications) {
case SubGhzNotificationStateRx:
notification_message(subghz->notifications, &sequence_blink_cyan_10);
break;
case SubGhzNotificationStateRxDone:
- notification_message(subghz->notifications, &subghs_sequence_rx);
+ if(subghz->lock != SubGhzLockOn) {
+ notification_message(subghz->notifications, &subghs_sequence_rx);
+ } else {
+ notification_message(subghz->notifications, &subghs_sequence_rx_locked);
+ }
subghz->state_notifications = SubGhzNotificationStateRx;
break;
default:
break;
}
}
- return false;
+ return consumed;
}
void subghz_scene_receiver_on_exit(void* context) {
diff --git a/applications/subghz/scenes/subghz_scene_receiver_config.c b/applications/subghz/scenes/subghz_scene_receiver_config.c
index 8789a243..cf31c1e9 100644
--- a/applications/subghz/scenes/subghz_scene_receiver_config.c
+++ b/applications/subghz/scenes/subghz_scene_receiver_config.c
@@ -1,5 +1,12 @@
#include "../subghz_i.h"
+enum SubGhzSettingIndex {
+ SubGhzSettingIndexFrequency,
+ SubGhzSettingIndexHopping,
+ SubGhzSettingIndexModulation,
+ SubGhzSettingIndexLock,
+};
+
#define PRESET_COUNT 4
const char* const preset_text[PRESET_COUNT] = {
"AM270",
@@ -137,6 +144,15 @@ static void subghz_scene_receiver_config_set_hopping_runing(VariableItem* item)
subghz->txrx->hopper_state = hopping_value[index];
}
+static void subghz_scene_receiver_config_var_list_enter_callback(void* context, uint32_t index) {
+ furi_assert(context);
+ SubGhz* subghz = context;
+ if(index == SubGhzSettingIndexLock) {
+ view_dispatcher_send_custom_event(
+ subghz->view_dispatcher, SubGhzCustomEventSceneSettingLock);
+ }
+}
+
void subghz_scene_receiver_config_on_enter(void* context) {
SubGhz* subghz = context;
VariableItem* item;
@@ -185,13 +201,29 @@ void subghz_scene_receiver_config_on_enter(void* context) {
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, preset_text[value_index]);
+ if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) !=
+ SubGhzCustomEventManagerSet) {
+ variable_item_list_add(subghz->variable_item_list, "Lock Keyboard", 1, NULL, NULL);
+ variable_item_list_set_enter_callback(
+ subghz->variable_item_list,
+ subghz_scene_receiver_config_var_list_enter_callback,
+ subghz);
+ }
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdVariableItemList);
}
bool subghz_scene_receiver_config_on_event(void* context, SceneManagerEvent event) {
- UNUSED(context);
- UNUSED(event);
- return false;
+ SubGhz* subghz = context;
+ bool consumed = false;
+
+ if(event.type == SceneManagerEventTypeCustom) {
+ if(event.event == SubGhzCustomEventSceneSettingLock) {
+ subghz->lock = SubGhzLockOn;
+ scene_manager_previous_scene(subghz->scene_manager);
+ consumed = true;
+ }
+ }
+ return consumed;
}
void subghz_scene_receiver_config_on_exit(void* context) {
diff --git a/applications/subghz/subghz.c b/applications/subghz/subghz.c
index d9dc19f4..ade7a844 100644
--- a/applications/subghz/subghz.c
+++ b/applications/subghz/subghz.c
@@ -133,7 +133,8 @@ SubGhz* subghz_alloc() {
subghz->setting = subghz_setting_alloc();
subghz_setting_load(subghz->setting, "/ext/subghz/assets/setting_user");
- //init Worker & Protocol & History
+ //init Worker & Protocol & History & KeyBoard
+ subghz->lock = SubGhzLockOff;
subghz->txrx = malloc(sizeof(SubGhzTxRx));
subghz->txrx->frequency = subghz_setting_get_default_frequency(subghz->setting);
subghz->txrx->preset = FuriHalSubGhzPresetOok650Async;
diff --git a/applications/subghz/subghz_i.h b/applications/subghz/subghz_i.h
index 5d1b0699..d75e92a7 100644
--- a/applications/subghz/subghz_i.h
+++ b/applications/subghz/subghz_i.h
@@ -1,5 +1,6 @@
#pragma once
+#include "helpers/subghz_types.h"
#include "subghz.h"
#include "views/receiver.h"
#include "views/transmitter.h"
@@ -37,52 +38,6 @@
#define SUBGHZ_MAX_LEN_NAME 64
-/** SubGhzNotification state */
-typedef enum {
- SubGhzNotificationStateStarting,
- SubGhzNotificationStateIDLE,
- SubGhzNotificationStateTx,
- SubGhzNotificationStateRx,
- SubGhzNotificationStateRxDone,
-} SubGhzNotificationState;
-
-/** SubGhzTxRx state */
-typedef enum {
- SubGhzTxRxStateIDLE,
- SubGhzTxRxStateRx,
- SubGhzTxRxStateTx,
- SubGhzTxRxStateSleep,
-} SubGhzTxRxState;
-
-/** SubGhzHopperState state */
-typedef enum {
- SubGhzHopperStateOFF,
- SubGhzHopperStateRunnig,
- SubGhzHopperStatePause,
- SubGhzHopperStateRSSITimeOut,
-} SubGhzHopperState;
-
-/** SubGhzRxKeyState state */
-typedef enum {
- SubGhzRxKeyStateIDLE,
- SubGhzRxKeyStateNoSave,
- SubGhzRxKeyStateNeedSave,
- SubGhzRxKeyStateBack,
- SubGhzRxKeyStateStart,
- SubGhzRxKeyStateAddKey,
- SubGhzRxKeyStateExit,
- SubGhzRxKeyStateRAWLoad,
- SubGhzRxKeyStateRAWSave,
-} SubGhzRxKeyState;
-
-/** SubGhzLoadKeyState state */
-typedef enum {
- SubGhzLoadKeyStateUnknown,
- SubGhzLoadKeyStateOK,
- SubGhzLoadKeyStateParseErr,
- SubGhzLoadKeyStateOnlyRx,
-} SubGhzLoadKeyState;
-
struct SubGhzTxRx {
SubGhzWorker* worker;
@@ -135,24 +90,9 @@ struct SubGhz {
SubGhzTestPacket* subghz_test_packet;
string_t error_str;
SubGhzSetting* setting;
+ SubGhzLock lock;
};
-typedef enum {
- SubGhzViewIdMenu,
- SubGhzViewIdReceiver,
- SubGhzViewIdPopup,
- SubGhzViewIdTextInput,
- SubGhzViewIdWidget,
- SubGhzViewIdTransmitter,
- SubGhzViewIdVariableItemList,
- SubGhzViewIdFrequencyAnalyzer,
- SubGhzViewIdReadRAW,
-
- SubGhzViewIdStatic,
- SubGhzViewIdTestCarrier,
- SubGhzViewIdTestPacket,
-} SubGhzViewId;
-
bool subghz_set_preset(SubGhz* subghz, const char* preset);
void subghz_get_frequency_modulation(SubGhz* subghz, string_t frequency, string_t modulation);
void subghz_begin(SubGhz* subghz, FuriHalSubGhzPreset preset);
diff --git a/applications/subghz/views/receiver.c b/applications/subghz/views/receiver.c
index 866d8272..bb4a8f16 100644
--- a/applications/subghz/views/receiver.c
+++ b/applications/subghz/views/receiver.c
@@ -11,6 +11,7 @@
#define FRAME_HEIGHT 12
#define MAX_LEN_PX 100
#define MENU_ITEMS 4u
+#define UNLOCK_CNT 3
typedef struct {
string_t item_str;
@@ -34,7 +35,17 @@ static const Icon* ReceiverItemIcons[] = {
[SubGhzProtocolTypeDynamic] = &I_Lock_7x8,
};
+typedef enum {
+ SubGhzViewReceiverBarShowDefault,
+ SubGhzViewReceiverBarShowLock,
+ SubGhzViewReceiverBarShowToUnlockPress,
+ SubGhzViewReceiverBarShowUnlock,
+} SubGhzViewReceiverBarShow;
+
struct SubGhzViewReceiver {
+ SubGhzLock lock;
+ uint8_t lock_count;
+ osTimerId_t timer;
View* view;
SubGhzViewReceiverCallback callback;
void* context;
@@ -48,8 +59,29 @@ typedef struct {
uint16_t idx;
uint16_t list_offset;
uint16_t history_item;
+ SubGhzViewReceiverBarShow bar_show;
} SubGhzViewReceiverModel;
+void subghz_view_receiver_set_lock(SubGhzViewReceiver* subghz_receiver, SubGhzLock lock) {
+ furi_assert(subghz_receiver);
+ subghz_receiver->lock_count = 0;
+ if(lock == SubGhzLockOn) {
+ subghz_receiver->lock = lock;
+ with_view_model(
+ subghz_receiver->view, (SubGhzViewReceiverModel * model) {
+ model->bar_show = SubGhzViewReceiverBarShowLock;
+ return true;
+ });
+ osTimerStart(subghz_receiver->timer, pdMS_TO_TICKS(1000));
+ } else {
+ with_view_model(
+ subghz_receiver->view, (SubGhzViewReceiverModel * model) {
+ model->bar_show = SubGhzViewReceiverBarShowDefault;
+ return true;
+ });
+ }
+}
+
void subghz_view_receiver_set_callback(
SubGhzViewReceiver* subghz_receiver,
SubGhzViewReceiverCallback callback,
@@ -138,17 +170,6 @@ void subghz_view_receiver_draw(Canvas* canvas, SubGhzViewReceiverModel* model) {
canvas_set_font(canvas, FontSecondary);
elements_button_left(canvas, "Config");
-
- canvas_draw_str(canvas, 44, 62, string_get_cstr(model->frequency_str));
- canvas_draw_str(canvas, 79, 62, string_get_cstr(model->preset_str));
- canvas_draw_str(canvas, 96, 62, string_get_cstr(model->history_stat_str));
- if(model->history_item == 0) {
- canvas_draw_icon(canvas, 0, 0, &I_Scanning_123x52);
- canvas_set_font(canvas, FontPrimary);
- canvas_draw_str(canvas, 63, 46, "Scanning...");
- canvas_draw_line(canvas, 46, 51, 125, 51);
- return;
- }
canvas_draw_line(canvas, 46, 51, 125, 51);
bool scrollbar = model->history_item > 4;
@@ -175,12 +196,96 @@ void subghz_view_receiver_draw(Canvas* canvas, SubGhzViewReceiverModel* model) {
elements_scrollbar_pos(canvas, 128, 0, 49, model->idx, model->history_item);
}
string_clear(str_buff);
+
+ canvas_set_color(canvas, ColorBlack);
+
+ if(model->history_item == 0) {
+ canvas_draw_icon(canvas, 0, 0, &I_Scanning_123x52);
+ canvas_set_font(canvas, FontPrimary);
+ canvas_draw_str(canvas, 63, 46, "Scanning...");
+ canvas_draw_line(canvas, 46, 51, 125, 51);
+ canvas_set_font(canvas, FontSecondary);
+ }
+
+ switch(model->bar_show) {
+ case SubGhzViewReceiverBarShowLock:
+ canvas_draw_icon(canvas, 64, 55, &I_Lock_7x8);
+ canvas_draw_str(canvas, 74, 62, "Locked");
+ break;
+ case SubGhzViewReceiverBarShowToUnlockPress:
+ canvas_draw_str(canvas, 44, 62, string_get_cstr(model->frequency_str));
+ canvas_draw_str(canvas, 79, 62, string_get_cstr(model->preset_str));
+ canvas_draw_str(canvas, 96, 62, string_get_cstr(model->history_stat_str));
+ canvas_set_font(canvas, FontSecondary);
+ elements_bold_rounded_frame(canvas, 14, 8, 99, 48);
+ elements_multiline_text(canvas, 65, 26, "To unlock\npress:");
+ canvas_draw_icon(canvas, 65, 42, &I_Pin_back_arrow_10x8);
+ canvas_draw_icon(canvas, 80, 42, &I_Pin_back_arrow_10x8);
+ canvas_draw_icon(canvas, 95, 42, &I_Pin_back_arrow_10x8);
+ canvas_draw_icon(canvas, 16, 13, &I_WarningDolphin_45x42);
+ canvas_draw_dot(canvas, 17, 61);
+ break;
+ case SubGhzViewReceiverBarShowUnlock:
+ canvas_draw_icon(canvas, 64, 55, &I_Unlock_7x8);
+ canvas_draw_str(canvas, 74, 62, "Unlocked");
+ break;
+ default:
+ canvas_draw_str(canvas, 44, 62, string_get_cstr(model->frequency_str));
+ canvas_draw_str(canvas, 79, 62, string_get_cstr(model->preset_str));
+ canvas_draw_str(canvas, 96, 62, string_get_cstr(model->history_stat_str));
+ break;
+ }
+}
+
+static void subghz_view_receiver_timer_callback(void* context) {
+ furi_assert(context);
+ SubGhzViewReceiver* subghz_receiver = context;
+ with_view_model(
+ subghz_receiver->view, (SubGhzViewReceiverModel * model) {
+ model->bar_show = SubGhzViewReceiverBarShowDefault;
+ return true;
+ });
+ if(subghz_receiver->lock_count < UNLOCK_CNT) {
+ subghz_receiver->callback(
+ SubGhzCustomEventViewReceiverOffDisplay, subghz_receiver->context);
+ } else {
+ subghz_receiver->lock = SubGhzLockOff;
+ subghz_receiver->callback(SubGhzCustomEventViewReceiverUnlock, subghz_receiver->context);
+ }
+ subghz_receiver->lock_count = 0;
}
bool subghz_view_receiver_input(InputEvent* event, void* context) {
furi_assert(context);
SubGhzViewReceiver* subghz_receiver = context;
+ if(subghz_receiver->lock == SubGhzLockOn) {
+ with_view_model(
+ subghz_receiver->view, (SubGhzViewReceiverModel * model) {
+ model->bar_show = SubGhzViewReceiverBarShowToUnlockPress;
+ return true;
+ });
+ if(subghz_receiver->lock_count == 0) {
+ osTimerStart(subghz_receiver->timer, pdMS_TO_TICKS(1000));
+ }
+ if(event->key == InputKeyBack && event->type == InputTypeShort) {
+ subghz_receiver->lock_count++;
+ }
+ if(subghz_receiver->lock_count >= UNLOCK_CNT) {
+ // subghz_receiver->callback(
+ // SubGhzCustomEventViewReceiverUnlock, subghz_receiver->context);
+ with_view_model(
+ subghz_receiver->view, (SubGhzViewReceiverModel * model) {
+ model->bar_show = SubGhzViewReceiverBarShowUnlock;
+ return true;
+ });
+ //subghz_receiver->lock = SubGhzLockOff;
+ osTimerStart(subghz_receiver->timer, pdMS_TO_TICKS(650));
+ }
+
+ return true;
+ }
+
if(event->key == InputKeyBack && event->type == InputTypeShort) {
subghz_receiver->callback(SubGhzCustomEventViewReceiverBack, subghz_receiver->context);
} else if(
@@ -240,6 +345,7 @@ void subghz_view_receiver_exit(void* context) {
model->history_item = 0;
return false;
});
+ osTimerStop(subghz_receiver->timer);
}
SubGhzViewReceiver* subghz_view_receiver_alloc() {
@@ -247,6 +353,9 @@ SubGhzViewReceiver* subghz_view_receiver_alloc() {
// View allocation and configuration
subghz_receiver->view = view_alloc();
+
+ subghz_receiver->lock = SubGhzLockOff;
+ subghz_receiver->lock_count = 0;
view_allocate_model(
subghz_receiver->view, ViewModelTypeLocking, sizeof(SubGhzViewReceiverModel));
view_set_context(subghz_receiver->view, subghz_receiver);
@@ -260,11 +369,13 @@ SubGhzViewReceiver* subghz_view_receiver_alloc() {
string_init(model->frequency_str);
string_init(model->preset_str);
string_init(model->history_stat_str);
+ model->bar_show = SubGhzViewReceiverBarShowDefault;
model->history = malloc(sizeof(SubGhzReceiverHistory));
SubGhzReceiverMenuItemArray_init(model->history->data);
return true;
});
-
+ subghz_receiver->timer =
+ osTimerNew(subghz_view_receiver_timer_callback, osTimerOnce, subghz_receiver, NULL);
return subghz_receiver;
}
@@ -285,6 +396,7 @@ void subghz_view_receiver_free(SubGhzViewReceiver* subghz_receiver) {
free(model->history);
return false;
});
+ osTimerDelete(subghz_receiver->timer);
view_free(subghz_receiver->view);
free(subghz_receiver);
}
diff --git a/applications/subghz/views/receiver.h b/applications/subghz/views/receiver.h
index 87065ef0..aab7a76c 100644
--- a/applications/subghz/views/receiver.h
+++ b/applications/subghz/views/receiver.h
@@ -1,12 +1,15 @@
#pragma once
#include <gui/view.h>
+#include "../helpers/subghz_types.h"
#include "../helpers/subghz_custom_event.h"
typedef struct SubGhzViewReceiver SubGhzViewReceiver;
typedef void (*SubGhzViewReceiverCallback)(SubGhzCustomEvent event, void* context);
+void subghz_view_receiver_set_lock(SubGhzViewReceiver* subghz_receiver, SubGhzLock keyboard);
+
void subghz_view_receiver_set_callback(
SubGhzViewReceiver* subghz_receiver,
SubGhzViewReceiverCallback callback,