Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ComboBlade and associated wrappers #668

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

KeeganMorrow
Copy link

Here is the combo blade code that I came up with. I admit that my current test case of combining the two crystal chamber LEDs is about as simple as it gets, but it seems to work pretty nicely for my use case.

The ComboBladeWrapper is used to send out calls to the the actual blades controlling real hardware. The style on the actual blades is set to a ComboBladeStyleWrapper, which forwards the calls for the on to the actual style code, but running against the original ComboBladeWrapper. This allows the ComboBladeWrapper to dispatch the led control calls on to the actual blade hardware while simulating a single blade with the length of both blades put together.

Also see discussion on crucible

Copy link
Owner

@profezzorn profezzorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not bad, needs some cleaning up, but I don't see anything wrong with it. :)

blades/combo_blade.h Outdated Show resolved Hide resolved
blades/combo_blade.h Outdated Show resolved Hide resolved
blades/combo_blade.h Outdated Show resolved Hide resolved
blades/combo_blade.h Outdated Show resolved Hide resolved
blades/combo_blade.h Outdated Show resolved Hide resolved
blades/combo_blade.h Outdated Show resolved Hide resolved
blades/combo_blade.h Outdated Show resolved Hide resolved
blades/combo_blade.h Show resolved Hide resolved
@KeeganMorrow KeeganMorrow force-pushed the combo_blade_pr branch 2 times, most recently from 8f2a33a to 200a0b4 Compare June 29, 2024 19:08
@KeeganMorrow
Copy link
Author

Not bad, needs some cleaning up, but I don't see anything wrong with it. :)

Thanks for the feedback, I made some updates based on your comments.

return real_style_->NoOnOff();
}

virtual bool Charging() { return real_style_->Charging();}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add space after ;

}

int num_leds() const override {
int result = blade1_num_leds_;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would be shorter and easier to read:

return blade1_num_leds + blade2->num_leds();

}

BladeStyle* UnSetStyle() override {
if (dummy_style_)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you call blade_ / blade2_->UnsetStyle() here then dummy_style will never have a null style (when used), and we can drop the if() statements in that class.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving these into a single object resolves this, thanks!

blade2_(blade2)
{
blade_ = blade1;
dummy_style_ = new ComboBladeStyleWrapper(this, blade1);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ProffieOS code avoids using 'new' as much as possible to avoid memory fragmentation.
Just make "dummy_style" a ComboBladeStyleWrapper instead of a ComboBladeStyleWrapper*.

blades/combo_blade.h Outdated Show resolved Hide resolved

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

BladeStyle* GetRealStyle(){return real_style_;}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs 3 more more spaces, should be:
BladeStyle* GetRealStyle() { return real_style_; }

(same comment applies in other places as well.)


BladeStyle* UnSetStyle() override {
BladeStyle* result = real_style_;
real_style_ = nullptr;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also call blade_ / blade2_ -> UnSetStyle() here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why, but it actually seems like I get a crash due to a null pointer somewhere when I tried this, willing to explore more if you think this idea is still worth pursuing

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have a config file that crashes (and instructions for how to make it crash if needed) I can run it with a debugger to see exactly where the crash occurs.

bool Charging() override { return real_style_->Charging(); }

bool IsHandled(HandledFeature effect) override {
if (real_style_)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

once UnsetStyle is called properly below, real_style_ will never be null here.

blades/combo_blade.h Show resolved Hide resolved
{
blade_ = blade1;
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a destructor that deletes the blade2_cache_


BladeStyle* UnSetStyle() override {
BladeStyle* result = real_style_;
real_style_ = nullptr;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have a config file that crashes (and instructions for how to make it crash if needed) I can run it with a debugger to see exactly where the crash occurs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants