Implemented a few functions.

main
Avamander 2021-08-21 21:58:03 +07:00
parent 0ed256ba15
commit ed6f0aade4
4 changed files with 85 additions and 41 deletions

@ -122,7 +122,7 @@ namespace Pinetime {
* Events have types * Events have types
* then they're easier to parse after sending them over the air * then they're easier to parse after sending them over the air
*/ */
enum class eventtype { enum class eventtype : uint8_t {
/** @see obscuration */ /** @see obscuration */
Obscuration = 0, Obscuration = 0,
/** @see precipitation */ /** @see precipitation */
@ -141,6 +141,8 @@ namespace Pinetime {
Location = 7, Location = 7,
/** @see cloud */ /** @see cloud */
Clouds = 8, Clouds = 8,
/** @see humidity */
Humidity = 9,
Length Length
}; };

@ -90,7 +90,7 @@ namespace Pinetime {
airquality->polluter = std::make_unique<std::string>(static_cast<const char*>(String.ptr), String.len); airquality->polluter = std::make_unique<std::string>(static_cast<const char*>(String.ptr), String.len);
int64_t tmpAmount = 0; int64_t tmpAmount = 0;
QCBORDecode_GetInt64InMapSZ(&decodeContext, "Amount", &tmpAmount); QCBORDecode_GetInt64InMapSZ(&decodeContext, "Amount", &tmpAmount);
if (tmpAmount < 0 || tmpAmount > 4294967295) { if (tmpAmount < 0) {
return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN; return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
} }
airquality->amount = tmpAmount; airquality->amount = tmpAmount;
@ -162,6 +162,14 @@ namespace Pinetime {
timeline.push_back(std::move(clouds)); timeline.push_back(std::move(clouds));
break; 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: { default: {
break; break;
} }
@ -201,46 +209,94 @@ namespace Pinetime {
return 0; return 0;
} }
WeatherData::Location WeatherService::GetCurrentLocation() const {
return WeatherData::Location();
}
WeatherData::Clouds WeatherService::GetCurrentClouds() const { 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 { 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 { 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 { 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 { 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 { 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 { WeatherData::Pressure WeatherService::GetCurrentPressure() const {
uint64_t currentTimestamp = GetCurrentUnixTimestamp(); uint64_t currentTimestamp = GetCurrentUnixTimestamp();
for (auto&& header : timeline) { for (auto&& header : timeline) {
if (header->eventType == WeatherData::eventtype::Pressure && header->timestamp + header->expires <= currentTimestamp) { if (header->eventType == WeatherData::eventtype::Pressure && header->timestamp + header->expires <= currentTimestamp) {
return WeatherData::Pressure(); return reinterpret_cast<const WeatherData::Pressure&>(header);
} }
} }
return WeatherData::Pressure(); 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::AirQuality WeatherService::GetCurrentQuality() const { 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 { size_t WeatherService::GetTimelineLength() const {

@ -77,42 +77,42 @@ namespace Pinetime {
* Checks if an event of a certain type exists in the timeline * Checks if an event of a certain type exists in the timeline
* @return * @return
*/ */
bool HasTimelineEventOfType(const WeatherData::eventtype type) const; bool HasTimelineEventOfType(WeatherData::eventtype type) const;
private: private:
// 00030000-78fc-48fe-8e23-433b3a1942d0 // 00030000-78fc-48fe-8e23-433b3a1942d0
static constexpr ble_uuid128_t BaseUUID() { static constexpr ble_uuid128_t BaseUuid() {
return CharUUID(0x00, 0x00); return CharUuid(0x00, 0x00);
} }
// 0003yyxx-78fc-48fe-8e23-433b3a1942d0 // 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}, 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}}; .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 * 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, * This doesn't take timeline data,
* provides some control over it * 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] = { const struct ble_gatt_chr_def characteristicDefinition[3] = {
{.uuid = &weatherDataCharUUID.u, {.uuid = &weatherDataCharUuid.u,
.access_cb = WeatherCallback, .access_cb = WeatherCallback,
.arg = this, .arg = this,
.flags = BLE_GATT_CHR_F_WRITE, .flags = BLE_GATT_CHR_F_WRITE,
.val_handle = &eventHandle}, .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}}; {nullptr}};
const struct ble_gatt_svc_def serviceDefinition[2] = { 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 {}; uint16_t eventHandle {};

@ -105,7 +105,6 @@ bool sortById(const TaskStatus_t& lhs, const TaskStatus_t& rhs) {
} }
std::unique_ptr<Screen> Weather::CreateScreen4() { std::unique_ptr<Screen> Weather::CreateScreen4() {
TaskStatus_t tasksStatus[7];
lv_obj_t* infoTask = lv_table_create(lv_scr_act(), nullptr); lv_obj_t* infoTask = lv_table_create(lv_scr_act(), nullptr);
lv_table_set_col_cnt(infoTask, 3); lv_table_set_col_cnt(infoTask, 3);
lv_table_set_row_cnt(infoTask, 8); lv_table_set_row_cnt(infoTask, 8);
@ -118,19 +117,6 @@ std::unique_ptr<Screen> Weather::CreateScreen4() {
lv_table_set_cell_value(infoTask, 0, 2, "Free"); lv_table_set_cell_value(infoTask, 0, 2, "Free");
lv_table_set_col_width(infoTask, 2, 90); lv_table_set_col_width(infoTask, 2, 90);
auto nb = uxTaskGetSystemState(tasksStatus, 7, nullptr);
std::sort(tasksStatus, tasksStatus + nb, sortById);
for (uint8_t i = 0; i < nb; i++) {
lv_table_set_cell_value(infoTask, i + 1, 0, std::to_string(tasksStatus[i].xTaskNumber).c_str());
lv_table_set_cell_value(infoTask, i + 1, 1, tasksStatus[i].pcTaskName);
if (tasksStatus[i].usStackHighWaterMark < 20) {
std::string str1 = std::to_string(tasksStatus[i].usStackHighWaterMark) + " low";
lv_table_set_cell_value(infoTask, i + 1, 2, str1.c_str());
} else {
lv_table_set_cell_value(infoTask, i + 1, 2, std::to_string(tasksStatus[i].usStackHighWaterMark).c_str());
}
}
return std::unique_ptr<Screen>(new Screens::Label(3, 5, app, infoTask)); return std::unique_ptr<Screen>(new Screens::Label(3, 5, app, infoTask));
} }