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

SNS - LED Driver #44

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

SNS - LED Driver #44

wants to merge 8 commits into from

Conversation

H-Allen
Copy link
Contributor

@H-Allen H-Allen commented Nov 23, 2023

No description provided.

@licornes-fluos licornes-fluos marked this pull request as draft November 25, 2023 10:30
Copy link
Contributor

@TomLonergan03 TomLonergan03 left a comment

Choose a reason for hiding this comment

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

looking good, mostly stylistic changes

std::shared_ptr<io::II2c> i2c,
const std::uint8_t device_address)
{
if (device_address != kDefaultLedDriverAddress) {
Copy link
Contributor

Choose a reason for hiding this comment

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

what's the point of taking an argument for the LED driver if it must match the default?

logger.log(core::LogLevel::kFatal, "Invalid device address for LED driver");
return std::nullopt;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

avoid using whitespace (see the style guide here). the metaphor is that whitespace in code is similar to whitespace in an essay, it should separate paragraphs but you wouldn't have a line break after every sentence

{
}

std::optional<core::Result> LedDriver::initialise()
Copy link
Contributor

Choose a reason for hiding this comment

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

this doesn't need to be optional, just return core::Result::kFailure/core::Result::kSuccess

Copy link
Contributor

Choose a reason for hiding this comment

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

same for all the others that currently return std::optional<core::Result>

std::optional<core::Result> LedDriver::set_colour(std::uint8_t channel,
std::uint8_t red,
std::uint8_t green,
std::uint8_t blue)
Copy link
Contributor

Choose a reason for hiding this comment

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

all these args should be const

#include <core/logger.hpp>
#include <io/i2c.hpp>

int kDefaultLedDriverAddress = 0x30;
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be static constexpr std::uint8_t

static std::optional<LedDriver> create(core::ILogger &logger,
std::shared_ptr<io::II2c> i2c,
const std::uint8_t device_address
= kDefaultLedDriverAddress);
Copy link
Contributor

Choose a reason for hiding this comment

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

we don't use default parameters, but here we don't need the param at all so it's a kinda meaningless point to make

= kDefaultLedDriverAddress);
~LedDriver();

std::optional<core::Result> initialise();
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be private i think

~LedDriver();

std::optional<core::Result> initialise();
std::optional<core::Result> set_colour(std::uint8_t channel,
Copy link
Contributor

Choose a reason for hiding this comment

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

functions names should be in lowerCamelCase

std::uint8_t green,
std::uint8_t blue);
std::optional<core::Result> set_intensity(std::uint8_t channel, std::uint8_t intensity);
std::optional<core::Result> reset();
Copy link
Contributor

Choose a reason for hiding this comment

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

can you write a docstring for all of these methods, especially reset as it is a little unclear what it does


LedDriver::LedDriver(core::ILogger &logger, std::shared_ptr<io::II2c> i2c)
: logger_(logger),
i2c_(i2c)
Copy link
Contributor

Choose a reason for hiding this comment

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

might need a std::move here?

core::Result setIntensity(std::uint8_t channel, std::uint8_t intensity);
core::Result reset();

private:
Copy link
Contributor

Choose a reason for hiding this comment

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

don't need multiple private's

Copy link
Contributor

Choose a reason for hiding this comment

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

at some point someone decided we have a second one separating variables from methods, idk if i like it tho

core::Result reset();

private:
LedDriver(core::ILogger &logger, std::shared_ptr<io::II2c> i2c);
Copy link
Contributor

Choose a reason for hiding this comment

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

Constructor should be public

Copy link
Contributor

Choose a reason for hiding this comment

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

although I'm not sure it needs to be if it is only called from create

Copy link
Contributor

Choose a reason for hiding this comment

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

i feel like it has had to be public even with the create, but i dont remembeer why. if it builds it builds

logger.log(core::LogLevel::kFatal, "Failed to initialise LED driver");
return std::nullopt;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

remove the whitespace, same throughout the PR

@licornes-fluos licornes-fluos marked this pull request as ready for review February 1, 2024 18:08
@davidbeechey davidbeechey added the needs-testing Awaiting testing in the lab before merge label Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-testing Awaiting testing in the lab before merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants