@@ -87,9 +87,9 @@ TouchControllerWS touchController(&ts);
87
87
void calibrationCallback (int16_t x, int16_t y);
88
88
CalibrationCallback calibration = &calibrationCallback;
89
89
90
-
91
90
OpenWeatherMapCurrentData currentWeather;
92
91
OpenWeatherMapForecastData forecasts[MAX_FORECASTS];
92
+
93
93
SunMoonCalc::Moon moonData;
94
94
95
95
void updateData ();
@@ -100,6 +100,7 @@ void drawCurrentWeather();
100
100
void drawForecast ();
101
101
void drawForecastDetail (uint16_t x, uint16_t y, uint8_t dayIndex);
102
102
void drawAstronomy ();
103
+ char determineMoonIcon ();
103
104
void drawCurrentWeatherDetail ();
104
105
void drawLabelValue (uint8_t line, String label, String value);
105
106
void drawForecastTable (uint8_t start);
@@ -386,8 +387,8 @@ void updateData() {
386
387
delete forecastClient;
387
388
forecastClient = nullptr ;
388
389
389
- drawProgress (80 , " Updating astronomy data ..." );
390
- // 'now' has to be UTC , lat/lng in degrees not radians
390
+ drawProgress (80 , " Updating astronomy..." );
391
+ // 'now' has to be epoch instant , lat/lng in degrees not radians
391
392
SunMoonCalc *smCalc = new SunMoonCalc (now, currentWeather.lat , currentWeather.lon );
392
393
moonData = smCalc->calculateSunAndMoonData ().moon ;
393
394
delete smCalc;
@@ -519,13 +520,14 @@ void drawForecastDetail(uint16_t x, uint16_t y, uint8_t dayIndex) {
519
520
gfx.drawString (x + 25 , y + 60 , String (forecasts[dayIndex].rain , 1 ) + (IS_METRIC ? " mm" : " in" ));
520
521
}
521
522
522
- // draw moonphase and sunrise/set and moonrise/set
523
+ // draw moonphase, sunrise/set and moonrise/set
523
524
void drawAstronomy () {
524
525
525
526
gfx.setFont (MoonPhases_Regular_36);
526
527
gfx.setColor (MINI_WHITE);
527
528
gfx.setTextAlignment (TEXT_ALIGN_CENTER);
528
- gfx.drawString (120 , 275 , String ((char ) (97 + (moonData.illumination * 26 ))));
529
+ // gfx.drawString(120, 275, String((char) (97 + (moonData.illumination * 26))));
530
+ gfx.drawString (120 , 275 , String (determineMoonIcon ()));
529
531
530
532
gfx.setColor (MINI_WHITE);
531
533
gfx.setFont (ArialRoundedMTBold_14);
@@ -548,12 +550,35 @@ void drawAstronomy() {
548
550
gfx.setColor (MINI_YELLOW);
549
551
gfx.drawString (235 , 250 , SUN_MOON_TEXT[3 ]);
550
552
gfx.setColor (MINI_WHITE);
553
+
554
+ float lunarMonth = 29.53 ;
555
+ // approximate moon age
551
556
gfx.drawString (190 , 276 , SUN_MOON_TEXT[4 ] + " :" );
552
557
gfx.drawString (235 , 276 , String (moonData.age , 1 ) + " d" );
553
558
gfx.drawString (190 , 291 , SUN_MOON_TEXT[5 ] + " :" );
554
559
gfx.drawString (235 , 291 , String (moonData.illumination * 100 , 0 ) + " %" );
555
560
}
556
561
562
+ // The Moon Phases font has 26 icons for gradiations, 1 full icon, and 1 empty icon: https://www.dafont.com/moon-phases.font
563
+ // All of them are an approximation.
564
+ // Depending on date and location they would have to be rotated left or right by a varying degree.
565
+ // GOTCHA I: as we use white to display the moon icon, what is black on that font page (link above) will effectively be rendered white!
566
+ // GOTCHA II: illumination in the range {0,1} will with near certainty never be exactly 0 or 1; rounding is, therefore, essential to ever get full/new moon!
567
+ char determineMoonIcon () {
568
+ char moonIcon;
569
+ // index in range of 0..14
570
+ char index = round (moonData.illumination * 14 );
571
+ // Serial.printf("Moon illumination: %f -> moon icon index: %d\n", moonData.illumination, index);
572
+ if (moonData.phase .index > 4 ) {
573
+ // waning (4 = full moon)
574
+ moonIcon = currentWeather.lat > 0 ? MOON_ICONS_NORTH_WANING[index ] : MOON_ICONS_SOUTH_WANING[index ];
575
+ } else {
576
+ // waxing
577
+ moonIcon = currentWeather.lat > 0 ? MOON_ICONS_NORTH_WAXING[index ] : MOON_ICONS_SOUTH_WAXING[index ];
578
+ }
579
+ return moonIcon;
580
+ }
581
+
557
582
void drawCurrentWeatherDetail () {
558
583
gfx.setFont (ArialRoundedMTBold_14);
559
584
gfx.setTextAlignment (TEXT_ALIGN_CENTER);
@@ -791,6 +816,8 @@ void loadPropertiesFromSpiffs() {
791
816
Serial.printf (msg, " is12hStyle" );
792
817
}
793
818
}
819
+ } else {
820
+ Serial.println (" Does not exist." );
794
821
}
795
822
f.close ();
796
823
Serial.println (" Effective properties now as follows:" );
0 commit comments