-
Notifications
You must be signed in to change notification settings - Fork 100
/
Weather.cpp
70 lines (59 loc) · 1.82 KB
/
Weather.cpp
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
// Weather.cpp
// This file manages the retrieval of Weather related information and adjustment of durations
// Author: Richard Zimmerman
// Copyright (c) 2013 Richard Zimmerman
//
#include "Weather.h"
#include "core.h"
#include "port.h"
#include <string.h>
#include <stdlib.h>
Weather::Settings Weather::GetSettings(void) {
Settings settings = {0};
GetApiKey(settings.key);
GetApiId(settings.apiId);
GetApiSecret(settings.apiSecret);
GetPWS(settings.pws);
GetLoc(settings.location);
settings.zip = GetZip();
settings.usePws = GetUsePWS();
return settings;
}
int16_t Weather::GetScale(void) const
{
ReturnVals vals = this->GetVals();
return this->GetScale(vals);
}
int16_t Weather::GetScale(const Weather::Settings & settings) const
{
ReturnVals vals = this->GetVals(settings);
return this->GetScale(vals);
}
int16_t Weather::GetScale(const ReturnVals & vals) const
{
if (!vals.valid)
return 100;
const int humid_factor = NEUTRAL_HUMIDITY - (vals.maxhumidity + vals.minhumidity) / 2;
const int temp_factor = (vals.meantempi - 70) * 4;
const int rain_factor = (vals.precipi + vals.precip_today) * -2;
const int16_t adj = (uint16_t)spi_min(spi_max(0, 100+humid_factor+temp_factor+rain_factor), 200);
trace(F("Adjusting H(%d)T(%d)R(%d):%d\n"), humid_factor, temp_factor, rain_factor, adj);
return adj;
}
Weather::ReturnVals Weather::GetVals(void) const
{
Settings settings = this->GetSettings();
return this->InternalGetVals(settings);
}
Weather::ReturnVals Weather::GetVals(const Settings & settings) const
{
return this->InternalGetVals(settings);
}
Weather::ReturnVals Weather::InternalGetVals(const Settings & settings) const
{
// You must override and implement this function
trace("Warning: Placeholder weather provider called. No weather scaling used.\n");
ReturnVals vals = {0};
vals.valid = false;
return vals;
}