Subversion Repositories LedShow

Rev

Rev 8 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8 mjames 1
/*
2
 * sendLeds.c
3
 *
4
 *  Created on: 17 Aug 2019
5
 *      Author: Mike
6
 */
7
 
8
#include "main.h"
9 mjames 9
#include "libWS2812/leds.h"
10
#include "libWS2812/spiInterface.h"
8 mjames 11
#include "sendLeds.h"
12
 
13
#include <stdint.h>
14
 
15
/* This is xoroshiro128+ 1.0, our best and fastest small-state generator
9 mjames 16
 for floating-point numbers. We suggest to use its upper bits for
17
 floating-point generation, as it is slightly faster than
18
 xoroshiro128**. It passes all tests we are aware of except for the four
19
 lower bits, which might fail linearity tests (and just those), so if
20
 low linear complexity is not considered an issue (as it is usually the
21
 case) it can be used to generate 64-bit outputs, too; moreover, this
22
 generator has a very mild Hamming-weight dependency making our test
23
 (http://prng.di.unimi.it/hwd.php) fail after 5 TB of output; we believe
24
 this slight bias cannot affect any application. If you are concerned,
25
 use xoroshiro128++, xoroshiro128** or xoshiro256+.
8 mjames 26
 
9 mjames 27
 We suggest to use a sign test to extract a random Boolean value, and
28
 right shifts to extract subsets of bits.
8 mjames 29
 
9 mjames 30
 The state must be seeded so that it is not everywhere zero. If you have
31
 a 64-bit seed, we suggest to seed a splitmix64 generator and use its
32
 output to fill s.
8 mjames 33
 
9 mjames 34
 NOTE: the parameters (a=24, b=16, b=37) of this version give slightly
35
 better results in our test than the 2016 version (a=55, b=14, c=36).
36
 */
8 mjames 37
 
9 mjames 38
static inline uint64_t
39
rotl (const uint64_t x, int k)
40
{
41
  return (x << k) | (x >> (64 - k));
8 mjames 42
}
43
 
9 mjames 44
static uint64_t s[2] =
45
  { 102, 33 };
8 mjames 46
 
9 mjames 47
uint64_t
48
next (void)
49
{
50
  const uint64_t s0 = s[0];
51
  uint64_t s1 = s[1];
52
  const uint64_t result = s0 + s1;
8 mjames 53
 
9 mjames 54
  s1 ^= s0;
55
  s[0] = rotl (s0, 24) ^ s1 ^ (s1 << 16); // a, b
56
  s[1] = rotl (s1, 37); // c
8 mjames 57
 
9 mjames 58
  return result;
8 mjames 59
}
60
 
9 mjames 61
#if defined WS2812
62
frgbw_t led0 = { 128, 0, 0, 0 };
63
frgbw_t led1 = { 128, 0, 0, 2 };
64
frgbw_t ledZ = { 0,0,0 };
65
#else
66
frgbw_t led0 =
67
  { 128, 0, 0, 0 };
68
frgbw_t led1 =
69
  { 128, 0, 0, 2 };
70
frgbw_t ledZ =
71
  { 0, 0, 0, };
72
#endif
8 mjames 73
int counter = 1;
74
 
9 mjames 75
void
76
sendLeds ()
8 mjames 77
{
78
 
9 mjames 79
  initCode ();
80
  codeReset ();
8 mjames 81
 
9 mjames 82
  int target = 128;
83
  counter--;
8 mjames 84
 
9 mjames 85
  if (counter == 0)
8 mjames 86
    {
9 mjames 87
      counter = (next () & 0xF0) + 16;
8 mjames 88
 
9 mjames 89
      led0.red = next () & 0xFF;
90
      led0.green = next () & 0xFF;
91
      led0.blue = next () & 0xFF;
92
#if defined WS2812
93
      led0.white = 0;
94
      // led0.white = next() & 0xFF;
95
#endif
8 mjames 96
 
9 mjames 97
      led1.red = next () & 0xFF;
98
      led1.green = next () & 0xFF;
99
      led1.blue = next () & 0xFF;
100
#if defined WS2812
101
      led1.white = 0;
102
      //led1.white = next() & 0xFF;
103
#endif
104
 
105
 
8 mjames 106
    }
9 mjames 107
  if (led1.fader < target)
108
    led1.fader++;
109
  if (led1.fader > target)
110
    led1.fader--;
8 mjames 111
 
9 mjames 112
  if ((counter & 8) == 0)
113
    target = (next () & 0x70) + 0x00;
8 mjames 114
 
9 mjames 115
  codeFRGBW (led0);
116
  codeFRGBW (led1);
117
  // send terminal
8 mjames 118
 
9 mjames 119
  codeStop ();
120
  sendCode (); // send coded pattern
8 mjames 121
}
122