Skip to content

Commit

Permalink
Merge pull request #6 from dleo/dev-0.7.0
Browse files Browse the repository at this point in the history
Dev 0.7.0
  • Loading branch information
dleo authored Apr 7, 2022
2 parents d985dfe + 651339d commit d6b5458
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 45 deletions.
16 changes: 11 additions & 5 deletions include/weather.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,24 @@
#define VOLT_PIN 33
#define TEMP_PIN 4 // DS18B20 hooked up to GPIO pin 4
#define LED_BUILTIN 2
#define SOLAR_RADIATION 36
#define REF_3V3 39

/**
* @brief Var definitios
*
*/
#define WDT_TIMEOUT 60
#define SEC 1E6 //Multiplier for uS based math
#define SEC 1E6 //Multiplier for uS based math
#define S_IN_DAY 86400
#define S_IN_HR 3600
#define NO_RAIN_SAMPLES 2000
#define SEALEVELPRESSURE_HPA (1013.25)
#define LATITUDE (7.810944) //Latitude for Granja Rosal
#define LATITUDE (7.810944) //Latitude for Granja Rosal
#define SEA_LEVEL 1500
#define SOLAR_RADIATION 36
#define REF_3V3 39
#define RAIN_TICK (0.011)

#define MOON_SYNODIC_PERIOD 29.530588853 // Period of moon cycle in days.
#define MOON_SYNODIC_OFFSET 2451550.26 // Reference cycle offset in days.

/**
* Struct definitions
Expand Down
5 changes: 4 additions & 1 deletion src/sensors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ void readSensorsData(struct sensorData *environment)

/**
* Read moonphase
* @author David Lopez <[email protected]>
*/
void readMoonPhase(struct sensorData *environment)
{
Expand All @@ -40,7 +41,9 @@ void readMoonPhase(struct sensorData *environment)
}

/**
* Read eto
* @brief Read eto
*
*
*/
void readEto(struct sensorData *environment)
{
Expand Down
58 changes: 19 additions & 39 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,52 +45,32 @@ int moonPhases(unsigned long time)
{
// calculates the age of the moon phase(0 to 7)
// there are eight stages, 0 is full moon and 4 is a new moon
double jd = 0; // Julian Date
double ed = 0; // days elapsed since start of full moon
int b = 0;
double jd = 0; // Julian Date
float phase;
jd = julianDate(time);
jd = int(jd - 2244116.75); // start at Jan 1 1972
jd /= 29.53; // divide by the moon cycle
b = jd;
jd -= b; // leaves the fractional part of jd
ed = jd * 29.53; // days elapsed this month
b = jd * 8 + 0.5;
b = b & 7;
return b;
// Calculate illumination (synodic) phase.
// From number of days since new moon on Julian date MOON_SYNODIC_OFFSET
// (1815UTC January 6, 2000), determine remainder of incomplete cycle.
phase = (jd - MOON_SYNODIC_OFFSET) / MOON_SYNODIC_PERIOD;
phase -= floor(phase);

return (int)(phase * 8 + 0.5) % 8;
}

/**
* Moon phase on string
* @brief Moon phase on string
*
* @param phase
* @return char*
*
*/
char *moonPhaseToString(int phase)
{
switch (phase)
{
case 0:
return "Full moon";
break;
case 1:
return "Waning Gibbous";
break;
case 2:
return "Last Quarter";
break;
case 3:
return "Old Crescent";
break;
case 4:
return "New Moon";
break;
case 5:
return "New Crescent";
break;
case 6:
return "First Quarter";
break;
case 7:
return "Waxing Gibbous";
break;
}
char *phaseNames[] = {"New Moon", "Old Crescent", "First Quarter",
"Waxing Gibbous", "Full moon", "Waning Gibbous",
"Last Quarter", "Morning Crescent"};

return phaseNames[phase];
}

/**
Expand Down

0 comments on commit d6b5458

Please sign in to comment.