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

Party mode #167

Merged
merged 3 commits into from
Jul 1, 2024
Merged

Party mode #167

merged 3 commits into from
Jul 1, 2024

Conversation

martin-geissinger-CA
Copy link
Contributor

"PARTY" command added which cycles through all colors on all 3 ports to ease function testing the boards. Could also be used by production to see if the LED strips work properly.

}state;

bool teststate = false;
state partystate = OFF;
Copy link
Contributor

Choose a reason for hiding this comment

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

Typically we'd make all the above variables "static"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

GREEN,
BLUE,
WHITE
}state;
Copy link
Contributor

Choose a reason for hiding this comment

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

Although technically fine, "state" is a little too generic. Consider "test_mode_state", or "test_mode_colour"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}state;

bool teststate = false;
state partystate = OFF;
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, technically fine, but typically use CamelCase or snake_case for variable names

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -76,9 +92,48 @@ static void LightControllerStatus()
writeUSB(buf, len);
}

static void updateLEDCtrl(int channel, unsigned int red, unsigned int green, unsigned int blue, int whiteOn)
Copy link
Contributor

Choose a reason for hiding this comment

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

Its much harder to spot changes if you move a chunk of code around like this. If you need to access a function from earlier in the file, the preferred method is to declare it at the top. E.g. see lines 50/51.

Really this is the previous authors mistake, because all static functions should already have been pre-declared.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved it back and added declaration

for (int channel = 0;channel < 3;channel++){
updateLEDCtrl(channel,red,green,blue,whiteon);
};
return true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why return anything if you always return true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed that to false in case someone wants to use the return value in the future

updateLEDCtrl(channel,red,green,blue,whiteon);
};
return true;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

A shorter way to write this:

if(OFF == partystate) {
    partystate = RED;
    for(int i = 0; i < 3; i++) {
        updateLEDCtrl(i, 0xFF, 0, 0, false);
    }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}
break;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This entire if statement is good, but should be moved to a new function. LightControllerLoop shouldn't be polluted too much (its a public function).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

if (teststate == true){

// Turn on every colour for 2 second during the test
switch(partystate){
Copy link
Contributor

Choose a reason for hiding this comment

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

Typically we add a "default" case. This catches if the state variable is wrong somehow. in this situation, I would go to teststate = false;\partystate = OFF; by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

int whiteon = false;
for (int channel = 0;channel < 3;channel++){
updateLEDCtrl(channel,red,green,blue,whiteon);
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Reading how the rest of the function is written and used, I don't think it was intended to have side-effects, and this introduces one. I would remove this entire if statement.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is the only thing I've read by the end of the review that might cause the unit test failure by the way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@martin-geissinger-CA martin-geissinger-CA merged commit 7e44219 into main Jul 1, 2024
3 checks passed
@martin-geissinger-CA martin-geissinger-CA deleted the PartyMode branch July 1, 2024 12:46
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