Преглед изворни кода

Bug Fixes and some housekeeping

OrionW06 пре 8 месеци
родитељ
комит
d23fbe5cba
3 измењених фајлова са 22 додато и 10 уклоњено
  1. 5 0
      README.md
  2. 4 5
      application.fam
  3. 13 5
      main.c

+ 5 - 0
README.md

@@ -1,2 +1,7 @@
 # Flame-RNG
 Inspired by [this repo](https://github.com/dipdowel/flipper-fire-rng) I have implemented a similar functionality entirely in the flipper zero
+
+It uses the IR sensor on the Flipper Zero to gather entropy from IR sources (such as a lighter) to seed a random number generator. The idea is that fire and other similar IR sources are not predictable sources of data, and thus it can be a reliable source of entropy. Obviously the flipper doesn't gather enough data (unless you *really* like flicking a lighter near your nearly $200 toy) to get any sort of decent entropy, this is more of a PoC.
+
+I am NOT responsible for any damage to the flipper or yourself! Be safe with fire, and be safe with your other entropic sources!
+    I am also NOT responsible if you generate insecure keys using this as a source of entropy! 

+ 4 - 5
application.fam

@@ -7,11 +7,10 @@ App(
     entry_point="flame_rng",
     stack_size=2 * 1024,
     fap_category="Infrared",
-    # Optional values
-    # fap_version="0.1",
+    fap_version="0.1",
     fap_icon="flame_rng.png",  # 10x10 1-bit PNG
-    # fap_description="A simple app",
-    # fap_author="J. Doe",
-    # fap_weburl="https://github.com/user/flame_rng",
+    fap_description="An RNG intended for use with Flames and other IR sources.",
+    fap_author="OrionW06",
+    fap_weburl="https://github.com/OrionW06/Flame-RNG",
     fap_icon_assets="images",  # Image assets to compile for this application
 )

+ 13 - 5
main.c

@@ -21,6 +21,7 @@ typedef struct {
     uint8_t history_index;
     bool new_value;
     FuriMutex* mutex;
+    uint32_t message_timestamp;
 } FlameRngState;
 
 static uint32_t generate_rng_from_ir(InfraredWorkerSignal* signal) {
@@ -50,6 +51,7 @@ static void ir_callback(void* ctx, InfraredWorkerSignal* signal) {
     state->seed = seed;
     update_history(state, state->rng_value);
     state->new_value = true;
+    state->message_timestamp = furi_get_tick(); // Record when the message appeared
     furi_mutex_release(state->mutex);
 
     FURI_LOG_I(TAG, "Generated RNG: %lu (seed: %lu)", state->rng_value, state->seed);
@@ -106,17 +108,23 @@ static void render_callback(Canvas* canvas, void* ctx) {
     canvas_set_font(canvas, FontPrimary);
     canvas_draw_str(canvas, 2, 10, "Flame RNG");
 
-    // Main random number display
+    // Main random number display (always updates)
     canvas_set_font(canvas, FontBigNumbers);
     char value_str[32];
     snprintf(value_str, sizeof(value_str), "%06lu", state->rng_value);
     canvas_draw_str_aligned(canvas, 64, 30, AlignCenter, AlignCenter, value_str);
 
-    // Status message
+    // Status message (disappears after some time)
     if(state->new_value) {
-        canvas_set_font(canvas, FontSecondary);
-        canvas_draw_str(canvas, 2, 55, "New value! Press OK to save");
-        state->new_value = false;
+        uint32_t current_time = furi_get_tick();
+        uint32_t elapsed_time = current_time - state->message_timestamp;
+
+        if(elapsed_time < 1000) {
+            canvas_set_font(canvas, FontSecondary);
+            canvas_draw_str(canvas, 2, 55, "New value! Press OK to save");
+        } else {
+            state->new_value = false; // Clear the message after delay
+        }
     } else {
         canvas_set_font(canvas, FontSecondary);
         canvas_draw_str(canvas, 2, 55, "Waiting for IR signal...");