Skip to content
4 changes: 3 additions & 1 deletion include/pbl/services/vibes/vibe_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ typedef enum VibeClient {
VibeClient_Notifications = 0,
VibeClient_PhoneCalls,
VibeClient_Alarms,
VibeClient_AlarmsLPM
VibeClient_AlarmsLPM,
VibeClient_Hourly,
VibeClient_OnDisconnect,
} VibeClient;

// Returns the appropriate vibe score for the client.
Expand Down
6 changes: 6 additions & 0 deletions include/pbl/services/vibes/vibe_score_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,20 @@ typedef enum VibeScoreId {
#define DEFAULT_VIBE_SCORE_NOTIFS (VibeScoreId_Pulse)
#define DEFAULT_VIBE_SCORE_INCOMING_CALLS (VibeScoreId_Pulse)
#define DEFAULT_VIBE_SCORE_ALARMS (VibeScoreId_Pulse)
#define DEFAULT_VIBE_SCORE_HOURLY (VibeScoreId_Disabled)
#define DEFAULT_VIBE_SCORE_ON_DISCONNECT (VibeScoreId_Disabled)
#elif PLATFORM_ASTERIX
#define DEFAULT_VIBE_SCORE_NOTIFS (VibeScoreId_StandardShortPulseHigh)
#define DEFAULT_VIBE_SCORE_INCOMING_CALLS (VibeScoreId_Pulse)
#define DEFAULT_VIBE_SCORE_ALARMS (VibeScoreId_Reveille)
#define DEFAULT_VIBE_SCORE_HOURLY (VibeScoreId_Disabled)
#define DEFAULT_VIBE_SCORE_ON_DISCONNECT (VibeScoreId_Disabled)
#else
#define DEFAULT_VIBE_SCORE_NOTIFS (VibeScoreId_NudgeNudge)
#define DEFAULT_VIBE_SCORE_INCOMING_CALLS (VibeScoreId_Pulse)
#define DEFAULT_VIBE_SCORE_ALARMS (VibeScoreId_Reveille)
#define DEFAULT_VIBE_SCORE_HOURLY (VibeScoreId_Disabled)
#define DEFAULT_VIBE_SCORE_ON_DISCONNECT (VibeScoreId_Disabled)
#endif

// Returns the ResourceId for the VibeScore represented by this id.
Expand Down
28 changes: 28 additions & 0 deletions src/fw/apps/system/settings/vibe_patterns.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ typedef enum VibeSettingsRow {
VibeSettingsRow_Notifications = 0,
VibeSettingsRow_PhoneCalls,
VibeSettingsRow_Alarms,
VibeSettingsRow_Hourly,
VibeSettingsRow_OnDisconnect,
VibeSettingsRow_System,
VibeSettingsRow_Count,
} VibeSettingsRow;
Expand Down Expand Up @@ -61,6 +63,16 @@ static void prv_draw_row_cb(SettingsCallbacks *context, GContext *ctx,
client = VibeClient_Alarms;
break;
}
case VibeSettingsRow_Hourly: {
title = i18n_noop("Hourly Notice");
client = VibeClient_Hourly;
break;
}
case VibeSettingsRow_OnDisconnect: {
title = i18n_noop("On Disconnect");
client = VibeClient_OnDisconnect;
break;
}
case VibeSettingsRow_System: {
/// Refers to the class of all non-score vibes, e.g. 3rd party app vibes
title = i18n_noop("System");
Expand Down Expand Up @@ -101,6 +113,14 @@ static void prv_selection_changed_cb(SettingsCallbacks *context, uint16_t new_ro
score = vibe_client_get_score(VibeClient_Alarms);
break;
}
case VibeSettingsRow_Hourly: {
score = vibe_client_get_score(VibeClient_Hourly);
break;
}
case VibeSettingsRow_OnDisconnect: {
score = vibe_client_get_score(VibeClient_OnDisconnect);
break;
}
case VibeSettingsRow_System: {
// Vibe a short pulse so the user can feel the current system default vibe intensity
vibes_short_pulse();
Expand Down Expand Up @@ -135,6 +155,14 @@ static void prv_select_click_cb(SettingsCallbacks *context, uint16_t row) {
client = VibeClient_Alarms;
break;
}
case VibeSettingsRow_Hourly: {
client = VibeClient_Hourly;
break;
}
case VibeSettingsRow_OnDisconnect: {
client = VibeClient_OnDisconnect;
break;
}
case VibeSettingsRow_System: {
const VibeIntensity current_system_default_vibe_intensity = vibe_intensity_get();
const VibeIntensity next_system_default_vibe_intensity =
Expand Down
23 changes: 23 additions & 0 deletions src/fw/services/clock/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
#include "util/string.h"
#include "pbl/services/analytics/analytics.h"

#ifndef RECOVERY_FW
#include "pbl/services/notifications/do_not_disturb.h"
#include "pbl/services/notifications/alerts.h"
#include "pbl/services/notifications/alerts_preferences_private.h"
#include "pbl/services/vibes/vibe_client.h"
#include "pbl/services/vibes/vibe_score.h"
#endif

#include <stdio.h>

// NOTE: There are RECOVERY_FW ifdefs in this file because PRF does not have
Expand Down Expand Up @@ -403,6 +411,21 @@ void clock_protocol_msg_callback(CommSession *session, const uint8_t* data, unsi
static void prv_watch_dst(void* user) {
const bool was_dst = (bool)user;
const bool is_dst = time_get_isdst(rtc_get_time());

#ifndef RECOVERY_FW
if (alerts_should_vibrate_for_type(AlertOther)) {
if (time_utc_to_local(rtc_get_time()) % 3600 == 0) {
uint32_t vibe_id = vibe_score_info_get_resource_id(
alerts_preferences_get_vibe_score_for_client(VibeClient_Hourly));
VibeScore *score = vibe_score_create_with_resource_system(0, vibe_id);
if (score) {
vibe_score_do_vibe(score);
vibe_score_destroy(score);
}
}
}
#endif

if (is_dst != was_dst) {
PebbleEvent e = {
.type = PEBBLE_SET_TIME_EVENT,
Expand Down
21 changes: 21 additions & 0 deletions src/fw/services/debounced_connection_service/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
#include "pbl/services/regular_timer.h"
#include "syscall/syscall_internal.h"

#ifndef RECOVERY_FW
#include "pbl/services/notifications/do_not_disturb.h"
#include "pbl/services/notifications/alerts.h"
#include "pbl/services/notifications/alerts_preferences_private.h"
#include "pbl/services/vibes/vibe_client.h"
#include "pbl/services/vibes/vibe_score.h"
#endif

#include "system/logging.h"

//! This module is responsible for propagating debounced connection events.
//! Connection events are passed through right away to subscribers but
//! disconnection events are only passed through if a re-connection did not
Expand Down Expand Up @@ -40,6 +50,17 @@ static void prv_handle_disconnection_debounced(void *data) {
DebounceConnection conn_id = (DebounceConnection)data;
s_debounced_state_is_connected[conn_id] = false;
prv_put_debounced_connection_event(conn_id);
#ifndef RECOVERY_FW
if (alerts_should_vibrate_for_type(AlertOther)) {
uint32_t vibe_id = vibe_score_info_get_resource_id(
alerts_preferences_get_vibe_score_for_client(VibeClient_OnDisconnect));
VibeScore *score = vibe_score_create_with_resource_system(0, vibe_id);
if (score) {
vibe_score_do_vibe(score);
vibe_score_destroy(score);
}
}
#endif
regular_timer_remove_callback(&s_debounce_timers[conn_id]);
}

Expand Down
39 changes: 37 additions & 2 deletions src/fw/services/notifications/alerts_preferences.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ static VibeScoreId s_vibe_score_incoming_calls = DEFAULT_VIBE_SCORE_INCOMING_CAL
#define PREF_KEY_VIBE_SCORE_ALARMS ("vibeScoreAlarms")
static VibeScoreId s_vibe_score_alarms = DEFAULT_VIBE_SCORE_ALARMS;

#define PREF_KEY_VIBE_SCORE_HOURLY ("vibeScoreHourly")
static VibeScoreId s_vibe_score_hourly = DEFAULT_VIBE_SCORE_HOURLY;

#define PREF_KEY_VIBE_SCORE_ON_DISCONNECT ("vibeScoreOnDisconnect")
static VibeScoreId s_vibe_score_on_disconnect = DEFAULT_VIBE_SCORE_ON_DISCONNECT;

#define PREF_KEY_DND_MANUALLY_ENABLED "dndManuallyEnabled"
static bool s_do_not_disturb_manually_enabled = false;

Expand Down Expand Up @@ -181,7 +187,9 @@ static void prv_migrate_legacy_first_use_settings(SettingsFile *file) {
static void prv_save_changed_vibe_scores_to_file(SettingsFile *file,
VibeScoreId orig_notifications,
VibeScoreId orig_incoming_calls,
VibeScoreId orig_alarms) {
VibeScoreId orig_alarms,
VibeScoreId orig_hourly,
VibeScoreId orig_on_disconnect) {
#define SET_PREF_IF_CHANGED(key, value, orig) \
do { \
if ((value) != (orig)) { \
Expand All @@ -194,6 +202,9 @@ static void prv_save_changed_vibe_scores_to_file(SettingsFile *file,
SET_PREF_IF_CHANGED(PREF_KEY_VIBE_SCORE_INCOMING_CALLS, s_vibe_score_incoming_calls,
orig_incoming_calls);
SET_PREF_IF_CHANGED(PREF_KEY_VIBE_SCORE_ALARMS, s_vibe_score_alarms, orig_alarms);
SET_PREF_IF_CHANGED(PREF_KEY_VIBE_SCORE_HOURLY, s_vibe_score_hourly, orig_hourly);
SET_PREF_IF_CHANGED(PREF_KEY_VIBE_SCORE_ON_DISCONNECT, s_vibe_score_on_disconnect,
orig_on_disconnect);
#undef SET_PREF_IF_CHANGED
}

Expand All @@ -209,6 +220,10 @@ static void prv_ensure_valid_vibe_scores(void) {
DEFAULT_VIBE_SCORE_INCOMING_CALLS);
s_vibe_score_alarms = prv_return_default_if_invalid(s_vibe_score_alarms,
DEFAULT_VIBE_SCORE_ALARMS);
s_vibe_score_hourly = prv_return_default_if_invalid(s_vibe_score_hourly,
DEFAULT_VIBE_SCORE_HOURLY);
s_vibe_score_on_disconnect = prv_return_default_if_invalid(s_vibe_score_on_disconnect,
DEFAULT_VIBE_SCORE_ON_DISCONNECT);
}

static void prv_set_vibe_scores_based_on_legacy_intensity(VibeIntensity intensity) {
Expand Down Expand Up @@ -285,6 +300,8 @@ void alerts_preferences_init(void) {
RESTORE_PREF(PREF_KEY_VIBE_SCORE_NOTIFICATIONS, s_vibe_score_notifications);
RESTORE_PREF(PREF_KEY_VIBE_SCORE_INCOMING_CALLS, s_vibe_score_incoming_calls);
RESTORE_PREF(PREF_KEY_VIBE_SCORE_ALARMS, s_vibe_score_alarms);
RESTORE_PREF(PREF_KEY_VIBE_SCORE_HOURLY, s_vibe_score_hourly);
RESTORE_PREF(PREF_KEY_VIBE_SCORE_ON_DISCONNECT, s_vibe_score_on_disconnect);
RESTORE_PREF(PREF_KEY_DND_MANUALLY_ENABLED, s_do_not_disturb_manually_enabled);
RESTORE_PREF(PREF_KEY_DND_SMART_ENABLED, s_do_not_disturb_smart_dnd_enabled);
RESTORE_PREF(PREF_KEY_DND_INTERRUPTIONS_MASK, s_dnd_interruptions_mask);
Expand Down Expand Up @@ -312,13 +329,17 @@ void alerts_preferences_init(void) {
const VibeScoreId orig_vibe_score_notifications = s_vibe_score_notifications;
const VibeScoreId orig_vibe_score_incoming_calls = s_vibe_score_incoming_calls;
const VibeScoreId orig_vibe_score_alarms = s_vibe_score_alarms;
const VibeScoreId orig_vibe_score_hourly = s_vibe_score_hourly;
const VibeScoreId orig_vibe_score_on_disconnect = s_vibe_score_on_disconnect;

prv_migrate_legacy_first_use_settings(&file);
prv_migrate_vibe_intensity_to_vibe_scores(&file);
prv_ensure_valid_vibe_scores();
prv_save_changed_vibe_scores_to_file(&file, orig_vibe_score_notifications,
orig_vibe_score_incoming_calls,
orig_vibe_score_alarms);
orig_vibe_score_alarms,
orig_vibe_score_hourly,
orig_vibe_score_on_disconnect);

settings_file_close(&file);
}
Expand Down Expand Up @@ -418,6 +439,10 @@ VibeScoreId alerts_preferences_get_vibe_score_for_client(VibeClient client) {
return s_vibe_score_incoming_calls;
case VibeClient_Alarms:
return s_vibe_score_alarms;
case VibeClient_Hourly:
return s_vibe_score_hourly;
case VibeClient_OnDisconnect:
return s_vibe_score_on_disconnect;
default:
WTF;
}
Expand All @@ -441,6 +466,16 @@ void alerts_preferences_set_vibe_score_for_client(VibeClient client, VibeScoreId
key = PREF_KEY_VIBE_SCORE_ALARMS;
break;
}
case VibeClient_Hourly: {
s_vibe_score_hourly = id;
key = PREF_KEY_VIBE_SCORE_HOURLY;
break;
}
case VibeClient_OnDisconnect: {
s_vibe_score_on_disconnect = id;
key = PREF_KEY_VIBE_SCORE_ON_DISCONNECT;
break;
}
default: {
WTF;
}
Expand Down
12 changes: 11 additions & 1 deletion src/fw/services/vibes/vibe_score_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ typedef enum AlertType {
AlertType_Calls = 1 << 1,
AlertType_Alarms = 1 << 2,
AlertType_AlarmsLPM = 1 << 3,
AlertType_All = AlertType_Notifications | AlertType_Calls | AlertType_Alarms,
AlertType_Hourly = 1 << 4,
AlertType_OnDisconnect = 1 << 5,
AlertType_All = AlertType_Notifications | AlertType_Calls | AlertType_Alarms | AlertType_Hourly | AlertType_OnDisconnect,
} AlertType;

typedef struct {
Expand Down Expand Up @@ -79,6 +81,14 @@ VibeScoreId vibe_score_info_cycle_next(VibeClient client, VibeScoreId curr_id) {
alert_type = AlertType_Alarms;
break;
}
case VibeClient_Hourly: {
alert_type = AlertType_Hourly;
break;
}
case VibeClient_OnDisconnect: {
alert_type = AlertType_OnDisconnect;
break;
}
default: {
WTF;
}
Expand Down
6 changes: 3 additions & 3 deletions src/fw/services/vibes/vibes.def
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// IDs must be monotonically increasing, i.e. they must never be reused
// ID 0 is reserved for "Invalid". Do not use!

VIBE_DEF(1, Disabled, i18n_ctx_noop("NotifVibe", "Disabled"), (AlertType_Notifications | AlertType_Calls), RESOURCE_ID_INVALID)
VIBE_DEF(2, StandardShortPulseLow, i18n_noop("Standard - Low"), AlertType_Notifications, RESOURCE_ID_VIBE_SCORE_STANDARD_SHORT_LOW)
VIBE_DEF(1, Disabled, i18n_ctx_noop("NotifVibe", "Disabled"), (AlertType_Notifications | AlertType_Calls | AlertType_Hourly| AlertType_OnDisconnect), RESOURCE_ID_INVALID)
VIBE_DEF(2, StandardShortPulseLow, i18n_noop("Standard - Low"), (AlertType_Notifications | AlertType_Hourly | AlertType_OnDisconnect), RESOURCE_ID_VIBE_SCORE_STANDARD_SHORT_LOW)
VIBE_DEF(3, StandardLongPulseLow, i18n_noop("Standard - Low"), (AlertType_Calls | AlertType_Alarms), RESOURCE_ID_VIBE_SCORE_STANDARD_LONG_LOW)
VIBE_DEF(4, StandardShortPulseHigh, i18n_noop("Standard - High"), AlertType_Notifications, RESOURCE_ID_VIBE_SCORE_STANDARD_SHORT_HIGH)
VIBE_DEF(4, StandardShortPulseHigh, i18n_noop("Standard - High"), (AlertType_Notifications | AlertType_Hourly | AlertType_OnDisconnect), RESOURCE_ID_VIBE_SCORE_STANDARD_SHORT_HIGH)
VIBE_DEF(5, StandardLongPulseHigh, i18n_noop("Standard - High"), (AlertType_Calls | AlertType_Alarms), RESOURCE_ID_VIBE_SCORE_STANDARD_LONG_HIGH)
VIBE_DEF(8, Pulse, i18n_noop("Pulse"), AlertType_All, RESOURCE_ID_VIBE_SCORE_PULSE)
VIBE_DEF(9, NudgeNudge, i18n_noop("Nudge Nudge"), AlertType_All, RESOURCE_ID_VIBE_SCORE_NUDGE_NUDGE)
Expand Down
Loading