mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2025-12-12 12:42:30 +04:00
Merge remote-tracking branch 'OFW/portasynthinca3/3332-autolock-fixes' into dev
This commit is contained in:
@@ -2,6 +2,10 @@
|
|||||||
#include <furi_hal_usb_cdc.h>
|
#include <furi_hal_usb_cdc.h>
|
||||||
#include <furi_hal.h>
|
#include <furi_hal.h>
|
||||||
#include <furi.h>
|
#include <furi.h>
|
||||||
|
#include <gui/gui.h>
|
||||||
|
#include <gui/view_port.h>
|
||||||
|
#include <assets_icons.h>
|
||||||
|
#include <applications/services/desktop/desktop.h>
|
||||||
|
|
||||||
#define TAG "CliVcp"
|
#define TAG "CliVcp"
|
||||||
|
|
||||||
@@ -43,6 +47,13 @@ typedef struct {
|
|||||||
FuriHalUsbInterface* usb_if_prev;
|
FuriHalUsbInterface* usb_if_prev;
|
||||||
|
|
||||||
uint8_t data_buffer[USB_CDC_PKT_LEN];
|
uint8_t data_buffer[USB_CDC_PKT_LEN];
|
||||||
|
|
||||||
|
// CLI icon
|
||||||
|
Gui* gui;
|
||||||
|
ViewPort* view_port;
|
||||||
|
|
||||||
|
// Autolocking inhibition
|
||||||
|
Desktop* desktop;
|
||||||
} CliVcp;
|
} CliVcp;
|
||||||
|
|
||||||
static int32_t vcp_worker(void* context);
|
static int32_t vcp_worker(void* context);
|
||||||
@@ -64,6 +75,13 @@ static CliVcp* vcp = NULL;
|
|||||||
static const uint8_t ascii_soh = 0x01;
|
static const uint8_t ascii_soh = 0x01;
|
||||||
static const uint8_t ascii_eot = 0x04;
|
static const uint8_t ascii_eot = 0x04;
|
||||||
|
|
||||||
|
static void cli_vcp_icon_draw_callback(Canvas* canvas, void* context) {
|
||||||
|
furi_assert(canvas);
|
||||||
|
furi_assert(context);
|
||||||
|
const Icon* icon = context;
|
||||||
|
canvas_draw_icon(canvas, 0, 0, icon);
|
||||||
|
}
|
||||||
|
|
||||||
static void cli_vcp_init(void) {
|
static void cli_vcp_init(void) {
|
||||||
if(vcp == NULL) {
|
if(vcp == NULL) {
|
||||||
vcp = malloc(sizeof(CliVcp));
|
vcp = malloc(sizeof(CliVcp));
|
||||||
@@ -103,6 +121,15 @@ static int32_t vcp_worker(void* context) {
|
|||||||
FURI_LOG_D(TAG, "Start");
|
FURI_LOG_D(TAG, "Start");
|
||||||
vcp->running = true;
|
vcp->running = true;
|
||||||
|
|
||||||
|
// GUI icon
|
||||||
|
vcp->desktop = furi_record_open(RECORD_DESKTOP);
|
||||||
|
const Icon* icon = &I_Console_active_8x8;
|
||||||
|
vcp->gui = furi_record_open(RECORD_GUI);
|
||||||
|
vcp->view_port = view_port_alloc();
|
||||||
|
view_port_set_width(vcp->view_port, icon_get_width(icon));
|
||||||
|
// casting const away. we know that we cast it right back in the callback
|
||||||
|
view_port_draw_callback_set(vcp->view_port, cli_vcp_icon_draw_callback, (void*)icon);
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
uint32_t flags =
|
uint32_t flags =
|
||||||
furi_thread_flags_wait(VCP_THREAD_FLAG_ALL, FuriFlagWaitAny, FuriWaitForever);
|
furi_thread_flags_wait(VCP_THREAD_FLAG_ALL, FuriFlagWaitAny, FuriWaitForever);
|
||||||
@@ -115,6 +142,8 @@ static int32_t vcp_worker(void* context) {
|
|||||||
if(vcp->connected == false) {
|
if(vcp->connected == false) {
|
||||||
vcp->connected = true;
|
vcp->connected = true;
|
||||||
furi_stream_buffer_send(vcp->rx_stream, &ascii_soh, 1, FuriWaitForever);
|
furi_stream_buffer_send(vcp->rx_stream, &ascii_soh, 1, FuriWaitForever);
|
||||||
|
gui_add_view_port(vcp->gui, vcp->view_port, GuiLayerStatusBarLeft);
|
||||||
|
desktop_api_add_external_inhibitor(vcp->desktop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,6 +155,8 @@ static int32_t vcp_worker(void* context) {
|
|||||||
vcp->connected = false;
|
vcp->connected = false;
|
||||||
furi_stream_buffer_receive(vcp->tx_stream, vcp->data_buffer, USB_CDC_PKT_LEN, 0);
|
furi_stream_buffer_receive(vcp->tx_stream, vcp->data_buffer, USB_CDC_PKT_LEN, 0);
|
||||||
furi_stream_buffer_send(vcp->rx_stream, &ascii_eot, 1, FuriWaitForever);
|
furi_stream_buffer_send(vcp->rx_stream, &ascii_eot, 1, FuriWaitForever);
|
||||||
|
gui_remove_view_port(vcp->gui, vcp->view_port);
|
||||||
|
desktop_api_remove_external_inhibitor(vcp->desktop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,6 +221,10 @@ static int32_t vcp_worker(void* context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(flags & VcpEvtStop) {
|
if(flags & VcpEvtStop) {
|
||||||
|
if(vcp->connected) {
|
||||||
|
gui_remove_view_port(vcp->gui, vcp->view_port);
|
||||||
|
desktop_api_remove_external_inhibitor(vcp->desktop);
|
||||||
|
}
|
||||||
vcp->connected = false;
|
vcp->connected = false;
|
||||||
vcp->running = false;
|
vcp->running = false;
|
||||||
furi_hal_cdc_set_callbacks(VCP_IF_NUM, NULL, NULL);
|
furi_hal_cdc_set_callbacks(VCP_IF_NUM, NULL, NULL);
|
||||||
@@ -203,6 +238,11 @@ static int32_t vcp_worker(void* context) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
view_port_free(vcp->view_port);
|
||||||
|
furi_record_close(RECORD_DESKTOP);
|
||||||
|
furi_record_close(RECORD_GUI);
|
||||||
|
|
||||||
FURI_LOG_D(TAG, "End");
|
FURI_LOG_D(TAG, "End");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ static void desktop_auto_lock_arm(Desktop*);
|
|||||||
static void desktop_auto_lock_inhibit(Desktop*);
|
static void desktop_auto_lock_inhibit(Desktop*);
|
||||||
static void desktop_start_auto_lock_timer(Desktop*);
|
static void desktop_start_auto_lock_timer(Desktop*);
|
||||||
static void desktop_apply_settings(Desktop*);
|
static void desktop_apply_settings(Desktop*);
|
||||||
|
static void desktop_auto_lock_add_inhibitor(Desktop* desktop);
|
||||||
|
static void desktop_auto_lock_remove_inhibitor(Desktop* desktop);
|
||||||
|
|
||||||
static void desktop_loader_callback(const void* message, void* context) {
|
static void desktop_loader_callback(const void* message, void* context) {
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
@@ -130,16 +132,22 @@ static bool desktop_custom_event_callback(void* context, uint32_t event) {
|
|||||||
animation_manager_unload_and_stall_animation(desktop->animation_manager);
|
animation_manager_unload_and_stall_animation(desktop->animation_manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
desktop_auto_lock_inhibit(desktop);
|
desktop_auto_lock_add_inhibitor(desktop);
|
||||||
desktop->app_running = true;
|
desktop->app_running = true;
|
||||||
|
|
||||||
furi_semaphore_release(desktop->animation_semaphore);
|
furi_semaphore_release(desktop->animation_semaphore);
|
||||||
|
|
||||||
} else if(event == DesktopGlobalAfterAppFinished) {
|
} else if(event == DesktopGlobalAfterAppFinished) {
|
||||||
animation_manager_load_and_continue_animation(desktop->animation_manager);
|
animation_manager_load_and_continue_animation(desktop->animation_manager);
|
||||||
desktop_auto_lock_arm(desktop);
|
desktop_auto_lock_remove_inhibitor(desktop);
|
||||||
desktop->app_running = false;
|
desktop->app_running = false;
|
||||||
|
|
||||||
|
} else if(event == DesktopGlobalAddExternalInhibitor) {
|
||||||
|
desktop_auto_lock_add_inhibitor(desktop);
|
||||||
|
|
||||||
|
} else if(event == DesktopGlobalRemoveExternalInhibitor) {
|
||||||
|
desktop_auto_lock_remove_inhibitor(desktop);
|
||||||
|
|
||||||
} else if(event == DesktopGlobalAutoLock) {
|
} else if(event == DesktopGlobalAutoLock) {
|
||||||
if(!desktop->app_running && !desktop->locked) {
|
if(!desktop->app_running && !desktop->locked) {
|
||||||
desktop_lock(desktop);
|
desktop_lock(desktop);
|
||||||
@@ -205,6 +213,24 @@ static void desktop_auto_lock_arm(Desktop* desktop) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void desktop_auto_lock_add_inhibitor(Desktop* desktop) {
|
||||||
|
furi_check(furi_semaphore_release(desktop->auto_lock_inhibitors) == FuriStatusOk);
|
||||||
|
FURI_LOG_D(
|
||||||
|
TAG,
|
||||||
|
"%lu autolock inhibitors (+1)",
|
||||||
|
furi_semaphore_get_count(desktop->auto_lock_inhibitors));
|
||||||
|
desktop_auto_lock_inhibit(desktop);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void desktop_auto_lock_remove_inhibitor(Desktop* desktop) {
|
||||||
|
furi_check(furi_semaphore_acquire(desktop->auto_lock_inhibitors, 0) == FuriStatusOk);
|
||||||
|
uint32_t inhibitors = furi_semaphore_get_count(desktop->auto_lock_inhibitors);
|
||||||
|
FURI_LOG_D(TAG, "%lu autolock inhibitors (-1)", inhibitors);
|
||||||
|
if(inhibitors == 0) {
|
||||||
|
desktop_auto_lock_arm(desktop);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void desktop_auto_lock_inhibit(Desktop* desktop) {
|
static void desktop_auto_lock_inhibit(Desktop* desktop) {
|
||||||
desktop_stop_auto_lock_timer(desktop);
|
desktop_stop_auto_lock_timer(desktop);
|
||||||
if(desktop->input_events_subscription) {
|
if(desktop->input_events_subscription) {
|
||||||
@@ -371,6 +397,7 @@ static Desktop* desktop_alloc(void) {
|
|||||||
desktop->notification = furi_record_open(RECORD_NOTIFICATION);
|
desktop->notification = furi_record_open(RECORD_NOTIFICATION);
|
||||||
desktop->input_events_pubsub = furi_record_open(RECORD_INPUT_EVENTS);
|
desktop->input_events_pubsub = furi_record_open(RECORD_INPUT_EVENTS);
|
||||||
|
|
||||||
|
desktop->auto_lock_inhibitors = furi_semaphore_alloc(UINT32_MAX, 0);
|
||||||
desktop->auto_lock_timer =
|
desktop->auto_lock_timer =
|
||||||
furi_timer_alloc(desktop_auto_lock_timer_callback, FuriTimerTypeOnce, desktop);
|
furi_timer_alloc(desktop_auto_lock_timer_callback, FuriTimerTypeOnce, desktop);
|
||||||
|
|
||||||
@@ -503,6 +530,18 @@ void desktop_api_set_settings(Desktop* instance, const DesktopSettings* settings
|
|||||||
view_dispatcher_send_custom_event(instance->view_dispatcher, DesktopGlobalSaveSettings);
|
view_dispatcher_send_custom_event(instance->view_dispatcher, DesktopGlobalSaveSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void desktop_api_add_external_inhibitor(Desktop* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
view_dispatcher_send_custom_event(
|
||||||
|
instance->view_dispatcher, DesktopGlobalAddExternalInhibitor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void desktop_api_remove_external_inhibitor(Desktop* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
view_dispatcher_send_custom_event(
|
||||||
|
instance->view_dispatcher, DesktopGlobalRemoveExternalInhibitor);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Application thread
|
* Application thread
|
||||||
*/
|
*/
|
||||||
@@ -523,7 +562,7 @@ int32_t desktop_srv(void* p) {
|
|||||||
|
|
||||||
scene_manager_next_scene(desktop->scene_manager, DesktopSceneMain);
|
scene_manager_next_scene(desktop->scene_manager, DesktopSceneMain);
|
||||||
|
|
||||||
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagLock)) {
|
if(desktop_pin_code_is_set()) {
|
||||||
desktop_lock(desktop);
|
desktop_lock(desktop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,3 +21,17 @@ FuriPubSub* desktop_api_get_status_pubsub(Desktop* instance);
|
|||||||
void desktop_api_get_settings(Desktop* instance, DesktopSettings* settings);
|
void desktop_api_get_settings(Desktop* instance, DesktopSettings* settings);
|
||||||
|
|
||||||
void desktop_api_set_settings(Desktop* instance, const DesktopSettings* settings);
|
void desktop_api_set_settings(Desktop* instance, const DesktopSettings* settings);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Adds 1 to the count of active external autolock inhibitors
|
||||||
|
*
|
||||||
|
* Autolocking will not get triggered while there's at least 1 inhibitor
|
||||||
|
*/
|
||||||
|
void desktop_api_add_external_inhibitor(Desktop* instance);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Removes 1 from the count of active external autolock inhibitors
|
||||||
|
*
|
||||||
|
* Autolocking will not get triggered while there's at least 1 inhibitor
|
||||||
|
*/
|
||||||
|
void desktop_api_remove_external_inhibitor(Desktop* instance);
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ struct Desktop {
|
|||||||
FuriPubSub* input_events_pubsub;
|
FuriPubSub* input_events_pubsub;
|
||||||
FuriPubSubSubscription* input_events_subscription;
|
FuriPubSubSubscription* input_events_subscription;
|
||||||
|
|
||||||
|
FuriSemaphore* auto_lock_inhibitors;
|
||||||
FuriTimer* auto_lock_timer;
|
FuriTimer* auto_lock_timer;
|
||||||
FuriTimer* update_clock_timer;
|
FuriTimer* update_clock_timer;
|
||||||
|
|
||||||
|
|||||||
@@ -62,4 +62,6 @@ typedef enum {
|
|||||||
DesktopGlobalApiUnlock,
|
DesktopGlobalApiUnlock,
|
||||||
DesktopGlobalSaveSettings,
|
DesktopGlobalSaveSettings,
|
||||||
DesktopGlobalReloadSettings,
|
DesktopGlobalReloadSettings,
|
||||||
|
DesktopGlobalAddExternalInhibitor,
|
||||||
|
DesktopGlobalRemoveExternalInhibitor,
|
||||||
} DesktopEvent;
|
} DesktopEvent;
|
||||||
|
|||||||
BIN
assets/icons/StatusBar/Console_active_8x8.png
Normal file
BIN
assets/icons/StatusBar/Console_active_8x8.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 75 B |
@@ -13,7 +13,9 @@ def main():
|
|||||||
parser.add_argument("-p", "--port", help="CDC Port", default="auto")
|
parser.add_argument("-p", "--port", help="CDC Port", default="auto")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
if not (port := resolve_port(logger, args.port)):
|
if not (port := resolve_port(logger, args.port)):
|
||||||
logger.error("Is Flipper connected via USB and not in DFU mode?")
|
logger.error(
|
||||||
|
"Is Flipper connected via USB, currently unlocked and not in DFU mode?"
|
||||||
|
)
|
||||||
return 1
|
return 1
|
||||||
subprocess.call(
|
subprocess.call(
|
||||||
[
|
[
|
||||||
|
|||||||
Reference in New Issue
Block a user