cooling/cooling.cc
/// Establish the direction and initial stat of a GPIO_pin.
/// This catches all std exceptions
/// \arg \c line ref of unique_ptr to the line to configure
/// \arg \x pnum the pin number
/// \arg \c dir either Gpio::IN or Gpio::OUT direction
/// \arg \c state initial value (ON, OFF, NC to indicate don't set).
/// \return false on failure true on success.
///
Establish the direction and initial stat of a GPIO_pin.
Establish the direction and initial stat of a GPIO_pin .
bool
Cooling::config_gpio_pin( gpiod::line &line, unsigned pnum,
                          Gpio dir, int state )
{
    try {
        if (line) {
            int cdir=((dir==Gpio::IN) ? gpiod::line_request::DIRECTION_INPUT
                      : gpiod::line_request::DIRECTION_OUTPUT);
            if (line.offset()==pnum and line.direction()==cdir) {
                LOG_DEBUG(Lgr) << "GPIO Pin " << pnum
                               << "is already configured correctly";
                return true;
            }
            LOG_DEBUG(Lgr) << "GPIO Pin " << pnum << " must be reconfigured--release";
            line.release();
        }
        if (!m_gpio_chip) {     
            m_gpio_chip = std::make_unique<gpiod::chip>("gpiochip0");
        }
        line = m_gpio_chip->get_line( pnum );
        if (Gpio::OUT == dir) {
            gpiod::line_request config_o
            {AppName,gpiod::line_request::DIRECTION_OUTPUT,0};
            line.request( config_o, state );
            LOG_INFO(Lgr) << "GPIO " << pnum << " exported, direction OUTPUT"
                " Initially " << state;
        } else {
            gpiod::line_request config_i
               {AppName,gpiod::line_request::DIRECTION_INPUT,0};
            line.request( config_i );
            LOG_INFO(Lgr) << "GPIO " << pnum << " exported, direction INPUT";
        }
        return true;
    }
    catch ( std::exception &ex ) {
        LOG_ERROR(Lgr) << "GPIO " << pnum << " setup failed: " << ex.what();
        m_gpio_errors++;
    }
    return false;
}
bool Cooling :: config_gpio_pin ( gpiod :: line & line , unsigned pnum , Gpio dir , int state ) { try { if ( line ) { int cdir = ( ( dir == Gpio :: IN ) ? gpiod :: line_request :: DIRECTION_INPUT : gpiod :: line_request :: DIRECTION_OUTPUT ) ; if ( line . offset ( ) == pnum and line . direction ( ) == cdir ) { LOG_DEBUG ( Lgr ) << " " << pnum << " " ; return true ; } LOG_DEBUG ( Lgr ) << " " << pnum << " " ; line . release ( ) ; } if ( ! m_gpio_chip ) { m_gpio_chip = std :: make_unique < gpiod :: chip > ( " " ) ; } line = m_gpio_chip -> get_line ( pnum ) ; if ( Gpio :: OUT == dir ) { gpiod :: line_request config_o { AppName , gpiod :: line_request :: DIRECTION_OUTPUT , 0 } ; line . request ( config_o , state ) ; LOG_INFO ( Lgr ) << " " << pnum << " " " " << state ; } else { gpiod :: line_request config_i { AppName , gpiod :: line_request :: DIRECTION_INPUT , 0 } ; line . request ( config_i ) ; LOG_INFO ( Lgr ) << " " << pnum << " " ; } return true ; } catch ( std :: exception & ex ) { LOG_ERROR ( Lgr ) << " " << pnum << " " << ex . what ( ) ; m_gpio_errors ++ ; } return false ; }
Establish the direction and initial stat of a GPIO_pin.
Establish the direction and initial stat of a GPIO_pin .
// if the line is already configured correctly, just return // maybe set state to state if an output // chip required to access any lines...