Skip to content

Commit cff1060

Browse files
committed
Use SunMoonCalc class instead of Astronomy
1 parent 5b34146 commit cff1060

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

esp8266-weather-station-color.ino

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
#include <JsonListener.h>
4747
#include <OpenWeatherMapCurrent.h>
4848
#include <OpenWeatherMapForecast.h>
49-
#include <Astronomy.h>
5049
#include <MiniGrafx.h>
5150
#include <Carousel.h>
5251
#include <ILI9341_SPI.h>
@@ -93,9 +92,7 @@ CalibrationCallback calibration = &calibrationCallback;
9392

9493
OpenWeatherMapCurrentData currentWeather;
9594
OpenWeatherMapForecastData forecasts[MAX_FORECASTS];
96-
97-
Astronomy::MoonData moonData;
98-
//SunMoonCalc::Moon moonData;
95+
SunMoonCalc::Moon moonData;
9996

10097
void updateData();
10198
void drawProgress(uint8_t percentage, String text);
@@ -360,18 +357,12 @@ void updateData() {
360357
delete forecastClient;
361358
forecastClient = nullptr;
362359

363-
drawProgress(80, "Updating astronomy...");
364-
Astronomy *astronomy = new Astronomy();
365-
moonData = astronomy->calculateMoonData(now);
366-
moonData.phase = astronomy->calculateMoonPhase(now);
367-
delete astronomy;
368-
astronomy = nullptr;
369-
//https://github.com/ThingPulse/esp8266-weather-station/issues/144 prevents using this
370-
// // 'now' has to be UTC, lat/lng in degrees not raadians
371-
// SunMoonCalc *smCalc = new SunMoonCalc(now - dstOffset, currentWeather.lat, currentWeather.lon);
372-
// moonData = smCalc->calculateSunAndMoonData().moon;
373-
// delete smCalc;
374-
// smCalc = nullptr;
360+
drawProgress(80, "Updating astronomy data...");
361+
// 'now' has to be UTC, lat/lng in degrees not radians
362+
SunMoonCalc *smCalc = new SunMoonCalc(now, currentWeather.lat, currentWeather.lon);
363+
moonData = smCalc->calculateSunAndMoonData().moon;
364+
delete smCalc;
365+
smCalc = nullptr;
375366
Serial.printf("Free mem: %d\n", ESP.getFreeHeap());
376367

377368
delay(1000);
@@ -511,7 +502,7 @@ void drawAstronomy() {
511502
gfx.setFont(ArialRoundedMTBold_14);
512503
gfx.setTextAlignment(TEXT_ALIGN_CENTER);
513504
gfx.setColor(MINI_YELLOW);
514-
gfx.drawString(120, 250, MOON_PHASES[moonData.phase]);
505+
gfx.drawString(120, 250, MOON_PHASES[moonData.phase.index]);
515506

516507
gfx.setTextAlignment(TEXT_ALIGN_LEFT);
517508
gfx.setColor(MINI_YELLOW);
@@ -528,12 +519,10 @@ void drawAstronomy() {
528519
gfx.setColor(MINI_YELLOW);
529520
gfx.drawString(235, 250, SUN_MOON_TEXT[3]);
530521
gfx.setColor(MINI_WHITE);
531-
float lunarMonth = 29.53;
532-
// approximate moon age
533-
gfx.drawString(235, 276, String(moonData.phase <= 4 ? lunarMonth * moonData.illumination / 2.0 : lunarMonth - moonData.illumination * lunarMonth / 2.0, 1) + "d");
534-
gfx.drawString(235, 291, String(moonData.illumination * 100, 0) + "%");
535522
gfx.drawString(190, 276, SUN_MOON_TEXT[4] + ":");
523+
gfx.drawString(235, 276, String(moonData.age, 1) + "d");
536524
gfx.drawString(190, 291, SUN_MOON_TEXT[5] + ":");
525+
gfx.drawString(235, 291, String(moonData.illumination * 100, 0) + "%");
537526
}
538527

539528
void drawCurrentWeatherDetail() {

0 commit comments

Comments
 (0)