-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutil.hpp
49 lines (41 loc) · 1.09 KB
/
util.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#pragma once
#include "ws281x.hpp"
#include <stdlib.h>
#include <time.h>
#include <math.h>
namespace ws281x
{
static void RunRing(const TWS2812B* const arr, const unsigned n_pixels, const unsigned delay)
{
// attach an instance of the SPI-driver to the first SPI device on the first bus (0.0)
// set the transfer speed to 2500000 Hz (required to drive NeoPixels)
TSPIDriver spi_dev_1("/dev/spidev0.0", HZ_SPI_NEOPIXEL);
unsigned i = 0;
for(;;)
{
spi_dev_1.SendData(arr + i, sizeof(TWS2812B) * n_pixels);
usleep(delay);
i++;
if(i >= n_pixels)
i = 0;
}
}
static void GenerateBarGraph(TWS2812B* arr_pixels, const unsigned n_pixels, const bool reverse, const float value, const char red, const char green, const char blue)
{
const unsigned n_on = lrint((float)n_pixels * value);
for(unsigned i = 0; i < n_pixels; i++)
{
TWS2812B& pixel = arr_pixels[(reverse ? (n_pixels - i - 1) : i)];
if(i < n_on)
pixel.RGB(red,green,blue);
else
pixel.RGB(0,0,0);
}
}
static float Limit01(const float v)
{
if(v < 0) return 0;
if(v > 1) return 1;
return v;
}
}