mirror of
https://github.com/InfiniTimeOrg/InfiniTime.git
synced 2024-12-26 11:13:16 +03:00
Implemented a few functions.
This commit is contained in:
parent
0ed256ba15
commit
ed6f0aade4
@ -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 {
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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::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 {
|
||||
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 {
|
||||
|
@ -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 {};
|
||||
|
||||
|
@ -105,7 +105,6 @@ bool sortById(const TaskStatus_t& lhs, const TaskStatus_t& rhs) {
|
||||
}
|
||||
|
||||
std::unique_ptr<Screen> Weather::CreateScreen4() {
|
||||
TaskStatus_t tasksStatus[7];
|
||||
lv_obj_t* infoTask = lv_table_create(lv_scr_act(), nullptr);
|
||||
lv_table_set_col_cnt(infoTask, 3);
|
||||
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_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));
|
||||
}
|
||||
|
||||
@ -148,4 +134,4 @@ std::unique_ptr<Screen> Weather::CreateScreen5() {
|
||||
lv_label_set_align(label, LV_LABEL_ALIGN_CENTER);
|
||||
lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
|
||||
return std::unique_ptr<Screen>(new Screens::Label(4, 5, app, label));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user