-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUConverter.pas
102 lines (91 loc) · 3.93 KB
/
UConverter.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
{* Copyright (C) 2010-2011 Karl-Michael Schindler
*
* This file is part of Heat Wizard.
*
* Heat Wizard 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; either version 3
* of the License, or (at your option) any later version.
*
* Heat Wizard is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Heat Wizard; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/> or write to the
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301, USA
*
* $URL$
* $Id$
*}
unit UConverter;
{$mode objfpc}
{$H+}
interface
uses
UThermoCouple;
type
TConverter = class
public
ThermoCouple: TThermoCouple;
constructor Create;
function GetTemperature(const Voltage, Reference: double;
const ThermoelementType: char;
const TemperatureUnit: char): double;
function GetVoltage(const Temperature, Reference: double;
const ThermoelementType: char;
const TemperatureUnit: char): double;
function GetReference(const Temperature, Voltage: double;
const ThermoelementType: char;
const TemperatureUnit: char): double;
end;
implementation
constructor TConverter.Create;
begin
Inherited;
ThermoCouple := TThermoCouple.Create;
end;
function TConverter.GetTemperature(const Voltage, Reference: double;
const ThermoelementType: char;
const TemperatureUnit: char): double;
var
code: word;
begin
val(ThermoelementType, ThermoCouple.ThermoElementType, code);
case TemperatureUnit of
'C': Result := ThermoCouple.Volt2Temp(Voltage + ThermoCouple.Temp2Volt( Reference));
'K': Result := double(273.15) + ThermoCouple.Volt2Temp(Voltage + ThermoCouple.Temp2Volt( Reference - double(273.15)));
'F': Result := double(32.0) + double(1.8) * ThermoCouple.Volt2Temp(Voltage + ThermoCouple.Temp2Volt((Reference - double(32.0)) / double(1.8)));
end;
end;
function TConverter.GetVoltage(const Temperature, Reference: double;
const ThermoelementType: char;
const TemperatureUnit: char): double;
var
code: word;
begin
val(ThermoelementType, ThermoCouple.ThermoElementType, code);
case TemperatureUnit of
'C': Result := ThermoCouple.Temp2Volt( Temperature) - ThermoCouple.Temp2Volt( Reference);
'K': Result := ThermoCouple.Temp2Volt( Temperature - double(273.15)) - ThermoCouple.Temp2Volt( Reference - double(273.15));
'F': Result := ThermoCouple.Temp2Volt((Temperature - double(32.0)) / double(1.8)) - ThermoCouple.Temp2Volt((Reference - double(32.0)) / double(1.8));
end;
end;
function TConverter.GetReference(const Temperature, Voltage: double;
const ThermoelementType: char;
const TemperatureUnit: char): double;
var
code: word;
begin
val(ThermoelementType, ThermoCouple.ThermoElementType, code);
case TemperatureUnit of
'C': Result := ThermoCouple.Volt2Temp(Voltage + ThermoCouple.Temp2Volt( Temperature));
'K': Result := double(273.15) + ThermoCouple.Volt2Temp(Voltage + ThermoCouple.Temp2Volt( Temperature - double(273.15)));
'F': Result := double(32.0) + double(1.8) * ThermoCouple.Volt2Temp(Voltage + ThermoCouple.Temp2Volt((Temperature - double(32.0)) / double(1.8)));
end;
end;
end.