Merge branch 'develop' into remove-nm-reference
This commit is contained in:
@@ -54,7 +54,8 @@ void AlarmController::ScheduleAlarm() {
|
||||
|
||||
auto now = dateTimeController.CurrentDateTime();
|
||||
alarmTime = now;
|
||||
time_t ttAlarmTime = std::chrono::system_clock::to_time_t(alarmTime);
|
||||
time_t ttAlarmTime = std::chrono::system_clock::to_time_t(
|
||||
std::chrono::time_point_cast<std::chrono::system_clock::duration>(alarmTime));
|
||||
tm* tmAlarmTime = std::localtime(&ttAlarmTime);
|
||||
|
||||
// If the time being set has already passed today,the alarm should be set for tomorrow
|
||||
|
@@ -2,6 +2,7 @@
|
||||
#include <algorithm>
|
||||
#include "components/ble/NotificationManager.h"
|
||||
#include "systemtask/SystemTask.h"
|
||||
#include <nrf_log.h>
|
||||
|
||||
using namespace Pinetime::Controllers;
|
||||
constexpr ble_uuid16_t AlertNotificationClient::ansServiceUuid;
|
||||
|
@@ -2,6 +2,10 @@
|
||||
|
||||
using namespace Pinetime::Controllers;
|
||||
|
||||
bool Ble::IsConnected() const {
|
||||
return isConnected;
|
||||
}
|
||||
|
||||
void Ble::Connect() {
|
||||
isConnected = true;
|
||||
}
|
||||
@@ -10,6 +14,18 @@ void Ble::Disconnect() {
|
||||
isConnected = false;
|
||||
}
|
||||
|
||||
bool Ble::IsRadioEnabled() const {
|
||||
return isRadioEnabled;
|
||||
}
|
||||
|
||||
void Ble::EnableRadio() {
|
||||
isRadioEnabled = true;
|
||||
}
|
||||
|
||||
void Ble::DisableRadio() {
|
||||
isRadioEnabled = false;
|
||||
}
|
||||
|
||||
void Ble::StartFirmwareUpdate() {
|
||||
isFirmwareUpdating = true;
|
||||
}
|
||||
|
@@ -12,12 +12,14 @@ namespace Pinetime {
|
||||
enum class AddressTypes { Public, Random, RPA_Public, RPA_Random };
|
||||
|
||||
Ble() = default;
|
||||
bool IsConnected() const {
|
||||
return isConnected;
|
||||
}
|
||||
bool IsConnected() const;
|
||||
void Connect();
|
||||
void Disconnect();
|
||||
|
||||
bool IsRadioEnabled() const;
|
||||
void EnableRadio();
|
||||
void DisableRadio();
|
||||
|
||||
void StartFirmwareUpdate();
|
||||
void StopFirmwareUpdate();
|
||||
void FirmwareUpdateTotalBytes(uint32_t totalBytes);
|
||||
@@ -57,6 +59,7 @@ namespace Pinetime {
|
||||
|
||||
private:
|
||||
bool isConnected = false;
|
||||
bool isRadioEnabled = true;
|
||||
bool isFirmwareUpdating = false;
|
||||
uint32_t firmwareUpdateTotalBytes = 0;
|
||||
uint32_t firmwareUpdateCurrentBytes = 0;
|
||||
|
@@ -3,6 +3,7 @@
|
||||
#include "components/ble/BleController.h"
|
||||
#include "drivers/SpiNorFlash.h"
|
||||
#include "systemtask/SystemTask.h"
|
||||
#include <nrf_log.h>
|
||||
|
||||
using namespace Pinetime::Controllers;
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
#include "components/ble/HeartRateService.h"
|
||||
#include "components/heartrate/HeartRateController.h"
|
||||
#include "systemtask/SystemTask.h"
|
||||
#include <nrf_log.h>
|
||||
|
||||
using namespace Pinetime::Controllers;
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
#include "components/ble/MotionService.h"
|
||||
#include "components/motion/MotionController.h"
|
||||
#include "systemtask/SystemTask.h"
|
||||
#include <nrf_log.h>
|
||||
|
||||
using namespace Pinetime::Controllers;
|
||||
|
||||
|
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
#include "components/ble/MusicService.h"
|
||||
#include "systemtask/SystemTask.h"
|
||||
#include <cstring>
|
||||
|
||||
namespace {
|
||||
// 0000yyxx-78fc-48fe-8e23-433b3a1942d0
|
||||
@@ -47,6 +48,8 @@ namespace {
|
||||
constexpr ble_uuid128_t msRepeatCharUuid {CharUuid(0x0b, 0x00)};
|
||||
constexpr ble_uuid128_t msShuffleCharUuid {CharUuid(0x0c, 0x00)};
|
||||
|
||||
constexpr uint8_t MaxStringSize {40};
|
||||
|
||||
int MusicCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt, void* arg) {
|
||||
return static_cast<Pinetime::Controllers::MusicService*>(arg)->OnCommand(conn_handle, attr_handle, ctxt);
|
||||
}
|
||||
@@ -125,9 +128,21 @@ void Pinetime::Controllers::MusicService::Init() {
|
||||
int Pinetime::Controllers::MusicService::OnCommand(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt) {
|
||||
if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
|
||||
size_t notifSize = OS_MBUF_PKTLEN(ctxt->om);
|
||||
char data[notifSize + 1];
|
||||
data[notifSize] = '\0';
|
||||
os_mbuf_copydata(ctxt->om, 0, notifSize, data);
|
||||
size_t bufferSize = notifSize;
|
||||
if (notifSize > MaxStringSize) {
|
||||
bufferSize = MaxStringSize;
|
||||
}
|
||||
|
||||
char data[bufferSize + 1];
|
||||
os_mbuf_copydata(ctxt->om, 0, bufferSize, data);
|
||||
|
||||
if (notifSize > bufferSize) {
|
||||
data[bufferSize-1] = '.';
|
||||
data[bufferSize-2] = '.';
|
||||
data[bufferSize-3] = '.';
|
||||
}
|
||||
data[bufferSize] = '\0';
|
||||
|
||||
char* s = &data[0];
|
||||
if (ble_uuid_cmp(ctxt->chr->uuid, &msArtistCharUuid.u) == 0) {
|
||||
artistName = s;
|
||||
|
@@ -2,6 +2,7 @@
|
||||
#include <cstring>
|
||||
|
||||
#include <hal/nrf_rtc.h>
|
||||
#include <nrf_log.h>
|
||||
#define min // workaround: nimble's min/max macros conflict with libstdc++
|
||||
#define max
|
||||
#include <host/ble_gap.h>
|
||||
@@ -23,14 +24,14 @@
|
||||
using namespace Pinetime::Controllers;
|
||||
|
||||
NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask,
|
||||
Pinetime::Controllers::Ble& bleController,
|
||||
Ble& bleController,
|
||||
DateTime& dateTimeController,
|
||||
Pinetime::Controllers::NotificationManager& notificationManager,
|
||||
Controllers::Battery& batteryController,
|
||||
NotificationManager& notificationManager,
|
||||
Battery& batteryController,
|
||||
Pinetime::Drivers::SpiNorFlash& spiNorFlash,
|
||||
Controllers::HeartRateController& heartRateController,
|
||||
Controllers::MotionController& motionController,
|
||||
Controllers::FS& fs)
|
||||
HeartRateController& heartRateController,
|
||||
MotionController& motionController,
|
||||
FS& fs)
|
||||
: systemTask {systemTask},
|
||||
bleController {bleController},
|
||||
dateTimeController {dateTimeController},
|
||||
@@ -75,6 +76,7 @@ int GAPEventCallback(struct ble_gap_event* event, void* arg) {
|
||||
|
||||
void NimbleController::Init() {
|
||||
while (!ble_hs_synced()) {
|
||||
vTaskDelay(10);
|
||||
}
|
||||
|
||||
nptr = this;
|
||||
@@ -183,7 +185,9 @@ int NimbleController::OnGAPEvent(ble_gap_event* event) {
|
||||
case BLE_GAP_EVENT_ADV_COMPLETE:
|
||||
NRF_LOG_INFO("Advertising event : BLE_GAP_EVENT_ADV_COMPLETE");
|
||||
NRF_LOG_INFO("reason=%d; status=%0X", event->adv_complete.reason, event->connect.status);
|
||||
StartAdvertising();
|
||||
if (bleController.IsRadioEnabled() && !bleController.IsConnected()) {
|
||||
StartAdvertising();
|
||||
}
|
||||
break;
|
||||
|
||||
case BLE_GAP_EVENT_CONNECT:
|
||||
@@ -219,9 +223,11 @@ int NimbleController::OnGAPEvent(ble_gap_event* event) {
|
||||
currentTimeClient.Reset();
|
||||
alertNotificationClient.Reset();
|
||||
connectionHandle = BLE_HS_CONN_HANDLE_NONE;
|
||||
bleController.Disconnect();
|
||||
fastAdvCount = 0;
|
||||
StartAdvertising();
|
||||
if(bleController.IsConnected()) {
|
||||
bleController.Disconnect();
|
||||
fastAdvCount = 0;
|
||||
StartAdvertising();
|
||||
}
|
||||
break;
|
||||
|
||||
case BLE_GAP_EVENT_CONN_UPDATE:
|
||||
@@ -396,6 +402,23 @@ void NimbleController::NotifyBatteryLevel(uint8_t level) {
|
||||
}
|
||||
}
|
||||
|
||||
void NimbleController::EnableRadio() {
|
||||
bleController.EnableRadio();
|
||||
bleController.Disconnect();
|
||||
fastAdvCount = 0;
|
||||
StartAdvertising();
|
||||
}
|
||||
|
||||
void NimbleController::DisableRadio() {
|
||||
bleController.DisableRadio();
|
||||
if (bleController.IsConnected()) {
|
||||
ble_gap_terminate(connectionHandle, BLE_ERR_REM_USER_CONN_TERM);
|
||||
bleController.Disconnect();
|
||||
} else {
|
||||
ble_gap_adv_stop();
|
||||
}
|
||||
}
|
||||
|
||||
void NimbleController::PersistBond(struct ble_gap_conn_desc& desc) {
|
||||
union ble_store_key key;
|
||||
union ble_store_value our_sec, peer_sec, peer_cccd_set[MYNEWT_VAL(BLE_STORE_MAX_CCCDS)] = {0};
|
||||
|
@@ -14,6 +14,7 @@
|
||||
#include "components/ble/CurrentTimeService.h"
|
||||
#include "components/ble/DeviceInformationService.h"
|
||||
#include "components/ble/DfuService.h"
|
||||
#include "components/ble/FSService.h"
|
||||
#include "components/ble/HeartRateService.h"
|
||||
#include "components/ble/ImmediateAlertService.h"
|
||||
#include "components/ble/MusicService.h"
|
||||
@@ -22,7 +23,6 @@
|
||||
#include "components/ble/MotionService.h"
|
||||
#include "components/ble/weather/WeatherService.h"
|
||||
#include "components/fs/FS.h"
|
||||
#include "components/ble/FSService.h"
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Drivers {
|
||||
@@ -42,27 +42,17 @@ namespace Pinetime {
|
||||
|
||||
public:
|
||||
NimbleController(Pinetime::System::SystemTask& systemTask,
|
||||
Pinetime::Controllers::Ble& bleController,
|
||||
Ble& bleController,
|
||||
DateTime& dateTimeController,
|
||||
Pinetime::Controllers::NotificationManager& notificationManager,
|
||||
Controllers::Battery& batteryController,
|
||||
NotificationManager& notificationManager,
|
||||
Battery& batteryController,
|
||||
Pinetime::Drivers::SpiNorFlash& spiNorFlash,
|
||||
Controllers::HeartRateController& heartRateController,
|
||||
Controllers::MotionController& motionController,
|
||||
Pinetime::Controllers::FS& fs);
|
||||
HeartRateController& heartRateController,
|
||||
MotionController& motionController,
|
||||
FS& fs);
|
||||
void Init();
|
||||
void StartAdvertising();
|
||||
int OnGAPEvent(ble_gap_event* event);
|
||||
|
||||
int OnDiscoveryEvent(uint16_t i, const ble_gatt_error* pError, const ble_gatt_svc* pSvc);
|
||||
int OnCTSCharacteristicDiscoveryEvent(uint16_t connectionHandle, const ble_gatt_error* error, const ble_gatt_chr* characteristic);
|
||||
int OnANSCharacteristicDiscoveryEvent(uint16_t connectionHandle, const ble_gatt_error* error, const ble_gatt_chr* characteristic);
|
||||
int OnCurrentTimeReadResult(uint16_t connectionHandle, const ble_gatt_error* error, ble_gatt_attr* attribute);
|
||||
int OnANSDescriptorDiscoveryEventCallback(uint16_t connectionHandle,
|
||||
const ble_gatt_error* error,
|
||||
uint16_t characteristicValueHandle,
|
||||
const ble_gatt_dsc* descriptor);
|
||||
|
||||
void StartDiscovery();
|
||||
|
||||
Pinetime::Controllers::MusicService& music() {
|
||||
@@ -83,7 +73,10 @@ namespace Pinetime {
|
||||
|
||||
void RestartFastAdv() {
|
||||
fastAdvCount = 0;
|
||||
}
|
||||
};
|
||||
|
||||
void EnableRadio();
|
||||
void DisableRadio();
|
||||
|
||||
private:
|
||||
void PersistBond(struct ble_gap_conn_desc& desc);
|
||||
@@ -91,11 +84,11 @@ namespace Pinetime {
|
||||
|
||||
static constexpr const char* deviceName = "InfiniTime";
|
||||
Pinetime::System::SystemTask& systemTask;
|
||||
Pinetime::Controllers::Ble& bleController;
|
||||
Ble& bleController;
|
||||
DateTime& dateTimeController;
|
||||
Pinetime::Drivers::SpiNorFlash& spiNorFlash;
|
||||
Pinetime::Controllers::FS& fs;
|
||||
Pinetime::Controllers::DfuService dfuService;
|
||||
FS& fs;
|
||||
DfuService dfuService;
|
||||
|
||||
DeviceInformationService deviceInformationService;
|
||||
CurrentTimeClient currentTimeClient;
|
||||
|
@@ -108,11 +108,11 @@ void DateTime::UpdateTime(uint32_t systickCounter) {
|
||||
}
|
||||
}
|
||||
|
||||
const char* DateTime::MonthShortToString() {
|
||||
const char* DateTime::MonthShortToString() const {
|
||||
return MonthsString[static_cast<uint8_t>(month)];
|
||||
}
|
||||
|
||||
const char* DateTime::DayOfWeekShortToString() {
|
||||
const char* DateTime::DayOfWeekShortToString() const {
|
||||
return DaysStringShort[static_cast<uint8_t>(dayOfWeek)];
|
||||
}
|
||||
|
||||
|
@@ -61,8 +61,8 @@ namespace Pinetime {
|
||||
return second;
|
||||
}
|
||||
|
||||
const char* MonthShortToString();
|
||||
const char* DayOfWeekShortToString();
|
||||
const char* MonthShortToString() const;
|
||||
const char* DayOfWeekShortToString() const;
|
||||
static const char* MonthShortToStringLow(Months month);
|
||||
|
||||
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> CurrentDateTime() const {
|
||||
|
@@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include "components/heartrate/Biquad.h"
|
||||
#include "components/heartrate/Ptagc.h"
|
||||
|
||||
|
@@ -12,7 +12,7 @@ namespace Pinetime {
|
||||
void Init();
|
||||
void RunForDuration(uint8_t motorDuration);
|
||||
void StartRinging();
|
||||
static void StopRinging();
|
||||
void StopRinging();
|
||||
|
||||
private:
|
||||
static void Ring(void* p_context);
|
||||
|
@@ -26,7 +26,7 @@ void Settings::LoadSettingsFromFile() {
|
||||
SettingsData bufferSettings;
|
||||
lfs_file_t settingsFile;
|
||||
|
||||
if ( fs.FileOpen(&settingsFile, "/settings.dat", LFS_O_RDWR | LFS_O_CREAT) != LFS_ERR_OK) {
|
||||
if ( fs.FileOpen(&settingsFile, "/settings.dat", LFS_O_RDONLY) != LFS_ERR_OK) {
|
||||
return;
|
||||
}
|
||||
fs.FileRead(&settingsFile, reinterpret_cast<uint8_t*>(&bufferSettings), sizeof(settings));
|
||||
@@ -39,7 +39,7 @@ void Settings::LoadSettingsFromFile() {
|
||||
void Settings::SaveSettingsToFile() {
|
||||
lfs_file_t settingsFile;
|
||||
|
||||
if ( fs.FileOpen(&settingsFile, "/settings.dat", LFS_O_RDWR | LFS_O_CREAT) != LFS_ERR_OK) {
|
||||
if ( fs.FileOpen(&settingsFile, "/settings.dat", LFS_O_WRONLY | LFS_O_CREAT) != LFS_ERR_OK) {
|
||||
return;
|
||||
}
|
||||
fs.FileWrite(&settingsFile, reinterpret_cast<uint8_t*>(&settings), sizeof(settings));
|
||||
|
@@ -18,7 +18,23 @@ namespace Pinetime {
|
||||
Shake = 3,
|
||||
};
|
||||
enum class Colors : uint8_t {
|
||||
White, Silver, Gray, Black, Red, Maroon, Yellow, Olive, Lime, Green, Cyan, Teal, Blue, Navy, Magenta, Purple, Orange
|
||||
White,
|
||||
Silver,
|
||||
Gray,
|
||||
Black,
|
||||
Red,
|
||||
Maroon,
|
||||
Yellow,
|
||||
Olive,
|
||||
Lime,
|
||||
Green,
|
||||
Cyan,
|
||||
Teal,
|
||||
Blue,
|
||||
Navy,
|
||||
Magenta,
|
||||
Purple,
|
||||
Orange
|
||||
};
|
||||
struct PineTimeStyle {
|
||||
Colors ColorTime = Colors::Teal;
|
||||
@@ -170,18 +186,29 @@ namespace Pinetime {
|
||||
}
|
||||
settings.brightLevel = level;
|
||||
};
|
||||
|
||||
Controllers::BrightnessController::Levels GetBrightness() const {
|
||||
return settings.brightLevel;
|
||||
};
|
||||
|
||||
void SetStepsGoal( uint32_t goal ) {
|
||||
if ( goal != settings.stepsGoal ) {
|
||||
void SetStepsGoal(uint32_t goal) {
|
||||
if (goal != settings.stepsGoal) {
|
||||
settingsChanged = true;
|
||||
}
|
||||
settings.stepsGoal = goal;
|
||||
};
|
||||
|
||||
uint32_t GetStepsGoal() const { return settings.stepsGoal; };
|
||||
uint32_t GetStepsGoal() const {
|
||||
return settings.stepsGoal;
|
||||
};
|
||||
|
||||
void SetBleRadioEnabled(bool enabled) {
|
||||
bleRadioEnabled = enabled;
|
||||
};
|
||||
|
||||
bool GetBleRadioEnabled() const {
|
||||
return bleRadioEnabled;
|
||||
};
|
||||
|
||||
private:
|
||||
Pinetime::Controllers::FS& fs;
|
||||
@@ -210,6 +237,10 @@ namespace Pinetime {
|
||||
|
||||
uint8_t appMenu = 0;
|
||||
uint8_t settingsMenu = 0;
|
||||
/* ble state is intentionally not saved with the other watch settings and initialized
|
||||
* to off (false) on every boot because we always want ble to be enabled on startup
|
||||
*/
|
||||
bool bleRadioEnabled = true;
|
||||
|
||||
void LoadSettingsFromFile();
|
||||
void SaveSettingsToFile();
|
||||
|
Reference in New Issue
Block a user