SNS - High Power Relay - #81
Conversation
uses GPIO for 1st attempt to program to write to GPIO.There are a couple of cannot open source file and #include errors I'm not sure how to solve.
TomLonergan03
left a comment
There was a problem hiding this comment.
You don't need to reimplement all the GPIO stuff. Take a IGpio in a static create function, then call getWriter on that and pass the writer to the constructor. See #72 for an example of what I mean. Then, you will just make Relay::setState() and Relay::getState() methods on the object, which call gpiowriter_.write().
You also might as well rename it all to be for a generic relay, so Relay instead of HPRelay cos we'll have a few of them around
feedback. Aware will not pass all tests as having clang-format problems on laptop -looking into this.
names were correct
TomLonergan03
left a comment
There was a problem hiding this comment.
good start! I think there's a nicer abstraction where the client interacts with a relay by simply doing
auto optional_relay = Sensors::Relay::create(/* args */);
// do the optional checks
auto relay = *optional_relay;
relay.close();
// do the high power stuff or whatever
relay.open();| Relay::~Relay() { | ||
| } | ||
|
|
||
| std::optional<RelayWriter> RelayWriter::getWriter(const std::uint8_t pin, |
There was a problem hiding this comment.
this function isn't needed
| RelayWriter::~RelayWriter() { | ||
| } | ||
|
|
||
| bool RelayWriter::Write() { |
There was a problem hiding this comment.
return type should be core::Result, also refactor to be like:
core::Result Relay::open() {
// set relay to be open by writing the GPIO signal if needed
}and similarly a Relay::close() method
| Relay(core::ILogger& logger, std::shared_ptr<io::IGpioWriter> gpio_writer); | ||
| }; | ||
|
|
||
| class RelayWriter { |
There was a problem hiding this comment.
you can get rid of this whole class, it isn't needed
| } | ||
|
|
||
| bool RelayWriter::Write() { | ||
| core::DigitalSignal result = gpio_writer_->write(); |
There was a problem hiding this comment.
This returns a core::Result type I believe, so you can simply do return result; instead of needing the conditionals
|
Change file names to |
licornes-fluos
left a comment
There was a problem hiding this comment.
I think you should start from scratch and look at #72.
Your code is overcomplicated and somehow doesn't use the protocols properly.
You need to call methods from the gpio protocol (hyped-2024/lib/io/gpio.hpp) and use those in your code.
Referred to hardware.gpio and keyence which alsouses GPIO for 1st attempt to program to write to GPIO. There are a couple of cannot open source file and #include errors I'm not sure how to solve.