Skip to content

SNS - LED Driver - #44

Open
H-Allen wants to merge 8 commits into
masterfrom
led_sensors
Open

SNS - LED Driver#44
H-Allen wants to merge 8 commits into
masterfrom
led_sensors

Conversation

@H-Allen

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

Copy link
Copy Markdown
Contributor

No description provided.

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

@TomLonergan03 TomLonergan03 left a comment

Copy link
Copy Markdown
Contributor

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

Comment thread lib/sensors/led_driver.cpp Outdated
std::shared_ptr<io::II2c> i2c,
const std::uint8_t device_address)
{
if (device_address != kDefaultLedDriverAddress) {

Copy link
Copy Markdown
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?

Comment thread lib/sensors/led_driver.cpp Outdated
logger.log(core::LogLevel::kFatal, "Invalid device address for LED driver");
return std::nullopt;
}

Copy link
Copy Markdown
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

Comment thread lib/sensors/led_driver.cpp Outdated
{
}

std::optional<core::Result> LedDriver::initialise()

Copy link
Copy Markdown
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
Copy Markdown
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>

Comment thread lib/sensors/led_driver.cpp Outdated
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
Copy Markdown
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

Comment thread lib/sensors/led_driver.hpp Outdated
#include <core/logger.hpp>
#include <io/i2c.hpp>

int kDefaultLedDriverAddress = 0x30;

Copy link
Copy Markdown
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

Comment thread lib/sensors/led_driver.hpp Outdated
static std::optional<LedDriver> create(core::ILogger &logger,
std::shared_ptr<io::II2c> i2c,
const std::uint8_t device_address
= kDefaultLedDriverAddress);

Copy link
Copy Markdown
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

Comment thread lib/sensors/led_driver.hpp Outdated
= kDefaultLedDriverAddress);
~LedDriver();

std::optional<core::Result> initialise();

Copy link
Copy Markdown
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

Comment thread lib/sensors/led_driver.hpp Outdated
~LedDriver();

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

Copy link
Copy Markdown
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

Comment thread lib/sensors/led_driver.hpp Outdated
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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