Skip to content

Commit

Permalink
Notification when receiving/sending.
Browse files Browse the repository at this point in the history
  • Loading branch information
antirez committed Jan 19, 2023
1 parent 2fe4ce3 commit cb88bdc
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ ProtoViewApp* protoview_app_alloc() {

// GUI
app->gui = furi_record_open(RECORD_GUI);
app->notification = furi_record_open(RECORD_NOTIFICATION);
app->view_port = view_port_alloc();
view_port_draw_callback_set(app->view_port, render_callback, app);
view_port_input_callback_set(app->view_port, input_callback, app);
Expand Down Expand Up @@ -189,6 +190,7 @@ void protoview_app_free(ProtoViewApp *app) {
gui_remove_view_port(app->gui, app->view_port);
view_port_free(app->view_port);
furi_record_close(RECORD_GUI);
furi_record_close(RECORD_NOTIFICATION);
furi_message_queue_free(app->event_queue);
app->gui = NULL;

Expand Down
1 change: 1 addition & 0 deletions app.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ typedef struct ProtoViewMsgInfo {
struct ProtoViewApp {
/* GUI */
Gui *gui;
NotificationApp *notification;
ViewPort *view_port; /* We just use a raw viewport and we render
everything into the low level canvas. */
ProtoViewCurrentView current_view; /* Active left-right view ID. */
Expand Down
26 changes: 26 additions & 0 deletions signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,31 @@ uint32_t search_coherent_signal(RawSamplesBuffer *s, uint32_t idx) {
return len;
}

/* Called when we detect a message. Just blinks when the message was
* not decoded. Vibrates, too, when the message was correctly decoded. */
void notify_signal_detected(ProtoViewApp *app, bool decoded) {
static const NotificationSequence decoded_seq = {
&message_vibro_on,
&message_green_255,
&message_delay_50,
&message_green_0,
&message_vibro_off,
NULL
};

static const NotificationSequence unknown_seq = {
&message_red_255,
&message_delay_50,
&message_red_0,
NULL
};

if (decoded)
notification_message(app->notification, &decoded_seq);
else
notification_message(app->notification, &unknown_seq);
}

/* Search the buffer with the stored signal (last N samples received)
* in order to find a coherent signal. If a signal that does not appear to
* be just noise is found, it is set in DetectedSamples global signal
Expand Down Expand Up @@ -179,6 +204,7 @@ void scan_for_signal(ProtoViewApp *app) {
app->us_scale = 10;
else if (DetectedSamples->short_pulse_dur < 145)
app->us_scale = 30;
notify_signal_detected(app,decoded);
} else {
/* If the structure was not filled, discard it. Otherwise
* now the owner is app->msg_info. */
Expand Down
14 changes: 14 additions & 0 deletions view_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,19 @@ LevelDuration radio_tx_feed_data(void *ctx) {
return level_duration_reset();
}

/* Vibrate and produce a click sound when a signal is sent. */
void notify_signal_sent(ProtoViewApp *app) {
static const NotificationSequence sent_seq = {
&message_vibro_on,
&message_note_g1,
&message_delay_10,
&message_sound_off,
&message_vibro_off,
NULL
};
notification_message(app->notification, &sent_seq);
}

/* Handle input for the info view. */
void process_input_info(ProtoViewApp *app, InputEvent input) {
if (process_subview_updown(app,input,SubViewInfoLast)) return;
Expand Down Expand Up @@ -265,6 +278,7 @@ void process_input_info(ProtoViewApp *app, InputEvent input) {
SendSignalCtx send_state;
send_signal_init(&send_state,app);
radio_tx_signal(app,radio_tx_feed_data,&send_state);
notify_signal_sent(app);
}
}
}

0 comments on commit cb88bdc

Please sign in to comment.