Disable subghz item scrolling

* Show time on receive new signal also
This commit is contained in:
Nikita Vostokov 2023-06-26 14:48:57 +03:00
parent b92f7c669b
commit 3d1ef1aae3

View File

@ -14,8 +14,7 @@
#define SUBGHZ_RAW_THRESHOLD_MIN -90.0f #define SUBGHZ_RAW_THRESHOLD_MIN -90.0f
#define SCROLL_INTERVAL (606) #define FLIP_TIMEOUT (500)
#define SCROLL_DELAY (2)
typedef struct { typedef struct {
FuriString* item_str; FuriString* item_str;
@ -55,7 +54,7 @@ struct SubGhzViewReceiver {
View* view; View* view;
SubGhzViewReceiverCallback callback; SubGhzViewReceiverCallback callback;
void* context; void* context;
FuriTimer* scroll_timer; FuriTimer* flip_time_timer;
}; };
typedef struct { typedef struct {
@ -70,7 +69,7 @@ typedef struct {
SubGhzViewReceiverBarShow bar_show; SubGhzViewReceiverBarShow bar_show;
SubGhzViewReceiverMode mode; SubGhzViewReceiverMode mode;
uint8_t u_rssi; uint8_t u_rssi;
size_t scroll_counter; bool show_time;
bool nodraw; bool nodraw;
} SubGhzViewReceiverModel; } SubGhzViewReceiverModel;
@ -148,6 +147,24 @@ static void subghz_view_receiver_update_offset(SubGhzViewReceiver* subghz_receiv
true); true);
} }
static void subghz_view_receiver_show_time_moment(void* context) {
furi_assert(context);
SubGhzViewReceiver* subghz_receiver = context;
with_view_model(
subghz_receiver->view, SubGhzViewReceiverModel * model, { model->show_time = true; }, true);
furi_timer_start(subghz_receiver->flip_time_timer, FLIP_TIMEOUT);
}
static void subghz_view_receiver_flip_string_callback(void* context) {
furi_assert(context);
SubGhzViewReceiver* subghz_receiver = context;
with_view_model(
subghz_receiver->view,
SubGhzViewReceiverModel * model,
{ model->show_time = false; },
true);
}
void subghz_view_receiver_add_item_to_menu( void subghz_view_receiver_add_item_to_menu(
SubGhzViewReceiver* subghz_receiver, SubGhzViewReceiver* subghz_receiver,
const char* name, const char* name,
@ -166,6 +183,7 @@ void subghz_view_receiver_add_item_to_menu(
if((model->idx == model->history_item - 1)) { if((model->idx == model->history_item - 1)) {
model->history_item++; model->history_item++;
model->idx++; model->idx++;
subghz_view_receiver_show_time_moment(subghz_receiver);
} else { } else {
model->history_item++; model->history_item++;
} }
@ -255,29 +273,17 @@ void subghz_view_receiver_draw(Canvas* canvas, SubGhzViewReceiverModel* model) {
break; break;
} }
furi_string_set(str_buff, item_menu->item_str); furi_string_set(str_buff, item_menu->item_str);
size_t scroll_counter = model->scroll_counter;
if(model->idx == idx) { if(model->idx == idx) {
subghz_view_receiver_draw_frame(canvas, i, scrollbar); subghz_view_receiver_draw_frame(canvas, i, scrollbar);
if(scroll_counter < SCROLL_DELAY) { if(model->show_time) {
// Show time of signal one moment // Show time of signal one moment
furi_string_set(str_buff, item_menu->time); furi_string_set(str_buff, item_menu->time);
scroll_counter = 0;
} else {
scroll_counter -= SCROLL_DELAY;
} }
} else { } else {
canvas_set_color(canvas, ColorBlack); canvas_set_color(canvas, ColorBlack);
scroll_counter = 0;
} }
canvas_draw_icon(canvas, 4, 2 + i * FRAME_HEIGHT, ReceiverItemIcons[item_menu->type]); canvas_draw_icon(canvas, 4, 2 + i * FRAME_HEIGHT, ReceiverItemIcons[item_menu->type]);
elements_scrollable_text_line( canvas_draw_str(canvas, 15, 9 + i * FRAME_HEIGHT, furi_string_get_cstr(str_buff));
canvas,
15,
9 + i * FRAME_HEIGHT,
(scrollbar ? MAX_LEN_PX - 6 : MAX_LEN_PX),
str_buff,
scroll_counter,
(model->idx != idx));
furi_string_reset(str_buff); furi_string_reset(str_buff);
} }
if(scrollbar) { if(scrollbar) {
@ -384,13 +390,6 @@ void subghz_view_receiver_draw(Canvas* canvas, SubGhzViewReceiverModel* model) {
} }
} }
static void subghz_view_receiver_scroll_timer_callback(void* context) {
furi_assert(context);
SubGhzViewReceiver* subghz_receiver = context;
with_view_model(
subghz_receiver->view, SubGhzViewReceiverModel * model, { model->scroll_counter++; }, true);
}
static void subghz_view_receiver_timer_callback(void* context) { static void subghz_view_receiver_timer_callback(void* context) {
furi_assert(context); furi_assert(context);
SubGhzViewReceiver* subghz_receiver = context; SubGhzViewReceiver* subghz_receiver = context;
@ -450,7 +449,7 @@ bool subghz_view_receiver_input(InputEvent* event, void* context) {
SubGhzViewReceiverModel * model, SubGhzViewReceiverModel * model,
{ {
if(model->idx != 0) model->idx--; if(model->idx != 0) model->idx--;
model->scroll_counter = 0; subghz_view_receiver_show_time_moment(context);
}, },
true); true);
} else if( } else if(
@ -460,9 +459,10 @@ bool subghz_view_receiver_input(InputEvent* event, void* context) {
subghz_receiver->view, subghz_receiver->view,
SubGhzViewReceiverModel * model, SubGhzViewReceiverModel * model,
{ {
if((model->history_item != 0) && (model->idx != model->history_item - 1)) if((model->history_item != 0) && (model->idx != model->history_item - 1)) {
model->idx++; model->idx++;
model->scroll_counter = 0; subghz_view_receiver_show_time_moment(context);
}
}, },
true); true);
} else if(event->key == InputKeyLeft && event->type == InputTypeShort) { } else if(event->key == InputKeyLeft && event->type == InputTypeShort) {
@ -499,13 +499,7 @@ bool subghz_view_receiver_input(InputEvent* event, void* context) {
void subghz_view_receiver_enter(void* context) { void subghz_view_receiver_enter(void* context) {
furi_assert(context); furi_assert(context);
SubGhzViewReceiver* subghz_receiver = context; subghz_view_receiver_show_time_moment(context);
with_view_model(
subghz_receiver->view,
SubGhzViewReceiverModel * model,
{ model->scroll_counter = 0; },
true);
furi_timer_start(subghz_receiver->scroll_timer, SCROLL_INTERVAL);
} }
void subghz_view_receiver_exit(void* context) { void subghz_view_receiver_exit(void* context) {
@ -533,7 +527,7 @@ void subghz_view_receiver_exit(void* context) {
}, },
false); false);
furi_timer_stop(subghz_receiver->timer); furi_timer_stop(subghz_receiver->timer);
furi_timer_stop(subghz_receiver->scroll_timer); furi_timer_stop(subghz_receiver->flip_time_timer);
} }
SubGhzViewReceiver* subghz_view_receiver_alloc() { SubGhzViewReceiver* subghz_view_receiver_alloc() {
@ -552,8 +546,8 @@ SubGhzViewReceiver* subghz_view_receiver_alloc() {
view_set_enter_callback(subghz_receiver->view, subghz_view_receiver_enter); view_set_enter_callback(subghz_receiver->view, subghz_view_receiver_enter);
view_set_exit_callback(subghz_receiver->view, subghz_view_receiver_exit); view_set_exit_callback(subghz_receiver->view, subghz_view_receiver_exit);
subghz_receiver->scroll_timer = furi_timer_alloc( subghz_receiver->flip_time_timer = furi_timer_alloc(
subghz_view_receiver_scroll_timer_callback, FuriTimerTypePeriodic, subghz_receiver); subghz_view_receiver_flip_string_callback, FuriTimerTypeOnce, subghz_receiver);
with_view_model( with_view_model(
subghz_receiver->view, subghz_receiver->view,
@ -577,7 +571,7 @@ SubGhzViewReceiver* subghz_view_receiver_alloc() {
void subghz_view_receiver_free(SubGhzViewReceiver* subghz_receiver) { void subghz_view_receiver_free(SubGhzViewReceiver* subghz_receiver) {
furi_assert(subghz_receiver); furi_assert(subghz_receiver);
furi_timer_free(subghz_receiver->scroll_timer); furi_timer_free(subghz_receiver->flip_time_timer);
with_view_model( with_view_model(
subghz_receiver->view, subghz_receiver->view,