Skip to content

Commit

Permalink
Updated PR #376 (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmicro authored Apr 6, 2024
2 parents 1d0d71a + 7fdd287 commit e800dbd
Show file tree
Hide file tree
Showing 6 changed files with 215 additions and 127 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
15 changes: 12 additions & 3 deletions docs/firmware/apps/OswWeather.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# OSW WEATHER

# OSW WEATHER
![](/assets/apps/OswWeather/h.png)
Author: [@LorenzoSciacca](https://github.com/Lorenzosciacca)
## How to install
Add the flag `OSW_FEATURE_WEATHER` to the file `platformio.ini`:
```ini
Expand Down Expand Up @@ -58,7 +60,8 @@ The / \ and \ / arrows are used to decrease/increase the current selection (da
- Humidity: [relative humidity](https://en.wikipedia.org/wiki/Humidity#Relative_humidity)
- Pressure: [hPa](https://en.wikipedia.org/wiki/Pascal_(unit)#Multiples_and_submultiples)

### Weather conditions
### Weather conditions

Visit [this link](https://openweathermap.org/weather-conditions#Weather-Condition-Codes-2) for a more detailed description of each weather condition.

<table>
Expand Down Expand Up @@ -164,4 +167,10 @@ Visit [this link](https://openweathermap.org/weather-conditions#Weather-Conditio
<td>Unknown</td>
<td></td>
</tr>
</table>
</table>

## Using the emulator
To use this app while using the OSW emulator, in order to retireve the data, it is necessary to perform the API request using the browser and to save the response in `file_weather.json` in the `/build` folder.



52 changes: 50 additions & 2 deletions include/apps/_experiments/OswAppWeather.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <osw_hal.h>
#include <vector>
#include <OswAppV1.h>
#include "ArduinoJson.h"
#include "OswAppWeatherIconPrinter.h"

class OswAppWeather : public OswApp {
Expand All @@ -20,6 +21,52 @@ class OswAppWeather : public OswApp {
virtual void stop() override;
~OswAppWeather() {};
private:
class WeatherDecoder {
public:
WeatherDecoder(const String& input_String);
bool strIsValid();
time_t getTime();
std::vector<OswAppWeather::weather_update_t> getUpdates();
private:
time_t _str2time(const String& t);
int _str2temp(const String& temp);
int _str2hum(const String& humidity);
int _str2pres(const String& pressure);
int _str2wthr(const String& weather);
bool in_ok = true;
int nUpdates = 0;
String in_String;
};

class WeatherParser {
public:
WeatherParser();
std::optional<String> encodeWeather(DynamicJsonDocument& doc);
private:
int _getWCond(int weather_code);
int cnt;
std::vector<OswAppWeather::weather_update_t> updates;
std::vector<int>clearCode{800};//0
std::vector<int>cloudsMin{801};//1
std::vector<int>cloudsMed{802};//2
std::vector<int>cloudsHigh{803, 804};//3
std::vector<int>mist{701};//4
std::vector<int>fog{741};//5
std::vector<int>snowMin{611, 612, 615, 616};//6
std::vector<int>snowMed{600, 613, 601, 620};//7
std::vector<int>snowHigh{602, 621, 622};//8
std::vector<int>rainMin{500, 300, 301, 302, 310, 311, 312, 313, 314, 321};//9
std::vector<int>rainMed{502, 501};//10
std::vector<int>rainHigh{503, 504, 511, 520, 521, 522, 531};//11
std::vector<int>thunderstorm{200, 201, 210, 211, 231, 230};//12
std::vector<int>thunderstormHeavy{202, 212, 221, 232};//13
std::vector<int>squallTornado{771, 781};//14
//15 ->unknown
std::vector<std::vector<int>>weather_conditions{clearCode, cloudsMin, cloudsMed, cloudsHigh, mist, fog, snowMin, snowMed,
snowHigh, rainMin, rainMed, rainHigh, thunderstorm,
thunderstormHeavy, squallTornado };
};

void getW();
void printW();
void drawLayout();
Expand All @@ -46,7 +93,7 @@ class OswAppWeather : public OswApp {
uint8_t daySelector = 0;
uint8_t placeSelector = 0;
uint8_t updtSelector = 0;
OswHal* hal = OswHal::getInstance();
OswHal* hal = nullptr;
std::vector<weather_update_t> forecast;//one update each 3h
time_t initTimestamp;
char initTimeMD[6];
Expand All @@ -60,5 +107,6 @@ class OswAppWeather : public OswApp {
tm* tmInit;
std::vector<int> dayFirstUpdt{};// n-th entry is the index of first update of the n-th day
bool _request();
void drawPopUp();
};
#endif
#endif
5 changes: 4 additions & 1 deletion include/apps/_experiments/OswAppWeatherEncoder.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#pragma once
#ifdef OSW_FEATURE_WEATHER

#include <optional>

#include "apps/_experiments/OswAppWeather.h"

class OswAppWeatherEncoder {
public:
OswAppWeatherEncoder();
bool setUpdate(OswAppWeather::weather_update_t update);
bool setTimestamp(time_t t);
String getEncoded();
std::optional<String> getEncoded();

private:
String _time2str(time_t time);
Expand Down
Loading

0 comments on commit e800dbd

Please sign in to comment.