Skip to content

Commit 3decdd0

Browse files
committed
Fixing isMetric bug, cleaning up
1 parent 659edda commit 3decdd0

File tree

2 files changed

+83
-63
lines changed

2 files changed

+83
-63
lines changed

src/WundergroundAstronomy.cpp

Lines changed: 82 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ WundergroundAstronomy::WundergroundAstronomy(boolean _usePM) {
3434
void WundergroundAstronomy::updateAstronomy(WGAstronomy *astronomy, String apiKey, String language, String country, String city) {
3535
doUpdate(astronomy, "/api/" + apiKey + "/astronomy/lang:" + language + "/q/" + country + "/" + city + ".json");
3636
}
37-
// end JJG add ////////////////////////////////////////////////////////////////////
3837

3938
void WundergroundAstronomy::updateAstronomyPWS(WGAstronomy *astronomy, String apiKey, String language, String pws) {
4039
doUpdate(astronomy, "/api/" + apiKey + "/astronomy/lang:" + language + "/q/pws:" + pws + ".json");
@@ -114,83 +113,104 @@ void WundergroundAstronomy::value(String value) {
114113

115114

116115
if (currentParent == "sunrise") { // Has a Parent key and 2 sub-keys
117-
if (currentKey == "hour") {
118-
int tempHour = value.toInt(); // do this to concert to 12 hour time (make it a function!)
119-
if (usePM && tempHour > 12){
120-
tempHour -= 12;
121-
isPM = true;
122-
}
123-
else isPM = false;
124-
char tempHourBuff[3] = ""; // fowlerk add for formatting, 12/22/16
125-
sprintf(tempHourBuff, "%2d", tempHour); // fowlerk add for formatting, 12/22/16
126-
astronomy->sunriseTime = String(tempHourBuff); // fowlerk add for formatting, 12/22/16
127-
//sunriseTime = value;
116+
if (currentKey == "hour") {
117+
int tempHour = value.toInt(); // do this to concert to 12 hour time (make it a function!)
118+
if (usePM && tempHour > 12){
119+
tempHour -= 12;
120+
isPM = true;
128121
}
129-
if (currentKey == "minute") {
130-
char tempMinBuff[3] = ""; // fowlerk add for formatting, 12/22/16
131-
sprintf(tempMinBuff, "%02d", value.toInt()); // fowlerk add for formatting, 12/22/16
132-
astronomy->sunriseTime += ":" + String(tempMinBuff); // fowlerk add for formatting, 12/22/16
133-
if (isPM) sunriseTime += "pm";
134-
else if (usePM) sunriseTime += "am";
135-
}
122+
else {
123+
isPM = false;
124+
}
125+
char tempHourBuff[3] = "";
126+
sprintf(tempHourBuff, "%02d", tempHour);
127+
astronomy->sunriseTime = String(tempHourBuff);
128+
}
129+
if (currentKey == "minute") {
130+
char tempMinBuff[4] = "";
131+
if (usePM) {
132+
sprintf(tempMinBuff, "%02d%s", value.toInt(), isPM?"pm":"am");
133+
} else {
134+
sprintf(tempMinBuff, "%02d", value.toInt());
135+
}
136+
astronomy->sunriseTime += ":" + String(tempMinBuff);
137+
138+
}
139+
this->sunriseTime.trim();
136140
}
137141

138142

139143
if (currentParent == "sunset") { // Has a Parent key and 2 sub-keys
140-
if (currentKey == "hour") {
141-
int tempHour = value.toInt(); // do this to concert to 12 hour time (make it a function!)
142-
if (usePM && tempHour > 12){
143-
tempHour -= 12;
144-
isPM = true;
145-
}
146-
else isPM = false;
147-
char tempHourBuff[3] = ""; // fowlerk add for formatting, 12/22/16
148-
sprintf(tempHourBuff, "%2d", tempHour); // fowlerk add for formatting, 12/22/16
149-
astronomy->sunsetTime = String(tempHourBuff); // fowlerk add for formatting, 12/22/16
150-
// sunsetTime = value;
144+
if (currentKey == "hour") {
145+
int tempHour = value.toInt(); // do this to concert to 12 hour time (make it a function!)
146+
if (usePM && tempHour > 12) {
147+
tempHour -= 12;
148+
isPM = true;
149+
} else {
150+
isPM = false;
151151
}
152-
if (currentKey == "minute") {
153-
char tempMinBuff[3] = ""; // fowlerk add for formatting, 12/22/16
154-
sprintf(tempMinBuff, "%02d", value.toInt()); // fowlerk add for formatting, 12/22/16
155-
astronomy->sunsetTime += ":" + String(tempMinBuff); // fowlerk add for formatting, 12/22/16
156-
if (isPM) sunsetTime += "pm";
157-
else if(usePM) sunsetTime += "am";
152+
char tempHourBuff[3] = "";
153+
sprintf(tempHourBuff, "%02d", tempHour);
154+
astronomy->sunsetTime = String(tempHourBuff);
158155
}
156+
if (currentKey == "minute") {
157+
char tempMinBuff[4] = "";
158+
if (usePM) {
159+
sprintf(tempMinBuff, "%02d%s", value.toInt(), isPM?"pm":"am");
160+
} else {
161+
sprintf(tempMinBuff, "%02d", value.toInt());
162+
}
163+
astronomy->sunsetTime += ":" + String(tempMinBuff);
164+
}
165+
this->sunsetTime.trim();
159166
}
160167

161168
if (currentParent == "moonrise") { // Has a Parent key and 2 sub-keys
162-
if (currentKey == "hour") {
163-
int tempHour = value.toInt(); // do this to concert to 12 hour time (make it a function!)
164-
if (usePM && tempHour > 12){
165-
tempHour -= 12;
166-
isPM = true;
167-
}
168-
else isPM = false;
169-
char tempHourBuff[3] = ""; // fowlerk add for formatting, 12/22/16
170-
sprintf(tempHourBuff, "%2d", tempHour); // fowlerk add for formatting, 12/22/16
171-
astronomy->moonriseTime = String(tempHourBuff); // fowlerk add for formatting, 12/22/16
172-
// moonriseTime = value;
169+
if (currentKey == "hour") {
170+
int tempHour = value.toInt(); // do this to concert to 12 hour time (make it a function!)
171+
if (usePM && tempHour > 12){
172+
tempHour -= 12;
173+
isPM = true;
174+
}
175+
else isPM = false;
176+
char tempHourBuff[3] = "";
177+
sprintf(tempHourBuff, "%02d", tempHour);
178+
astronomy->moonriseTime = String(tempHourBuff);
179+
}
180+
if (currentKey == "minute") {
181+
char tempMinBuff[4] = "";
182+
if (usePM) {
183+
sprintf(tempMinBuff, "%02d%s", value.toInt(), isPM?"pm":"am");
184+
} else {
185+
sprintf(tempMinBuff, "%02d", value.toInt());
173186
}
174-
if (currentKey == "minute") {
175-
char tempMinBuff[3] = ""; // fowlerk add for formatting, 12/22/16
176-
sprintf(tempMinBuff, "%02d", value.toInt()); // fowlerk add for formatting, 12/22/16
177-
astronomy->moonriseTime += ":" + String(tempMinBuff); // fowlerk add for formatting, 12/22/16
178-
if (isPM) moonriseTime += "pm";
179-
else if (usePM) moonriseTime += "am";
187+
astronomy->moonriseTime += ":" + String(tempMinBuff);
180188
}
189+
this->moonriseTime.trim();
181190
}
182191

183-
if (currentParent == "moonset") { // Not used - has a Parent key and 2 sub-keys
184-
if (currentKey == "hour") {
185-
char tempHourBuff[3] = ""; // fowlerk add for formatting, 12/22/16
186-
sprintf(tempHourBuff, "%2d", value.toInt()); // fowlerk add for formatting, 12/22/16
187-
astronomy->moonsetTime = String(tempHourBuff); // fowlerk add for formatting, 12/22/16
192+
if (currentParent == "moonset") { // Has a Parent key and 2 sub-keys
193+
if (currentKey == "hour") {
194+
int tempHour = value.toInt(); // do this to concert to 12 hour time (make it a function!)
195+
if (usePM && tempHour > 12){
196+
tempHour -= 12;
197+
isPM = true;
198+
}
199+
else isPM = false;
200+
char tempHourBuff[3] = "";
201+
sprintf(tempHourBuff, "%02d", tempHour);
202+
astronomy->moonsetTime = String(tempHourBuff);
188203
}
189-
if (currentKey == "minute") {
190-
char tempMinBuff[3] = ""; // fowlerk add for formatting, 12/22/16
191-
sprintf(tempMinBuff, "%02d", value.toInt()); // fowlerk add for formatting, 12/22/16
192-
astronomy->moonsetTime += ":" + String(tempMinBuff); // fowlerk add for formatting, 12/22/16
204+
if (currentKey == "minute") {
205+
char tempMinBuff[4] = "";
206+
if (usePM) {
207+
sprintf(tempMinBuff, "%02d%s", value.toInt(), isPM?"pm":"am");
208+
} else {
209+
sprintf(tempMinBuff, "%02d", value.toInt());
210+
}
211+
astronomy->moonsetTime += ":" + String(tempMinBuff);
193212
}
213+
astronomy->moonsetTime.trim();
194214
}
195215

196216
}

src/WundergroundForecast.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void WundergroundForecast::value(String value) {
153153
forecasts[dailyForecastPeriod].forecastLowTemp = value;
154154
}
155155
}
156-
if (currentKey == "celsius" && dailyForecastPeriod < maxForecasts) {
156+
if (currentKey == "celsius" && isMetric && dailyForecastPeriod < maxForecasts) {
157157

158158
if (currentParent == "high") {
159159
Serial.println(String(currentForecastPeriod)+ ": " + value);

0 commit comments

Comments
 (0)