int main(void) { volatile float filteredTemp = readTemperature(); uint32_t lastTemperatureUpdate = 0; temperature = filteredTemp*10; ClockInit(); ModuloInit(); while(1) { ModuloUpdateStatusLED(); // Constantly read the temperature (every 1ms) and apply a low pass IIR filter. float filterRate = .01; float newTemperature = readTemperature(); filteredTemp = filterRate*newTemperature + (1.0-filterRate)*filteredTemp; _delay_ms(1); // Every 100ms, update the temperature from the current filtered value if ((millis()-lastTemperatureUpdate) > 100) { lastTemperatureUpdate = millis(); // Disable interrupts and atomically update the state noInterrupts(); temperature = filteredTemp*10; // tenths of degrees interrupts(); } } }
bool SuperIOMonitor::updateSensor(const char *key, const char *type, unsigned char size, SuperIOSensorGroup group, unsigned long index) { long value = 0; switch (group) { case kSuperIOTemperatureSensor: value = readTemperature(index); break; case kSuperIOVoltageSensor: value = readVoltage(index); break; case kSuperIOTachometerSensor: value = readTachometer(index); break; default: break; } if (strcmp(type, TYPE_FP2E) == 0) { value = encode_fp2e(value); } else if (strcmp(type, TYPE_FPE2) == 0) { value = encode_fpe2(value); } if (kIOReturnSuccess != fakeSMC->callPlatformFunction(kFakeSMCSetKeyValue, true, (void*)key, (void*)size, (void*)&value, 0)) return false; return true; }
void PTIDSensors::parseTemperatureName(OSString *name, UInt32 index) { if (name && readTemperature(index)) { char key[5]; char str[64]; key[0] = '\0'; if (name->isEqualTo("CPU Core Package DTS") || name->isEqualTo("CPU Package Temperature")) snprintf(key, 5, KEY_CPU_PACKAGE_TEMPERATURE); else if (name->isEqualTo("CPU Temperature")) snprintf(key, 5, KEY_CPU_PROXIMITY_TEMPERATURE); else if (name->isEqualTo("PCH Temperature") || name->isEqualTo("PCH DTS Temperature from PCH")) snprintf(key, 5, KEY_PCH_DIE_TEMPERATURE); else if (name->isEqualTo("MCH DTS Temperature from PCH")) snprintf(key, 5, KEY_MCH_DIODE_TEMPERATURE); else if (name->isEqualTo("Ambient Temperature")) snprintf(key, 5, KEY_AMBIENT_TEMPERATURE); else { for (UInt8 i = 0; i < 4; i++) { snprintf(str, 64, "TS-on-DIMM%X Temperature", i); if (name->isEqualTo(str)) { snprintf(key, 5, KEY_FORMAT_DIMM_TEMPERATURE, i); break; } snprintf(str, 64, "Channel %X DIMM Temperature", i); if (name->isEqualTo(str)) { snprintf(key, 5, KEY_FORMAT_DIMM_TEMPERATURE, i); break; } } if (key[0] == '\0') { for (UInt8 i = 0; i < 8; i++) { snprintf(str, 64, "TZ0%X _TMP", i); if (name->isEqualTo(str)) { snprintf(key, 5, KEY_FORMAT_THERMALZONE_TEMPERATURE, i + 1); break; } snprintf(str, 64, "CPU Core %X DTS", i); if (name->isEqualTo(str)) { snprintf(key, 5, KEY_FORMAT_CPU_DIODE_TEMPERATURE, i); break; } } } } if (key[0] != '\0') { HWSensorsDebugLog("adding %s sensor", name->getCStringNoCopy()); addSensor(key, TYPE_SP78, TYPE_SPXX_SIZE, kFakeSMCTemperatureSensor, index); } } }
bool LPCSensors::willReadSensorValue(FakeSMCSensor *sensor, float *outValue) { if (sensor) { switch (sensor->getGroup()) { case kFakeSMCTemperatureSensor: *outValue = sensor->getOffset() + readTemperature(sensor->getIndex()); break; case kFakeSMCVoltageSensor: { float v = readVoltage(sensor->getIndex()); *outValue = sensor->getOffset() + v + (v - sensor->getReference()) * sensor->getGain(); break; } case kFakeSMCTachometerSensor: *outValue = readTachometer(sensor->getIndex()); break; case kLPCSensorsFanManualSwitch: case kLPCSensorsFanMinController: case kLPCSensorsFanTargetController: default: // Just return stored key value return false; } return true; } return false; }
void AltitudeUpdate(void) { int32_t BaroAlt; BaroInfo_T *BaroInfo; static float baroGroundTemperatureScale=0,logBaroGroundPressureSum=0; BaroInfo = GetBaroInfo(); if(calibratingB > 0) { logBaroGroundPressureSum = log(BaroInfo->baroPressureSum); #ifdef BMP085 baroGroundTemperatureScale = (readTemperature(BaroInfo->baroTemperature)*100 + 27315) * 29.271267f; #else baroGroundTemperatureScale = (BaroInfo->baroTemperature*100 + 27315) * 29.271267f; #endif calibratingB--; } BaroAlt = ( logBaroGroundPressureSum - log(BaroInfo->baroPressureSum) ) * baroGroundTemperatureScale; aslRaw = (float)BaroAlt/100; asl = asl * aslAlpha + aslRaw * (1 - aslAlpha); SetBaroAltitude(asl); }
void show() { if(++swcnt > (sw?10:30)) { swcnt = 0; sw++; sw &= 3; } switch(sw) { case 0: get_time(); putchr(0,(hour+dst)/10); putchr(1,(hour+dst)%10); putchr(2,minute/10); putchr(3,minute%10); break; case 1: if(swcnt == 0) { temp = readTemperature() / 10; } putchr(2,temp%10); t = temp / 10; putchr(0,t/10); putchr(1,t%10); putchr(3,0x0c); break; case 2: if(swcnt == 0) { hum = readHumidity() * 5 / 512; } putchr(2,hum%10); t = hum / 10; putchr(0,t/10); putchr(1,t%10); dsp_buf[3] = chrH; break; case 3: if(swcnt == 0) { pres = readPressure() / 100; } t = pres; if(t > 999) { putchr(3,t%10); t /= 10; putchr(2,t%10); t /= 10; putchr(1,t%10); t /= 10; putchr(0,t); } else { dsp_buf[0] = chrP; putchr(3,t%10); t /= 10; putchr(2,t%10); t /= 10; putchr(1,t%10); } break; default:; } }
float INT340EMonitor::getSensorValue(FakeSMCSensor *sensor) { switch(sensor->getGroup()) { case kFakeSMCTemperatureSensor: return readTemperature(sensor->getIndex()); } return 0; }
int main() { init(); printf("Hello\r\n"); PORTD |= (1 << PD3); DDRD |= (1 << PD3); DDRB |= (1 << PB1); PORTB &= ~(1 << PB1); _delay_ms(100); lcd.init(); lcd.clear(); lcd.go(10, 10); fprintf(&lcd.lcdf, "lala"); lcd.sync(); for (;;) { uint8_t ambient; uint16_t tip; readTemperature(&ambient, &tip); uint16_t setTemp = (((float) adc()) / 0xffff) * 210 + 190; regulator.setWanted(setTemp); lcd.clear(); lcd.go(10, 2); fprintf(&lcd.lcdf, "Ext %3d C", ambient); lcd.go(10, 12); fprintf(&lcd.lcdf, "Tip %3d C", tip); lcd.go(10, 22); regulator.processInput(tip); if (setTemp >= 200) { pwm1::setDuty(regulator.getOutput()); fprintf(&lcd.lcdf, "Set %3d C", setTemp); lcd.go(10, 32); fprintf(&lcd.lcdf, "%3d%% %3d%%", (int16_t) (regulator.getP() * 100), (int16_t) (regulator.getI() * 100)); } else { pwm1::setDuty(0); fprintf(&lcd.lcdf, "OFF"); } lcd.sync(); _delay_ms(50); } }
/** Perform pressure and temperature reading and calculation at once. * Contains sleeps, better perform operations separately. */ void MS5611::update() { refreshPressure(); usleep(10000); // Waiting for pressure data ready readPressure(); refreshTemperature(); usleep(10000); // Waiting for temperature data ready readTemperature(); calculatePressureAndTemperature(); }
float PTIDSensors::getSensorValue(FakeSMCSensor *sensor) { switch(sensor->getGroup()) { case kFakeSMCTemperatureSensor: return readTemperature(sensor->getIndex()); case kFakeSMCTachometerSensor: return readTachometer(sensor->getIndex()); } return 0; }
void INT340EMonitor::parseTemperatureName(OSString *name, UInt32 index) { if (name && readTemperature(index)) { char key[5]; char str[64]; for (UInt8 i = 0; i < 8; i++) { snprintf(str, 64, "CPU Core %x DTS", i); if (name->isEqualTo(str)) { snprintf(key, 5, KEY_FORMAT_CPU_DIODE_TEMPERATURE, i); break; } } if (name->isEqualTo("CPU Core Package DTS") || name->isEqualTo("CPU Package Temperature")) snprintf(key, 5, KEY_CPU_PACKAGE_TEMPERATURE); if (name->isEqualTo("CPU Temperature")) snprintf(key, 5, KEY_CPU_PROXIMITY_TEMPERATURE); if (name->isEqualTo("PCH Temperature") || name->isEqualTo("PCH DTS Temperature from PCH")) snprintf(key, 5, KEY_PCH_DIE_TEMPERATURE); if (name->isEqualTo("MCH DTS Temperature from PCH")) snprintf(key, 5, KEY_MCH_DIODE_TEMPERATURE); if (name->isEqualTo("Ambient Temperature")) snprintf(key, 5, KEY_AMBIENT_TEMPERATURE); for (UInt8 i = 0; i < 4; i++) { snprintf(str, 64, "TS-on-DIMM%x Temperature", i); if (name->isEqualTo(str)) { snprintf(key, 5, KEY_FORMAT_DIMM_TEMPERATURE, i); break; } } for (UInt8 i = 0; i < 8; i++) { snprintf(str, 64, "TZ0%x _TMP", i); if (name->isEqualTo(str)) { snprintf(key, 5, KEY_FORMAT_THERMALZONE_TEMPERATURE, i + 1); break; } } if (strlen(key)) addSensor(key, TYPE_SP78, TYPE_SPXX_SIZE, kFakeSMCTemperatureSensor, index); } }
int _Esplora::readTemperature(const byte scale) { long rawT = readChannel(CH_TEMPERATURE); if (scale == DEGREES_C) { return (int)((rawT * 500 / 1024) - 50); } else if (scale == DEGREES_F) { return (int)((rawT * 450 / 512 ) - 58); } else { return readTemperature(DEGREES_C); } }
boolean DHT11::readVal( HardwareTypeIdentifier type, HardwareCommandResult* result ) { if(result == NULL) return false; if(type == HWType_temprature) { readTemperature(result); return true; } else if(type == HWType_humidity) { readHumidity(result); return true; } return false; }
int main(int argc, char** argv) { char deviceName[200]; if (NULL!=getDeviceName(VENDOR, PRODUCT, deviceName)) { return readTemperature(deviceName); } else { fprintf(stderr, "No device found with vendor id=%s and product id=%s\n", VENDOR, PRODUCT); return(1); } }
void PTIDSensors::parseTemperatureName(OSString *name, UInt32 index) { if (name && readTemperature(index)) { if (name->isEqualTo("CPU Core Package DTS") || name->isEqualTo("CPU Package Temperature")) addSensor("CPU Package", kFakeSMCCategoryTemperature, kFakeSMCTemperatureSensor, index); else if (name->isEqualTo("CPU Temperature")) addSensor("CPU Proximity", kFakeSMCCategoryTemperature, kFakeSMCTemperatureSensor, index); else if (name->isEqualTo("PCH Temperature") || name->isEqualTo("PCH DTS Temperature from PCH")) addSensor("PCH Die", kFakeSMCCategoryTemperature, kFakeSMCTemperatureSensor, index); else if (name->isEqualTo("MCH DTS Temperature from PCH")) addSensor("MCH Die", kFakeSMCCategoryTemperature, kFakeSMCTemperatureSensor, index); else if (name->isEqualTo("Ambient Temperature")) addSensor("Ambient", kFakeSMCCategoryTemperature, kFakeSMCTemperatureSensor, index); else { char str[64]; for (UInt8 i = 0; i < 4; i++) { snprintf(str, 64, "TS-on-DIMM%X Temperature", i); if (name->isEqualTo(str)) { addSensor("Memory Module", kFakeSMCCategoryTemperature, kFakeSMCTemperatureSensor, index); break; } snprintf(str, 64, "Channel %X DIMM Temperature", i); if (name->isEqualTo(str)) { addSensor("Memory Proximity", kFakeSMCCategoryTemperature, kFakeSMCTemperatureSensor, index); break; } } for (UInt8 i = 0; i < 8; i++) { snprintf(str, 64, "TZ0%X _TMP", i); if (name->isEqualTo(str)) { addSensor("Thermal Zone", kFakeSMCCategoryTemperature, kFakeSMCTemperatureSensor, index); break; } snprintf(str, 64, "CPU Core %X DTS", i); if (name->isEqualTo(str)) { addSensor("CPU Core", kFakeSMCCategoryTemperature, kFakeSMCTemperatureSensor, index); break; } } } } }
bool NStep::updateProperties() { if (isConnected()) { // Read these values before defining focuser interface properties readPosition(); readSpeedInfo(); } INDI::Focuser::updateProperties(); if (isConnected()) { if (readTemperature()) defineNumber(&TemperatureNP); bool rc = getStartupValues(); // Settings defineNumber(&MaxSpeedNP); defineSwitch(&CompensationModeSP); defineSwitch(&PrimeManualSP); defineNumber(&CompensationSettingsNP); defineSwitch(&SteppingModeSP); defineNumber(&SteppingPhaseNP); defineSwitch(&CoilStatusSP); if (rc) LOG_INFO("NStep is ready."); else LOG_WARN("Failed to query startup values."); } else { if (TemperatureNP.s == IPS_OK) deleteProperty(TemperatureNP.name); deleteProperty(MaxSpeedNP.name); deleteProperty(CompensationModeSP.name); deleteProperty(PrimeManualSP.name); deleteProperty(CompensationSettingsNP.name); deleteProperty(SteppingModeSP.name); deleteProperty(SteppingPhaseNP.name); deleteProperty(CoilStatusSP.name); } return true; }
bool PTIDSensors::willReadSensorValue(FakeSMCSensor *sensor, float *outValue) { switch(sensor->getGroup()) { case kFakeSMCTemperatureSensor: *outValue = readTemperature(sensor->getIndex()); break; case kFakeSMCTachometerSensor: *outValue = readTachometer(sensor->getIndex()); break; default: return false; } return true; }
double readDewPoint(int file) { double A = 8.1332; double B = 1762.39; double C = 235.66; double dewpoint; double temp = readTemperature(file); double humi = readHumidity(file); //CALCULATE PARTIAL PRESSURE double exponent = (A - (B / (temp + C))); double PPtamb = pow(10, exponent); dewpoint = - ((B / (log10(humi * (PPtamb / 100)) - A)) + C); //printf("DewPoint %f C\n", dewpoint); return dewpoint; }
void onMain(void) { while (!stopping()) { if (isActive()) { m_delay.wait(); scanAnalogueInputs(); readTemperature(); consumeMessages(); } else { waitForMessages(1.0); } } }
void ASIEAF::TimerHit() { if (!isConnected()) { SetTimer(POLLMS); return; } bool rc = readPosition(); if (rc) { if (fabs(lastPos - FocusAbsPosN[0].value) > 5) { IDSetNumber(&FocusAbsPosNP, nullptr); lastPos = FocusAbsPosN[0].value; } } rc = readTemperature(); if (rc) { if (fabs(lastTemperature - TemperatureN[0].value) >= 0.1) { IDSetNumber(&TemperatureNP, nullptr); lastTemperature = TemperatureN[0].value; } } if (FocusAbsPosNP.s == IPS_BUSY || FocusRelPosNP.s == IPS_BUSY) { if (!isMoving()) { FocusAbsPosNP.s = IPS_OK; FocusRelPosNP.s = IPS_OK; IDSetNumber(&FocusAbsPosNP, nullptr); IDSetNumber(&FocusRelPosNP, nullptr); lastPos = FocusAbsPosN[0].value; LOG_INFO("Focuser reached requested position."); } } SetTimer(POLLMS); }
/********************************************************************* * @fn zcl_SendDeviceData * * @brief Process sensor send data to coordinator. * * @param none * * @return none */ static void zcl_SendDeviceData( void ) { uint8 *temperature; uint8 *battery; uint8 temperatureLength, batteryLength, dataLength; uint8 *data; temperature = readTemperature(); temperatureLength = strlen( ( char* )temperature ); battery = readBattery(); batteryLength = strlen( ( char* )battery ); dataLength = temperatureLength + batteryLength + 2; data = ( uint8* )osal_mem_alloc( dataLength ); strcpy( ( char* )data, ( char* )temperature ); strcpy( ( char* )data + temperatureLength + 1, ( char* )battery ); zcl_SendData( dataLength, data, 0 ); osal_mem_free( data ); }
float SuperIOPlugin::getSensorValue(FakeSMCSensor *sensor) { float value = 0; if (sensor) { switch (sensor->getGroup()) { case kFakeSMCTemperatureSensor: value = sensor->getOffset() + readTemperature(sensor->getIndex()); break; case kFakeSMCVoltageSensor: value = readVoltage(sensor->getIndex()); value = sensor->getOffset() + value + (value - sensor->getReference()) * sensor->getGain(); break; case kFakeSMCTachometerSensor: value = readTachometer(sensor->getIndex()); break; } } return value; }
float DHT::getTempKelvin() { return convertCtoK(readTemperature()); }
float DHT::getTempCelcius() { return readTemperature(); }
// This function is called repeatedly void loop(void) { // Temporary storage variables unsigned int i; unsigned char temperature; unsigned char data; char buffer[50]; // Check if the serial port has overflown, and clear the event if that happened. if (RCSTAbits.OERR) { RCSTA1bits.CREN = 0; RCSTA1bits.CREN = 1; } // Check if there is serial data waiting for us if (receiveCharacter != 0) { // See if we got a command switch (receiveCharacter) { case 'm': // Measure the current temperature // Read the temperature temperature = readTemperature(); // Write the results out to a string sprintf(buffer,"The current temperature is: %u\n\r", temperature); // Then send that string to the serial port puts1USART(buffer); break; case 'b': // Begin logging sprintf(buffer,"Logging started\n\r"); puts1USART(buffer); logging = 1; break; case 'e': // End logging sprintf(buffer,"Logging stopped\n\r"); puts1USART(buffer); logging = 0; break; case 'd': // Get the logged data sprintf(buffer,"Getting %u measurements: ", logCount); puts1USART(buffer); for (i = 0; i < logCount; i++) { temperature = readEEPROM( i ); // Write the results out to a string sprintf(buffer,"%u, ", temperature); // Then send that string to the serial port puts1USART(buffer); } sprintf(buffer,"\n\r", temperature); puts1USART(buffer); break; case 'r': // Reset the logger, clearing all data sprintf(buffer,"Logger reset\n\r"); puts1USART(buffer); logging = 0; logCount = 0; intervalCounter = 0; break; } receiveCharacter = 0; } // Wait for one second wait(1); // If data logging is enabled, see if we should log some now. if ( logging ) { // Record that another second has passed intervalCounter++; // If we have waited for enough time, measure the current temperature if (intervalCounter >= logInterval) { // Turn on the LED to signal that a log event is happening PORTAbits.RA0 = 1; // Reset the seconds counter intervalCounter = 0; // Read the temperature temperature = readTemperature(); // And record it in the EEPROM writeEEPROM( logCount, temperature ); // Then record that we have taken another sample logCount++; // And turn off the LED PORTAbits.RA0 = 0; } } }
void NStep::TimerHit() { if (isConnected() == false) return; double currentPosition = FocusAbsPosN[0].value; readPosition(); // Check if we have a pending motion // and if we STOPPED, then let's take the next action if ( (FocusAbsPosNP.s == IPS_BUSY || FocusRelPosNP.s == IPS_BUSY) && isMoving() == false) { // Are we done moving? if (m_TargetDiff == 0) { FocusAbsPosNP.s = IPS_OK; FocusRelPosNP.s = IPS_OK; IDSetNumber(&FocusAbsPosNP, nullptr); IDSetNumber(&FocusRelPosNP, nullptr); } else { // 999 is the max we can go in one command // so we need to go 999 or LESS // therefore for larger movements, we break it down. int nextMotion = (std::abs(m_TargetDiff) > 999) ? 999 : std::abs(m_TargetDiff); int direction = m_TargetDiff > 0 ? FOCUS_OUTWARD : FOCUS_INWARD; int mode = IUFindOnSwitchIndex(&SteppingModeSP); char cmd[NSTEP_LEN] = {0}; snprintf(cmd, NSTEP_LEN, ":F%d%d%03d#", direction, mode, nextMotion); if (sendCommand(cmd) == false) { LOG_ERROR("Failed to issue motion command."); if (FocusRelPosNP.s == IPS_BUSY) { FocusRelPosNP.s = IPS_ALERT; IDSetNumber(&FocusRelPosNP, nullptr); } if (FocusAbsPosNP.s == IPS_BUSY) { FocusAbsPosNP.s = IPS_ALERT; IDSetNumber(&FocusAbsPosNP, nullptr); } } else // Reduce target diff depending on the motion direction // Negative targetDiff increases eventually to zero // Positive targetDiff decreases eventually to zero m_TargetDiff = m_TargetDiff + (nextMotion * ((direction == FOCUS_INWARD) ? 1 : -1)); } // Check if can update the absolute position in case it changed. } else if (currentPosition != FocusAbsPosN[0].value) { IDSetNumber(&FocusAbsPosNP, nullptr); } // Read temperature if (TemperatureNP.s == IPS_OK && m_TemperatureCounter++ == NSTEP_TEMPERATURE_FREQ) { m_TemperatureCounter = 0; if (readTemperature()) IDSetNumber(&TemperatureNP, nullptr); } SetTimer(POLLMS); }
float DHT::getTempFarenheit() { return convertCtoF(readTemperature()); }
bool IT87x::start(IOService * provider) { DebugLog("starting ..."); if (!super::start(provider)) return false; InfoLog("found ITE %s", getModelName()); OSDictionary* list = OSDynamicCast(OSDictionary, getProperty("Sensors Configuration")); OSDictionary *configuration=NULL; OSData *data; IORegistryEntry * rootNode = fromPath("/efi/platform", gIODTPlane); if(rootNode) { data = OSDynamicCast(OSData, rootNode->getProperty("OEMVendor")); if (data) { bcopy(data->getBytesNoCopy(), vendor, data->getLength()); OSString * VendorNick = vendorID(OSString::withCString(vendor)); if (VendorNick) { data = OSDynamicCast(OSData, rootNode->getProperty("OEMBoard")); if (!data) { WarningLog("no OEMBoard"); data = OSDynamicCast(OSData, rootNode->getProperty("OEMProduct")); } if (data) { bcopy(data->getBytesNoCopy(), product, data->getLength()); OSDictionary *link = OSDynamicCast(OSDictionary, list->getObject(VendorNick)); if (link){ configuration = OSDynamicCast(OSDictionary, link->getObject(OSString::withCString(product))); InfoLog(" mother vendor=%s product=%s", vendor, product); } } } else { WarningLog("unknown OEMVendor %s", vendor); } } else { WarningLog("no OEMVendor"); } } if (list && !configuration) { configuration = OSDynamicCast(OSDictionary, list->getObject("Default")); WarningLog("set default configuration"); } if(configuration) { this->setProperty("Current Configuration", configuration); } // Temperature Sensors if (configuration) { for (int i = 0; i < 3; i++) { char key[8]; snprintf(key, 8, "TEMPIN%X", i); if(readTemperature(i)<MAX_TEMP_THRESHOLD) { // Need to check if temperature sensor valid if (OSString* name = OSDynamicCast(OSString, configuration->getObject(key))) { if (name->isEqualTo("CPU")) { if (!addSensor(KEY_CPU_HEATSINK_TEMPERATURE, TYPE_SP78, 2, kSuperIOTemperatureSensor, i)) { WarningLog("error adding heatsink temperature sensor"); } } else if (name->isEqualTo("System")) { if (!addSensor(KEY_NORTHBRIDGE_TEMPERATURE, TYPE_SP78, 2, kSuperIOTemperatureSensor,i)) { WarningLog("error adding system temperature sensor"); } } else if (name->isEqualTo("Ambient")) { if (!addSensor(KEY_AMBIENT_TEMPERATURE, TYPE_SP78, 2, kSuperIOTemperatureSensor,i)) { WarningLog("error adding Ambient temperature sensor"); } } } } } } else { if(readTemperature(0)<MAX_TEMP_THRESHOLD) // Need to check if temperature sensor valid if (!addSensor(KEY_CPU_HEATSINK_TEMPERATURE, TYPE_SP78, 2, kSuperIOTemperatureSensor, 0)) { WarningLog("error adding heatsink temperature sensor"); } if(readTemperature(1)<MAX_TEMP_THRESHOLD) // Need to check if temperature sensor valid if (!addSensor(KEY_AMBIENT_TEMPERATURE, TYPE_SP78, 2, kSuperIOTemperatureSensor, 1)) { WarningLog("error adding Ambient temperature sensor"); } if(readTemperature(2)<MAX_TEMP_THRESHOLD) // Need to check if temperature sensor valid if (!addSensor(KEY_NORTHBRIDGE_TEMPERATURE, TYPE_SP78, 2, kSuperIOTemperatureSensor, 2)) { WarningLog("error adding system temperature sensor"); } } // Voltage UInt8 tmp = readByte(address, ITE_ADC_CHANNEL_ENABLE); DebugLog("ADC Enable register = %X",tmp); vbat_updates = false; if(configuration) { OSBoolean* smartGuard = OSDynamicCast(OSBoolean, configuration->getObject("VBATNeedUpdates")); if(smartGuard && smartGuard->isTrue()) vbat_updates=true; } // Refresh VBAT reading on each access to the key if(vbat_updates) writeByte(address, ITE_CONFIGURATION_REGISTER, readByte(address, ITE_CONFIGURATION_REGISTER) | 0x40); if (configuration) { for (int i = 0; i < 9; i++) { char key[5]; OSString * name; long Ri=0; long Rf=1; long Vf=0; snprintf(key, 5, "VIN%X", i); if (process_sensor_entry(configuration->getObject(key), &name, &Ri, &Rf, &Vf)) { if (name->isEqualTo("CPU")) { if (!addSensor(KEY_CPU_VRM_SUPPLY0, TYPE_FP2E, 2, kSuperIOVoltageSensor, i,Ri,Rf,Vf)) WarningLog("error adding CPU voltage sensor"); } else if (name->isEqualTo("Memory")) { if (!addSensor(KEY_MEMORY_VOLTAGE, TYPE_FP2E, 2, kSuperIOVoltageSensor, i,Ri,Rf,Vf)) WarningLog("error adding memory voltage sensor"); } else if (name->isEqualTo("+5VC")) { if (!addSensor(KEY_5VC_VOLTAGE, TYPE_SP4B, 2, kSuperIOVoltageSensor, i,Ri,Rf,Vf)) { WarningLog("ERROR Adding AVCC Voltage Sensor!"); } } else if (name->isEqualTo("+5VSB")) { if (!addSensor(KEY_5VSB_VOLTAGE, TYPE_SP4B, 2, kSuperIOVoltageSensor, i,Ri,Rf,Vf)) { WarningLog("ERROR Adding AVCC Voltage Sensor!"); } } else if (name->isEqualTo("+12VC")) { if (!addSensor(KEY_12V_VOLTAGE, TYPE_SP4B, 2, kSuperIOVoltageSensor, i,Ri,Rf,Vf)) { WarningLog("ERROR Adding 12V Voltage Sensor!"); } } else if (name->isEqualTo("-12VC")) { if (!addSensor(KEY_N12VC_VOLTAGE, TYPE_SP4B, 2, kSuperIOVoltageSensor, i,Ri,Rf,Vf)) { WarningLog("ERROR Adding 12V Voltage Sensor!"); } } else if (name->isEqualTo("3VCC")) { if (!addSensor(KEY_3VCC_VOLTAGE, TYPE_FP2E, 2, kSuperIOVoltageSensor, i,Ri,Rf,Vf)) { WarningLog("ERROR Adding 3VCC Voltage Sensor!"); } } else if (name->isEqualTo("3VSB")) { if (!addSensor(KEY_3VSB_VOLTAGE, TYPE_FP2E, 2, kSuperIOVoltageSensor, i,Ri,Rf,Vf)) { WarningLog("ERROR Adding 3VSB Voltage Sensor!"); } } else if (name->isEqualTo("VBAT")) { if (!addSensor(KEY_VBAT_VOLTAGE, TYPE_FP2E, 2, kSuperIOVoltageSensor, i,Ri,Rf,Vf)) { WarningLog("ERROR Adding VBAT Voltage Sensor!"); } } } } } // Tachometers for (int i = 0; i < 5; i++) { OSString* name = NULL; char key[5]; if (configuration) { char key_temp[7]; snprintf(key_temp, 7, "FANIN%X", i); name = OSDynamicCast(OSString, configuration->getObject(key_temp)); } UInt32 nameLength = name ? (UInt32)strlen(name->getCStringNoCopy()) : 0; if (readTachometer(i) > 10 || nameLength > 0) { // Pff WTF ??? Add tachometer if it doesn't exist in a system but only the name defined in the config??? if (!addTachometer(i, (nameLength > 0 ? name->getCStringNoCopy() : 0))) // Need to look at this a bit later WarningLog("error adding tachometer sensor %d", i); } // Check if this chip support SmartGuardian feature hasSmartGuardian=false; if(configuration) { if(OSBoolean* smartGuard=OSDynamicCast(OSBoolean, configuration->getObject("SmartGuardian"))) if(smartGuard->isTrue()) hasSmartGuardian=true; } if(hasSmartGuardian) { // Ugly development hack started for (SuperIOSensorGroup) snprintf(key,5,KEY_FORMAT_FAN_TARGET_SPEED,i); if (!addSensor(key, TYPE_UI8, 1, (SuperIOSensorGroup)kSuperIOSmartGuardPWMControl, i)) WarningLog("error adding PWM fan control"); snprintf(key,5,KEY_FORMAT_FAN_START_TEMP,i); if (!addSensor(key, TYPE_UI8, 1, (SuperIOSensorGroup)kSuperIOSmartGuardTempFanStart, i)) WarningLog("error adding start temp fan control"); snprintf(key,5,KEY_FORMAT_FAN_OFF_TEMP,i); if (!addSensor(key, TYPE_UI8, 1, (SuperIOSensorGroup)kSuperIOSmartGuardTempFanStop, i)) WarningLog("error adding stop temp fan control"); snprintf(key,5,KEY_FORMAT_FAN_FULL_TEMP,i); if (!addSensor(key, TYPE_UI8, 1, (SuperIOSensorGroup)kSuperIOSmartGuardTempFanFullOn, i)) WarningLog("error adding full speed temp fan control"); snprintf(key,5,KEY_FORMAT_FAN_START_PWM,i); if (!addSensor(key, TYPE_UI8, 1, (SuperIOSensorGroup)kSuperIOSmartGuardPWMStart, i)) WarningLog("error adding start PWM fan control"); snprintf(key,5,KEY_FORMAT_FAN_TEMP_DELTA,i); if (!addSensor(key, TYPE_UI8, 1, (SuperIOSensorGroup)kSuperIOSmartGuardTempFanFullOff, i)) WarningLog("error adding temp full off fan control"); snprintf(key,5,KEY_FORMAT_FAN_CONTROL,i); if (!addSensor(key, TYPE_UI8, 1, (SuperIOSensorGroup)kSuperIOSmartGuardTempFanControl, i)) WarningLog("error adding register fan control"); } } if(hasSmartGuardian) { if (!addSensor(KEY_FORMAT_FAN_MAIN_CONTROL, TYPE_UI8, 1, (SuperIOSensorGroup)kSuperIOSmartGuardMainControl, 0)) WarningLog("error adding Main fan control"); if (!addSensor(KEY_FORMAT_FAN_REG_CONTROL, TYPE_UI8, 1, (SuperIOSensorGroup)kSuperIOSmartGuardRegControl, 0)) WarningLog("error adding Main fan control"); } return true; }
float DHT::getDewPoint() { return computeDewPoint(readTemperature(), readHumidity()); }
float DHT::getHeatIndex() { return convertFtoC(computeHeatIndex(convertCtoF(readTemperature()), readHumidity())); }