Skip to content

Commit

Permalink
Enable weather support in emulator + fixed error-handling there
Browse files Browse the repository at this point in the history
Signed-off-by: simonmicro <simon@simonmicro.de>
  • Loading branch information
simonmicro committed Apr 6, 2024
1 parent c6a07d5 commit bfa7726
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ target_compile_definitions(emulator.run PUBLIC
# LOCALE="locales/en-US.h"
# Comment these as you wish...
OSW_FEATURE_STATS_STEPS
OSW_FEATURE_WEATHER
OSW_APPS_EXAMPLES=1
GAME_SNAKE=1
GAME_BRICK_BREAKER=1
Expand Down
16 changes: 10 additions & 6 deletions src/apps/_experiments/OswAppWeather.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ void OswAppWeather::printDate() {
}

bool OswAppWeather::loadData() {
String wstr;
#ifdef OSW_EMULATOR
std::ifstream inFile;
inFile.open("file_weather.json"); //open the input file
Expand All @@ -381,13 +382,16 @@ bool OswAppWeather::loadData() {
DynamicJsonDocument doc(16432*2);// when in emulator more space is needed
deserializeJson(doc,strW);
WeatherParser pars;
String encoded = pars.encodeWeather(doc);
OSW_LOG_D("as encoded:");
OSW_LOG_D(encoded);
String wstr;
wstr += encoded; // this copies the value of "encoded" to "wstr" (just assignment does not take ownership of the value itself)
std::optional<String> encoded = pars.encodeWeather(doc);
if(encoded.has_value()) {
OSW_LOG_D("as encoded:");
OSW_LOG_D(encoded.value());
wstr += encoded.value(); // this copies the value of "encoded" to "wstr" (just assignment does not take ownership of the value itself)
} else {
OSW_LOG_E("Something went wrong with the encoding of the weather data from the local file?!");
}
#else
String wstr = this->pref.getString("wtr");
wstr = this->pref.getString("wtr");
#endif
if (wstr!="") {
OSW_LOG_D("size of wstr: ", wstr.length());
Expand Down

0 comments on commit bfa7726

Please sign in to comment.