Skip to content

Commit

Permalink
☦️ Rpc: implement SystemPlayAudiovisualAlert (flipperdevices#937)
Browse files Browse the repository at this point in the history
* Rpc: update protobuf sources
* Notification: allow user settings override
* Notification: add audiovisual alert sequence
* Rpc: implement SystemPlayAudiovisualAlert
  • Loading branch information
anna-oake authored Dec 28, 2021
1 parent c036ac6 commit 475fa91
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 6 deletions.
19 changes: 15 additions & 4 deletions applications/notification/notification-app.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ void notification_process_notification_message(
bool led_active = false;
uint8_t led_values[NOTIFICATION_LED_COUNT] = {0x00, 0x00, 0x00};
bool reset_notifications = true;
float speaker_volume_setting = app->settings.speaker_volume;
bool vibro_setting = app->settings.vibro_on;
float display_brightness_setting = app->settings.display_brightness;

uint8_t reset_mask = 0;

Expand All @@ -177,8 +180,7 @@ void notification_process_notification_message(
if(notification_message->data.led.value > 0x00) {
notification_apply_notification_led_layer(
&app->display,
notification_settings_get_display_brightness(
app, notification_message->data.led.value));
notification_message->data.led.value * display_brightness_setting);
} else {
notification_reset_notification_led_layer(&app->display);
if(osTimerIsRunning(app->display_timer)) {
Expand Down Expand Up @@ -207,15 +209,15 @@ void notification_process_notification_message(
break;
case NotificationMessageTypeVibro:
if(notification_message->data.vibro.on) {
if(app->settings.vibro_on) notification_vibro_on();
if(vibro_setting) notification_vibro_on();
} else {
notification_vibro_off();
}
reset_mask |= reset_vibro_mask;
break;
case NotificationMessageTypeSoundOn:
notification_sound_on(
notification_message->data.sound.pwm * app->settings.speaker_volume,
notification_message->data.sound.pwm * speaker_volume_setting,
notification_message->data.sound.frequency);
reset_mask |= reset_sound_mask;
break;
Expand Down Expand Up @@ -243,6 +245,15 @@ void notification_process_notification_message(
case NotificationMessageTypeDoNotReset:
reset_notifications = false;
break;
case NotificationMessageTypeForceSpeakerVolumeSetting:
speaker_volume_setting = notification_message->data.forced_settings.speaker_volume;
break;
case NotificationMessageTypeForceVibroSetting:
vibro_setting = notification_message->data.forced_settings.vibro;
break;
case NotificationMessageTypeForceDisplayBrightnessSetting:
display_brightness_setting =
notification_message->data.forced_settings.display_brightness;
}
notification_message_index++;
notification_message = (*message->sequence)[notification_message_index];
Expand Down
56 changes: 56 additions & 0 deletions applications/notification/notification-messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,27 @@ const NotificationMessage message_do_not_reset = {
.type = NotificationMessageTypeDoNotReset,
};

// Override user settings
const NotificationMessage message_force_speaker_volume_setting_1f = {
.type = NotificationMessageTypeForceSpeakerVolumeSetting,
.data.forced_settings.speaker_volume = 1.0f,
};

const NotificationMessage message_force_vibro_setting_on = {
.type = NotificationMessageTypeForceVibroSetting,
.data.forced_settings.vibro = true,
};

const NotificationMessage message_force_vibro_setting_off = {
.type = NotificationMessageTypeForceVibroSetting,
.data.forced_settings.vibro = false,
};

const NotificationMessage message_force_display_brightness_setting_1f = {
.type = NotificationMessageTypeForceDisplayBrightnessSetting,
.data.forced_settings.display_brightness = 1.0f,
};

/****************************** Message sequences ******************************/

// Reset
Expand Down Expand Up @@ -361,3 +382,38 @@ const NotificationSequence sequence_error = {
&message_sound_off,
NULL,
};

const NotificationSequence sequence_audiovisual_alert = {
&message_force_speaker_volume_setting_1f,
&message_force_vibro_setting_on,
&message_force_display_brightness_setting_1f,
&message_vibro_on,

&message_display_on,
&message_note_c7,
&message_delay_250,

&message_display_off,
&message_note_c4,
&message_delay_250,

&message_display_on,
&message_note_c7,
&message_delay_250,

&message_display_off,
&message_note_c4,
&message_delay_250,

&message_display_on,
&message_note_c7,
&message_delay_250,

&message_display_off,
&message_note_c4,
&message_delay_250,

&message_sound_off,
&message_vibro_off,
NULL,
};
7 changes: 7 additions & 0 deletions applications/notification/notification-messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ extern const NotificationMessage message_vibro_off;
// Reset
extern const NotificationMessage message_do_not_reset;

// Override user settings
extern const NotificationMessage message_force_speaker_volume_setting_1f;
extern const NotificationMessage message_force_vibro_setting_on;
extern const NotificationMessage message_force_vibro_setting_off;
extern const NotificationMessage message_force_display_brightness_setting_1f;

/****************************** Message sequences ******************************/

// Reset
Expand Down Expand Up @@ -93,6 +99,7 @@ extern const NotificationSequence sequence_single_vibro;
extern const NotificationSequence sequence_double_vibro;
extern const NotificationSequence sequence_success;
extern const NotificationSequence sequence_error;
extern const NotificationSequence sequence_audiovisual_alert;

#ifdef __cplusplus
}
Expand Down
10 changes: 10 additions & 0 deletions applications/notification/notification.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,18 @@ typedef struct {
uint32_t length;
} NotificationMessageDataDelay;

typedef struct {
float speaker_volume;
bool vibro;
float display_brightness;
} NotificationMessageDataForcedSettings;

typedef union {
NotificationMessageDataSound sound;
NotificationMessageDataLed led;
NotificationMessageDataVibro vibro;
NotificationMessageDataDelay delay;
NotificationMessageDataForcedSettings forced_settings;
} NotificationMessageData;

typedef enum {
Expand All @@ -41,6 +48,9 @@ typedef enum {
NotificationMessageTypeDelay,
NotificationMessageTypeLedDisplay,
NotificationMessageTypeDoNotReset,
NotificationMessageTypeForceSpeakerVolumeSetting,
NotificationMessageTypeForceVibroSetting,
NotificationMessageTypeForceDisplayBrightnessSetting,
} NotificationMessageType;

typedef struct {
Expand Down
17 changes: 17 additions & 0 deletions applications/rpc/rpc_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <furi-hal.h>
#include <power/power_service/power.h>
#include <notification/notification-messages.h>

void rpc_system_system_ping_process(const PB_Main* msg_request, void* context) {
furi_assert(msg_request);
Expand Down Expand Up @@ -157,6 +158,19 @@ void rpc_system_system_factory_reset_process(const PB_Main* request, void* conte
power_reboot(PowerBootModeNormal);
}

void rpc_system_system_play_audiovisual_alert_process(const PB_Main* request, void* context) {
furi_assert(request);
furi_assert(request->which_content == PB_Main_system_play_audiovisual_alert_request_tag);
furi_assert(context);
Rpc* rpc = context;

NotificationApp* notification = furi_record_open("notification");
notification_message(notification, &sequence_audiovisual_alert);
furi_record_close("notification");

rpc_send_and_release_empty(rpc, request->command_id, PB_CommandStatus_OK);
}

void* rpc_system_system_alloc(Rpc* rpc) {
RpcHandler rpc_handler = {
.message_handler = NULL,
Expand All @@ -182,5 +196,8 @@ void* rpc_system_system_alloc(Rpc* rpc) {
rpc_handler.message_handler = rpc_system_system_set_datetime_process;
rpc_add_handler(rpc, PB_Main_system_set_datetime_request_tag, &rpc_handler);

rpc_handler.message_handler = rpc_system_system_play_audiovisual_alert_process;
rpc_add_handler(rpc, PB_Main_system_play_audiovisual_alert_request_tag, &rpc_handler);

return NULL;
}
6 changes: 5 additions & 1 deletion assets/compiled/flipper.pb.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ typedef struct _PB_Main {
PB_System_GetDateTimeRequest system_get_datetime_request;
PB_System_GetDateTimeResponse system_get_datetime_response;
PB_System_SetDateTimeRequest system_set_datetime_request;
PB_System_PlayAudiovisualAlertRequest system_play_audiovisual_alert_request;
} content;
} PB_Main;

Expand Down Expand Up @@ -155,6 +156,7 @@ extern "C" {
#define PB_Main_system_get_datetime_request_tag 35
#define PB_Main_system_get_datetime_response_tag 36
#define PB_Main_system_set_datetime_request_tag 37
#define PB_Main_system_play_audiovisual_alert_request_tag 38

/* Struct field encoding specification for nanopb */
#define PB_Empty_FIELDLIST(X, a) \
Expand Down Expand Up @@ -204,7 +206,8 @@ X(a, STATIC, ONEOF, MSG_W_CB, (content,system_device_info_response,content.
X(a, STATIC, ONEOF, MSG_W_CB, (content,system_factory_reset_request,content.system_factory_reset_request), 34) \
X(a, STATIC, ONEOF, MSG_W_CB, (content,system_get_datetime_request,content.system_get_datetime_request), 35) \
X(a, STATIC, ONEOF, MSG_W_CB, (content,system_get_datetime_response,content.system_get_datetime_response), 36) \
X(a, STATIC, ONEOF, MSG_W_CB, (content,system_set_datetime_request,content.system_set_datetime_request), 37)
X(a, STATIC, ONEOF, MSG_W_CB, (content,system_set_datetime_request,content.system_set_datetime_request), 37) \
X(a, STATIC, ONEOF, MSG_W_CB, (content,system_play_audiovisual_alert_request,content.system_play_audiovisual_alert_request), 38)
#define PB_Main_CALLBACK NULL
#define PB_Main_DEFAULT NULL
#define PB_Main_content_empty_MSGTYPE PB_Empty
Expand Down Expand Up @@ -241,6 +244,7 @@ X(a, STATIC, ONEOF, MSG_W_CB, (content,system_set_datetime_request,content.
#define PB_Main_content_system_get_datetime_request_MSGTYPE PB_System_GetDateTimeRequest
#define PB_Main_content_system_get_datetime_response_MSGTYPE PB_System_GetDateTimeResponse
#define PB_Main_content_system_set_datetime_request_MSGTYPE PB_System_SetDateTimeRequest
#define PB_Main_content_system_play_audiovisual_alert_request_MSGTYPE PB_System_PlayAudiovisualAlertRequest

extern const pb_msgdesc_t PB_Empty_msg;
extern const pb_msgdesc_t PB_StopSession_msg;
Expand Down
3 changes: 3 additions & 0 deletions assets/compiled/system.pb.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@ PB_BIND(PB_System_SetDateTimeRequest, PB_System_SetDateTimeRequest, AUTO)
PB_BIND(PB_System_DateTime, PB_System_DateTime, AUTO)


PB_BIND(PB_System_PlayAudiovisualAlertRequest, PB_System_PlayAudiovisualAlertRequest, AUTO)




14 changes: 14 additions & 0 deletions assets/compiled/system.pb.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ typedef struct _PB_System_PingResponse {
pb_bytes_array_t *data;
} PB_System_PingResponse;

typedef struct _PB_System_PlayAudiovisualAlertRequest {
char dummy_field;
} PB_System_PlayAudiovisualAlertRequest;

typedef struct _PB_System_DateTime {
/* Time */
uint8_t hour; /* *< Hour in 24H format: 0-23 */
Expand Down Expand Up @@ -89,6 +93,7 @@ extern "C" {
#define PB_System_GetDateTimeResponse_init_default {false, PB_System_DateTime_init_default}
#define PB_System_SetDateTimeRequest_init_default {false, PB_System_DateTime_init_default}
#define PB_System_DateTime_init_default {0, 0, 0, 0, 0, 0, 0}
#define PB_System_PlayAudiovisualAlertRequest_init_default {0}
#define PB_System_PingRequest_init_zero {NULL}
#define PB_System_PingResponse_init_zero {NULL}
#define PB_System_RebootRequest_init_zero {_PB_System_RebootRequest_RebootMode_MIN}
Expand All @@ -99,6 +104,7 @@ extern "C" {
#define PB_System_GetDateTimeResponse_init_zero {false, PB_System_DateTime_init_zero}
#define PB_System_SetDateTimeRequest_init_zero {false, PB_System_DateTime_init_zero}
#define PB_System_DateTime_init_zero {0, 0, 0, 0, 0, 0, 0}
#define PB_System_PlayAudiovisualAlertRequest_init_zero {0}

/* Field tags (for use in manual encoding/decoding) */
#define PB_System_DeviceInfoResponse_key_tag 1
Expand Down Expand Up @@ -176,6 +182,11 @@ X(a, STATIC, SINGULAR, UINT32, weekday, 7)
#define PB_System_DateTime_CALLBACK NULL
#define PB_System_DateTime_DEFAULT NULL

#define PB_System_PlayAudiovisualAlertRequest_FIELDLIST(X, a) \

#define PB_System_PlayAudiovisualAlertRequest_CALLBACK NULL
#define PB_System_PlayAudiovisualAlertRequest_DEFAULT NULL

extern const pb_msgdesc_t PB_System_PingRequest_msg;
extern const pb_msgdesc_t PB_System_PingResponse_msg;
extern const pb_msgdesc_t PB_System_RebootRequest_msg;
Expand All @@ -186,6 +197,7 @@ extern const pb_msgdesc_t PB_System_GetDateTimeRequest_msg;
extern const pb_msgdesc_t PB_System_GetDateTimeResponse_msg;
extern const pb_msgdesc_t PB_System_SetDateTimeRequest_msg;
extern const pb_msgdesc_t PB_System_DateTime_msg;
extern const pb_msgdesc_t PB_System_PlayAudiovisualAlertRequest_msg;

/* Defines for backwards compatibility with code written before nanopb-0.4.0 */
#define PB_System_PingRequest_fields &PB_System_PingRequest_msg
Expand All @@ -198,6 +210,7 @@ extern const pb_msgdesc_t PB_System_DateTime_msg;
#define PB_System_GetDateTimeResponse_fields &PB_System_GetDateTimeResponse_msg
#define PB_System_SetDateTimeRequest_fields &PB_System_SetDateTimeRequest_msg
#define PB_System_DateTime_fields &PB_System_DateTime_msg
#define PB_System_PlayAudiovisualAlertRequest_fields &PB_System_PlayAudiovisualAlertRequest_msg

/* Maximum encoded size of messages (where known) */
/* PB_System_PingRequest_size depends on runtime parameters */
Expand All @@ -208,6 +221,7 @@ extern const pb_msgdesc_t PB_System_DateTime_msg;
#define PB_System_FactoryResetRequest_size 0
#define PB_System_GetDateTimeRequest_size 0
#define PB_System_GetDateTimeResponse_size 24
#define PB_System_PlayAudiovisualAlertRequest_size 0
#define PB_System_RebootRequest_size 2
#define PB_System_SetDateTimeRequest_size 24

Expand Down
2 changes: 1 addition & 1 deletion assets/protobuf
Submodule protobuf updated 2 files
+1 −0 flipper.proto
+3 −0 system.proto

0 comments on commit 475fa91

Please sign in to comment.