cooling/cooling.cc
/// Initialize fan control parameters and GPIO, if enabled.
/// \arg \c cfg  Configuration object
///
/// * May throw a Cooling_configuration_exception
///
Initialize fan control parameters and GPIO, if enabled.
\arg \c cfg  Configuration object

May throw a Cooling_configuration_exception
Initialize fan control parameters and GPIO if enabled . \ arg \ c cfg Configuration object May throw a Cooling_configuration_exception
void Cooling::init_cooling( Config &cfg )
{
    cfg.get_bool("Cooling", "enabled", m_fan_control_enabled);
    cfg.get_double("Cooling","cool_stop_temp",m_cool_stop_temp);
    cfg.get_double("Cooling","cool_start_temp",m_cool_start_temp);
    if (m_cool_start_temp <= m_cool_stop_temp) {
        LOG_ERROR(Lgr) << "cool_start_temp <= cool_stop_temp";
        throw Cooling_config_exception();
    }
    if (m_cool_stop_temp < Fan_lowest_stop_temp) {
        LOG_ERROR(Lgr) << "cool_stop_temp < 25C - unreasonable!";
        throw Cooling_config_exception();
    }
    if (m_cool_start_temp > Fan_highest_start_temp) {
        LOG_ERROR(Lgr) << "cool_start_temp > 80C - CPU would be toast";
        throw Cooling_config_exception();
    }
    int mcs=static_cast<int>(m_min_cool_secs);
    cfg.get_int("Cooling","min_cool_secs",mcs);
    if (mcs < Lowest_cool_secs) {
        LOG_ERROR(Lgr) << "min_cool_secs must be at least " << Lowest_cool_secs;
        throw Cooling_config_exception();
    }
    m_min_cool_secs = static_cast<time_t>(mcs);
    unsigned pin_num=4;
    cfg.get_unsigned("Cooling","fan_gpio",pin_num);
    cfg.get_pathname("Cooling","sensor",FileCond::MustExist,
                     m_temp_sensor_path);
    if (m_test_mode) return;
     Claim the GPIO--but only if fan control is enabled
    if (m_fan_control_enabled) {
        if (not config_gpio_pin( m_fan_gpio, pin_num, Gpio::OUT, GPIO_OFF)) {
            m_fan_control_enabled = false;
            LOG_ERROR(Lgr) << "No fan control available this session";
        } else {
            LOG_INFO(Lgr) << "Fan control enabled on GPIO " << pin_num;
        }
    } else if (m_fan_gpio) {     release the gpio if held
        m_fan_gpio.set_value(0);  turn it off
        m_fan_gpio.release();
    }
}
void Cooling :: init_cooling ( Config & cfg ) { cfg . get_bool ( " " , " " , m_fan_control_enabled ) ; cfg . get_double ( " " , " " , m_cool_stop_temp ) ; cfg . get_double ( " " , " " , m_cool_start_temp ) ; if ( m_cool_start_temp <= m_cool_stop_temp ) { LOG_ERROR ( Lgr ) << " " ; throw Cooling_config_exception ( ) ; } if ( m_cool_stop_temp < Fan_lowest_stop_temp ) { LOG_ERROR ( Lgr ) << " " ; throw Cooling_config_exception ( ) ; } if ( m_cool_start_temp > Fan_highest_start_temp ) { LOG_ERROR ( Lgr ) << " " ; throw Cooling_config_exception ( ) ; } int mcs = static_cast < int > ( m_min_cool_secs ) ; cfg . get_int ( " " , " " , mcs ) ; if ( mcs < Lowest_cool_secs ) { LOG_ERROR ( Lgr ) << " " << Lowest_cool_secs ; throw Cooling_config_exception ( ) ; } m_min_cool_secs = static_cast < time_t > ( mcs ) ; unsigned pin_num = 4 ; cfg . get_unsigned ( " " , " " , pin_num ) ; cfg . get_pathname ( " " , " " , FileCond :: MustExist , m_temp_sensor_path ) ; if ( m_test_mode ) return ; if ( m_fan_control_enabled ) { if ( not config_gpio_pin ( m_fan_gpio , pin_num , Gpio :: OUT , GPIO_OFF ) ) { m_fan_control_enabled = false ; LOG_ERROR ( Lgr ) << " " ; } else { LOG_INFO ( Lgr ) << " " << pin_num ; } } else if ( m_fan_gpio ) { m_fan_gpio . set_value ( 0 ) ; m_fan_gpio . release ( ) ; } }
Initialize fan control parameters and GPIO, if enabled.
Initialize fan control parameters and GPIO if enabled .
// // // Claim the GPIO--but only if fan control is enabled // release the gpio if held // turn it off