annotate Discovery/Src/unit.c @ 323:b43fa6a6c85a

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