SolarCalculator.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * SolarCalculator.h
8  *
9  ****/
10 
11 #pragma once
12 
13 #include <DateTime.h>
14 
18 struct SolarRef {
19  float latitude;
20  float longitude;
21 };
22 
29 {
30 public:
35  {
36  }
37 
41  SolarCalculator(const SolarRef& ref) : ref(ref)
42  {
43  }
44 
48  const SolarRef& getRef() const
49  {
50  return ref;
51  }
52 
56  void setRef(const SolarRef& ref)
57  {
58  this->ref = ref;
59  }
60 
70  int sunRiseSet(bool isRise, int y, int m, int d);
71 
72  int sunrise(int y, int m, int d)
73  {
74  return sunRiseSet(true, y, m, d);
75  }
76 
77  int sunset(int y, int m, int d)
78  {
79  return sunRiseSet(false, y, m, d);
80  }
81 
86 private:
87  /*
88  * Though most time zones are offset by whole hours, there are a few zones
89  * offset by 30 or 45 minutes, so the argument must be declared as a float.
90  *
91  * Royal Observatory, Greenwich, seems an appropriate default setting
92  */
93  SolarRef ref = {51.4769, 0.0005};
94 };
Calculation of apparent time of sunrise and sunset.
Definition: SolarCalculator.h:29
SolarCalculator()
Default constructor, uses Royal Observatory, Greenwich as default.
Definition: SolarCalculator.h:34
int sunset(int y, int m, int d)
Definition: SolarCalculator.h:77
SolarCalculator(const SolarRef &ref)
Perform calculations using the given solar reference.
Definition: SolarCalculator.h:41
int sunRiseSet(bool isRise, int y, int m, int d)
const SolarRef & getRef() const
Get the current location reference in use.
Definition: SolarCalculator.h:48
void setRef(const SolarRef &ref)
Set the location reference for calculations.
Definition: SolarCalculator.h:56
int sunrise(int y, int m, int d)
Definition: SolarCalculator.h:72
A location is required to compute solar times.
Definition: SolarCalculator.h:18
float longitude
Definition: SolarCalculator.h:20
float latitude
Definition: SolarCalculator.h:19