Skip to content

Commit

Permalink
Add isLoading()
Browse files Browse the repository at this point in the history
  • Loading branch information
亨睿 committed Feb 17, 2020
1 parent d99287f commit 4267496
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/examples/services/ServiceClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ void ServiceClientClass::update() {
// Routine Update
_lastUpdateTime = millis();
Serial.println("Fetching from my-cloudflare-services.you-fm.workers.dev...");
_isLoading = true;
_ajax.open("GET", "http://my-cloudflare-services.you-fm.workers.dev/");
_ajax.send();
} else {
Expand All @@ -26,6 +27,7 @@ void ServiceClientClass::update() {
if (millis() - _lastUpdateTime > 1.5 * 60 * 1000) {
_lastUpdateTime = millis();
Serial.println("Fetching from my-cloudflare-services.you-fm.workers.dev/stock...");
_isLoading = true;
_ajax.open("GET", "http://my-cloudflare-services.you-fm.workers.dev/stock");
_ajax.send();
}
Expand All @@ -34,6 +36,10 @@ void ServiceClientClass::update() {
}
}

bool ServiceClientClass::isLoading() {
return _isLoading;
}

Stock ServiceClientClass::getStock(uint8_t index) {
return _stocks[0];
}
Expand All @@ -47,6 +53,8 @@ WeatherForecast ServiceClientClass::getWeatherForecast(uint8_t day) {
}

void ServiceClientClass::handleCallback(asyncHTTPrequest *request) {
_isLoading = false;

Serial.print("Response HTTP Code: ");
Serial.println(request->responseHTTPcode());
Serial.println();
Expand Down
3 changes: 3 additions & 0 deletions src/examples/services/ServiceClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class ServiceClientClass {
void begin();
void update();

bool isLoading();

WeatherForecast getWeatherNow();
WeatherForecast getWeatherForecast(uint8_t day);
Stock getStock(uint8_t index);
Expand All @@ -28,6 +30,7 @@ class ServiceClientClass {
unsigned long UPDATE_TIMEOUT = 60 * 1000;

bool _initialized = false;
bool _isLoading = false;
unsigned long _lastUpdateTime = 0;

asyncHTTPrequest _ajax;
Expand Down

0 comments on commit 4267496

Please sign in to comment.