Skip to content

Commit

Permalink
Enabling tracker sets brightness to low and resets to previous bright…
Browse files Browse the repository at this point in the history
…ness when stopped

Also tweaked the Natural Wake Vibration a little.
  • Loading branch information
cyberneel committed Dec 13, 2024
1 parent 707eba8 commit 66aaaae
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
12 changes: 9 additions & 3 deletions src/components/infinisleep/InfiniSleepController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ using namespace std::chrono_literals;

InfiniSleepController::InfiniSleepController(Controllers::DateTime& dateTimeController,
Controllers::FS& fs,
Controllers::HeartRateController& heartRateController)
: dateTimeController {dateTimeController}, fs {fs}, heartRateController {heartRateController} {
Controllers::HeartRateController& heartRateController,
Controllers::BrightnessController& brightnessController)
: dateTimeController {dateTimeController}, fs {fs}, heartRateController {heartRateController}, brightnessController {brightnessController} {
}

namespace {
Expand Down Expand Up @@ -49,10 +50,14 @@ void InfiniSleepController::Init(System::SystemTask* systemTask) {
NRF_LOG_INFO("[InfiniSleepController] Loaded wake alarm was enabled, scheduling");
ScheduleWakeAlarm();
}

prevBrightnessLevel = brightnessController.Level();
}

void InfiniSleepController::EnableTracker() {
DisableTracker();
prevBrightnessLevel = brightnessController.Level();
brightnessController.Set(BrightnessController::Levels::Low);
// DisableTracker();
NRF_LOG_INFO("[InfiniSleepController] Enabling tracker");
isEnabled = true;
trackerUpdateTimer =
Expand All @@ -61,6 +66,7 @@ void InfiniSleepController::EnableTracker() {
}

void InfiniSleepController::DisableTracker() {
brightnessController.Set(prevBrightnessLevel);
NRF_LOG_INFO("[InfiniSleepController] Disabling tracker");
xTimerStop(trackerUpdateTimer, 0);
isEnabled = false;
Expand Down
6 changes: 5 additions & 1 deletion src/components/infinisleep/InfiniSleepController.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ namespace Pinetime {
public:
InfiniSleepController(Controllers::DateTime& dateTimeCOntroller,
Controllers::FS&,
Controllers::HeartRateController& heartRateController);
Controllers::HeartRateController& heartRateController,
Controllers::BrightnessController& brightnessController);

void Init(System::SystemTask* systemTask);
void SaveWakeAlarm();
Expand Down Expand Up @@ -169,6 +170,8 @@ namespace Pinetime {
return infiniSleepSettings;
}

BrightnessController::Levels prevBrightnessLevel;

bool ToggleTracker() {
if (isEnabled) {
prevSessionData.endTimeHours = GetCurrentHour();
Expand Down Expand Up @@ -216,6 +219,7 @@ namespace Pinetime {
Controllers::DateTime& dateTimeController;
Controllers::FS& fs;
Controllers::HeartRateController& heartRateController;
Controllers::BrightnessController& brightnessController;
System::SystemTask* systemTask = nullptr;
TimerHandle_t wakeAlarmTimer;
TimerHandle_t gradualWakeTimer;
Expand Down
8 changes: 6 additions & 2 deletions src/components/motor/MotorController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,14 @@ void MotorController::StartNaturalWakeAlarm() {
void MotorController::NaturalWakeAlarmRing(TimerHandle_t xTimer) {
auto* motorController = static_cast<MotorController*>(pvTimerGetTimerID(xTimer));
if (motorController->wakeAlarmStrength > (40 * motorController->infiniSleepMotorStrength) / 100) {
motorController->wakeAlarmStrength -= (30 * motorController->infiniSleepMotorStrength) / 100;
motorController->wakeAlarmStrength -= (15 * motorController->infiniSleepMotorStrength) / 100;
} else {
motorController->wakeAlarmStrength += (30 * motorController->infiniSleepMotorStrength) / 100;
}
if (motorController->wakeAlarmDuration < 500) {
motorController->wakeAlarmDuration += 180;
motorController->wakeAlarmDuration += 90;
} else {
motorController->wakeAlarmDuration -= 90;
}
motorController->SetMotorStrength(motorController->wakeAlarmStrength);
motorController->RunForDuration(motorController->wakeAlarmDuration);
Expand Down
4 changes: 3 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,14 @@ Pinetime::Drivers::Watchdog watchdog;
Pinetime::Controllers::NotificationManager notificationManager;
Pinetime::Controllers::MotionController motionController;
Pinetime::Controllers::AlarmController alarmController {dateTimeController, fs};
Pinetime::Controllers::InfiniSleepController infiniSleepController {dateTimeController, fs, heartRateController};

Pinetime::Controllers::TouchHandler touchHandler;
Pinetime::Controllers::ButtonHandler buttonHandler;
Pinetime::Controllers::BrightnessController brightnessController {};

Pinetime::Controllers::InfiniSleepController infiniSleepController {dateTimeController, fs, heartRateController, brightnessController};


Pinetime::Applications::DisplayApp displayApp(lcd,
touchPanel,
batteryController,
Expand Down

0 comments on commit 66aaaae

Please sign in to comment.