summaryrefslogtreecommitdiff
path: root/src/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/components')
-rw-r--r--src/components/alarm/AlarmController.cpp35
-rw-r--r--src/components/alarm/AlarmController.h2
-rw-r--r--src/components/battery/BatteryController.cpp2
3 files changed, 23 insertions, 16 deletions
diff --git a/src/components/alarm/AlarmController.cpp b/src/components/alarm/AlarmController.cpp
index cd011f6..4131f3f 100644
--- a/src/components/alarm/AlarmController.cpp
+++ b/src/components/alarm/AlarmController.cpp
@@ -20,6 +20,12 @@
#include "app_timer.h"
#include "task.h"
#include <chrono>
+#include <ratio>
+#include <cstdint>
+
+namespace {
+ typedef std::chrono::duration< int64_t, std::ratio<1, configTICK_RATE_HZ> > ticks_t;
+}
using namespace Pinetime::Controllers;
using namespace std::chrono_literals;
@@ -36,7 +42,7 @@ namespace {
void AlarmController::Init(System::SystemTask* systemTask) {
this->systemTask = systemTask;
- alarmAppTimer = xTimerCreate("alarmAppTm", 1, pdFALSE, this, SetOffAlarm);
+ alarmTimer = xTimerCreate("alarmAppTm", 1, pdFALSE, this, SetOffAlarm);
}
void AlarmController::SetAlarmTime(uint8_t alarmHr, uint8_t alarmMin) {
@@ -45,25 +51,26 @@ 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);
+ xTimerStop(alarmTimer, 0);
auto now = dateTimeController.CurrentDateTime();
- if (now > alarmTime) {
- xTimerChangePeriod(alarmAppTimer, 1, 0);
+ if (now >= alarmTime) {
+ xTimerChangePeriod(alarmTimer, 1, 0);
} else {
- auto mSecToAlarm = std::chrono::duration_cast<std::chrono::milliseconds>(alarmTime - now).count();
- xTimerChangePeriod(alarmAppTimer, APP_TIMER_TICKS(mSecToAlarm), 0);
+ auto ticksToAlarm = std::chrono::duration_cast<ticks_t>(alarmTime - now).count();
+ xTimerChangePeriod(alarmTimer, ++ticksToAlarm, 0);
}
- xTimerStart(alarmAppTimer, 0);
+ xTimerStart(alarmTimer, 0);
}
void AlarmController::ScheduleAlarm() {
// Determine the next time the alarm needs to go off and set the timer
- xTimerStop(alarmAppTimer, 0);
+ xTimerStop(alarmTimer, 0);
auto now = dateTimeController.CurrentDateTime();
alarmTime = now;
@@ -94,9 +101,9 @@ void AlarmController::ScheduleAlarm() {
// now can convert back to a time_point
alarmTime = std::chrono::system_clock::from_time_t(std::mktime(tmAlarmTime));
- auto mSecToAlarm = std::chrono::duration_cast<std::chrono::milliseconds>(alarmTime - now).count();
- xTimerChangePeriod(alarmAppTimer, APP_TIMER_TICKS(mSecToAlarm), 0);
- xTimerStart(alarmAppTimer, 0);
+ auto ticksToAlarm = std::chrono::duration_cast<ticks_t>(alarmTime - now).count();
+ xTimerChangePeriod(alarmTimer, ticksToAlarm, 0);
+ xTimerStart(alarmTimer, 0);
state = AlarmState::Set;
}
@@ -106,7 +113,7 @@ uint32_t AlarmController::SecondsToAlarm() {
}
void AlarmController::DisableAlarm() {
- xTimerStop(alarmAppTimer, 0);
+ xTimerStop(alarmTimer, 0);
state = AlarmState::Not_Set;
}
diff --git a/src/components/alarm/AlarmController.h b/src/components/alarm/AlarmController.h
index 6ad220f..a4f0c67 100644
--- a/src/components/alarm/AlarmController.h
+++ b/src/components/alarm/AlarmController.h
@@ -64,7 +64,7 @@ namespace Pinetime {
private:
Controllers::DateTime& dateTimeController;
System::SystemTask* systemTask = nullptr;
- TimerHandle_t alarmAppTimer;
+ TimerHandle_t alarmTimer;
uint8_t hours = 7;
uint8_t minutes = 0;
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> alarmTime;
diff --git a/src/components/battery/BatteryController.cpp b/src/components/battery/BatteryController.cpp
index 300d097..8575fff 100644
--- a/src/components/battery/BatteryController.cpp
+++ b/src/components/battery/BatteryController.cpp
@@ -61,7 +61,7 @@ void Battery::SaadcInit() {
void Battery::SaadcEventHandler(nrfx_saadc_evt_t const* p_event) {
const uint16_t battery_max = 4180; // maximum voltage of battery ( max charging voltage is 4.21 )
- const uint16_t battery_min = 3200; // minimum voltage of battery before shutdown ( depends on the battery )
+ const uint16_t battery_min = 3600; // battery voltage corresponding to 0%
if (p_event->type == NRFX_SAADC_EVT_DONE) {