summaryrefslogtreecommitdiff
path: root/src/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/components')
-rw-r--r--src/components/alarm/AlarmController.cpp4
-rw-r--r--src/components/ble/BleController.h5
-rw-r--r--src/components/ble/NimbleController.cpp47
-rw-r--r--src/components/brightness/BrightnessController.h2
-rw-r--r--src/components/datetime/DateTimeController.cpp43
-rw-r--r--src/components/datetime/DateTimeController.h19
-rw-r--r--src/components/motion/MotionController.cpp28
-rw-r--r--src/components/motion/MotionController.h15
-rw-r--r--src/components/motor/MotorController.h8
-rw-r--r--src/components/settings/Settings.h19
-rw-r--r--src/components/timer/TimerController.cpp27
-rw-r--r--src/components/timer/TimerController.h13
12 files changed, 131 insertions, 99 deletions
diff --git a/src/components/alarm/AlarmController.cpp b/src/components/alarm/AlarmController.cpp
index 7cecc9c..cd011f6 100644
--- a/src/components/alarm/AlarmController.cpp
+++ b/src/components/alarm/AlarmController.cpp
@@ -46,9 +46,7 @@ void AlarmController::SetAlarmTime(uint8_t alarmHr, uint8_t alarmMin) {
void AlarmController::OnAdjustTime() {
- if (state != AlarmState::Set) {
- return;
- }
+ if (state != AlarmState::Set) { return; }
xTimerStop(alarmAppTimer, 0);
auto now = dateTimeController.CurrentDateTime();
diff --git a/src/components/ble/BleController.h b/src/components/ble/BleController.h
index 675ede2..b15d688 100644
--- a/src/components/ble/BleController.h
+++ b/src/components/ble/BleController.h
@@ -20,6 +20,10 @@ namespace Pinetime {
void EnableRadio();
void DisableRadio();
+ void EnablePasskey() { isPasskeyEnabled = true; }
+ void DisablePasskey() { isPasskeyEnabled = false; }
+ bool IsPasskeyEnabled() { return isPasskeyEnabled; }
+
void StartFirmwareUpdate();
void StopFirmwareUpdate();
void FirmwareUpdateTotalBytes(uint32_t totalBytes);
@@ -60,6 +64,7 @@ namespace Pinetime {
private:
bool isConnected = false;
bool isRadioEnabled = true;
+ bool isPasskeyEnabled = false;
bool isFirmwareUpdating = false;
uint32_t firmwareUpdateTotalBytes = 0;
uint32_t firmwareUpdateCurrentBytes = 0;
diff --git a/src/components/ble/NimbleController.cpp b/src/components/ble/NimbleController.cpp
index d2d6dc0..ce54bb7 100644
--- a/src/components/ble/NimbleController.cpp
+++ b/src/components/ble/NimbleController.cpp
@@ -115,25 +115,38 @@ void NimbleController::Init() {
ASSERT(rc == 0);
bleController.Address(std::move(address));
- switch (addrType) {
- case BLE_OWN_ADDR_PUBLIC:
- bleController.AddressType(Ble::AddressTypes::Public);
- break;
- case BLE_OWN_ADDR_RANDOM:
- bleController.AddressType(Ble::AddressTypes::Random);
- break;
- case BLE_OWN_ADDR_RPA_PUBLIC_DEFAULT:
- bleController.AddressType(Ble::AddressTypes::RPA_Public);
- break;
- case BLE_OWN_ADDR_RPA_RANDOM_DEFAULT:
- bleController.AddressType(Ble::AddressTypes::RPA_Random);
- break;
+ if (bleController.IsPasskeyEnabled()) {
+ switch (addrType) {
+ case BLE_OWN_ADDR_PUBLIC:
+ bleController.AddressType(Ble::AddressTypes::Public);
+ break;
+ case BLE_OWN_ADDR_RANDOM:
+ bleController.AddressType(Ble::AddressTypes::Random);
+ break;
+ case BLE_OWN_ADDR_RPA_PUBLIC_DEFAULT:
+ bleController.AddressType(Ble::AddressTypes::RPA_Public);
+ break;
+ case BLE_OWN_ADDR_RPA_RANDOM_DEFAULT:
+ bleController.AddressType(Ble::AddressTypes::RPA_Random);
+ break;
+ }
+ } else {
+ switch (addrType) {
+ case BLE_OWN_ADDR_PUBLIC:
+ bleController.AddressType(Ble::AddressTypes::Public);
+ break;
+ default:
+ bleController.AddressType(Ble::AddressTypes::Random);
+ break;
+ }
}
rc = ble_gatts_start();
ASSERT(rc == 0);
- RestoreBond();
+ if (bleController.IsPasskeyEnabled()) {
+ RestoreBond();
+ }
StartAdvertising();
}
@@ -216,7 +229,7 @@ int NimbleController::OnGAPEvent(ble_gap_event* event) {
NRF_LOG_INFO("Disconnect event : BLE_GAP_EVENT_DISCONNECT");
NRF_LOG_INFO("disconnect reason=%d", event->disconnect.reason);
- if (event->disconnect.conn.sec_state.bonded) {
+ if (bleController.IsPasskeyEnabled() && event->disconnect.conn.sec_state.bonded) {
PersistBond(event->disconnect.conn);
}
@@ -251,7 +264,7 @@ int NimbleController::OnGAPEvent(ble_gap_event* event) {
NRF_LOG_INFO("Security event : BLE_GAP_EVENT_ENC_CHANGE");
NRF_LOG_INFO("encryption change event; status=%0X ", event->enc_change.status);
- if (event->enc_change.status == 0) {
+ if (bleController.IsPasskeyEnabled() && event->enc_change.status == 0) {
struct ble_gap_conn_desc desc;
ble_gap_conn_find(event->enc_change.conn_handle, &desc);
if (desc.sec_state.bonded) {
@@ -280,7 +293,7 @@ int NimbleController::OnGAPEvent(ble_gap_event* event) {
* Use the tinycrypt prng here since rand() is predictable.
*/
NRF_LOG_INFO("Security event : BLE_GAP_EVENT_PASSKEY_ACTION");
- if (event->passkey.params.action == BLE_SM_IOACT_DISP) {
+ if (bleController.IsPasskeyEnabled() && event->passkey.params.action == BLE_SM_IOACT_DISP) {
struct ble_sm_io pkey = {0};
pkey.action = event->passkey.params.action;
diff --git a/src/components/brightness/BrightnessController.h b/src/components/brightness/BrightnessController.h
index 0d7ac2f..1ee5603 100644
--- a/src/components/brightness/BrightnessController.h
+++ b/src/components/brightness/BrightnessController.h
@@ -6,7 +6,7 @@ namespace Pinetime {
namespace Controllers {
class BrightnessController {
public:
- enum class Levels { Off, Low, Medium, High };
+ enum class Levels : uint8_t { Off = 0, Low = 1, Medium = 2, High = 3 };
void Init();
void Set(Levels level);
diff --git a/src/components/datetime/DateTimeController.cpp b/src/components/datetime/DateTimeController.cpp
index 2656764..3d7df5a 100644
--- a/src/components/datetime/DateTimeController.cpp
+++ b/src/components/datetime/DateTimeController.cpp
@@ -14,7 +14,7 @@ namespace {
DateTime::DateTime(Controllers::Settings& settingsController) : settingsController {settingsController} {
}
-void DateTime::SetCurrentTime(std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> t) {
+void DateTime::SetCurrentTime(std::chrono::time_point<std::chrono::system_clock, std::chrono::seconds> t) {
this->currentDateTime = t;
UpdateTime(previousSystickCounter); // Update internal state without updating the time
}
@@ -31,7 +31,7 @@ void DateTime::SetTime(
};
tm.tm_isdst = -1; // Use DST value from local time zone
auto previousDateTime = currentDateTime;
- currentDateTime = std::chrono::system_clock::from_time_t(std::mktime(&tm));
+ currentDateTime = std::chrono::time_point_cast<std::chrono::seconds>(std::chrono::system_clock::from_time_t(std::mktime(&tm)));
NRF_LOG_INFO("%d %d %d ", day, month, year);
NRF_LOG_INFO("%d %d %d ", hour, minute, second);
@@ -39,7 +39,7 @@ void DateTime::SetTime(
UpdateTime(systickCounter);
NRF_LOG_INFO("* %d %d %d ", this->hour, this->minute, this->second);
- NRF_LOG_INFO("* %d %d %d ", this->day, this->month, this->year);
+ NRF_LOG_INFO("* %d %d %d ", this->day, ((int)this->month), this->year);
decltype(currentDateTime - previousDateTime) timeDifference;
@@ -56,27 +56,20 @@ void DateTime::SetTime(
void DateTime::UpdateTime(uint32_t systickCounter) {
// Handle systick counter overflow
- uint32_t systickDelta = 0;
- if (systickCounter < previousSystickCounter) {
- systickDelta = 0xffffff - previousSystickCounter;
- systickDelta += systickCounter + 1;
- } else {
- systickDelta = systickCounter - previousSystickCounter;
- }
+ uint32_t systickDelta = (systickCounter - previousSystickCounter) & 0xffffff;
+ previousSystickCounter = systickCounter;
/*
* 1000 ms = 1024 ticks
*/
- auto correctedDelta = systickDelta / 1024;
- auto rest = (systickDelta - (correctedDelta * 1024));
- if (systickCounter >= rest) {
- previousSystickCounter = systickCounter - rest;
- } else {
- previousSystickCounter = 0xffffff - (rest - systickCounter);
- }
+ // auto newSeconds = systickDelta >> 10;
+ // auto rest = systickDelta & ((1 << 10)-1);
+ subsecondTicks += systickDelta & ((1 << 10)-1);
+ systickDelta = (systickDelta >> 10) + (subsecondTicks >> 10);
+ subsecondTicks &= ((1 << 10)-1);
- currentDateTime += std::chrono::seconds(correctedDelta);
- uptime += std::chrono::seconds(correctedDelta);
+ currentDateTime += std::chrono::seconds(systickDelta);
+ uptime += std::chrono::seconds(systickDelta);
auto dp = date::floor<date::days>(currentDateTime);
auto time = date::make_time(currentDateTime - dp);
@@ -100,15 +93,15 @@ void DateTime::UpdateTime(uint32_t systickCounter) {
isHourAlreadyNotified = false;
}
- if ((minute == 0 || minute == 30) && !isHalfHourAlreadyNotified) {
- isHalfHourAlreadyNotified = true;
+ if (minute%chimePeriod) {
+ hasChimed = false;
+ } else if (!hasChimed) {
if (systemTask != nullptr) {
- systemTask->PushMessage(System::Messages::OnNewHalfHour);
+ systemTask->PushMessage(System::Messages::OnChime);
+ hasChimed = true;
}
- } else if (minute != 0 && minute != 30) {
- isHalfHourAlreadyNotified = false;
}
-
+
// Notify new day to SystemTask
if (hour == 0 and not isMidnightAlreadyNotified) {
isMidnightAlreadyNotified = true;
diff --git a/src/components/datetime/DateTimeController.h b/src/components/datetime/DateTimeController.h
index 00bbc2e..ca7320c 100644
--- a/src/components/datetime/DateTimeController.h
+++ b/src/components/datetime/DateTimeController.h
@@ -60,12 +60,17 @@ namespace Pinetime {
uint8_t Seconds() const {
return second;
}
+ uint8_t Deciseconds() const {
+ uint16_t x = subsecondTicks;
+ x *= 10;
+ return x >> 10;
+ }
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 {
+ std::chrono::time_point<std::chrono::system_clock, std::chrono::seconds> CurrentDateTime() const {
return currentDateTime;
}
std::chrono::seconds Uptime() const {
@@ -73,7 +78,7 @@ namespace Pinetime {
}
void Register(System::SystemTask* systemTask);
- void SetCurrentTime(std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> t);
+ void SetCurrentTime(std::chrono::time_point<std::chrono::system_clock, std::chrono::seconds> t);
std::string FormattedTime();
private:
@@ -84,14 +89,18 @@ namespace Pinetime {
uint8_t hour = 0;
uint8_t minute = 0;
uint8_t second = 0;
+ uint16_t subsecondTicks = 0;
- uint32_t previousSystickCounter = 0;
- std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> currentDateTime;
+ uint32_t previousSystickCounter = 0; // FIXME: This could probably be 16 bits?
+ std::chrono::time_point<std::chrono::system_clock, std::chrono::seconds> currentDateTime;
std::chrono::seconds uptime {0};
bool isMidnightAlreadyNotified = false;
bool isHourAlreadyNotified = true;
- bool isHalfHourAlreadyNotified = true;
+ bool hasChimed = true;
+ public:
+ uint8_t chimePeriod = 5;
+ private:
System::SystemTask* systemTask = nullptr;
Controllers::Settings& settingsController;
};
diff --git a/src/components/motion/MotionController.cpp b/src/components/motion/MotionController.cpp
index 7dd3212..c57d8aa 100644
--- a/src/components/motion/MotionController.cpp
+++ b/src/components/motion/MotionController.cpp
@@ -11,6 +11,7 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps)
service->OnNewMotionValues(x, y, z);
}
+ lastY = this->y;
this->x = x;
this->y = y;
this->z = z;
@@ -21,27 +22,8 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps)
}
}
-bool MotionController::Should_RaiseWake(bool isSleeping) {
- if ((x + 335) <= 670 && z < 0) {
- if (not isSleeping) {
- if (y <= 0) {
- return false;
- } else {
- lastYForWakeUp = 0;
- return false;
- }
- }
-
- if (y >= 0) {
- lastYForWakeUp = 0;
- return false;
- }
- if (y + 230 < lastYForWakeUp) {
- lastYForWakeUp = y;
- return true;
- }
- }
- return false;
+bool MotionController::ShouldRaiseWake() const {
+ return x >= -384 && x <= 384 && z <= 0 && y <= -160 && y <= lastY - 160;
}
bool MotionController::Should_ShakeWake(uint16_t thresh) {
@@ -66,6 +48,10 @@ int32_t MotionController::currentShakeSpeed() {
return accumulatedspeed;
}
+bool MotionController::ShouldLowerSleep() const {
+ return y >= 512 && y >= lastY + 192;
+}
+
void MotionController::IsSensorOk(bool isOk) {
isSensorOk = isOk;
}
diff --git a/src/components/motion/MotionController.h b/src/components/motion/MotionController.h
index f80b11b..297db59 100644
--- a/src/components/motion/MotionController.h
+++ b/src/components/motion/MotionController.h
@@ -25,6 +25,9 @@ namespace Pinetime {
int16_t Z() const {
return z;
}
+ int16_t LastY() const {
+ return lastY;
+ }
uint32_t NbSteps() const {
return nbSteps;
}
@@ -36,9 +39,10 @@ namespace Pinetime {
return currentTripSteps;
}
+ bool ShouldRaiseWake() const;
bool Should_ShakeWake(uint16_t thresh);
- bool Should_RaiseWake(bool isSleeping);
int32_t currentShakeSpeed();
+ bool ShouldLowerSleep() const;
void IsSensorOk(bool isOk);
bool IsSensorOk() const {
return isSensorOk;
@@ -54,9 +58,10 @@ namespace Pinetime {
private:
uint32_t nbSteps;
uint32_t currentTripSteps = 0;
- int16_t x;
- int16_t y;
- int16_t z;
+ int16_t x = 0;
+ int16_t y = 0;
+ int16_t z = 0;
+ int16_t lastY = 0;
int16_t lastYForWakeUp = 0;
bool isSensorOk = false;
DeviceTypes deviceType = DeviceTypes::Unknown;
@@ -69,4 +74,4 @@ namespace Pinetime {
uint32_t lastShakeTime = 0;
};
}
-} \ No newline at end of file
+}
diff --git a/src/components/motor/MotorController.h b/src/components/motor/MotorController.h
index 3c6cbd2..8dfa2bd 100644
--- a/src/components/motor/MotorController.h
+++ b/src/components/motor/MotorController.h
@@ -5,17 +5,23 @@
#include <cstdint>
namespace Pinetime {
+ namespace System {
+ class SystemTask;
+ }
namespace Controllers {
class MotorController {
public:
MotorController() = default;
- void Init();
void RunForDuration(uint8_t motorDuration);
void StartRinging();
void StopRinging();
+ protected:
+ friend class Pinetime::System::SystemTask;
+ void Init();
+
private:
static void Ring(TimerHandle_t xTimer);
static void StopMotor(TimerHandle_t xTimer);
diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h
index 44a1a85..b85b5b4 100644
--- a/src/components/settings/Settings.h
+++ b/src/components/settings/Settings.h
@@ -10,12 +10,13 @@ namespace Pinetime {
public:
enum class ClockType : uint8_t { H24, H12 };
enum class Notification : uint8_t { ON, OFF };
- enum class ChimesOption : uint8_t { None, Hours, HalfHours };
+ enum class ChimesOption : uint8_t { None, Hours, HalfHours, FiveMinutes };
enum class WakeUpMode : uint8_t {
SingleTap = 0,
DoubleTap = 1,
RaiseWrist = 2,
Shake = 3,
+ LowerWrist = 4
};
enum class Colors : uint8_t {
White,
@@ -172,7 +173,7 @@ namespace Pinetime {
}
};
- std::bitset<4> getWakeUpModes() const {
+ std::bitset<5> getWakeUpModes() const {
return settings.wakeUpMode;
}
@@ -210,10 +211,18 @@ namespace Pinetime {
return bleRadioEnabled;
};
+ void SetBluetoothPasskeyEnabled(bool enabled) {
+ settings.bluetoothPasskeyEnabled = enabled;
+ };
+
+ bool GetBluetoothPasskeyEnabled() const {
+ return settings.bluetoothPasskeyEnabled;
+ };
+
private:
Pinetime::Controllers::FS& fs;
- static constexpr uint32_t settingsVersion = 0x0003;
+ static constexpr uint32_t settingsVersion = 0x3505;
struct SettingsData {
uint32_t version = settingsVersion;
uint32_t stepsGoal = 10000;
@@ -227,9 +236,11 @@ namespace Pinetime {
PineTimeStyle PTS;
- std::bitset<4> wakeUpMode {0};
+ std::bitset<5> wakeUpMode {0};
uint16_t shakeWakeThreshold = 150;
+
Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium;
+ bool bluetoothPasskeyEnabled = false;
};
SettingsData settings;
diff --git a/src/components/timer/TimerController.cpp b/src/components/timer/TimerController.cpp
index 31635a5..9456909 100644
--- a/src/components/timer/TimerController.cpp
+++ b/src/components/timer/TimerController.cpp
@@ -28,35 +28,36 @@ void TimerController::StartTimer(uint32_t duration) {
xTimerStart(timerAppTimer, 0);
endTicks = currentTicks + durationTicks;
timerRunning = true;
+ overtime = false;
}
-uint32_t TimerController::GetTimeRemaining() {
+int32_t TimerController::GetSecondsRemaining() {
if (!timerRunning) {
return 0;
}
auto currentTicks = xTaskGetTickCount();
- TickType_t deltaTicks = 0;
- if (currentTicks > endTicks) {
- deltaTicks = 0xffffffff - currentTicks;
- deltaTicks += (endTicks + 1);
- } else {
- deltaTicks = endTicks - currentTicks;
- }
+ int32_t deltaTicks = static_cast<int32_t>(endTicks) - static_cast<int32_t>(currentTicks);
- return (static_cast<TickType_t>(deltaTicks) / static_cast<TickType_t>(configTICK_RATE_HZ)) * 1000;
+ return (deltaTicks / static_cast<int32_t>(configTICK_RATE_HZ));
}
void TimerController::StopTimer() {
xTimerStop(timerAppTimer, 0);
timerRunning = false;
+ overtime = false;
}
-bool TimerController::IsRunning() {
- return timerRunning;
+void TimerController::StopAlerting() {
+ if (systemTask != nullptr) {
+ systemTask->PushMessage(System::Messages::StopRinging);
+ }
}
+
void TimerController::OnTimerEnd() {
- timerRunning = false;
- if (systemTask != nullptr)
+ overtime = true;
+ if (systemTask != nullptr) {
systemTask->PushMessage(System::Messages::OnTimerDone);
+ }
}
+
diff --git a/src/components/timer/TimerController.h b/src/components/timer/TimerController.h
index 24d7150..b1b8d3c 100644
--- a/src/components/timer/TimerController.h
+++ b/src/components/timer/TimerController.h
@@ -18,10 +18,14 @@ namespace Pinetime {
void StartTimer(uint32_t duration);
void StopTimer();
-
- uint32_t GetTimeRemaining();
-
- bool IsRunning();
+ void StopAlerting();
+ int32_t GetSecondsRemaining();
+ bool IsOvertime() {
+ return overtime;
+ }
+ bool IsRunning() {
+ return timerRunning;
+ }
void OnTimerEnd();
@@ -34,6 +38,7 @@ namespace Pinetime {
TimerHandle_t timerAppTimer;
TickType_t endTicks;
bool timerRunning = false;
+ bool overtime = false;
};
}
} \ No newline at end of file