1
0
Fork 0

Move PinetimeService to CurrentTimeService witha view to implement CTS

for time handling
This commit is contained in:
Adam Pigg 2020-05-04 21:43:51 +01:00
parent d33be52bc9
commit 206bdbf5eb
5 changed files with 27 additions and 28 deletions

View file

@ -319,7 +319,7 @@ list(APPEND SOURCE_FILES
Components/Ble/DeviceInformationService.cpp
Components/Ble/CurrentTimeClient.cpp
Components/Ble/AlertNotificationClient.cpp
Components/Ble/PinetimeService.cpp
Components/Ble/CurrentTimeService.cpp
Components/Ble/AlertNotificationService.cpp
drivers/Cst816s.cpp
FreeRTOS/port.c

View file

@ -1,24 +1,24 @@
#include "PinetimeService.h"
#include "CurrentTimeService.h"
#include <hal/nrf_rtc.h>
using namespace Pinetime::Controllers;
constexpr ble_uuid16_t PinetimeService::pinetimeUuid;
constexpr ble_uuid16_t PinetimeService::timeUuid;
constexpr ble_uuid16_t CurrentTimeService::ctsUuid;
constexpr ble_uuid16_t CurrentTimeService::ctChrUuid;
int PinetimeTimeCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg) {
auto pinetimeService = static_cast<PinetimeService*>(arg);
return pinetimeService->OnTimeAccessed(conn_handle, attr_handle, ctxt);
int CTSCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg) {
auto cts = static_cast<CurrentTimeService*>(arg);
return cts->OnTimeAccessed(conn_handle, attr_handle, ctxt);
}
void PinetimeService::Init() {
void CurrentTimeService::Init() {
ble_gatts_count_cfg(serviceDefinition);
ble_gatts_add_svcs(serviceDefinition);
}
int PinetimeService::OnTimeAccessed(uint16_t conn_handle, uint16_t attr_handle,
int CurrentTimeService::OnTimeAccessed(uint16_t conn_handle, uint16_t attr_handle,
struct ble_gatt_access_ctxt *ctxt) {
NRF_LOG_INFO("Setting time...");
@ -35,17 +35,18 @@ int PinetimeService::OnTimeAccessed(uint16_t conn_handle, uint16_t attr_handle,
0, result.hour, result.minute, result.second, nrf_rtc_counter_get(portNRF_RTC_REG));
}
//!TODO need to support reading the time.
return 0;
}
PinetimeService::PinetimeService(DateTime &dateTimeController) : m_dateTimeController{dateTimeController},
CurrentTimeService::CurrentTimeService(DateTime &dateTimeController) : m_dateTimeController{dateTimeController},
characteristicDefinition{
{
.uuid = (ble_uuid_t *) &timeUuid,
.access_cb = PinetimeTimeCallback,
.uuid = (ble_uuid_t *) &ctChrUuid,
.access_cb = CTSCallback,
.arg = this,
.flags = BLE_GATT_CHR_F_WRITE
.flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ
},
{
0
@ -55,7 +56,7 @@ PinetimeService::PinetimeService(DateTime &dateTimeController) : m_dateTimeContr
{
/* Device Information Service */
.type = BLE_GATT_SVC_TYPE_PRIMARY,
.uuid = (ble_uuid_t *) &pinetimeUuid,
.uuid = (ble_uuid_t *) &ctsUuid,
.characteristics = characteristicDefinition
},
{

View file

@ -6,28 +6,26 @@
namespace Pinetime {
namespace Controllers {
class PinetimeService {
class CurrentTimeService {
public:
PinetimeService(DateTime &dateTimeController);
CurrentTimeService(DateTime &dateTimeController);
void Init();
int OnTimeAccessed(uint16_t conn_handle, uint16_t attr_handle,
struct ble_gatt_access_ctxt *ctxt);
void setDateTimeController(DateTime *dateTimeController);
private:
static constexpr uint16_t pinetimeId {0x6666};
static constexpr uint16_t timeCharId {0x6667};
static constexpr uint16_t ctsId {0x1805};
static constexpr uint16_t ctsCharId {0x2a2b};
static constexpr ble_uuid16_t pinetimeUuid {
static constexpr ble_uuid16_t ctsUuid {
.u { .type = BLE_UUID_TYPE_16 },
.value = pinetimeId
.value = ctsId
};
static constexpr ble_uuid16_t timeUuid {
static constexpr ble_uuid16_t ctChrUuid {
.u { .type = BLE_UUID_TYPE_16 },
.value = timeCharId
.value = ctsCharId
};
struct ble_gatt_chr_def characteristicDefinition[2];

View file

@ -32,7 +32,7 @@ NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask,
currentTimeClient{dateTimeController},
alertNotificationClient{systemTask, notificationManager},
anService{systemTask, notificationManager},
pinetimeService{dateTimeController} {
currentTimeService{dateTimeController} {
}
@ -76,7 +76,7 @@ void NimbleController::Init() {
deviceInformationService.Init();
currentTimeClient.Init();
pinetimeService.Init();
currentTimeService.Init();
anService.Init();

View file

@ -5,7 +5,7 @@
#include "AlertNotificationClient.h"
#include "DeviceInformationService.h"
#include "CurrentTimeClient.h"
#include "PinetimeService.h"
#include "CurrentTimeService.h"
#include <host/ble_gap.h>
namespace Pinetime {
@ -38,7 +38,7 @@ namespace Pinetime {
CurrentTimeClient currentTimeClient;
AlertNotificationService anService;
AlertNotificationClient alertNotificationClient;
PinetimeService pinetimeService;
CurrentTimeService currentTimeService;
uint8_t addrType;
uint16_t connectionHandle;