-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLight.h
More file actions
130 lines (106 loc) · 3.13 KB
/
Light.h
File metadata and controls
130 lines (106 loc) · 3.13 KB
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
126
127
128
129
130
/*********************************************************************
*
* File Name: Light.h
*
* Description: Individual light class
*
* Date Created: Sep 20, 2011
*
* Revision History:
*
* NNN - MMM YY - Name - Change
*
* Copyright (C) 2011, Erissoft
*
* This file is part of Erissoft GE CE library
*
* GE CE library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*********************************************************************/
#ifndef __GE_CE_WRITER_LIGHT_H__
#define __GE_CE_WRITER_LIGHT_H__
#include "Color.h"
namespace ESoft {
namespace GECEWriter {
class Light {
public:
static const Light SKIP_LIGHT;
Light() : data_(0) {}
Light &setAddr(uint8_t addr) {
addr_ = addr;
return *this;
}
uint8_t getBrightness() { return bright_; }
Light &setBrightness(uint8_t bright) {
bright_ = bright;
return *this;
}
Light &dim() {
if (bright_ > 0)
bright_--;
return *this;
}
Light &bright() {
if (bright_ < 255)
bright_++;
return *this;
}
Light &setColor(const Color &color) {
red_ = color.getRed().getValue();
green_ = color.getGreen().getValue();
blue_ = color.getBlue().getValue();
return *this;
}
Light &setTrack(uint8_t track) {
track_ = track;
return *this;
}
uint8_t getTrack() { return track_; }
uint32_t getData() { return data_; }
void setData(uint8_t *data) {
field1_ = data[0];
field2_ = data[1];
field3_ = data[2];
field4_ = data[3];
}
// if skip bit is set, the light is equal regardless of the other fields
bool operator==(const Light &light) {
return skip_ == light.skip_ || data_ == light.data_;
}
bool operator!=(const Light &light) { return !(*this == light); }
private:
Light(bool skip) : data_(0), skip_(skip) {}
uint8_t track_;
union {
uint32_t data_;
struct {
uint32_t red_ : 4;
uint32_t green_ : 4;
uint32_t blue_ : 4;
uint32_t bright_ : 8;
uint32_t addr_ : 6;
uint32_t skip_ : 1;
};
struct {
uint8_t field4_;
uint8_t field3_;
uint8_t field2_;
uint8_t field1_;
};
};
};
}
}
#endif //__GE_CE_WRITER_LIGHT_H__