38
+ − 1 ///////////////////////////////////////////////////////////////////////////////
+ − 2 /// -*- coding: UTF-8 -*-
+ − 3 ///
+ − 4 /// \file Discovery/Src/unit.c
+ − 5 /// \brief input to meter/celsius or feet/farenheit
+ − 6 /// \author heinrichs weikamp gmbh
+ − 7 /// \date 24-Feb-2015
+ − 8 ///
+ − 9 /// \details
+ − 10 ///
+ − 11 /// $Id$
+ − 12 ///////////////////////////////////////////////////////////////////////////////
+ − 13 /// \par Copyright (c) 2014-2018 Heinrichs Weikamp gmbh
+ − 14 ///
+ − 15 /// This program is free software: you can redistribute it and/or modify
+ − 16 /// it under the terms of the GNU General Public License as published by
+ − 17 /// the Free Software Foundation, either version 3 of the License, or
+ − 18 /// (at your option) any later version.
+ − 19 ///
+ − 20 /// This program is distributed in the hope that it will be useful,
+ − 21 /// but WITHOUT ANY WARRANTY; without even the implied warranty of
+ − 22 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ − 23 /// GNU General Public License for more details.
+ − 24 ///
+ − 25 /// You should have received a copy of the GNU General Public License
+ − 26 /// along with this program. If not, see <http://www.gnu.org/licenses/>.
+ − 27 //////////////////////////////////////////////////////////////////////////////
+ − 28
+ − 29 /* Includes ------------------------------------------------------------------*/
+ − 30 #include "unit.h"
+ − 31 #include "settings.h"
+ − 32
+ − 33 /* Exported variables --------------------------------------------------------*/
+ − 34
+ − 35 /* Private types -------------------------------------------------------------*/
+ − 36 uint8_t test;
+ − 37
+ − 38 /* Private variables ---------------------------------------------------------*/
+ − 39
+ − 40 /* Private variables with external access via get_xxx() function -------------*/
+ − 41
+ − 42 /* Private function prototypes -----------------------------------------------*/
+ − 43
+ − 44 /* Announced function prototypes -----------------------------------------------*/
+ − 45
+ − 46 /* Exported functions --------------------------------------------------------*/
+ − 47
+ − 48 char unit_depth_char1_T105(void)
+ − 49 {
+ − 50 if(settingsGetPointer()->nonMetricalSystem)
+ − 51 return '\'';
+ − 52 else
+ − 53 return 'm';
+ − 54 }
+ − 55
+ − 56 char unit_depth_char2_T105(void)
+ − 57 {
+ − 58 if(settingsGetPointer()->nonMetricalSystem)
+ − 59 return ' ';
+ − 60 else
+ − 61 return '\004'; // 004 is nop
+ − 62 }
+ − 63
+ − 64 char unit_depth_char1(void)
+ − 65 {
+ − 66 if(settingsGetPointer()->nonMetricalSystem)
+ − 67 return 'f';
+ − 68 else
+ − 69 return 'm';
+ − 70 }
+ − 71
+ − 72 char unit_depth_char2(void)
+ − 73 {
+ − 74 if(settingsGetPointer()->nonMetricalSystem)
+ − 75 return 't';
+ − 76 else
+ − 77 return '\004'; // 004 is nop
+ − 78 }
+ − 79
+ − 80 float unit_depth_float(float input_meter)
+ − 81 {
+ − 82 if(settingsGetPointer()->nonMetricalSystem == 0)
+ − 83 return input_meter;
+ − 84 else
+ − 85 {
+ − 86 return 3.2808f * input_meter;
+ − 87 }
+ − 88 }
+ − 89
+ − 90 uint16_t unit_depth_integer(uint16_t input_meter)
+ − 91 {
+ − 92 if(settingsGetPointer()->nonMetricalSystem == 0)
+ − 93 return input_meter;
+ − 94 else
+ − 95 {
+ − 96 return (input_meter * 10) / 3;
+ − 97 }
+ − 98 }
+ − 99
+ − 100 float unit_temperature_float(float input_celsius)
+ − 101 {
+ − 102 if(settingsGetPointer()->nonMetricalSystem == 0)
+ − 103 return input_celsius;
+ − 104 else
+ − 105 {
+ − 106 return input_celsius * (9.0f/5.0f) + 32;
+ − 107 }
+ − 108 }
+ − 109
+ − 110 uint16_t unit_speed_integer(uint16_t input_meterPerMinute)
+ − 111 {
+ − 112 if(settingsGetPointer()->nonMetricalSystem == 0)
+ − 113 return input_meterPerMinute;
+ − 114 else
+ − 115 {
+ − 116 return (input_meterPerMinute * 10) / 3;
+ − 117 }
+ − 118 }
+ − 119
+ − 120 /* Quelle: https://de.wikipedia.org/wiki/Luftdruck */
+ − 121 /*
+ − 122 const float luftdruckStartMinus300[15] =
+ − 123 {
+ − 124 1.0530f,
+ − 125 1.0396f,
+ − 126 1.0263f,
+ − 127 1.01325f, // 0 m
+ − 128 1.0003f,
+ − 129 0.9876f,
+ − 130 0.9750f,
+ − 131 0.9625f,
+ − 132 0.9503f,
+ − 133 0.9381f,
+ − 134 0.9262f,
+ − 135 0.9144f,
+ − 136 0.9027f,
+ − 137 0.8912f, // 1000 m
+ − 138 0.8358f
+ − 139 };
+ − 140 */
+ − 141
+ − 142 const int luftdruckStartMinus300[15] =
+ − 143 {
+ − 144 1053,
+ − 145 1040,
+ − 146 1026,
+ − 147 1013, // 0 m
+ − 148 1000,
+ − 149 988,
+ − 150 975,
+ − 151 962,
+ − 152 950,
+ − 153 938,
+ − 154 926,
+ − 155 914,
+ − 156 903,
+ − 157 891, // 1000 m
+ − 158 836
+ − 159 };
+ − 160
+ − 161
+ − 162 int unit_SeaLevelRelation_integer(int input_atmospheric_mbar)
+ − 163 {
+ − 164 int i = 0;
+ − 165 int distance1, distance2;
+ − 166 for(i=0;i<15;i++)
+ − 167 {
+ − 168 if(input_atmospheric_mbar >= luftdruckStartMinus300[i])
+ − 169 break;
+ − 170 }
+ − 171
+ − 172 if(i >= 14)
+ − 173 return 1500;
+ − 174 else if(i == 0)
+ − 175 return -300;
+ − 176 else
+ − 177 {
+ − 178 distance1 = input_atmospheric_mbar - luftdruckStartMinus300[i];
+ − 179 distance2 = luftdruckStartMinus300[i-1] - input_atmospheric_mbar;
+ − 180 if(distance2 < distance1)
+ − 181 i -= 1;
+ − 182 return (i*100) - 300;
+ − 183 }
+ − 184 }