]> oss.titaniummirror.com Git - rgblamp.git/blobdiff - main.c
Replace rand() with LFSR implementation
[rgblamp.git] / main.c
diff --git a/main.c b/main.c
index 627c94a3158d84a8933fee0436c7e227eaab950e..dc14185632af7ab30b90057d32ece16513376556 100644 (file)
--- a/main.c
+++ b/main.c
@@ -38,6 +38,7 @@
 #include <stdlib.h>
 #include "picinit.h"
 #include "unused.h"
+#include "lfsr.h"
 #include "btn.h"
 #include "rgb.h"
 #include "tmr.h"
@@ -104,7 +105,7 @@ enum {
   STD_FADE = 16,         /* Fade time in 32.768 ms units */
   STD_INCOLOR = 29491,   /* Time in color when MODE_CYCLE, in 32.768 ms units */
   PARTY_MIN = 8,         /* Min party fade and incolor units */
-  PARTY_RANGE = 8,       /* Party fade/incolor range mask for rand() */
+  PARTY_RANGE = 8,       /* Party fade/incolor range mask for lfsr_get() */
                          /* ... see start_fade() */
   CFG_MODE_ADDR = 0,     /* EEPROM address of mode variable */
   CFG_COLOR_ADDR,        /* EEPROM address of color variable */
@@ -181,8 +182,8 @@ void start_fade()
   /* Select the destination color and fade-to time depending upon mode. */
   fade_steps = STD_FADE;
   if (mode == MODE_PARTY) {
-    color = rand() % COLOR_COUNT;
-    fade_steps = PARTY_MIN + (rand() % PARTY_RANGE);
+    color = lfsr_get() % COLOR_COUNT;
+    fade_steps = PARTY_MIN + (lfsr_get() % PARTY_RANGE);
   } else if (mode == MODE_CYCLE) {
     if (++color == COLOR_COUNT)
       color = 0;
@@ -337,7 +338,7 @@ void fade_task()
     if (mode == MODE_CYCLE)
       tmr_start(TMR_INCOLOR, STD_INCOLOR);
     else if (mode == MODE_PARTY)
-      tmr_start(TMR_INCOLOR, PARTY_MIN + (rand() % PARTY_RANGE));
+      tmr_start(TMR_INCOLOR, PARTY_MIN + (lfsr_get() % PARTY_RANGE));
   }
   leds_set();
 }
@@ -358,7 +359,7 @@ void auto_offon_task()
 void user_boot()
 {
   dbgpin_high();
-  srand((adc_random() << 8) + adc_random());
+  lfsr_init((adc_random() << 8) + adc_random());
   cfg_read(mode, color);
   rs_task();
 }