improved linux libgpiod interface

This commit is contained in:
2021-02-12 21:23:35 +01:00
parent 375995e562
commit 3f41adf340
6 changed files with 155 additions and 74 deletions

View File

@ -213,15 +213,22 @@ void HeaterHandler::handleSwitchOnCommand(HeaterMapIter heaterMapIter) {
if (!checkSwitchState(switchNr)) {
gpioId_t gpioId = getGpioIdFromSwitchNr(switchNr);
result = gpioInterface->pullHigh(gpioId);
result = RETURN_OK;
if (result != RETURN_OK) {
sif::error << "HeaterHandler::handleSwitchOffCommand: Failed to pull gpio with id"
sif::error << "HeaterHandler::handleSwitchOnCommand: Failed to pull gpio with id"
<< gpioId << "high" << std::endl;
triggerEvent(GPIO_PULL_HIGH_FAILED, result);
}
else {
switchStates[switchNr] = ON;
}
int gpioState;
result = gpioInterface->readGpio(gpioId, &gpioState);
if (result != RETURN_OK) {
sif::debug << "HeaterHandler::handleSwitchOnCommand: Failed to read gpio"
<< std::endl;
}
sif::debug << "HeaterHandler::handleSwitchOnCommand: GPIO state: " << gpioState
<< std::endl;
}
else {
triggerEvent(SWITCH_ALREADY_ON, switchNr);
@ -264,7 +271,6 @@ void HeaterHandler::handleSwitchOffCommand(HeaterMapIter heaterMapIter) {
if (checkSwitchState(switchNr)) {
gpioId_t gpioId = getGpioIdFromSwitchNr(switchNr);
result = gpioInterface->pullLow(gpioId);
result = RETURN_OK;
if (result != RETURN_OK) {
sif::error << "HeaterHandler::handleSwitchOffCommand: Failed to pull gpio with id"
<< gpioId << " low" << std::endl;
@ -277,6 +283,14 @@ void HeaterHandler::handleSwitchOffCommand(HeaterMapIter heaterMapIter) {
mainLineSwitcher->sendSwitchCommand(mainLineSwitch, PowerSwitchIF::SWITCH_OFF);
}
}
int gpioState;
result = gpioInterface->readGpio(gpioId, &gpioState);
if (result != RETURN_OK) {
sif::debug << "HeaterHandler::handleSwitchOnCommand: Failed to read gpio"
<< std::endl;
}
sif::debug << "HeaterHandler::handleSwitchOnCommand: GPIO state: " << gpioState
<< std::endl;
}
else {
sif::info << "HeaterHandler::handleSwitchOffCommand: Switch already off" << std::endl;