Skip to content

Commit 200a0b4

Browse files
committed
Updates based on CR feedback
1 parent 683ec6e commit 200a0b4

File tree

1 file changed

+64
-55
lines changed

1 file changed

+64
-55
lines changed

blades/combo_blade.h

+64-55
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Usage: ComboBlade(blade1, blade2)
66
This allows multiple blades to be combined into a single linear blade even if
77
they use different data lines for control.
88
9-
The resulting blade will have a length of the number of leds in the first and
9+
The resulting blade will have a length of the number of LEDs in the first and
1010
second blade combined. When the style is running, the second blade's LEDs will
1111
be controlled as though they were in line and after the first blade's LEDs
1212
@@ -39,30 +39,45 @@ is the only thing that counts as an entry in the blade array.
3939

4040
class ComboBladeWrapper;
4141

42+
43+
/*
44+
This class is used by ComboBladeWrapper to allow intercepting the style run()
45+
calls sent from the blades inside the ComboBladeWrapper.
46+
47+
The style of the wrapped blades will be set to an instance of this class, which
48+
will then call the real style with our ComboBladeWrapper instance as the
49+
active blade.
50+
51+
Since the same style is being executed for both blades we only actually run
52+
the style calls sent by the primary blade.
53+
54+
*/
4255
class ComboBladeStyleWrapper : public BladeStyle {
4356
public:
4457
// Bladestyle implementation
4558
virtual void activate() override {
46-
if (real_style_)
47-
real_style_->activate();
59+
real_style_->activate();
4860
}
4961
virtual void deactivate() override {
50-
if (real_style_)
51-
real_style_->deactivate();
62+
real_style_->deactivate();
5263
}
5364
virtual void run(BladeBase* blade) override;
5465

66+
bool NoOnOff() override {
67+
return real_style_->NoOnOff();
68+
}
69+
70+
virtual bool Charging() { return real_style_->Charging();}
71+
5572
bool IsHandled(HandledFeature effect) override {
5673
if (real_style_)
5774
return real_style_->IsHandled(effect);
5875
return false;
5976
}
6077

61-
bool NoOnOff() override {
62-
if (real_style_)
63-
return real_style_->NoOnOff();
64-
return true;
65-
}
78+
OverDriveColor getColor(int i) override {return real_style_->getColor(i);}
79+
80+
int get_max_arg(int arg) override { return real_style_->get_max_arg(arg);}
6681

6782
void setRealStyle(BladeStyle* style){real_style_ = style;}
6883

@@ -85,77 +100,72 @@ class ComboBladeStyleWrapper : public BladeStyle {
85100
BladeStyle* real_style_;
86101
};
87102

103+
/*
104+
This class is used by ComboBladeWrapper to allow intercepting the style run()
105+
calls sent from the blades inside the ComboBladeWrapper.
106+
107+
This class acts as our entry in the blade array. When activated, it will
108+
activate the loops of the two assigned blades, pointing them at an instance of
109+
ComboBladeStyleWrapper. This will then be used to intercept the style run()
110+
calls of the indivdual blades and instead run the style against the
111+
ComboBladeWrapper. The ComboBladeWrapper will then send the led set calls
112+
to the appropriate blade based on the led number.
113+
114+
*/
88115
class ComboBladeWrapper : public BladeWrapper {
89116
public:
90-
ComboBladeWrapper(BladeBase* blade1, BladeBase* blade2):blade2_(blade2){
117+
ComboBladeWrapper(BladeBase* blade1, BladeBase* blade2):
118+
blade1_num_leds_(blade1->num_leds()),
119+
blade2_(blade2)
120+
{
91121
blade_ = blade1;
92122
dummy_style_ = new ComboBladeStyleWrapper(this, blade1);
93-
if (blade1)
94-
blade1->SetStyle(dummy_style_);
95-
if (blade2)
96-
blade2->SetStyle(dummy_style_);
97123
}
98124

99125
int num_leds() const override {
100-
int result = 0;
101-
if (blade_) {
102-
result += blade_->num_leds();
103-
}
104-
if (blade2_) {
105-
result += blade2_->num_leds();
106-
}
126+
int result = blade1_num_leds_;
127+
result += blade2_->num_leds();
107128
return result;
108129
}
109130
void set(int led, Color16 c) override {
110-
if (led < blade_->num_leds()) {
111-
if (blade_)
112-
return blade_->set(led, c);
131+
if (led < blade1_num_leds_) {
132+
return blade_->set(led, c);
113133
} else {
114-
if (blade2_ && blade_)
115-
return blade2_->set(led - blade_->num_leds(), c);
134+
return blade2_->set(led - blade1_num_leds_, c);
116135
}
117136
}
118137
void set_overdrive(int led, Color16 c) override {
119-
if (led < blade_->num_leds()) {
120-
if (blade_)
121-
return blade_->set_overdrive(led, c);
138+
if (led < blade1_num_leds_) {
139+
return blade_->set_overdrive(led, c);
122140
} else {
123-
if (blade2_ && blade_)
124-
return blade2_->set_overdrive(led - blade_->num_leds(), c);
141+
return blade2_->set_overdrive(led - blade1_num_leds_, c);
125142
}
126143
}
127144

128145
void allow_disable() override {
129-
if (blade_)
130-
blade_->allow_disable();
131-
if (blade2_)
132-
blade2_->allow_disable();
146+
blade_->allow_disable();
147+
blade2_->allow_disable();
133148
}
134149

135150
void clear() override {
136-
if (blade_)
137-
blade_->clear();
138-
if (blade2_)
139-
blade2_->clear();
151+
blade_->clear();
152+
blade2_->clear();
140153
}
141154

142155
void Activate(int blade_number) override {
143-
if (blade_)
144-
blade_->Activate(blade_number);
145-
if (blade2_)
146-
blade2_->Activate(blade_number);
156+
blade_->Activate(blade_number);
157+
blade2_->Activate(blade_number);
147158
}
148159

149160
void Deactivate() override {
150-
if (blade_)
151-
blade_->Deactivate();
152-
if (blade2_)
153-
blade2_->Deactivate();
161+
blade_->Deactivate();
162+
blade2_->Deactivate();
154163
}
155164

156165
void SetStyle(BladeStyle* style) override {
157-
if (dummy_style_)
158-
dummy_style_->setRealStyle(style);
166+
dummy_style_->setRealStyle(style);
167+
blade_->SetStyle(dummy_style_);
168+
blade2_->SetStyle(dummy_style_);
159169
}
160170

161171
BladeStyle* UnSetStyle() override {
@@ -173,19 +183,18 @@ class ComboBladeWrapper : public BladeWrapper {
173183
}
174184

175185
private:
186+
int blade1_num_leds_;
176187
BladeBase* blade2_;
177188
ComboBladeStyleWrapper* dummy_style_;
178189
};
179190

180191
void ComboBladeStyleWrapper::run(BladeBase* blade) {
181-
if (real_style_ && comboBlade_ && blade && blade == primary_blade_) {
182-
real_style_->run(static_cast<BladeBase*>(comboBlade_));
192+
if (blade == primary_blade_) {
193+
real_style_->run(comboBlade_);
183194
}
184195
}
185-
186196
BladeBase* ComboBlade(BladeBase* blade1, BladeBase* blade2)
187197
{
188-
ComboBladeWrapper*result = new ComboBladeWrapper(blade1, blade2);
189-
return result;
198+
return new ComboBladeWrapper(blade1, blade2);
190199
}
191200
#endif

0 commit comments

Comments
 (0)