X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=ao-tools%2Flib%2Fcc-convert.c;h=4a7e52fc8d3fa55ec1ebb14e38f3e28ac04909a5;hp=ac6962ba254e6a82ef000f62631e2dafd172718e;hb=6f729ff46b2f4531db68f0af85e7e9fe0f6d1969;hpb=35c54b3a278fa9bc2bc7f4b5ee04866697c93ba0 diff --git a/ao-tools/lib/cc-convert.c b/ao-tools/lib/cc-convert.c index ac6962ba..4a7e52fc 100644 --- a/ao-tools/lib/cc-convert.c +++ b/ao-tools/lib/cc-convert.c @@ -3,7 +3,8 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of @@ -108,6 +109,29 @@ cc_altitude_to_pressure(double altitude) return pressure; } +double +cc_altitude_to_temperature(double altitude) +{ + + double base_temperature = LAYER0_BASE_TEMPERATURE; + double temperature; + + int layer_number; /* identifies layer in the atmosphere */ + double delta_z; /* difference between two altitudes */ + + /* calculate the base temperature for the atmospheric layer + associated with the inputted altitude */ + for(layer_number = 0; layer_number < NUMBER_OF_LAYERS - 1 && altitude > base_altitude[layer_number + 1]; layer_number++) { + delta_z = base_altitude[layer_number + 1] - base_altitude[layer_number]; + base_temperature += delta_z * lapse_rate[layer_number]; + } + + /* calculate the pressure at the inputted altitude */ + delta_z = altitude - base_altitude[layer_number]; + temperature = base_temperature + lapse_rate[layer_number] * delta_z; + + return temperature - 273.15; +} /* outputs the altitude associated with the given pressure. the altitude returned is measured with respect to the mean sea level */ @@ -189,9 +213,6 @@ cc_pressure_to_altitude(double pressure) * 2.82V * 2047 / 3.3 counts/V = 1749 counts/115 kPa */ -static const double counts_per_kPa = 27 * 2047 / 3300; -static const double counts_at_101_3kPa = 1674.0; - double cc_barometer_to_pressure(double count) { @@ -213,10 +234,19 @@ cc_accelerometer_to_acceleration(double accel, double ground_accel) return (ground_accel - accel) / count_per_mss; } +/* Value for the CC1111 built-in temperature sensor + * Output voltage at 0°C = 0.755V + * Coefficient = 0.00247V/°C + * Reference voltage = 1.25V + * + * temp = ((value / 32767) * 1.25 - 0.755) / 0.00247 + * = (value - 19791.268) / 32768 * 1.25 / 0.00247 + */ + double cc_thermometer_to_temperature(double thermo) { - return ((thermo / 32767 * 3.3) - 0.5) / 0.01; + return (thermo - 19791.268) / 32728.0 * 1.25 / 0.00247; } double