Skip to content

Commit

Permalink
✨ (CoreBufferedSerial): Add enable/disable_input methods
Browse files Browse the repository at this point in the history
This would allow us to turn off input and improve power saving
  • Loading branch information
ladislas committed Nov 25, 2022
1 parent c6b7c0b commit fc8e800
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions drivers/CoreBufferedSerial/include/CoreBufferedSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class CoreBufferedSerial : public interface::BufferedSerial

auto readable() -> bool final;

void enable_input() final;
void disable_input() final;

void sigio(mbed::Callback<void()> func) final;

private:
Expand Down
10 changes: 10 additions & 0 deletions drivers/CoreBufferedSerial/source/CoreBufferedSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ auto CoreBufferedSerial::readable() -> bool
return _serial.readable();
}

void CoreBufferedSerial::enable_input()
{
_serial.enable_input(true);
}

void CoreBufferedSerial::disable_input()
{
_serial.enable_input(false);
}

void CoreBufferedSerial::sigio(mbed::Callback<void()> func)
{
_serial.sigio(func);
Expand Down
3 changes: 3 additions & 0 deletions include/interface/drivers/BufferedSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class BufferedSerial

virtual auto readable() -> bool = 0;

virtual void disable_input() = 0;
virtual void enable_input() = 0;

virtual void sigio(mbed::Callback<void()> func) = 0; // TODO (@HPezz) replace mbed callback by std function
};

Expand Down
2 changes: 2 additions & 0 deletions tests/unit/mocks/mocks/leka/CoreBufferedSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class CoreBufferedSerial : public interface::BufferedSerial
MOCK_METHOD(std::size_t, read, (uint8_t *, std::size_t), (override));
MOCK_METHOD(std::size_t, write, (const uint8_t *, std::size_t), (override));
MOCK_METHOD(bool, readable, (), (override));
MOCK_METHOD(void, disable_input, (), (override));
MOCK_METHOD(void, enable_input, (), (override));
MOCK_METHOD(void, sigio, (mbed::Callback<void()>), (override));
};

Expand Down

0 comments on commit fc8e800

Please sign in to comment.