-
Notifications
You must be signed in to change notification settings - Fork 10
/
IRFShowControl.cpp
125 lines (113 loc) · 3.02 KB
/
IRFShowControl.cpp
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* IRFShowControl.cpp
*
* Created on: Mar 19, 2013
* Author: Greg Scull/Mat Mrosko
*
* Updated: May 18, 2014 - Mat Mrosko, Materdaddy, rfpixelcontrol@matmrosko.com
*
* License:
* Users of this software agree to hold harmless the creators and
* contributors of this software. By using this software you agree that
* you are doing so at your own risk, you could kill yourself or someone
* else by using this software and/or modifying the factory controller.
* By using this software you are assuming all legal responsibility for
* the use of the software and any hardware it is used on.
*
* The Commercial Use of this Software is Prohibited.
*/
#include "IRFShowControl.h"
IRFShowControl::IRFShowControl(void)
{
dataPin = 2;
}
IRFShowControl::~IRFShowControl(void)
{
if (pixels != NULL)
free(pixels);
}
void IRFShowControl::Begin(uint8_t* pDataPointer, int pNumLEDs)
{
this->pixels = pDataPointer;
this->numLEDs = pNumLEDs;
}
uint16_t IRFShowControl::GetElementCount( void )
{
return numLEDs;
}
void IRFShowControl::SetElementCount(uint16_t count)
{
if (pixels != NULL)
free(pixels);
numLEDs = ((pixels = (uint8_t *)calloc(count, 3)) != NULL) ? count : 0;
}
uint32_t IRFShowControl::GetElementColor(uint16_t n)
{
if (n < numLEDs)
{
uint16_t ofs = n * 3;
// To keep the show() loop as simple & fast as possible, the
// internal color representation is native to different pixel
// types. For compatibility with existing code, 'packed' RGB
// values passed in or out are always 0xRRGGBB order.
return ((uint32_t)pixels[ofs] << 16) | ((uint16_t) pixels[ofs + 1] << 8) | pixels[ofs + 2];
}
return 0; // Pixel # is out of bounds
}
void IRFShowControl::SetElementColor(uint16_t n, uint32_t c, uint8_t pColorOrder)
{
if (n < numLEDs)
{
uint8_t *p = &pixels[n * 3];
if (pColorOrder == RGB_ORDER )
{
// To keep the show() loop as simple & fast as possible, the
// internal color representation is native to different pixel
// types. For compatibility with existing code, 'packed' RGB
// values passed in or out are always 0xRRGGBB order.
*p++ = c >> 16; // Red
*p++ = c >> 8; // Green
*p++ = c; // Blue
}
else if (pColorOrder == BGR_ORDER )
{
*p++ = c; // Red
*p++ = c >> 8; // Green
*p++ = c >> 16; // Blue
}
}
}
void IRFShowControl::SetElementColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b, uint8_t pColorOrder)
{
if(n < numLEDs) // Arrays are 0-indexed, thus NOT '<='
{
uint8_t *p = &pixels[n * 3];
if (pColorOrder == RGB_ORDER )
{
// See notes later regarding color order
*p++ = r;
*p++ = g;
*p++ = b;
}
else if (pColorOrder == BGR_ORDER )
{
*p++ = b;
*p++ = g;
*p++ = r;
}
}
}
uint32_t IRFShowControl::Color(byte r, byte g, byte b)
{
uint32_t c;
c = r;
c <<= 8;
c |= g;
c <<= 8;
c |= b;
return c;
}
void IRFShowControl::SetDataBasePointer(uint8_t* dataPointer)
{
this->pixels = dataPointer;
}