Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members | Related Pages

LOW_compTempSensor.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           LOW_compTempSensor.cpp  -  description
00003                              -------------------
00004     begin                : Fri Jul 12 2002
00005     copyright            : (C) 2002 by Harald Roelle
00006     email                : roelle@informatik.uni-muenchen.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include <stdio.h>
00019  
00020 #include "LOW_compTempSensor.h"
00021 
00022 
00023 //=====================================================================================
00024 //
00025 // constructors
00026 //
00027   
00028 LOW_compTempSensor::LOW_compTempSensor( const LOW_devDS1820 &inSensorDevice) :
00029   sensorDevice( inSensorDevice)
00030 {
00031   recallAlarmLevels();
00032 }
00033 
00034 
00035 LOW_compTempSensor::~LOW_compTempSensor()
00036 {
00037 }
00038 
00039 
00040 
00041 //=====================================================================================
00042 //
00043 // methods
00044 //
00045   
00046 float LOW_compTempSensor::getTemperature( const bool inDoConversion)
00047 {
00048   LOW_devDS1820::scratchpadDS1820_t  scratchpad;
00049     
00050   for( int a=0; a<3; a++) {
00051     if ( inDoConversion )
00052       sensorDevice.cmd_ConvertT();
00053     
00054     sensorDevice.cmd_ReadScratchpad( &scratchpad);
00055     if ( ! (scratchpad.tempLSB==0xaa && scratchpad.tempMSB==0x00) )
00056       break;
00057   }    
00058   if ( scratchpad.tempLSB==0xaa && scratchpad.tempMSB==0x00 )
00059     throw data_error( "Illeagal data in scratchpad", __FILE__, __LINE__);
00060 
00061   int16_t halfDegBit = scratchpad.tempLSB & 0x01;
00062   int16_t intPart    = (scratchpad.tempMSB<<8) | (scratchpad.tempMSB==0x00?0x00:0x80) | (scratchpad.tempLSB>>1);
00063   float   floatPart  = -0.25 + (static_cast<float>(scratchpad.cntPerCelsius-scratchpad.cntRemain))/(static_cast<float>(scratchpad.cntPerCelsius));
00064     
00065   return (static_cast<float>(intPart))+floatPart;
00066 }
00067 
00068 
00069 void LOW_compTempSensor::recallAlarmLevels()
00070 {
00071   sensorDevice.cmd_RecallE2();
00072 }
00073 
00074   
00075 void LOW_compTempSensor::getAlarmLevels( int8_t &outLowBound, int8_t &outHighBound)
00076 {
00077   LOW_devDS1820::scratchpadDS1820_t  scratchpad;
00078     
00079   sensorDevice.cmd_ReadScratchpad( &scratchpad);
00080   
00081   outLowBound  = (scratchpad.tL&0x7f) * ((scratchpad.tL&0x80)?-1:1);
00082   outHighBound = (scratchpad.tH&0x7f) * ((scratchpad.tH&0x80)?-1:1);
00083 }
00084 
00085   
00086 void LOW_compTempSensor::setAlarmLevels( const int8_t inLowBound, const int8_t inHighBound, const bool inPermanent)
00087 {
00088   if ( (inLowBound <= -55) || (inLowBound >= inHighBound) || (inHighBound >= 125) )
00089     throw data_error( "Illegal range given. Must be -55 < lowBound < highBound < 125.", __FILE__, __LINE__);
00090   
00091   uint8_t tl = (inLowBound<0)  ? ((-inLowBound&0x7f)  | 0x80) : (inLowBound&0x7f);
00092   uint8_t th = (inHighBound<0) ? ((-inHighBound&0x7f) | 0x80) : (inHighBound&0x7f);
00093   
00094   sensorDevice.cmd_WriteScratchpad( tl, th);
00095   
00096   if ( inPermanent ) {
00097     sensorDevice.cmd_CopyScratchpad();
00098   }
00099 }
00100 
00101 
00102 bool LOW_compTempSensor::checkAlarm( const bool inRecalcTemp)
00103 {
00104   if (inRecalcTemp)
00105     sensorDevice.cmd_ConvertT();
00106   
00107   return sensorDevice.verifyDevice( true);
00108 }
00109 
00110 
00111 bool LOW_compTempSensor::getIsExternalPowered() const
00112 {
00113   return sensorDevice.getIsExternalPowered();
00114 }
00115 

Generated on Tue Feb 3 11:30:24 2004 for OneWireLibrary++ by doxygen 1.3.2