Prof Greg Egan
/
UAVXArm-GKE
UAVX Multicopter Flight Controller.
temperature.c@0:62a1c91a859a, 2011-02-18 (annotated)
- Committer:
- gke
- Date:
- Fri Feb 18 22:28:05 2011 +0000
- Revision:
- 0:62a1c91a859a
- Child:
- 2:90292f8bd179
First release
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gke | 0:62a1c91a859a | 1 | // =============================================================================================== |
gke | 0:62a1c91a859a | 2 | // = UAVXArm Quadrocopter Controller = |
gke | 0:62a1c91a859a | 3 | // = Copyright (c) 2008 by Prof. Greg Egan = |
gke | 0:62a1c91a859a | 4 | // = Original V3.15 Copyright (c) 2007 Ing. Wolfgang Mahringer = |
gke | 0:62a1c91a859a | 5 | // = http://code.google.com/p/uavp-mods/ http://uavp.ch = |
gke | 0:62a1c91a859a | 6 | // =============================================================================================== |
gke | 0:62a1c91a859a | 7 | |
gke | 0:62a1c91a859a | 8 | // This is part of UAVXArm. |
gke | 0:62a1c91a859a | 9 | |
gke | 0:62a1c91a859a | 10 | // UAVXArm is free software: you can redistribute it and/or modify it under the terms of the GNU |
gke | 0:62a1c91a859a | 11 | // General Public License as published by the Free Software Foundation, either version 3 of the |
gke | 0:62a1c91a859a | 12 | // License, or (at your option) any later version. |
gke | 0:62a1c91a859a | 13 | |
gke | 0:62a1c91a859a | 14 | // UAVXArm is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without |
gke | 0:62a1c91a859a | 15 | // even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
gke | 0:62a1c91a859a | 16 | // See the GNU General Public License for more details. |
gke | 0:62a1c91a859a | 17 | |
gke | 0:62a1c91a859a | 18 | // You should have received a copy of the GNU General Public License along with this program. |
gke | 0:62a1c91a859a | 19 | // If not, see http://www.gnu.org/licenses/ |
gke | 0:62a1c91a859a | 20 | |
gke | 0:62a1c91a859a | 21 | #include "UAVXArm.h" |
gke | 0:62a1c91a859a | 22 | void GetTemperature(void); |
gke | 0:62a1c91a859a | 23 | void InitTemperature(void); |
gke | 0:62a1c91a859a | 24 | |
gke | 0:62a1c91a859a | 25 | i16u AmbientTemperature; |
gke | 0:62a1c91a859a | 26 | |
gke | 0:62a1c91a859a | 27 | void GetTemperature(void) { |
gke | 0:62a1c91a859a | 28 | |
gke | 0:62a1c91a859a | 29 | I2CTEMP.start(); |
gke | 0:62a1c91a859a | 30 | if ( I2CTEMP.write(TMP100_RD) != I2C_ACK ) goto Terror; |
gke | 0:62a1c91a859a | 31 | AmbientTemperature.b1 = I2CTEMP.read(I2C_ACK); |
gke | 0:62a1c91a859a | 32 | AmbientTemperature.b0 = I2CTEMP.read(I2C_NACK); |
gke | 0:62a1c91a859a | 33 | I2CTEMP.stop(); |
gke | 0:62a1c91a859a | 34 | |
gke | 0:62a1c91a859a | 35 | // Top 9 bits 0.5C res. scale to 0.1C |
gke | 0:62a1c91a859a | 36 | AmbientTemperature.i16 = SRS16( AmbientTemperature.i16, 7) * 5; |
gke | 0:62a1c91a859a | 37 | if ( AmbientTemperature.i16 > Stats[MaxTempS]) |
gke | 0:62a1c91a859a | 38 | Stats[MaxTempS] = AmbientTemperature.i16; |
gke | 0:62a1c91a859a | 39 | else |
gke | 0:62a1c91a859a | 40 | if ( AmbientTemperature.i16 < Stats[MinTempS] ) |
gke | 0:62a1c91a859a | 41 | Stats[MinTempS] = AmbientTemperature.i16; |
gke | 0:62a1c91a859a | 42 | return; |
gke | 0:62a1c91a859a | 43 | |
gke | 0:62a1c91a859a | 44 | Terror: |
gke | 0:62a1c91a859a | 45 | I2CTEMP.stop(); |
gke | 0:62a1c91a859a | 46 | AmbientTemperature.i16 = 0; |
gke | 0:62a1c91a859a | 47 | |
gke | 0:62a1c91a859a | 48 | return; |
gke | 0:62a1c91a859a | 49 | } // GetTemperature |
gke | 0:62a1c91a859a | 50 | |
gke | 0:62a1c91a859a | 51 | void InitTemperature(void) { |
gke | 0:62a1c91a859a | 52 | I2CTEMP.start(); |
gke | 0:62a1c91a859a | 53 | if( I2CTEMP.write(TMP100_WR) != I2C_ACK ) goto Terror; |
gke | 0:62a1c91a859a | 54 | if( I2CTEMP.write(TMP100_CMD) != I2C_ACK ) goto Terror; |
gke | 0:62a1c91a859a | 55 | if( I2CTEMP.write(TMP100_CFG) != I2C_ACK ) goto Terror; |
gke | 0:62a1c91a859a | 56 | I2CTEMP.stop(); |
gke | 0:62a1c91a859a | 57 | |
gke | 0:62a1c91a859a | 58 | I2CTEMP.start(); |
gke | 0:62a1c91a859a | 59 | if( I2CTEMP.write(TMP100_WR) != I2C_ACK ) goto Terror; |
gke | 0:62a1c91a859a | 60 | if( I2CTEMP.write(TMP100_TMP) != I2C_ACK ) goto Terror; // Select temperature |
gke | 0:62a1c91a859a | 61 | I2CTEMP.stop(); |
gke | 0:62a1c91a859a | 62 | |
gke | 0:62a1c91a859a | 63 | GetTemperature(); |
gke | 0:62a1c91a859a | 64 | |
gke | 0:62a1c91a859a | 65 | return; |
gke | 0:62a1c91a859a | 66 | |
gke | 0:62a1c91a859a | 67 | Terror: |
gke | 0:62a1c91a859a | 68 | I2CTEMP.stop(); |
gke | 0:62a1c91a859a | 69 | AmbientTemperature.i16 = 0; |
gke | 0:62a1c91a859a | 70 | |
gke | 0:62a1c91a859a | 71 | } // InitTemperature |