Wiselib
|
00001 /*************************************************************************** 00002 ** This file is part of the generic algorithm library Wiselib. ** 00003 ** Copyright (C) 2008,2009 by the Wisebed (www.wisebed.eu) project. ** 00004 ** ** 00005 ** The Wiselib is free software: you can redistribute it and/or modify ** 00006 ** it under the terms of the GNU Lesser General Public License as ** 00007 ** published by the Free Software Foundation, either version 3 of the ** 00008 ** License, or (at your option) any later version. ** 00009 ** ** 00010 ** The Wiselib is distributed in the hope that it will be useful, ** 00011 ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** 00012 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** 00013 ** GNU Lesser General Public License for more details. ** 00014 ** ** 00015 ** You should have received a copy of the GNU Lesser General Public ** 00016 ** License along with the Wiselib. ** 00017 ** If not, see <http://www.gnu.org/licenses/>. ** 00018 ***************************************************************************/ 00019 00020 #ifndef _ISENSE_TEMP_SENSOR_H 00021 #define _ISENSE_TEMP_SENSOR_H 00022 00023 #include "config_testing.h" 00024 #include "external_interface/isense/isense_types.h" 00025 #include "util/base_classes/state_callback_base.h" 00026 #include <isense/time.h> 00027 00028 #include <isense/config.h> 00029 #include <isense/os.h> 00030 #include <isense/types.h> 00031 #include <isense/application.h> 00032 #include <isense/task.h> 00033 #include <isense/modules/environment_module/environment_module.h> 00034 #include <isense/modules/environment_module/temp_sensor.h> 00035 #include <isense/data_handlers.h> 00036 00037 namespace wiselib 00038 { 00039 template<typename OsModel_P > 00040 class iSenseTempSensor 00041 //: public isense::SensorHandler 00042 { 00043 public: 00044 typedef OsModel_P OsModel; 00045 00046 typedef iSenseTempSensor<OsModel> self_type; 00047 typedef self_type* self_pointer_t; 00048 00049 typedef int16_t value_t; 00050 // -------------------------------------------------------------------- 00051 enum ErrorCodes 00052 { 00053 SUCCESS = OsModel::SUCCESS, 00054 ERR_UNSPEC = OsModel::ERR_UNSPEC 00055 }; 00056 // -------------------------------------------------------------------- 00057 enum States 00058 { 00059 READY = OsModel::READY, 00060 NO_VALUE = OsModel::NO_VALUE, 00061 INACTIVE = OsModel::INACTIVE 00062 }; 00063 // -------------------------------------------------------------------- 00064 iSenseTempSensor( isense::Os& ios ) 00065 : os_ ( ios ), 00066 state_ ( INACTIVE ), 00067 em_ (NULL) 00068 { 00069 // output boot notification message 00070 #if (ISENSE_RADIO_ADDRESS_LENGTH == 16) 00071 os().debug("Booting Environment Module Demo Application, id=%x", os().id()); 00072 #else 00073 os().debug("Booting Environment Module Demo Application, id=%lx", os().id()); 00074 #endif 00075 00076 // create EnvironmentModule instance 00077 em_ = new isense::EnvironmentModule(os()); 00078 00079 // if allocation of EnvironmentModule was successful 00080 if (em_!=NULL) 00081 { 00082 if (em_->temp_sensor() != NULL) 00083 { 00084 //--------- configure the light sensor ---------- 00085 // set the temperature threshold to 35°C and the hysteresis 00086 // value to 30°C 00087 // em_->temp_sensor()->set_threshold(35,30); 00088 // set this application as the data handler called if 00089 // temperature threshold is exceed or falls back below 00090 // the hysteresis value 00091 // em_->temp_sensor()->set_data_handler(this); 00092 } else 00093 os().fatal("Could not allocate temp sensor"); 00094 00095 // enable the Environmental Sensor Module, 00096 // including its sensors 00097 em_->enable(true); 00098 } else 00099 os().fatal("Could not allocate EnvironmentModule"); 00100 state_ = READY; 00101 } 00102 // -------------------------------------------------------------------- 00103 int state() 00104 { 00105 return state_; 00106 } 00107 // -------------------------------------------------------------------- 00108 value_t operator()() 00109 { 00110 return em_->temp_sensor()->temperature(); 00111 } 00112 //--------------------------------------------------------------------- 00113 00114 00115 private: 00116 // -------------------------------------------------------------------- 00117 isense::Os& os() 00118 { return os_; } 00119 // -------------------------------------------------------------------- 00120 isense::Os& os_; 00121 States state_; 00122 isense::EnvironmentModule* em_; 00123 00124 00125 00126 }; 00127 } 00128 00129 #endif /* _ISENSE_TEMP_SENSOR_H */ 00130