alex.kopachov 2 лет назад
Родитель
Сommit
7054937fa8
4 измененных файлов с 23 добавлено и 15 удалено
  1. 1 1
      features_config.h
  2. 13 9
      services/idle_timeout/idle_timeout.c
  3. 4 1
      services/idle_timeout/idle_timeout.h
  4. 5 4
      totp_app.c

+ 1 - 1
features_config.h

@@ -29,7 +29,7 @@
 #endif
 // End of FlipC.org definition checks
 
-// If target firmware is not yet set, default it to OFW because there is no chance to force Flipper Devices to update their build pipelines :angry:. 
+// If target firmware is not yet set, default it to OFW because there is no chance to force Flipper Devices to update their build pipelines :angry:.
 // I'm still using Xtreme firmware, it is still the best one and I highly recommend it to everybody.
 #ifndef TOTP_TARGET_FIRMWARE
 #define TOTP_TARGET_FIRMWARE TOTP_FIRMWARE_OFFICIAL_STABLE

+ 13 - 9
services/idle_timeout/idle_timeout.c

@@ -3,7 +3,7 @@
 #include <furi/core/timer.h>
 
 #define IDLE_TIMER_CHECK_PERIODICITY_SEC (1)
-#define SEC_TO_TICKS(sec) ((sec) * 1000)
+#define SEC_TO_TICKS(sec) ((sec)*1000)
 
 struct IdleTimeoutContext {
     FuriTimer* timer;
@@ -17,25 +17,29 @@ struct IdleTimeoutContext {
 
 static void idle_timer_callback(void* context) {
     IdleTimeoutContext* instance = context;
-    if (instance->activity_reported) {
+    if(instance->activity_reported) {
         instance->idle_period_sec = 0;
         instance->idle_handled = false;
         instance->activity_reported = false;
-    } else if (!instance->idle_handled) {
-        if (instance->idle_period_sec >= instance->timeout_sec) {
-            instance->idle_handled = instance->on_idle_callback(instance->on_idle_callback_context);
+    } else if(!instance->idle_handled) {
+        if(instance->idle_period_sec >= instance->timeout_sec) {
+            instance->idle_handled =
+                instance->on_idle_callback(instance->on_idle_callback_context);
         } else {
             instance->idle_period_sec += IDLE_TIMER_CHECK_PERIODICITY_SEC;
         }
-    }   
+    }
 }
 
-IdleTimeoutContext* idle_timeout_alloc(uint16_t timeout_sec, IDLE_TIMEOUT_CALLBACK on_idle_callback, void* on_idle_callback_context) {
+IdleTimeoutContext* idle_timeout_alloc(
+    uint16_t timeout_sec,
+    IDLE_TIMEOUT_CALLBACK on_idle_callback,
+    void* on_idle_callback_context) {
     IdleTimeoutContext* instance = malloc(sizeof(IdleTimeoutContext));
-    if (instance == NULL) return NULL;
+    if(instance == NULL) return NULL;
 
     instance->timer = furi_timer_alloc(&idle_timer_callback, FuriTimerTypePeriodic, instance);
-    if (instance->timer == NULL) return NULL;
+    if(instance->timer == NULL) return NULL;
 
     instance->timeout_sec = timeout_sec;
     instance->on_idle_callback = on_idle_callback;

+ 4 - 1
services/idle_timeout/idle_timeout.h

@@ -14,7 +14,10 @@ typedef bool (*IDLE_TIMEOUT_CALLBACK)(void* context);
  * @param on_idle_callback_context callback function context
  * @return IDLE timeout context
  */
-IdleTimeoutContext* idle_timeout_alloc(uint16_t timeout_sec, IDLE_TIMEOUT_CALLBACK on_idle_callback, void* on_idle_callback_context);
+IdleTimeoutContext* idle_timeout_alloc(
+    uint16_t timeout_sec,
+    IDLE_TIMEOUT_CALLBACK on_idle_callback,
+    void* on_idle_callback_context);
 
 /**
  * @brief Starts IDLE timeout

+ 5 - 4
totp_app.c

@@ -107,7 +107,7 @@ static bool totp_activate_initial_scene(PluginState* const plugin_state) {
 static bool on_user_idle(void* context) {
     PluginState* plugin_state = context;
     if(plugin_state->current_scene != TotpSceneAuthentication &&
-        plugin_state->current_scene != TotpSceneStandby) {
+       plugin_state->current_scene != TotpSceneStandby) {
         totp_scene_director_activate_scene(plugin_state, TotpSceneAuthentication);
         return true;
     }
@@ -136,8 +136,9 @@ static bool totp_plugin_state_init(PluginState* const plugin_state) {
     }
 #endif
 
-    if (plugin_state->pin_set) {
-        plugin_state->idle_timeout_context = idle_timeout_alloc(TOTP_AUTO_LOCK_IDLE_TIMEOUT_SEC, &on_user_idle, plugin_state);
+    if(plugin_state->pin_set) {
+        plugin_state->idle_timeout_context =
+            idle_timeout_alloc(TOTP_AUTO_LOCK_IDLE_TIMEOUT_SEC, &on_user_idle, plugin_state);
         idle_timeout_start(plugin_state->idle_timeout_context);
     } else {
         plugin_state->idle_timeout_context = NULL;
@@ -147,7 +148,7 @@ static bool totp_plugin_state_init(PluginState* const plugin_state) {
 }
 
 static void totp_plugin_state_free(PluginState* plugin_state) {
-    if (plugin_state->idle_timeout_context != NULL) {
+    if(plugin_state->idle_timeout_context != NULL) {
         idle_timeout_stop(plugin_state->idle_timeout_context);
         idle_timeout_free(plugin_state->idle_timeout_context);
     }