Move PinetimeService to CurrentTimeService witha view to implement CTS
for time handling
This commit is contained in:
parent
5df4c1016a
commit
9935fb193c
5 changed files with 27 additions and 28 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
},
|
||||
{
|
|
@ -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];
|
|
@ -30,7 +30,7 @@ NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask,
|
|||
currentTimeClient{dateTimeController},
|
||||
alertNotificationClient{systemTask, notificationManager},
|
||||
anService{systemTask, notificationManager},
|
||||
pinetimeService{dateTimeController} {
|
||||
currentTimeService{dateTimeController} {
|
||||
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,7 @@ void NimbleController::Init() {
|
|||
|
||||
deviceInformationService.Init();
|
||||
currentTimeClient.Init();
|
||||
pinetimeService.Init();
|
||||
currentTimeService.Init();
|
||||
|
||||
anService.Init();
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
@ -37,7 +37,7 @@ namespace Pinetime {
|
|||
CurrentTimeClient currentTimeClient;
|
||||
AlertNotificationService anService;
|
||||
AlertNotificationClient alertNotificationClient;
|
||||
PinetimeService pinetimeService;
|
||||
CurrentTimeService currentTimeService;
|
||||
|
||||
uint8_t addrType;
|
||||
uint16_t connectionHandle;
|
||||
|
|
Loading…
Reference in a new issue