summaryrefslogtreecommitdiff
path: root/src/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/components')
-rw-r--r--src/components/datetime/DateTimeController.cpp31
-rw-r--r--src/components/datetime/DateTimeController.h9
-rw-r--r--src/components/motion/MotionController.cpp28
-rw-r--r--src/components/motion/MotionController.h15
-rw-r--r--src/components/settings/Settings.h6
-rw-r--r--src/components/timer/TimerController.cpp36
-rw-r--r--src/components/timer/TimerController.h19
7 files changed, 66 insertions, 78 deletions
diff --git a/src/components/datetime/DateTimeController.cpp b/src/components/datetime/DateTimeController.cpp
index 3bfbdc7..fbaa01b 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
}
@@ -30,7 +30,7 @@ void DateTime::SetTime(
/* .tm_year = */ year - 1900,
};
tm.tm_isdst = -1; // Use DST value from local time zone
- 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);
@@ -45,27 +45,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);
- }
-
- currentDateTime += std::chrono::seconds(correctedDelta);
- uptime += std::chrono::seconds(correctedDelta);
+ // 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(systickDelta);
+ uptime += std::chrono::seconds(systickDelta);
auto dp = date::floor<date::days>(currentDateTime);
auto time = date::make_time(currentDateTime - dp);
diff --git a/src/components/datetime/DateTimeController.h b/src/components/datetime/DateTimeController.h
index 00bbc2e..cf9d52c 100644
--- a/src/components/datetime/DateTimeController.h
+++ b/src/components/datetime/DateTimeController.h
@@ -65,7 +65,7 @@ namespace Pinetime {
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 +73,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,9 +84,10 @@ 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;
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/settings/Settings.h b/src/components/settings/Settings.h
index 44a1a85..34e1af4 100644
--- a/src/components/settings/Settings.h
+++ b/src/components/settings/Settings.h
@@ -16,6 +16,7 @@ namespace Pinetime {
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;
}
@@ -227,8 +228,9 @@ 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;
};
diff --git a/src/components/timer/TimerController.cpp b/src/components/timer/TimerController.cpp
index 79e44d6..d6f8ffd 100644
--- a/src/components/timer/TimerController.cpp
+++ b/src/components/timer/TimerController.cpp
@@ -9,18 +9,16 @@
using namespace Pinetime::Controllers;
-
APP_TIMER_DEF(timerAppTimer);
namespace {
void TimerEnd(void* p_context) {
- auto* controller = static_cast<Pinetime::Controllers::TimerController*> (p_context);
- if(controller != nullptr)
+ auto* controller = static_cast<Pinetime::Controllers::TimerController*>(p_context);
+ if (controller != nullptr)
controller->OnTimerEnd();
}
}
-
void TimerController::Init() {
app_timer_create(&timerAppTimer, APP_TIMER_MODE_SINGLE_SHOT, TimerEnd);
}
@@ -31,37 +29,37 @@ void TimerController::StartTimer(uint32_t duration) {
app_timer_start(timerAppTimer, APP_TIMER_TICKS(duration), this);
endTicks = currentTicks + APP_TIMER_TICKS(duration);
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;
- }
-
- return (static_cast<TickType_t>(deltaTicks) / static_cast<TickType_t>(configTICK_RATE_HZ)) * 1000;
+
+ int32_t deltaTicks = static_cast<int32_t>(endTicks) - static_cast<int32_t>(currentTicks);
+
+ return (deltaTicks / static_cast<int32_t>(configTICK_RATE_HZ));
}
void TimerController::StopTimer() {
app_timer_stop(timerAppTimer);
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);
+ }
}
void TimerController::Register(Pinetime::System::SystemTask* systemTask) {
diff --git a/src/components/timer/TimerController.h b/src/components/timer/TimerController.h
index fa7bc90..dbc9863 100644
--- a/src/components/timer/TimerController.h
+++ b/src/components/timer/TimerController.h
@@ -9,20 +9,22 @@ namespace Pinetime {
class SystemTask;
}
namespace Controllers {
-
+
class TimerController {
public:
TimerController() = default;
-
+
void Init();
-
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();
@@ -32,6 +34,7 @@ namespace Pinetime {
System::SystemTask* systemTask = nullptr;
TickType_t endTicks;
bool timerRunning = false;
+ bool overtime = false;
};
}
} \ No newline at end of file