IOReturn LPCSensors::setPowerState(unsigned long powerState, IOService *device) { switch (powerState) { // Power Off case 0: willPowerOff(); break; // Power On case 1: // Restore fan speed after wake from sleep if it was set before for (int index = 0; index < tachometerSensorsLimit(); index ++) { if (tachometerControls[index].target >= 0) { tachometerControlInit(index, tachometerControls[index].target); } } hasPoweredOn(); break; default: break; } return(IOPMAckImplied); }
void LPCSensors::hasPoweredOn() { // Restore fan speed after wake from sleep if it was set before for (int index = 0; index < tachometerSensorsLimit(); index ++) { if (tachometerControls[index].target >= 0) { tachometerControlInit(index, tachometerControls[index].target); } } // Override, but call super }
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; }