From ae43f7c2d638de3ac4e7d836cb774fc36817ac1d Mon Sep 17 00:00:00 2001 From: Mourad Latoundji Date: Mon, 14 Nov 2022 14:42:00 +0100 Subject: [PATCH] :recycle: (drivers): Refactor pin_is_on --- drivers/CoreIOExpander/source/CoreIOExpander.cpp | 4 ++-- drivers/CoreIOExpander/tests/CoreIOExpander_test.cpp | 2 +- drivers/CoreTouchSensor/source/CoreTouchSensor.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/CoreIOExpander/source/CoreIOExpander.cpp b/drivers/CoreIOExpander/source/CoreIOExpander.cpp index 2ea2162b9a..8f0575dead 100644 --- a/drivers/CoreIOExpander/source/CoreIOExpander.cpp +++ b/drivers/CoreIOExpander/source/CoreIOExpander.cpp @@ -78,8 +78,8 @@ auto CoreIOExpanderMCP23017::getModeForPin(uint16_t pin) -> PinMode auto CoreIOExpanderMCP23017::readPin(uint16_t pin) -> int { _registers.gpio = readRegister(mcp23017::internal_register::GPIO); - auto value = _registers.gpio & pin; - return pin == value ? 1 : 0; + auto pin_is_on = _registers.gpio & pin; + return pin_is_on; } void CoreIOExpanderMCP23017::writePin(uint16_t pin, int value) diff --git a/drivers/CoreIOExpander/tests/CoreIOExpander_test.cpp b/drivers/CoreIOExpander/tests/CoreIOExpander_test.cpp index 22e08786b4..1965f3e638 100644 --- a/drivers/CoreIOExpander/tests/CoreIOExpander_test.cpp +++ b/drivers/CoreIOExpander/tests/CoreIOExpander_test.cpp @@ -140,7 +140,7 @@ TEST_F(CoreIOExpanderTest, readPinHigh) MOCK_FUNCTION_expectedCallsReadRegister(mcp23017::internal_register::GPIO, GPIO_expected_buffer); auto output_value = expander.readPin(pin_number); - EXPECT_EQ(1, output_value); + EXPECT_EQ(pin_number, output_value); } TEST_F(CoreIOExpanderTest, readPinLow) diff --git a/drivers/CoreTouchSensor/source/CoreTouchSensor.cpp b/drivers/CoreTouchSensor/source/CoreTouchSensor.cpp index 577faf7fb4..89382e7958 100644 --- a/drivers/CoreTouchSensor/source/CoreTouchSensor.cpp +++ b/drivers/CoreTouchSensor/source/CoreTouchSensor.cpp @@ -20,7 +20,7 @@ void CoreTouchSensor::init() auto CoreTouchSensor::read() -> bool { - _state = (1 == _detect_pin.read()); + _state = (_detect_pin.read() != 0); return _state; }