Пример #1
0
bool LPCSensors::didWriteSensorValue(FakeSMCSensor *sensor, float value)
{
    if (sensor) {
        switch (sensor->getGroup()) {
                
            case kLPCSensorsFanManualSwitch:
                for (int index = 0; index < tachometerSensorsLimit(); index++) {
                    if (isTachometerControlable(index) && !bit_get((UInt16)value, BIT(tachometerControls[index].number))) {
                        tachometerControlCancel(index);
                        tachometerControls[index].target = -1.0;
                    }
                }
                break;

            case kLPCSensorsFanMinController:
                if (isTachometerControlable(sensor->getIndex())) {
                    tachometerControls[sensor->getIndex()].minimum = value;
                    tachometerControlInit(sensor->getIndex(), value > tachometerControls[sensor->getIndex()].target ? value : tachometerControls[sensor->getIndex()].target);
                }
                break;

            case kLPCSensorsFanTargetController:
                if (isTachometerControlable(sensor->getIndex())) {
                    int manual = 0;
                    if (decodeIntValueForKey(KEY_FAN_MANUAL, &manual) && bit_get(manual, BIT(tachometerControls[sensor->getIndex()].number)) > 0 && value > tachometerControls[sensor->getIndex()].minimum) {
                        tachometerControlInit(sensor->getIndex(), value);
                    }
                }
                break;

            default: return false;
                
        }

        return true;
    }

    return false;
}
Пример #2
0
bool LPCSensors::addTachometerSensors(OSDictionary *configuration)
{
    HWSensorsDebugLog("adding tachometer sensors...");

    char key[7];
    UInt16 value = 0;

    // FAN manual control key
    addSensorForKey(KEY_FAN_MANUAL, SMC_TYPE_UI16, SMC_TYPE_UI16_SIZE, kLPCSensorsFanManualSwitch, 0);

    int location = LEFT_LOWER_FRONT;

    for (int i = 0; i < tachometerSensorsLimit(); i++) {
        
        UInt8 fanIndex;

        snprintf(key, 7, "FANIN%X", i);

        if (OSString* name = OSDynamicCast(OSString, configuration->getObject(key))){
            if (addTachometer(i, name->getLength() > 0 ? name->getCStringNoCopy() : 0, FAN_RPM, 0, (FanLocationType)location++, &fanIndex)){

                if (isTachometerControlable(i) && fanIndex < UINT8_MAX) {

                    tachometerControls[i].number = fanIndex;
                    tachometerControls[i].target = -1;
                    tachometerControls[i].minimum = -1;

                    // Minimum RPM and fan control sensor
                    snprintf(key, 5, KEY_FORMAT_FAN_MIN, fanIndex);
                    addSensorForKey(key, SMC_TYPE_FPE2, SMC_TYPE_FPXX_SIZE, kLPCSensorsFanMinController, i);

                    // Maximum RPM
                    snprintf(key, 5, KEY_FORMAT_FAN_MAX, fanIndex);
                    FakeSMCKey::encodeFloatValue(kLPCSensorsMaxRPM, SMC_TYPE_FPE2, SMC_TYPE_FPXX_SIZE, &value);
                    setKeyValue(key, SMC_TYPE_FPE2, SMC_TYPE_FPXX_SIZE, &value);

                    // Target RPM and fan control sensor
                    snprintf(key, 5, KEY_FORMAT_FAN_TARGET, fanIndex);
                    addSensorForKey(key, SMC_TYPE_FPE2, SMC_TYPE_FPXX_SIZE, kLPCSensorsFanTargetController, i);
                }
            }
            else HWSensorsWarningLog("failed to add tachometer sensor %d", i);
        }
    }

    return true;
}