summaryrefslogtreecommitdiff
path: root/src/components
diff options
context:
space:
mode:
authorAvamander <avamander@gmail.com>2021-08-21 21:58:03 +0300
committerAvamander <avamander@gmail.com>2021-12-04 22:03:40 +0200
commited6f0aade4db811b5013441c57944baff4528938 (patch)
tree576bbccdf1cd748f9889520e3932788479fb334c /src/components
parent0ed256ba15ceace2949f21ecbc1407b8553dd75d (diff)
Implemented a few functions.
Diffstat (limited to 'src/components')
-rw-r--r--src/components/ble/weather/WeatherData.h6
-rw-r--r--src/components/ble/weather/WeatherService.cpp84
-rw-r--r--src/components/ble/weather/WeatherService.h20
3 files changed, 84 insertions, 26 deletions
diff --git a/src/components/ble/weather/WeatherData.h b/src/components/ble/weather/WeatherData.h
index ee2a364d..9b424004 100644
--- a/src/components/ble/weather/WeatherData.h
+++ b/src/components/ble/weather/WeatherData.h
@@ -122,7 +122,7 @@ namespace Pinetime {
* Events have types
* then they're easier to parse after sending them over the air
*/
- enum class eventtype {
+ enum class eventtype : uint8_t {
/** @see obscuration */
Obscuration = 0,
/** @see precipitation */
@@ -141,6 +141,8 @@ namespace Pinetime {
Location = 7,
/** @see cloud */
Clouds = 8,
+ /** @see humidity */
+ Humidity = 9,
Length
};
@@ -340,4 +342,4 @@ namespace Pinetime {
};
};
}
-} \ No newline at end of file
+}
diff --git a/src/components/ble/weather/WeatherService.cpp b/src/components/ble/weather/WeatherService.cpp
index a9c9f114..22c80837 100644
--- a/src/components/ble/weather/WeatherService.cpp
+++ b/src/components/ble/weather/WeatherService.cpp
@@ -90,7 +90,7 @@ namespace Pinetime {
airquality->polluter = std::make_unique<std::string>(static_cast<const char*>(String.ptr), String.len);
int64_t tmpAmount = 0;
QCBORDecode_GetInt64InMapSZ(&decodeContext, "Amount", &tmpAmount);
- if (tmpAmount < 0 || tmpAmount > 4294967295) {
+ if (tmpAmount < 0) {
return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
}
airquality->amount = tmpAmount;
@@ -162,6 +162,14 @@ namespace Pinetime {
timeline.push_back(std::move(clouds));
break;
}
+ case WeatherData::eventtype::Humidity: {
+ std::unique_ptr<WeatherData::Humidity> humidity = std::make_unique<WeatherData::Humidity>();
+ humidity->timestamp = tmpTimestamp;
+ humidity->eventType = static_cast<WeatherData::eventtype>(tmpEventType);
+ humidity->expires = tmpExpires;
+ timeline.push_back(std::move(humidity));
+ break;
+ }
default: {
break;
}
@@ -201,46 +209,94 @@ namespace Pinetime {
return 0;
}
- WeatherData::Location WeatherService::GetCurrentLocation() const {
- return WeatherData::Location();
- }
-
WeatherData::Clouds WeatherService::GetCurrentClouds() const {
- return WeatherData::Clouds();
+ uint64_t currentTimestamp = GetCurrentUnixTimestamp();
+ for (auto&& header : timeline) {
+ if (header->eventType == WeatherData::eventtype::Clouds && header->timestamp + header->expires <= currentTimestamp) {
+ return reinterpret_cast<const WeatherData::Clouds&>(header);
+ }
+ }
+ return {};
}
WeatherData::Obscuration WeatherService::GetCurrentObscuration() const {
- return WeatherData::Obscuration();
+ uint64_t currentTimestamp = GetCurrentUnixTimestamp();
+ for (auto&& header : timeline) {
+ if (header->eventType == WeatherData::eventtype::Obscuration && header->timestamp + header->expires <= currentTimestamp) {
+ return reinterpret_cast<const WeatherData::Obscuration&>(header);
+ }
+ }
+ return {};
}
WeatherData::Precipitation WeatherService::GetCurrentPrecipitation() const {
- return WeatherData::Precipitation();
+ uint64_t currentTimestamp = GetCurrentUnixTimestamp();
+ for (auto&& header : timeline) {
+ if (header->eventType == WeatherData::eventtype::Precipitation && header->timestamp + header->expires <= currentTimestamp) {
+ return reinterpret_cast<const WeatherData::Precipitation&>(header);
+ }
+ }
+ return {};
}
WeatherData::Wind WeatherService::GetCurrentWind() const {
- return WeatherData::Wind();
+ uint64_t currentTimestamp = GetCurrentUnixTimestamp();
+ for (auto&& header : timeline) {
+ if (header->eventType == WeatherData::eventtype::Wind && header->timestamp + header->expires <= currentTimestamp) {
+ return reinterpret_cast<const WeatherData::Wind&>(header);
+ }
+ }
+ return {};
}
WeatherData::Temperature WeatherService::GetCurrentTemperature() const {
- return WeatherData::Temperature();
+ uint64_t currentTimestamp = GetCurrentUnixTimestamp();
+ for (auto&& header : timeline) {
+ if (header->eventType == WeatherData::eventtype::Temperature && header->timestamp + header->expires <= currentTimestamp) {
+ return reinterpret_cast<const WeatherData::Temperature&>(header);
+ }
+ }
+ return {};
}
WeatherData::Humidity WeatherService::GetCurrentHumidity() const {
- return WeatherData::Humidity();
+ uint64_t currentTimestamp = GetCurrentUnixTimestamp();
+ for (auto&& header : timeline) {
+ if (header->eventType == WeatherData::eventtype::Humidity && header->timestamp + header->expires <= currentTimestamp) {
+ return reinterpret_cast<const WeatherData::Humidity&>(header);
+ }
+ }
+ return {};
}
WeatherData::Pressure WeatherService::GetCurrentPressure() const {
uint64_t currentTimestamp = GetCurrentUnixTimestamp();
for (auto&& header : timeline) {
if (header->eventType == WeatherData::eventtype::Pressure && header->timestamp + header->expires <= currentTimestamp) {
- return WeatherData::Pressure();
+ return reinterpret_cast<const WeatherData::Pressure&>(header);
+ }
+ }
+ return {};
+ }
+
+ WeatherData::Location WeatherService::GetCurrentLocation() const {
+ uint64_t currentTimestamp = GetCurrentUnixTimestamp();
+ for (auto&& header : timeline) {
+ if (header->eventType == WeatherData::eventtype::Location && header->timestamp + header->expires <= currentTimestamp) {
+ return reinterpret_cast<const WeatherData::Location&>(header);
}
}
- return WeatherData::Pressure();
+ return {};
}
WeatherData::AirQuality WeatherService::GetCurrentQuality() const {
- return WeatherData::AirQuality();
+ uint64_t currentTimestamp = GetCurrentUnixTimestamp();
+ for (auto&& header : timeline) {
+ if (header->eventType == WeatherData::eventtype::AirQuality && header->timestamp + header->expires <= currentTimestamp) {
+ return reinterpret_cast<const WeatherData::AirQuality&>(header);
+ }
+ }
+ return {};
}
size_t WeatherService::GetTimelineLength() const {
diff --git a/src/components/ble/weather/WeatherService.h b/src/components/ble/weather/WeatherService.h
index 995f856e..5504ea49 100644
--- a/src/components/ble/weather/WeatherService.h
+++ b/src/components/ble/weather/WeatherService.h
@@ -77,42 +77,42 @@ namespace Pinetime {
* Checks if an event of a certain type exists in the timeline
* @return
*/
- bool HasTimelineEventOfType(const WeatherData::eventtype type) const;
+ bool HasTimelineEventOfType(WeatherData::eventtype type) const;
private:
// 00030000-78fc-48fe-8e23-433b3a1942d0
- static constexpr ble_uuid128_t BaseUUID() {
- return CharUUID(0x00, 0x00);
+ static constexpr ble_uuid128_t BaseUuid() {
+ return CharUuid(0x00, 0x00);
}
// 0003yyxx-78fc-48fe-8e23-433b3a1942d0
- static constexpr ble_uuid128_t CharUUID(uint8_t x, uint8_t y) {
+ static constexpr ble_uuid128_t CharUuid(uint8_t x, uint8_t y) {
return ble_uuid128_t {.u = {.type = BLE_UUID_TYPE_128},
.value = {0xd0, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, x, y, 0x03, 0x00}};
}
- ble_uuid128_t weatherUUID {BaseUUID()};
+ ble_uuid128_t weatherUuid {BaseUuid()};
/**
* Just write timeline data here
*/
- ble_uuid128_t weatherDataCharUUID {CharUUID(0x00, 0x01)};
+ ble_uuid128_t weatherDataCharUuid {CharUuid(0x00, 0x01)};
/**
* This doesn't take timeline data,
* provides some control over it
*/
- ble_uuid128_t weatherControlCharUUID {CharUUID(0x00, 0x02)};
+ ble_uuid128_t weatherControlCharUuid {CharUuid(0x00, 0x02)};
const struct ble_gatt_chr_def characteristicDefinition[3] = {
- {.uuid = &weatherDataCharUUID.u,
+ {.uuid = &weatherDataCharUuid.u,
.access_cb = WeatherCallback,
.arg = this,
.flags = BLE_GATT_CHR_F_WRITE,
.val_handle = &eventHandle},
- {.uuid = &weatherControlCharUUID.u, .access_cb = WeatherCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ},
+ {.uuid = &weatherControlCharUuid.u, .access_cb = WeatherCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ},
{nullptr}};
const struct ble_gatt_svc_def serviceDefinition[2] = {
- {.type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid = &weatherUUID.u, .characteristics = characteristicDefinition}, {0}};
+ {.type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid = &weatherUuid.u, .characteristics = characteristicDefinition}, {0}};
uint16_t eventHandle {};