-
Notifications
You must be signed in to change notification settings - Fork 24
/
G35StringGroup.cpp
61 lines (53 loc) · 1.57 KB
/
G35StringGroup.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
/*
G35: An Arduino library for GE Color Effects G-35 holiday lights.
Copyright © 2011 The G35 Authors. Use, modification, and distribution are
subject to the BSD license as described in the accompanying LICENSE file.
Original version by Paul Martis (http://www.digitalmisery.com). See
README for complete attributions.
*/
#include <G35StringGroup.h>
G35StringGroup::G35StringGroup()
: string_count_(0) {
light_count_ = 0;
}
void G35StringGroup::AddString(G35* g35) {
if (string_count_ == MAX_STRINGS) {
return;
}
uint16_t light_count = g35->get_light_count();
string_offsets_[string_count_] =
string_count_ == 0 ?
light_count :
string_offsets_[string_count_ - 1] + light_count;
strings_[string_count_] = g35;
++string_count_;
light_count_ += light_count;
}
uint16_t G35StringGroup::get_light_count() {
return light_count_;
}
void G35StringGroup::set_color(uint8_t bulb, uint8_t intensity, color_t color) {
uint8_t string = 0;
while (bulb >= string_offsets_[string] && string < string_count_) {
string++;
}
if (string < string_count_) {
if (string > 0) {
bulb -= string_offsets_[string - 1];
}
strings_[string]->set_color(bulb, intensity, color);
} else {
// A program is misbehaving.
#if 0
Serial.println("out of bounds");
#endif
}
}
void G35StringGroup::broadcast_intensity(uint8_t intensity) {
for (uint8_t i = 0; i < string_count_; ++i) {
strings_[i]->broadcast_intensity(intensity);
}
}
uint8_t G35StringGroup::get_broadcast_bulb() {
return 0; // In this implementation, shouldn't ever be called.
}