summaryrefslogtreecommitdiff
path: root/src/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/components')
-rw-r--r--src/components/ble/BatteryInformationService.cpp2
-rw-r--r--src/components/ble/NimbleController.cpp6
-rw-r--r--src/components/ble/NimbleController.h2
-rw-r--r--src/components/datetime/DateTimeController.cpp19
-rw-r--r--src/components/datetime/DateTimeController.h2
-rw-r--r--src/components/motion/MotionController.cpp47
-rw-r--r--src/components/motion/MotionController.h20
-rw-r--r--src/components/settings/Settings.h36
8 files changed, 113 insertions, 21 deletions
diff --git a/src/components/ble/BatteryInformationService.cpp b/src/components/ble/BatteryInformationService.cpp
index 82df7b15..9a3f86f5 100644
--- a/src/components/ble/BatteryInformationService.cpp
+++ b/src/components/ble/BatteryInformationService.cpp
@@ -17,7 +17,7 @@ BatteryInformationService::BatteryInformationService(Controllers::Battery& batte
characteristicDefinition {{.uuid = &batteryLevelUuid.u,
.access_cb = BatteryInformationServiceCallback,
.arg = this,
- .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_READ_ENC | BLE_GATT_CHR_F_READ_AUTHEN | BLE_GATT_CHR_F_NOTIFY,
+ .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_NOTIFY,
.val_handle = &batteryLevelHandle},
{0}},
serviceDefinition {
diff --git a/src/components/ble/NimbleController.cpp b/src/components/ble/NimbleController.cpp
index 3bf1ec80..d8510bd3 100644
--- a/src/components/ble/NimbleController.cpp
+++ b/src/components/ble/NimbleController.cpp
@@ -134,9 +134,7 @@ void NimbleController::Init() {
RestoreBond();
- if (!ble_gap_adv_active() && !bleController.IsConnected()) {
- StartAdvertising();
- }
+ StartAdvertising();
}
void NimbleController::StartAdvertising() {
@@ -274,7 +272,7 @@ int NimbleController::OnGAPEvent(ble_gap_event* event) {
* display capability only so we only handle the "display" action here.
*
* Standards insist that the rand() PRNG be deterministic.
- * Use the nimble TRNG here since rand() is predictable.
+ * 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) {
diff --git a/src/components/ble/NimbleController.h b/src/components/ble/NimbleController.h
index 7a387037..2b300e63 100644
--- a/src/components/ble/NimbleController.h
+++ b/src/components/ble/NimbleController.h
@@ -110,8 +110,8 @@ namespace Pinetime {
ImmediateAlertService immediateAlertService;
HeartRateService heartRateService;
MotionService motionService;
- ServiceDiscovery serviceDiscovery;
FSService fsService;
+ ServiceDiscovery serviceDiscovery;
uint8_t addrType;
uint16_t connectionHandle = BLE_HS_CONN_HANDLE_NONE;
diff --git a/src/components/datetime/DateTimeController.cpp b/src/components/datetime/DateTimeController.cpp
index 4ac9e1f1..673903cb 100644
--- a/src/components/datetime/DateTimeController.cpp
+++ b/src/components/datetime/DateTimeController.cpp
@@ -75,6 +75,24 @@ void DateTime::UpdateTime(uint32_t systickCounter) {
minute = time.minutes().count();
second = time.seconds().count();
+ if (minute == 0 && !isHourAlreadyNotified) {
+ isHourAlreadyNotified = true;
+ if (systemTask != nullptr) {
+ systemTask->PushMessage(System::Messages::OnNewHour);
+ }
+ } else if (minute != 0) {
+ isHourAlreadyNotified = false;
+ }
+
+ if ((minute == 0 || minute == 30) && !isHalfHourAlreadyNotified) {
+ isHalfHourAlreadyNotified = true;
+ if (systemTask != nullptr) {
+ systemTask->PushMessage(System::Messages::OnNewHalfHour);
+ }
+ } else if (minute != 0 && minute != 30) {
+ isHalfHourAlreadyNotified = false;
+ }
+
// Notify new day to SystemTask
if (hour == 0 and not isMidnightAlreadyNotified) {
isMidnightAlreadyNotified = true;
@@ -100,4 +118,3 @@ const char* DateTime::MonthShortToStringLow(Months month) {
void DateTime::Register(Pinetime::System::SystemTask* systemTask) {
this->systemTask = systemTask;
}
-
diff --git a/src/components/datetime/DateTimeController.h b/src/components/datetime/DateTimeController.h
index 77ed68e8..cbc80447 100644
--- a/src/components/datetime/DateTimeController.h
+++ b/src/components/datetime/DateTimeController.h
@@ -86,6 +86,8 @@ namespace Pinetime {
std::chrono::seconds uptime {0};
bool isMidnightAlreadyNotified = false;
+ bool isHourAlreadyNotified = true;
+ bool isHalfHourAlreadyNotified = true;
System::SystemTask* systemTask = nullptr;
};
}
diff --git a/src/components/motion/MotionController.cpp b/src/components/motion/MotionController.cpp
index cae49105..7dd32127 100644
--- a/src/components/motion/MotionController.cpp
+++ b/src/components/motion/MotionController.cpp
@@ -1,5 +1,5 @@
#include "components/motion/MotionController.h"
-
+#include "os/os_cputime.h"
using namespace Pinetime::Controllers;
void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps) {
@@ -7,17 +7,21 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps)
service->OnNewStepCountValue(nbSteps);
}
- if(service != nullptr && (this->x != x || this->y != y || this->z != z)) {
+ if (service != nullptr && (this->x != x || this->y != y || this->z != z)) {
service->OnNewMotionValues(x, y, z);
}
this->x = x;
this->y = y;
this->z = z;
+ int32_t deltaSteps = nbSteps - this->nbSteps;
this->nbSteps = nbSteps;
+ if (deltaSteps > 0) {
+ currentTripSteps += deltaSteps;
+ }
}
-bool MotionController::ShouldWakeUp(bool isSleeping) {
+bool MotionController::Should_RaiseWake(bool isSleeping) {
if ((x + 335) <= 670 && z < 0) {
if (not isSleeping) {
if (y <= 0) {
@@ -39,14 +43,43 @@ bool MotionController::ShouldWakeUp(bool isSleeping) {
}
return false;
}
+
+bool MotionController::Should_ShakeWake(uint16_t thresh) {
+ bool wake = false;
+ auto diff = xTaskGetTickCount() - lastShakeTime;
+ lastShakeTime = xTaskGetTickCount();
+ /* Currently Polling at 10hz, If this ever goes faster scalar and EMA might need adjusting */
+ int32_t speed = std::abs(z + (y / 2) + (x / 4) - lastYForShake - lastZForShake) / diff * 100;
+ //(.2 * speed) + ((1 - .2) * accumulatedspeed);
+ // implemented without floats as .25Alpha
+ accumulatedspeed = (speed / 5) + ((accumulatedspeed / 5) * 4);
+
+ if (accumulatedspeed > thresh) {
+ wake = true;
+ }
+ lastXForShake = x / 4;
+ lastYForShake = y / 2;
+ lastZForShake = z;
+ return wake;
+}
+int32_t MotionController::currentShakeSpeed() {
+ return accumulatedspeed;
+}
+
void MotionController::IsSensorOk(bool isOk) {
isSensorOk = isOk;
}
void MotionController::Init(Pinetime::Drivers::Bma421::DeviceTypes types) {
- switch(types){
- case Drivers::Bma421::DeviceTypes::BMA421: this->deviceType = DeviceTypes::BMA421; break;
- case Drivers::Bma421::DeviceTypes::BMA425: this->deviceType = DeviceTypes::BMA425; break;
- default: this->deviceType = DeviceTypes::Unknown; break;
+ switch (types) {
+ case Drivers::Bma421::DeviceTypes::BMA421:
+ this->deviceType = DeviceTypes::BMA421;
+ break;
+ case Drivers::Bma421::DeviceTypes::BMA425:
+ this->deviceType = DeviceTypes::BMA425;
+ break;
+ default:
+ this->deviceType = DeviceTypes::Unknown;
+ break;
}
}
void MotionController::SetService(Pinetime::Controllers::MotionService* service) {
diff --git a/src/components/motion/MotionController.h b/src/components/motion/MotionController.h
index c72d8a4a..f80b11b9 100644
--- a/src/components/motion/MotionController.h
+++ b/src/components/motion/MotionController.h
@@ -8,7 +8,7 @@ namespace Pinetime {
namespace Controllers {
class MotionController {
public:
- enum class DeviceTypes{
+ enum class DeviceTypes {
Unknown,
BMA421,
BMA425,
@@ -28,8 +28,17 @@ namespace Pinetime {
uint32_t NbSteps() const {
return nbSteps;
}
- bool ShouldWakeUp(bool isSleeping);
+ void ResetTrip() {
+ currentTripSteps = 0;
+ }
+ uint32_t GetTripSteps() const {
+ return currentTripSteps;
+ }
+
+ bool Should_ShakeWake(uint16_t thresh);
+ bool Should_RaiseWake(bool isSleeping);
+ int32_t currentShakeSpeed();
void IsSensorOk(bool isOk);
bool IsSensorOk() const {
return isSensorOk;
@@ -44,6 +53,7 @@ namespace Pinetime {
private:
uint32_t nbSteps;
+ uint32_t currentTripSteps = 0;
int16_t x;
int16_t y;
int16_t z;
@@ -51,6 +61,12 @@ namespace Pinetime {
bool isSensorOk = false;
DeviceTypes deviceType = DeviceTypes::Unknown;
Pinetime::Controllers::MotionService* service = nullptr;
+
+ int16_t lastXForShake = 0;
+ int16_t lastYForShake = 0;
+ int16_t lastZForShake = 0;
+ int32_t accumulatedspeed = 0;
+ uint32_t lastShakeTime = 0;
};
}
} \ No newline at end of file
diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h
index 2d7973d8..6de44aac 100644
--- a/src/components/settings/Settings.h
+++ b/src/components/settings/Settings.h
@@ -11,10 +11,12 @@ 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 WakeUpMode : uint8_t {
SingleTap = 0,
DoubleTap = 1,
RaiseWrist = 2,
+ Shake = 3,
};
enum class Colors : uint8_t {
White, Silver, Gray, Black, Red, Maroon, Yellow, Olive, Lime, Green, Cyan, Teal, Blue, Navy, Magenta, Purple, Orange
@@ -40,6 +42,16 @@ namespace Pinetime {
return settings.clockFace;
};
+ void SetChimeOption(ChimesOption chimeOption) {
+ if (chimeOption != settings.chimesOption) {
+ settingsChanged = true;
+ }
+ settings.chimesOption = chimeOption;
+ };
+ ChimesOption GetChimeOption() const {
+ return settings.chimesOption;
+ };
+
void SetPTSColorTime(Colors colorTime) {
if (colorTime != settings.PTS.ColorTime)
settingsChanged = true;
@@ -108,10 +120,23 @@ namespace Pinetime {
}
settings.screenTimeOut = timeout;
};
+
uint32_t GetScreenTimeOut() const {
return settings.screenTimeOut;
};
+ void SetShakeThreshold(uint16_t thresh){
+ if(settings.shakeWakeThreshold != thresh){
+ settings.shakeWakeThreshold = thresh;
+ settingsChanged = true;
+ }
+
+ }
+
+ int16_t GetShakeThreshold() const{
+ return settings.shakeWakeThreshold;
+ }
+
void setWakeUpMode(WakeUpMode wakeUp, bool enabled) {
if (enabled != isWakeUpModeOn(wakeUp)) {
settingsChanged = true;
@@ -126,13 +151,13 @@ namespace Pinetime {
case WakeUpMode::DoubleTap:
settings.wakeUpMode.set(static_cast<size_t>(WakeUpMode::SingleTap), false);
break;
- case WakeUpMode::RaiseWrist:
+ default:
break;
}
}
};
- std::bitset<3> getWakeUpModes() const {
+ std::bitset<4> getWakeUpModes() const {
return settings.wakeUpMode;
}
@@ -162,7 +187,7 @@ namespace Pinetime {
private:
Pinetime::Controllers::FS& fs;
- static constexpr uint32_t settingsVersion = 0x0002;
+ static constexpr uint32_t settingsVersion = 0x0003;
struct SettingsData {
uint32_t version = settingsVersion;
uint32_t stepsGoal = 10000;
@@ -172,11 +197,12 @@ namespace Pinetime {
Notification notificationStatus = Notification::ON;
uint8_t clockFace = 0;
+ ChimesOption chimesOption = ChimesOption::None;
PineTimeStyle PTS;
- std::bitset<3> wakeUpMode {0};
-
+ std::bitset<4> wakeUpMode {0};
+ uint16_t shakeWakeThreshold = 150;
Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium;
};