diff options
Diffstat (limited to 'applications')
-rw-r--r-- | applications/applications.c | 5 | ||||
-rw-r--r-- | applications/applications.mk | 8 | ||||
-rwxr-xr-x | applications/power/power_service/power.c | 5 | ||||
-rw-r--r-- | applications/power_observer/power_observer.c | 76 |
4 files changed, 5 insertions, 89 deletions
diff --git a/applications/applications.c b/applications/applications.c index 7b125f6a..8153dcfa 100644 --- a/applications/applications.c +++ b/applications/applications.c @@ -11,7 +11,6 @@ extern int32_t gui_srv(void* p); extern int32_t input_srv(void* p); extern int32_t loader_srv(void* p); extern int32_t notification_srv(void* p); -extern int32_t power_observer_srv(void* p); extern int32_t power_srv(void* p); extern int32_t storage_srv(void* p); extern int32_t desktop_srv(void* p); @@ -115,10 +114,6 @@ const FlipperApplication FLIPPER_SERVICES[] = { {.app = power_srv, .name = "PowerSrv", .stack_size = 1024, .icon = NULL}, #endif -#ifdef SRV_POWER_OBSERVER - {.app = power_observer_srv, .name = "PowerAuditSrv", .stack_size = 1024, .icon = NULL}, -#endif - #ifdef SRV_STORAGE {.app = storage_srv, .name = "StorageSrv", .stack_size = 3072, .icon = NULL}, #endif diff --git a/applications/applications.mk b/applications/applications.mk index aa17e05f..5733e761 100644 --- a/applications/applications.mk +++ b/applications/applications.mk @@ -18,7 +18,6 @@ SRV_INPUT = 1 SRV_LOADER = 1 SRV_NOTIFICATION = 1 SRV_POWER = 1 -SRV_POWER_OBSERVER = 1 SRV_RPC = 1 SRV_STORAGE = 1 @@ -256,13 +255,6 @@ endif endif -SRV_POWER_OBSERVER ?= 0 -ifeq ($(SRV_POWER_OBSERVER), 1) -CFLAGS += -DSRV_POWER_OBSERVER -SRV_POWER = 1 -endif - - SRV_POWER ?= 0 ifeq ($(SRV_POWER), 1) CFLAGS += -DSRV_POWER diff --git a/applications/power/power_service/power.c b/applications/power/power_service/power.c index 2659e2ec..3934b20d 100755 --- a/applications/power/power_service/power.c +++ b/applications/power/power_service/power.c @@ -196,6 +196,11 @@ int32_t power_srv(void* p) { // Update 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()) { + furi_hal_power_check_otg_status(); + } + osDelay(1000); } diff --git a/applications/power_observer/power_observer.c b/applications/power_observer/power_observer.c deleted file mode 100644 index b32447f0..00000000 --- a/applications/power_observer/power_observer.c +++ /dev/null @@ -1,76 +0,0 @@ -#include <furi.h> -#include <furi_hal.h> -#include <notification/notification_messages.h> - -typedef struct { - osThreadId_t thread; - -} PowerObserverSrv; - -const NotificationMessage message_green_110 = { - .type = NotificationMessageTypeLedGreen, - .data.led.value = 110, -}; - -static const NotificationSequence sequence_overconsumption = { - &message_green_110, - &message_red_255, - &message_delay_100, - NULL, -}; - -typedef enum { - EventReset = (1 << 0), - EventRequest = (1 << 1), -} UsbEvent; - -static void usb_state_callback(FuriHalUsbStateEvent state, void* context) { - PowerObserverSrv* srv = (PowerObserverSrv*)(context); - if(state == FuriHalUsbStateEventReset) { - osThreadFlagsSet(srv->thread, EventReset); - } else if(state == FuriHalUsbStateEventDescriptorRequest) { - osThreadFlagsSet(srv->thread, EventRequest); - } -} - -int32_t power_observer_srv(void* p) { - NotificationApp* notifications = furi_record_open("notification"); - PowerObserverSrv* srv = furi_alloc(sizeof(PowerObserverSrv)); - srv->thread = osThreadGetId(); - - const float overconsumption_limit = 0.03f; - bool usb_request_pending = false; - uint8_t usb_wait_time = 0; - - furi_hal_usb_set_state_callback(usb_state_callback, srv); - - while(true) { - uint32_t flags = osThreadFlagsWait(EventReset | EventRequest, osFlagsWaitAny, 500); - if((flags & osFlagsError) == 0) { - if(flags & EventReset) { - usb_request_pending = true; - usb_wait_time = 0; - } - if(flags & EventRequest) { - usb_request_pending = false; - } - } else if(usb_request_pending) { - usb_wait_time++; - if(usb_wait_time > 4) { - furi_hal_usb_reinit(); - usb_request_pending = false; - } - } - - float current = -furi_hal_power_get_battery_current(FuriHalPowerICFuelGauge); - if(current > overconsumption_limit) { - notification_message_block(notifications, &sequence_overconsumption); - } - if(furi_hal_power_is_otg_enabled()) { - furi_hal_power_check_otg_status(); - } - } - - free(srv); - return 0; -} |