Started initial work on the UI
This commit is contained in:
@@ -20,8 +20,8 @@
|
||||
#include "libs/QCBOR/inc/qcbor/qcbor.h"
|
||||
#include "systemtask/SystemTask.h"
|
||||
|
||||
int WeatherCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt, void* arg) {
|
||||
return static_cast<Pinetime::Controllers::WeatherService*>(arg)->OnCommand(conn_handle, attr_handle, ctxt);
|
||||
int WeatherCallback(uint16_t connHandle, uint16_t attrHandle, struct ble_gatt_access_ctxt* ctxt, void* arg) {
|
||||
return static_cast<Pinetime::Controllers::WeatherService*>(arg)->OnCommand(connHandle, attrHandle, ctxt);
|
||||
}
|
||||
|
||||
namespace Pinetime {
|
||||
@@ -39,7 +39,7 @@ namespace Pinetime {
|
||||
ASSERT(res == 0);
|
||||
}
|
||||
|
||||
int WeatherService::OnCommand(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt) {
|
||||
int WeatherService::OnCommand(uint16_t connHandle, uint16_t attrHandle, struct ble_gatt_access_ctxt* ctxt) {
|
||||
// TODO: Detect control messages
|
||||
if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
|
||||
const auto packetLen = OS_MBUF_PKTLEN(ctxt->om);
|
||||
@@ -167,9 +167,9 @@ namespace Pinetime {
|
||||
}
|
||||
}
|
||||
|
||||
getCurrentPressure();
|
||||
tidyTimeline();
|
||||
getTimelineLength();
|
||||
GetCurrentPressure();
|
||||
TidyTimeline();
|
||||
GetTimelineLength();
|
||||
QCBORDecode_ExitMap(&decodeContext);
|
||||
|
||||
auto uErr = QCBORDecode_Finish(&decodeContext);
|
||||
@@ -201,29 +201,36 @@ namespace Pinetime {
|
||||
return 0;
|
||||
}
|
||||
|
||||
WeatherData::Location WeatherService::getCurrentLocation() const {
|
||||
WeatherData::Location WeatherService::GetCurrentLocation() const {
|
||||
return WeatherData::Location();
|
||||
}
|
||||
WeatherData::Clouds WeatherService::getCurrentClouds() const {
|
||||
|
||||
WeatherData::Clouds WeatherService::GetCurrentClouds() const {
|
||||
return WeatherData::Clouds();
|
||||
}
|
||||
WeatherData::Obscuration WeatherService::getCurrentObscuration() const {
|
||||
|
||||
WeatherData::Obscuration WeatherService::GetCurrentObscuration() const {
|
||||
return WeatherData::Obscuration();
|
||||
}
|
||||
WeatherData::Precipitation WeatherService::getCurrentPrecipitation() const {
|
||||
|
||||
WeatherData::Precipitation WeatherService::GetCurrentPrecipitation() const {
|
||||
return WeatherData::Precipitation();
|
||||
}
|
||||
WeatherData::Wind WeatherService::getCurrentWind() const {
|
||||
|
||||
WeatherData::Wind WeatherService::GetCurrentWind() const {
|
||||
return WeatherData::Wind();
|
||||
}
|
||||
WeatherData::Temperature WeatherService::getCurrentTemperature() const {
|
||||
|
||||
WeatherData::Temperature WeatherService::GetCurrentTemperature() const {
|
||||
return WeatherData::Temperature();
|
||||
}
|
||||
WeatherData::Humidity WeatherService::getCurrentHumidity() const {
|
||||
|
||||
WeatherData::Humidity WeatherService::GetCurrentHumidity() const {
|
||||
return WeatherData::Humidity();
|
||||
}
|
||||
WeatherData::Pressure WeatherService::getCurrentPressure() const {
|
||||
uint64_t currentTimestamp = getCurrentUNIXTimestamp();
|
||||
|
||||
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();
|
||||
@@ -232,15 +239,15 @@ namespace Pinetime {
|
||||
return WeatherData::Pressure();
|
||||
}
|
||||
|
||||
WeatherData::AirQuality WeatherService::getCurrentQuality() const {
|
||||
WeatherData::AirQuality WeatherService::GetCurrentQuality() const {
|
||||
return WeatherData::AirQuality();
|
||||
}
|
||||
|
||||
size_t WeatherService::getTimelineLength() const {
|
||||
size_t WeatherService::GetTimelineLength() const {
|
||||
return timeline.size();
|
||||
}
|
||||
|
||||
bool WeatherService::addEventToTimeline(std::unique_ptr<WeatherData::TimelineHeader> event) {
|
||||
bool WeatherService::AddEventToTimeline(std::unique_ptr<WeatherData::TimelineHeader> event) {
|
||||
if (timeline.size() == timeline.max_size()) {
|
||||
return false;
|
||||
}
|
||||
@@ -249,8 +256,8 @@ namespace Pinetime {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WeatherService::hasTimelineEventOfType(const WeatherData::eventtype type) const {
|
||||
uint64_t currentTimestamp = getCurrentUNIXTimestamp();
|
||||
bool WeatherService::HasTimelineEventOfType(const WeatherData::eventtype type) const {
|
||||
uint64_t currentTimestamp = GetCurrentUnixTimestamp();
|
||||
for (auto&& header : timeline) {
|
||||
if (header->eventType == type && header->timestamp + header->expires <= currentTimestamp) {
|
||||
// TODO: Check if its currently valid
|
||||
@@ -260,7 +267,7 @@ namespace Pinetime {
|
||||
return false;
|
||||
}
|
||||
|
||||
void WeatherService::tidyTimeline() {
|
||||
void WeatherService::TidyTimeline() {
|
||||
uint64_t timeCurrent = 0;
|
||||
timeline.erase(std::remove_if(std::begin(timeline),
|
||||
std::end(timeline),
|
||||
@@ -269,15 +276,15 @@ namespace Pinetime {
|
||||
}),
|
||||
std::end(timeline));
|
||||
|
||||
std::sort(std::begin(timeline), std::end(timeline), compareTimelineEvents);
|
||||
std::sort(std::begin(timeline), std::end(timeline), CompareTimelineEvents);
|
||||
}
|
||||
|
||||
bool WeatherService::compareTimelineEvents(const std::unique_ptr<WeatherData::TimelineHeader>& first,
|
||||
bool WeatherService::CompareTimelineEvents(const std::unique_ptr<WeatherData::TimelineHeader>& first,
|
||||
const std::unique_ptr<WeatherData::TimelineHeader>& second) {
|
||||
return first->timestamp > second->timestamp;
|
||||
}
|
||||
|
||||
uint64_t WeatherService::getCurrentUNIXTimestamp() const {
|
||||
uint64_t WeatherService::GetCurrentUnixTimestamp() const {
|
||||
return std::chrono::duration_cast<std::chrono::seconds>(dateTimeController.CurrentDateTime().time_since_epoch()).count();
|
||||
}
|
||||
}
|
||||
|
@@ -32,7 +32,7 @@
|
||||
#include "WeatherData.h"
|
||||
#include <components/datetime/DateTimeController.h>
|
||||
|
||||
int WeatherCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt, void* arg);
|
||||
int WeatherCallback(uint16_t connHandle, uint16_t attrHandle, struct ble_gatt_access_ctxt* ctxt, void* arg);
|
||||
|
||||
namespace Pinetime {
|
||||
namespace System {
|
||||
@@ -46,20 +46,20 @@ namespace Pinetime {
|
||||
|
||||
void Init();
|
||||
|
||||
int OnCommand(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt);
|
||||
int OnCommand(uint16_t connHandle, uint16_t attrHandle, struct ble_gatt_access_ctxt* ctxt);
|
||||
|
||||
/*
|
||||
* Helper functions for quick access to currently valid data
|
||||
*/
|
||||
WeatherData::Location getCurrentLocation() const;
|
||||
WeatherData::Clouds getCurrentClouds() const;
|
||||
WeatherData::Obscuration getCurrentObscuration() const;
|
||||
WeatherData::Precipitation getCurrentPrecipitation() const;
|
||||
WeatherData::Wind getCurrentWind() const;
|
||||
WeatherData::Temperature getCurrentTemperature() const;
|
||||
WeatherData::Humidity getCurrentHumidity() const;
|
||||
WeatherData::Pressure getCurrentPressure() const;
|
||||
WeatherData::AirQuality getCurrentQuality() const;
|
||||
WeatherData::Location GetCurrentLocation() const;
|
||||
WeatherData::Clouds GetCurrentClouds() const;
|
||||
WeatherData::Obscuration GetCurrentObscuration() const;
|
||||
WeatherData::Precipitation GetCurrentPrecipitation() const;
|
||||
WeatherData::Wind GetCurrentWind() const;
|
||||
WeatherData::Temperature GetCurrentTemperature() const;
|
||||
WeatherData::Humidity GetCurrentHumidity() const;
|
||||
WeatherData::Pressure GetCurrentPressure() const;
|
||||
WeatherData::AirQuality GetCurrentQuality() const;
|
||||
|
||||
/*
|
||||
* Management functions
|
||||
@@ -68,16 +68,16 @@ namespace Pinetime {
|
||||
* Adds an event to the timeline
|
||||
* @return
|
||||
*/
|
||||
bool addEventToTimeline(std::unique_ptr<WeatherData::TimelineHeader> event);
|
||||
bool AddEventToTimeline(std::unique_ptr<WeatherData::TimelineHeader> event);
|
||||
/**
|
||||
* Gets the current timeline length
|
||||
*/
|
||||
size_t getTimelineLength() const;
|
||||
size_t GetTimelineLength() const;
|
||||
/**
|
||||
* Checks if an event of a certain type exists in the timeline
|
||||
* @return
|
||||
*/
|
||||
bool hasTimelineEventOfType(WeatherData::eventtype type) const;
|
||||
bool HasTimelineEventOfType(const WeatherData::eventtype type) const;
|
||||
|
||||
private:
|
||||
// 00030000-78fc-48fe-8e23-433b3a1942d0
|
||||
@@ -125,18 +125,18 @@ namespace Pinetime {
|
||||
* Cleans up the timeline of expired events
|
||||
* @return result code
|
||||
*/
|
||||
void tidyTimeline();
|
||||
void TidyTimeline();
|
||||
|
||||
/**
|
||||
* Compares two timeline events
|
||||
*/
|
||||
static bool compareTimelineEvents(const std::unique_ptr<WeatherData::TimelineHeader>& first,
|
||||
static bool CompareTimelineEvents(const std::unique_ptr<WeatherData::TimelineHeader>& first,
|
||||
const std::unique_ptr<WeatherData::TimelineHeader>& second);
|
||||
|
||||
/**
|
||||
* Returns current UNIX timestamp
|
||||
*/
|
||||
uint64_t getCurrentUNIXTimestamp() const;
|
||||
uint64_t GetCurrentUnixTimestamp() const;
|
||||
};
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user