mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-12 17:38:36 -07:00
Merge branch 'ul-dev' into xfw-dev
This commit is contained in:
@@ -240,7 +240,7 @@ static bool bt_on_gap_event_callback(GapEvent event, void* context) {
|
||||
furi_event_flag_clear(bt->rpc_event, BT_RPC_EVENT_DISCONNECTED);
|
||||
if(bt->profile == BtProfileSerial) {
|
||||
// Open RPC session
|
||||
bt->rpc_session = rpc_session_open(bt->rpc);
|
||||
bt->rpc_session = rpc_session_open(bt->rpc, RpcOwnerBle);
|
||||
if(bt->rpc_session) {
|
||||
FURI_LOG_I(TAG, "Open RPC connection");
|
||||
rpc_session_set_send_bytes_callback(bt->rpc_session, bt_rpc_send_bytes_callback);
|
||||
|
||||
@@ -39,6 +39,12 @@ static void desktop_lock_icon_draw_callback(Canvas* canvas, void* context) {
|
||||
canvas_draw_icon(canvas, 0, 0, &I_Lock_7x8);
|
||||
}
|
||||
|
||||
static void desktop_stealth_mode_icon_draw_callback(Canvas* canvas, void* context) {
|
||||
UNUSED(context);
|
||||
furi_assert(canvas);
|
||||
canvas_draw_icon(canvas, 0, 0, &I_Muted_8x8);
|
||||
}
|
||||
|
||||
static bool desktop_custom_event_callback(void* context, uint32_t event) {
|
||||
furi_assert(context);
|
||||
Desktop* desktop = (Desktop*)context;
|
||||
@@ -139,6 +145,18 @@ void desktop_unlock(Desktop* desktop) {
|
||||
desktop_auto_lock_arm(desktop);
|
||||
}
|
||||
|
||||
void desktop_set_stealth_mode_state(Desktop* desktop, bool enabled) {
|
||||
desktop->in_transition = true;
|
||||
if(enabled) {
|
||||
furi_hal_rtc_set_flag(FuriHalRtcFlagStealthMode);
|
||||
} else {
|
||||
furi_hal_rtc_reset_flag(FuriHalRtcFlagStealthMode);
|
||||
}
|
||||
desktop_lock_menu_set_stealth_mode_state(desktop->lock_menu, enabled);
|
||||
view_port_enabled_set(desktop->stealth_mode_icon_viewport, enabled);
|
||||
desktop->in_transition = false;
|
||||
}
|
||||
|
||||
Desktop* desktop_alloc() {
|
||||
Desktop* desktop = malloc(sizeof(Desktop));
|
||||
|
||||
@@ -222,6 +240,18 @@ Desktop* desktop_alloc() {
|
||||
view_port_enabled_set(desktop->lock_icon_viewport, false);
|
||||
gui_add_view_port(desktop->gui, desktop->lock_icon_viewport, GuiLayerStatusBarLeft);
|
||||
|
||||
// Stealth mode icon
|
||||
desktop->stealth_mode_icon_viewport = view_port_alloc();
|
||||
view_port_set_width(desktop->stealth_mode_icon_viewport, icon_get_width(&I_Muted_8x8));
|
||||
view_port_draw_callback_set(
|
||||
desktop->stealth_mode_icon_viewport, desktop_stealth_mode_icon_draw_callback, desktop);
|
||||
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagStealthMode)) {
|
||||
view_port_enabled_set(desktop->stealth_mode_icon_viewport, true);
|
||||
} else {
|
||||
view_port_enabled_set(desktop->stealth_mode_icon_viewport, false);
|
||||
}
|
||||
gui_add_view_port(desktop->gui, desktop->stealth_mode_icon_viewport, GuiLayerStatusBarLeft);
|
||||
|
||||
// Special case: autostart application is already running
|
||||
desktop->loader = furi_record_open(RECORD_LOADER);
|
||||
if(loader_is_locked(desktop->loader) &&
|
||||
|
||||
@@ -58,6 +58,7 @@ struct Desktop {
|
||||
DesktopViewPinInput* pin_input_view;
|
||||
|
||||
ViewPort* lock_icon_viewport;
|
||||
ViewPort* stealth_mode_icon_viewport;
|
||||
|
||||
AnimationManager* animation_manager;
|
||||
|
||||
@@ -77,3 +78,4 @@ Desktop* desktop_alloc();
|
||||
void desktop_free(Desktop* desktop);
|
||||
void desktop_lock(Desktop* desktop);
|
||||
void desktop_unlock(Desktop* desktop);
|
||||
void desktop_set_stealth_mode_state(Desktop* desktop, bool enabled);
|
||||
|
||||
@@ -28,6 +28,8 @@ void desktop_scene_lock_menu_on_enter(void* context) {
|
||||
scene_manager_set_scene_state(desktop->scene_manager, DesktopSceneLockMenu, 0);
|
||||
desktop_lock_menu_set_callback(desktop->lock_menu, desktop_scene_lock_menu_callback, desktop);
|
||||
desktop_lock_menu_set_pin_state(desktop->lock_menu, desktop->settings.pin_code.length > 0);
|
||||
desktop_lock_menu_set_stealth_mode_state(
|
||||
desktop->lock_menu, furi_hal_rtc_is_flag_set(FuriHalRtcFlagStealthMode));
|
||||
desktop_lock_menu_set_idx(desktop->lock_menu, 3);
|
||||
|
||||
Gui* gui = furi_record_open(RECORD_GUI);
|
||||
@@ -129,6 +131,12 @@ bool desktop_scene_lock_menu_on_event(void* context, SceneManagerEvent event) {
|
||||
desktop->loader, FAP_LOADER_APP_NAME, EXT_PATH("apps/.Main/xtreme_app.fap"));
|
||||
consumed = true;
|
||||
break;
|
||||
case DesktopLockMenuEventStealthModeOn:
|
||||
desktop_set_stealth_mode_state(desktop, true);
|
||||
break;
|
||||
case DesktopLockMenuEventStealthModeOff:
|
||||
desktop_set_stealth_mode_state(desktop, false);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -44,6 +44,8 @@ typedef enum {
|
||||
DesktopLockMenuEventLockPin,
|
||||
DesktopLockMenuEventLockPinOff,
|
||||
DesktopLockMenuEventXtreme,
|
||||
DesktopLockMenuEventStealthModeOn,
|
||||
DesktopLockMenuEventStealthModeOff,
|
||||
|
||||
DesktopAnimationEventCheckAnimation,
|
||||
DesktopAnimationEventNewIdleAnimation,
|
||||
|
||||
@@ -48,6 +48,14 @@ void desktop_lock_menu_set_pin_state(DesktopLockMenuView* lock_menu, bool pin_is
|
||||
true);
|
||||
}
|
||||
|
||||
void desktop_lock_menu_set_stealth_mode_state(DesktopLockMenuView* lock_menu, bool stealth_mode) {
|
||||
with_view_model(
|
||||
lock_menu->view,
|
||||
DesktopLockMenuViewModel * model,
|
||||
{ model->stealth_mode = stealth_mode; },
|
||||
true);
|
||||
}
|
||||
|
||||
void desktop_lock_menu_set_idx(DesktopLockMenuView* lock_menu, uint8_t idx) {
|
||||
furi_assert(idx < DesktopLockMenuIndexTotalCount);
|
||||
with_view_model(
|
||||
@@ -110,7 +118,7 @@ void desktop_lock_menu_draw_callback(Canvas* canvas, void* model) {
|
||||
value = total - m->lock_menu->notification->settings.display_brightness * total;
|
||||
break;
|
||||
case DesktopLockMenuIndexVolume:
|
||||
icon = &I_Volup_8x6;
|
||||
icon = m->stealth_mode ? &I_Muted_8x8 : &I_Volup_8x6;
|
||||
value = total - m->lock_menu->notification->settings.speaker_volume * total;
|
||||
break;
|
||||
default:
|
||||
@@ -181,6 +189,7 @@ bool desktop_lock_menu_input_callback(InputEvent* event, void* context) {
|
||||
uint8_t idx = 0;
|
||||
int pin_lock = 0;
|
||||
bool show_lock_menu = false;
|
||||
bool stealth_mode = false;
|
||||
bool consumed = true;
|
||||
|
||||
with_view_model(
|
||||
@@ -188,6 +197,7 @@ bool desktop_lock_menu_input_callback(InputEvent* event, void* context) {
|
||||
DesktopLockMenuViewModel * model,
|
||||
{
|
||||
show_lock_menu = model->show_lock_menu;
|
||||
stealth_mode = model->stealth_mode;
|
||||
if((event->type == InputTypeShort) || (event->type == InputTypeRepeat)) {
|
||||
if(model->show_lock_menu) {
|
||||
if(event->key == InputKeyUp) {
|
||||
@@ -292,6 +302,9 @@ bool desktop_lock_menu_input_callback(InputEvent* event, void* context) {
|
||||
case DesktopLockMenuIndexXtreme:
|
||||
desktop_event = DesktopLockMenuEventXtreme;
|
||||
break;
|
||||
case DesktopLockMenuIndexVolume:
|
||||
desktop_event = stealth_mode ? DesktopLockMenuEventStealthModeOff : DesktopLockMenuEventStealthModeOn;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ typedef struct {
|
||||
int pin_lock;
|
||||
bool show_lock_menu;
|
||||
DesktopLockMenuView* lock_menu;
|
||||
bool stealth_mode;
|
||||
} DesktopLockMenuViewModel;
|
||||
|
||||
void desktop_lock_menu_set_callback(
|
||||
@@ -37,6 +38,7 @@ void desktop_lock_menu_set_callback(
|
||||
|
||||
View* desktop_lock_menu_get_view(DesktopLockMenuView* lock_menu);
|
||||
void desktop_lock_menu_set_pin_state(DesktopLockMenuView* lock_menu, bool pin_is_set);
|
||||
void desktop_lock_menu_set_stealth_mode_state(DesktopLockMenuView* lock_menu, bool stealth_mode);
|
||||
void desktop_lock_menu_set_idx(DesktopLockMenuView* lock_menu, uint8_t idx);
|
||||
DesktopLockMenuView* desktop_lock_menu_alloc();
|
||||
void desktop_lock_menu_free(DesktopLockMenuView* lock_menu);
|
||||
|
||||
@@ -273,6 +273,8 @@ Menu* menu_alloc() {
|
||||
void menu_free(Menu* menu) {
|
||||
furi_assert(menu);
|
||||
menu_reset(menu);
|
||||
with_view_model(
|
||||
menu->view, MenuModel * model, { MenuItemArray_clear(model->items); }, false);
|
||||
view_free(menu->view);
|
||||
furi_timer_free(menu->scroll_timer);
|
||||
free(menu);
|
||||
|
||||
@@ -20,9 +20,9 @@ static const uint8_t reset_sound_mask = 1 << 4;
|
||||
static const uint8_t reset_display_mask = 1 << 5;
|
||||
static const uint8_t reset_blink_mask = 1 << 6;
|
||||
|
||||
void notification_vibro_on();
|
||||
void notification_vibro_on(bool force);
|
||||
void notification_vibro_off();
|
||||
void notification_sound_on(float freq, float volume);
|
||||
void notification_sound_on(float freq, float volume, bool force);
|
||||
void notification_sound_off();
|
||||
|
||||
uint8_t notification_settings_get_display_brightness(NotificationApp* app, uint8_t value);
|
||||
@@ -141,17 +141,21 @@ uint32_t notification_settings_display_off_delay_ticks(NotificationApp* app) {
|
||||
}
|
||||
|
||||
// generics
|
||||
void notification_vibro_on() {
|
||||
furi_hal_vibro_on(true);
|
||||
void notification_vibro_on(bool force) {
|
||||
if(!furi_hal_rtc_is_flag_set(FuriHalRtcFlagStealthMode) || force) {
|
||||
furi_hal_vibro_on(true);
|
||||
}
|
||||
}
|
||||
|
||||
void notification_vibro_off() {
|
||||
furi_hal_vibro_on(false);
|
||||
}
|
||||
|
||||
void notification_sound_on(float freq, float volume) {
|
||||
if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
|
||||
furi_hal_speaker_start(freq, volume);
|
||||
void notification_sound_on(float freq, float volume, bool force) {
|
||||
if(!furi_hal_rtc_is_flag_set(FuriHalRtcFlagStealthMode) || force) {
|
||||
if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
|
||||
furi_hal_speaker_start(freq, volume);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,6 +178,8 @@ void notification_process_notification_message(
|
||||
NotificationApp* app,
|
||||
NotificationAppMessage* message) {
|
||||
uint32_t notification_message_index = 0;
|
||||
bool force_volume = false;
|
||||
bool force_vibro = false;
|
||||
const NotificationMessage* notification_message;
|
||||
notification_message = (*message->sequence)[notification_message_index];
|
||||
|
||||
@@ -269,7 +275,7 @@ void notification_process_notification_message(
|
||||
break;
|
||||
case NotificationMessageTypeVibro:
|
||||
if(notification_message->data.vibro.on) {
|
||||
if(vibro_setting) notification_vibro_on();
|
||||
if(vibro_setting) notification_vibro_on(force_vibro);
|
||||
} else {
|
||||
notification_vibro_off();
|
||||
}
|
||||
@@ -278,7 +284,8 @@ void notification_process_notification_message(
|
||||
case NotificationMessageTypeSoundOn:
|
||||
notification_sound_on(
|
||||
notification_message->data.sound.frequency,
|
||||
notification_message->data.sound.volume * speaker_volume_setting);
|
||||
notification_message->data.sound.volume * speaker_volume_setting,
|
||||
force_volume);
|
||||
reset_mask |= reset_sound_mask;
|
||||
break;
|
||||
case NotificationMessageTypeSoundOff:
|
||||
@@ -307,9 +314,11 @@ void notification_process_notification_message(
|
||||
break;
|
||||
case NotificationMessageTypeForceSpeakerVolumeSetting:
|
||||
speaker_volume_setting = notification_message->data.forced_settings.speaker_volume;
|
||||
force_volume = true;
|
||||
break;
|
||||
case NotificationMessageTypeForceVibroSetting:
|
||||
vibro_setting = notification_message->data.forced_settings.vibro;
|
||||
force_vibro = true;
|
||||
break;
|
||||
case NotificationMessageTypeForceDisplayBrightnessSetting:
|
||||
display_brightness_setting =
|
||||
|
||||
@@ -512,6 +512,10 @@ static void power_check_battery_level_change(Power* power) {
|
||||
}
|
||||
}
|
||||
|
||||
void power_trigger_ui_update(Power* power) {
|
||||
view_port_update(power->battery_view_port);
|
||||
}
|
||||
|
||||
int32_t power_srv(void* p) {
|
||||
UNUSED(p);
|
||||
|
||||
@@ -543,7 +547,9 @@ int32_t power_srv(void* p) {
|
||||
power_check_battery_level_change(power);
|
||||
|
||||
// Update battery view port
|
||||
if(need_refresh) view_port_update(power->battery_view_port);
|
||||
if(need_refresh) {
|
||||
view_port_update(power->battery_view_port);
|
||||
}
|
||||
|
||||
// Check OTG status and disable it in case of fault
|
||||
if(furi_hal_power_is_otg_enabled()) {
|
||||
|
||||
@@ -113,6 +113,12 @@ bool power_is_battery_healthy(Power* power);
|
||||
*/
|
||||
void power_enable_low_battery_level_notification(Power* power, bool enable);
|
||||
|
||||
/** Trigger UI update for changing battery layout
|
||||
*
|
||||
* @param power Power instance
|
||||
*/
|
||||
void power_trigger_ui_update(Power* power);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -76,6 +76,7 @@ struct RpcSession {
|
||||
RpcBufferIsEmptyCallback buffer_is_empty_callback;
|
||||
RpcSessionClosedCallback closed_callback;
|
||||
RpcSessionTerminatedCallback terminated_callback;
|
||||
RpcOwner owner;
|
||||
void* context;
|
||||
};
|
||||
|
||||
@@ -83,6 +84,11 @@ struct Rpc {
|
||||
FuriMutex* busy_mutex;
|
||||
};
|
||||
|
||||
RpcOwner rpc_session_get_owner(RpcSession* session) {
|
||||
furi_assert(session);
|
||||
return session->owner;
|
||||
}
|
||||
|
||||
static void rpc_close_session_process(const PB_Main* request, void* context) {
|
||||
furi_assert(request);
|
||||
furi_assert(context);
|
||||
@@ -348,7 +354,7 @@ static void rpc_session_free_callback(FuriThreadState thread_state, void* contex
|
||||
}
|
||||
}
|
||||
|
||||
RpcSession* rpc_session_open(Rpc* rpc) {
|
||||
RpcSession* rpc_session_open(Rpc* rpc, RpcOwner owner) {
|
||||
furi_assert(rpc);
|
||||
|
||||
RpcSession* session = malloc(sizeof(RpcSession));
|
||||
@@ -357,6 +363,7 @@ RpcSession* rpc_session_open(Rpc* rpc) {
|
||||
session->rpc = rpc;
|
||||
session->terminate = false;
|
||||
session->decode_error = false;
|
||||
session->owner = owner;
|
||||
RpcHandlerDict_init(session->handlers);
|
||||
|
||||
session->decoded_message = malloc(sizeof(PB_Main));
|
||||
|
||||
@@ -30,6 +30,21 @@ typedef void (*RpcSessionClosedCallback)(void* context);
|
||||
* and all operations were finished */
|
||||
typedef void (*RpcSessionTerminatedCallback)(void* context);
|
||||
|
||||
/** RPC owner */
|
||||
typedef enum {
|
||||
RpcOwnerUnknown = 0,
|
||||
RpcOwnerBle,
|
||||
RpcOwnerUsb,
|
||||
RpcOwnerCount,
|
||||
} RpcOwner;
|
||||
|
||||
/** Get RPC session owner
|
||||
*
|
||||
* @param session pointer to RpcSession descriptor
|
||||
* @return session owner
|
||||
*/
|
||||
RpcOwner rpc_session_get_owner(RpcSession* session);
|
||||
|
||||
/** Open RPC session
|
||||
*
|
||||
* USAGE:
|
||||
@@ -44,10 +59,11 @@ typedef void (*RpcSessionTerminatedCallback)(void* context);
|
||||
*
|
||||
*
|
||||
* @param rpc instance
|
||||
* @param owner owner of session
|
||||
* @return pointer to RpcSession descriptor, or
|
||||
* NULL if RPC is busy and can't open session now
|
||||
*/
|
||||
RpcSession* rpc_session_open(Rpc* rpc);
|
||||
RpcSession* rpc_session_open(Rpc* rpc, RpcOwner owner);
|
||||
|
||||
/** Close RPC session
|
||||
* It is guaranteed that no callbacks will be called
|
||||
|
||||
@@ -47,7 +47,7 @@ void rpc_cli_command_start_session(Cli* cli, FuriString* args, void* context) {
|
||||
FURI_LOG_D(TAG, "Free memory %lu", mem_before);
|
||||
|
||||
furi_hal_usb_lock();
|
||||
RpcSession* rpc_session = rpc_session_open(rpc);
|
||||
RpcSession* rpc_session = rpc_session_open(rpc, RpcOwnerUsb);
|
||||
if(rpc_session == NULL) {
|
||||
printf("Session start error\r\n");
|
||||
furi_hal_usb_unlock();
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "rpc_i.h"
|
||||
#include "gui.pb.h"
|
||||
#include <gui/gui_i.h>
|
||||
#include <assets_icons.h>
|
||||
|
||||
#define TAG "RpcGui"
|
||||
|
||||
@@ -31,6 +32,8 @@ typedef struct {
|
||||
|
||||
uint32_t input_key_counter[InputKeyMAX];
|
||||
uint32_t input_counter;
|
||||
|
||||
ViewPort* rpc_session_active_viewport;
|
||||
} RpcGuiSystem;
|
||||
|
||||
static const PB_Gui_ScreenOrientation rpc_system_gui_screen_orientation_map[] = {
|
||||
@@ -352,6 +355,12 @@ static void rpc_system_gui_virtual_display_frame_process(const PB_Main* request,
|
||||
(void)session;
|
||||
}
|
||||
|
||||
static void rpc_active_session_icon_draw_callback(Canvas* canvas, void* context) {
|
||||
UNUSED(context);
|
||||
furi_assert(canvas);
|
||||
canvas_draw_icon(canvas, 0, 0, &I_Rpc_active_7x8);
|
||||
}
|
||||
|
||||
void* rpc_system_gui_alloc(RpcSession* session) {
|
||||
furi_assert(session);
|
||||
|
||||
@@ -359,6 +368,18 @@ void* rpc_system_gui_alloc(RpcSession* session) {
|
||||
rpc_gui->gui = furi_record_open(RECORD_GUI);
|
||||
rpc_gui->session = session;
|
||||
|
||||
// Active session icon
|
||||
rpc_gui->rpc_session_active_viewport = view_port_alloc();
|
||||
view_port_set_width(rpc_gui->rpc_session_active_viewport, icon_get_width(&I_Rpc_active_7x8));
|
||||
view_port_draw_callback_set(
|
||||
rpc_gui->rpc_session_active_viewport, rpc_active_session_icon_draw_callback, session);
|
||||
if(rpc_session_get_owner(rpc_gui->session) != RpcOwnerBle) {
|
||||
view_port_enabled_set(rpc_gui->rpc_session_active_viewport, true);
|
||||
} else {
|
||||
view_port_enabled_set(rpc_gui->rpc_session_active_viewport, false);
|
||||
}
|
||||
gui_add_view_port(rpc_gui->gui, rpc_gui->rpc_session_active_viewport, GuiLayerStatusBarLeft);
|
||||
|
||||
RpcHandler rpc_handler = {
|
||||
.message_handler = NULL,
|
||||
.decode_submessage = NULL,
|
||||
@@ -399,6 +420,9 @@ void rpc_system_gui_free(void* context) {
|
||||
rpc_gui->virtual_display_not_empty = false;
|
||||
}
|
||||
|
||||
gui_remove_view_port(rpc_gui->gui, rpc_gui->rpc_session_active_viewport);
|
||||
view_port_free(rpc_gui->rpc_session_active_viewport);
|
||||
|
||||
if(rpc_gui->is_streaming) {
|
||||
rpc_gui->is_streaming = false;
|
||||
// Remove GUI framebuffer callback
|
||||
@@ -415,4 +439,4 @@ void rpc_system_gui_free(void* context) {
|
||||
}
|
||||
furi_record_close(RECORD_GUI);
|
||||
free(rpc_gui);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user