Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Calendar / Timeline app and service #790

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Add timestamp and duration to events
Zorvalt committed Mar 8, 2022
commit b4fda1ffd3b19e0e5f88acf0df16c6858e318a8c
3 changes: 1 addition & 2 deletions src/components/ble/CalendarManager.cpp
Original file line number Diff line number Diff line change
@@ -9,8 +9,7 @@ using namespace Pinetime::Controllers;
* @return
*/
bool CalendarManager::isBefore(CalendarEvent& event1, CalendarEvent& event2) {
// TODO Use date instead of id for chronological order
return event1.id < event2.id;
return event1.timestamp < event2.timestamp;
}

CalendarManager::CalendarManager() {
2 changes: 2 additions & 0 deletions src/components/ble/CalendarManager.h
Original file line number Diff line number Diff line change
@@ -16,6 +16,8 @@ namespace Pinetime {
using Id = uint8_t;
Id id;
std::string title;
uint32_t timestamp;
uint32_t duration;
};

private:
8 changes: 7 additions & 1 deletion src/components/ble/CalendarService.cpp
Original file line number Diff line number Diff line change
@@ -8,6 +8,10 @@ int CalCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_acce
return pCalendarEventService->OnCommand(conn_handle, attr_handle, ctxt);
}

uint32_t bytesToInt(const char* bytes) {
return (bytes[0] << 24) | (bytes[1] << 16) | (bytes[2] << 8) | bytes[3];
}

CalendarService::CalendarService(Pinetime::System::SystemTask& system, CalendarManager& calendarManager)
: m_system(system), m_calendarManager(calendarManager) {
calUuid.value[14] = calId[0];
@@ -63,7 +67,9 @@ int CalendarService::OnCommand(uint16_t conn_handle, uint16_t attr_handle, struc
if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t*) &calAddEventUuid) == 0) {
CalendarManager::CalendarEvent event {
.id = s[0],
.title = &s[1],
.title = &s[9],
.timestamp = bytesToInt(&s[1]),
.duration = bytesToInt(&s[5]),
};
m_calendarManager.addEvent(event);
} else if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t*) &calDeleteEventUuid) == 0) {