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)
567
+ − 51 return 'f';
38
+ − 52 else
+ − 53 return 'm';
+ − 54 }
+ − 55
+ − 56 char unit_depth_char2_T105(void)
+ − 57 {
+ − 58 if(settingsGetPointer()->nonMetricalSystem)
567
+ − 59 return 't';
38
+ − 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
653
+ − 110 int16_t unit_temperature_integer(int16_t input_celsius)
567
+ − 111 {
+ − 112 if(settingsGetPointer()->nonMetricalSystem == 0)
+ − 113 return input_celsius;
+ − 114 else
+ − 115 {
653
+ − 116 return ((input_celsius * 9 / 5) + 32);
567
+ − 117 }
+ − 118 }
+ − 119
38
+ − 120 uint16_t unit_speed_integer(uint16_t input_meterPerMinute)
+ − 121 {
+ − 122 if(settingsGetPointer()->nonMetricalSystem == 0)
+ − 123 return input_meterPerMinute;
+ − 124 else
+ − 125 {
+ − 126 return (input_meterPerMinute * 10) / 3;
+ − 127 }
+ − 128 }
+ − 129
+ − 130 /* Quelle: https://de.wikipedia.org/wiki/Luftdruck */
+ − 131 /*
+ − 132 const float luftdruckStartMinus300[15] =
+ − 133 {
+ − 134 1.0530f,
+ − 135 1.0396f,
+ − 136 1.0263f,
+ − 137 1.01325f, // 0 m
+ − 138 1.0003f,
+ − 139 0.9876f,
+ − 140 0.9750f,
+ − 141 0.9625f,
+ − 142 0.9503f,
+ − 143 0.9381f,
+ − 144 0.9262f,
+ − 145 0.9144f,
+ − 146 0.9027f,
+ − 147 0.8912f, // 1000 m
+ − 148 0.8358f
+ − 149 };
+ − 150 */
+ − 151
+ − 152 const int luftdruckStartMinus300[15] =
+ − 153 {
+ − 154 1053,
+ − 155 1040,
+ − 156 1026,
+ − 157 1013, // 0 m
+ − 158 1000,
+ − 159 988,
+ − 160 975,
+ − 161 962,
+ − 162 950,
+ − 163 938,
+ − 164 926,
+ − 165 914,
+ − 166 903,
+ − 167 891, // 1000 m
+ − 168 836
+ − 169 };
+ − 170
+ − 171
+ − 172 int unit_SeaLevelRelation_integer(int input_atmospheric_mbar)
+ − 173 {
+ − 174 int i = 0;
+ − 175 int distance1, distance2;
+ − 176 for(i=0;i<15;i++)
+ − 177 {
+ − 178 if(input_atmospheric_mbar >= luftdruckStartMinus300[i])
+ − 179 break;
+ − 180 }
+ − 181
+ − 182 if(i >= 14)
+ − 183 return 1500;
+ − 184 else if(i == 0)
+ − 185 return -300;
+ − 186 else
+ − 187 {
+ − 188 distance1 = input_atmospheric_mbar - luftdruckStartMinus300[i];
+ − 189 distance2 = luftdruckStartMinus300[i-1] - input_atmospheric_mbar;
+ − 190 if(distance2 < distance1)
+ − 191 i -= 1;
+ − 192 return (i*100) - 300;
+ − 193 }
+ − 194 }