mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-06-12 01:25:59 +00:00
Modified GpioPin to offer PinState reading
This commit is contained in:
parent
38bdbbe526
commit
4eb1053ffd
@ -37,6 +37,13 @@ namespace sta
|
|||||||
* @param state Output state
|
* @param state Output state
|
||||||
*/
|
*/
|
||||||
virtual void setState(GpioPinState state) = 0;
|
virtual void setState(GpioPinState state) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get pin input state.
|
||||||
|
*
|
||||||
|
* @param state Input state
|
||||||
|
*/
|
||||||
|
virtual GpioPinState getState() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,6 +31,8 @@ namespace sta
|
|||||||
|
|
||||||
void setState(GpioPinState state) override;
|
void setState(GpioPinState state) override;
|
||||||
|
|
||||||
|
GpioPinState getState() override;
|
||||||
|
|
||||||
static RaspiGpioPin * DUMMY_GPIO;
|
static RaspiGpioPin * DUMMY_GPIO;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
namespace sta
|
namespace sta
|
||||||
{
|
{
|
||||||
RaspiGpioPin::RaspiGpioPin(uint8_t pin, GpioMode mode) : pin_{pin}, mode_{mode}
|
RaspiGpioPin::RaspiGpioPin(uint8_t pin, GpioMode mode) : pin_{ pin }, mode_{ mode }
|
||||||
{
|
{
|
||||||
pinMode(pin, mode == GpioMode::GPIO_INPUT ? INPUT : OUTPUT);
|
pinMode(pin, mode == GpioMode::GPIO_INPUT ? INPUT : OUTPUT);
|
||||||
}
|
}
|
||||||
@ -16,11 +16,22 @@ namespace sta
|
|||||||
digitalWrite(pin_, state == GpioPinState::GPIO_LOW ? LOW : HIGH);
|
digitalWrite(pin_, state == GpioPinState::GPIO_LOW ? LOW : HIGH);
|
||||||
}
|
}
|
||||||
|
|
||||||
class DummyGpioPin : public RaspiGpioPin {
|
GpioPinState RaspiGpioPin::getState()
|
||||||
|
{
|
||||||
|
return digitalRead(pin_) == LOW ? GpioPinState::GPIO_LOW : GpioPinState::GPIO_HIGH;
|
||||||
|
}
|
||||||
|
|
||||||
|
class DummyGpioPin : public RaspiGpioPin
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
DummyGpioPin() : RaspiGpioPin { 0, GpioMode::GPIO_INPUT } {}
|
DummyGpioPin() : RaspiGpioPin { 0, GpioMode::GPIO_INPUT } {}
|
||||||
|
|
||||||
void setState(GpioPinState state) override {}
|
void setState(GpioPinState state) override {}
|
||||||
|
|
||||||
|
GpioPinState getState() override {
|
||||||
|
// This should really never be called since the code might rely on the returned value to be accurate.
|
||||||
|
STA_UNREACHABLE();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static DummyGpioPin dummyGpio;
|
static DummyGpioPin dummyGpio;
|
||||||
|
@ -133,7 +133,7 @@ namespace sta
|
|||||||
|
|
||||||
if (result == -1) {
|
if (result == -1) {
|
||||||
printf("Sending failed with error '%s'! \n", strerror(errno));
|
printf("Sending failed with error '%s'! \n", strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
STA_DEBUG_IOCTL_SEND(result);
|
STA_DEBUG_IOCTL_SEND(result);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user