1////////////////////////////////////////////////////////////////////////////////
2// //
3// This software is supplied under the terms of a license agreement or //
4// nondisclosure agreement with Mitov Software and may not be copied //
5// or disclosed except in accordance with the terms of that agreement. //
6// Copyright(c) 2002-2016 Mitov Software. All Rights Reserved. //
7// //
8////////////////////////////////////////////////////////////////////////////////
9
10#ifndef _MITOV_HEAT_INDEDX_h
11#define _MITOV_HEAT_INDEDX_h
12
13#include <Mitov.h>
14
15namespace Mitov
16{
17 class HeatIndex : public Mitov::CommonEnableSource
18 {
19 typedef Mitov::CommonEnableSource inherited;
20
21 public:
22 OpenWire::SinkPin TemperatureInputPin;
23 OpenWire::SinkPin HumidityInputPin;
24
25 public:
26 float InitialTemperature = 0.0f;
27 float InitialHumidity = 0.0f;
28 bool InFahrenheit = false;
29
30 protected:
31 void DoTemperatureReceive( void *_Data )
32 {
33 float AValue = *(float*)_Data;
34 if( InitialTemperature == AValue )
35 return;
36
37 InitialTemperature = AValue;
38 CalculateOutput();
39 }
40
41 void DoHumidityReceive( void *_Data )
42 {
43 float AValue = *(float*)_Data;
44 if( InitialHumidity == AValue )
45 return;
46
47 InitialHumidity = AValue;
48 CalculateOutput();
49 }
50
51 void CalculateOutput()
52 {
53 // Using both Rothfusz and Steadman's equations
54 // http://www.wpc.ncep.noaa.gov/html/heatindex_equation.shtml
55
56 float temperature = InitialTemperature;
57 if ( ! InFahrenheit )
58 temperature = ConvertCtoF(temperature);
59
60 float hi = 0.5 * (temperature + 61.0 + ((temperature - 68.0) * 1.2) + (InitialHumidity * 0.094));
61
62 if( hi > 79 )
63 {
64 hi = -42.379 +
65 2.04901523 * temperature +
66 10.14333127 * InitialHumidity +
67 -0.22475541 * temperature * InitialHumidity +
68 -0.00683783 * pow(temperature, 2) +
69 -0.05481717 * pow(InitialHumidity, 2) +
70 0.00122874 * pow(temperature, 2) * InitialHumidity +
71 0.00085282 * temperature * pow(InitialHumidity, 2) +
72 -0.00000199 * pow(temperature, 2) * pow(InitialHumidity, 2);
73
74 if((InitialHumidity < 13) && (temperature >= 80.0) && (temperature <= 112.0))
75 hi -= ((13.0 - InitialHumidity) * 0.25) * sqrt((17.0 - abs(temperature - 95.0)) * 0.05882);
76
77 else if((InitialHumidity > 85.0) && (temperature >= 80.0) && (temperature <= 87.0))
78 hi += ((InitialHumidity - 85.0) * 0.1) * ((87.0 - temperature) * 0.2);
79 }
80
81 if( ! InFahrenheit )
82 hi = ConvertFtoC( hi );
83
84 inherited::OutputPin.Notify( &hi );
85 }
86
87 protected:
88 virtual void SystemStart()
89 {
90 inherited::SystemStart();
91 CalculateOutput();
92 }
93
94 public:
95 HeatIndex()
96 {
97 TemperatureInputPin.SetCallback( this, (OpenWire::TOnPinReceive)&HeatIndex::DoTemperatureReceive );
98 HumidityInputPin.SetCallback( this, (OpenWire::TOnPinReceive)&HeatIndex::DoHumidityReceive );
99 }
100
101 };
102}
103
104#endif