Skip to content

Commit

Permalink
Added a both option for wake mode that allows for natural wake with p…
Browse files Browse the repository at this point in the history
…re vibrations

added the similar ramping up effect to the natural wake alarm but with larger interval
  • Loading branch information
cyberneel committed Dec 10, 2024
1 parent 860fcb6 commit 37f81ba
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 31 deletions.
16 changes: 12 additions & 4 deletions src/components/motor/MotorController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,23 @@ void MotorController::StopWakeAlarm() {
}

void MotorController::StartNaturalWakeAlarm() {
SetMotorStrength((60 * infiniSleepMotorStrength) / 100);
RunForDuration(280);
wakeAlarmStrength = (80 * infiniSleepMotorStrength) / 100;
wakeAlarmDuration = 100;
SetMotorStrength(wakeAlarmStrength);
RunForDuration(wakeAlarmDuration);
xTimerStart(naturalWakeAlarmVib, 0);
}

void MotorController::NaturalWakeAlarmRing(TimerHandle_t xTimer) {
auto* motorController = static_cast<MotorController*>(pvTimerGetTimerID(xTimer));
motorController->SetMotorStrength((60 * motorController->infiniSleepMotorStrength) / 100);
motorController->RunForDuration(280);
if (motorController->wakeAlarmStrength > (40 * motorController->infiniSleepMotorStrength) / 100) {
motorController->wakeAlarmStrength -= (30 * motorController->infiniSleepMotorStrength) / 100;
}
if (motorController->wakeAlarmDuration < 500) {
motorController->wakeAlarmDuration += 180;
}
motorController->SetMotorStrength(motorController->wakeAlarmStrength);
motorController->RunForDuration(motorController->wakeAlarmDuration);
}

void MotorController::StopNaturalWakeAlarm() {
Expand Down
66 changes: 39 additions & 27 deletions src/displayapp/screens/Sleep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ void Sleep::UpdateDisplay() {
return;
}

lv_task_reset(taskRefresh);

// Clear the screen
lv_obj_clean(lv_scr_act());
if (infiniSleepController.IsAlerting()) {
Expand Down Expand Up @@ -199,12 +201,12 @@ void Sleep::DrawAlarmScreen() {
// lv_label_set_text_static(txtSuggestedAlarm, "Use Sugg.\nAlarmTime");

txtSuggestedAlarm = lv_label_create(lv_scr_act(), nullptr);
lv_obj_align(txtSuggestedAlarm, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, -15, -10);
lv_obj_align(txtSuggestedAlarm, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, -15, -13);
lv_label_set_text_static(txtSuggestedAlarm, "Auto");

iconSuggestedAlarm = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(iconSuggestedAlarm, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
lv_obj_align(iconSuggestedAlarm, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, -50, -10);
lv_obj_align(iconSuggestedAlarm, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, -50, -13);
lv_label_set_text_static(iconSuggestedAlarm, Symbols::sun);

enableSwitch = lv_switch_create(lv_scr_act(), nullptr);
Expand Down Expand Up @@ -245,7 +247,7 @@ void Sleep::DrawInfoScreen() {
// Total sleep time
label_total_sleep = lv_label_create(lv_scr_act(), nullptr);

uint16_t totalMinutes = infiniSleepController.GetTotalSleep();
const uint16_t totalMinutes = infiniSleepController.GetTotalSleep();

lv_label_set_text_fmt(label_total_sleep, "Time Asleep: %dh%dm", totalMinutes / 60, totalMinutes % 60);
lv_obj_align(label_total_sleep, lv_scr_act(), LV_ALIGN_CENTER, 0, -60);
Expand Down Expand Up @@ -310,8 +312,10 @@ void Sleep::DrawInfoScreen() {

// Gradual Wake info
label_gradual_wake = lv_label_create(lv_scr_act(), nullptr);
if (infiniSleepController.infiniSleepSettings.graddualWake) {
lv_label_set_text_static(label_gradual_wake, "Wake Mode: Gradual");
if (infiniSleepController.infiniSleepSettings.graddualWake && infiniSleepController.infiniSleepSettings.naturalWake) {
lv_label_set_text_static(label_gradual_wake, "Wake Mode: Both");
} else if (infiniSleepController.infiniSleepSettings.graddualWake) {
lv_label_set_text_static(label_gradual_wake, "Wake Mode: PreWake");
} else if (infiniSleepController.infiniSleepSettings.naturalWake) {
lv_label_set_text_static(label_gradual_wake, "Wake Mode: Natural");
} else {
Expand Down Expand Up @@ -365,9 +369,11 @@ void Sleep::DrawSettingsScreen() {
lv_obj_align(btnWakeMode, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 130, y_offset);
btnWakeMode->user_data = this;
lv_obj_set_event_cb(btnWakeMode, btnEventHandler);
const char* mode = infiniSleepController.infiniSleepSettings.graddualWake ? "Grad."
: infiniSleepController.infiniSleepSettings.naturalWake ? "Nat."
: "Off";
const char* mode = (infiniSleepController.infiniSleepSettings.graddualWake && infiniSleepController.infiniSleepSettings.naturalWake)
? "Both"
: infiniSleepController.infiniSleepSettings.graddualWake ? "Pre."
: infiniSleepController.infiniSleepSettings.naturalWake ? "Nat."
: "Off";
lblWakeModeValue = lv_label_create(btnWakeMode, nullptr);
lv_label_set_text_static(lblWakeModeValue, mode);
lv_obj_align(lblWakeModeValue, nullptr, LV_ALIGN_CENTER, 0, 0);
Expand Down Expand Up @@ -464,13 +470,13 @@ void Sleep::OnButtonEvent(lv_obj_t* obj, lv_event_t event) {
}
if (obj == btnSuggestedAlarm) {
// Set the suggested time
uint16_t totalSuggestedMinutes = infiniSleepController.GetSuggestedSleepTime();
uint8_t suggestedHours = totalSuggestedMinutes / 60;
uint8_t suggestedMinutes = totalSuggestedMinutes % 60;
const uint16_t totalSuggestedMinutes = infiniSleepController.GetSuggestedSleepTime();
const uint8_t suggestedHours = totalSuggestedMinutes / 60;
const uint8_t suggestedMinutes = totalSuggestedMinutes % 60;

// Time for alarm, current time + suggested sleep time
uint8_t alarmHour = (infiniSleepController.GetCurrentHour() + suggestedHours) % 24;
uint8_t alarmMinute = (infiniSleepController.GetCurrentMinute() + suggestedMinutes) % 60;
const uint8_t alarmHour = (infiniSleepController.GetCurrentHour() + suggestedHours) % 24;
const uint8_t alarmMinute = (infiniSleepController.GetCurrentMinute() + suggestedMinutes) % 60;

infiniSleepController.SetWakeAlarmTime(alarmHour, alarmMinute);

Expand All @@ -483,19 +489,25 @@ void Sleep::OnButtonEvent(lv_obj_t* obj, lv_event_t event) {
return;
}
if (obj == btnWakeMode) {
if (infiniSleepController.infiniSleepSettings.graddualWake) {
if (infiniSleepController.infiniSleepSettings.graddualWake && infiniSleepController.infiniSleepSettings.naturalWake) {
infiniSleepController.infiniSleepSettings.graddualWake = false;
infiniSleepController.infiniSleepSettings.naturalWake = true;
} else if (infiniSleepController.infiniSleepSettings.naturalWake) {
infiniSleepController.infiniSleepSettings.naturalWake = false;
} else if (infiniSleepController.infiniSleepSettings.graddualWake) {
infiniSleepController.infiniSleepSettings.graddualWake = false;
infiniSleepController.infiniSleepSettings.naturalWake = true;
} else if (infiniSleepController.infiniSleepSettings.naturalWake) {
infiniSleepController.infiniSleepSettings.naturalWake = true;
infiniSleepController.infiniSleepSettings.graddualWake = true;
} else if (!infiniSleepController.infiniSleepSettings.graddualWake && !infiniSleepController.infiniSleepSettings.naturalWake) {
infiniSleepController.infiniSleepSettings.graddualWake = true;
infiniSleepController.infiniSleepSettings.naturalWake = false;
}
infiniSleepController.SetSettingsChanged();
const char* mode = infiniSleepController.infiniSleepSettings.graddualWake ? "Grad."
: infiniSleepController.infiniSleepSettings.naturalWake ? "Nat."
: "Off";
const char* mode = (infiniSleepController.infiniSleepSettings.graddualWake && infiniSleepController.infiniSleepSettings.naturalWake)
? "Both"
: infiniSleepController.infiniSleepSettings.graddualWake ? "Pre."
: infiniSleepController.infiniSleepSettings.naturalWake ? "Nat."
: "Off";
lv_label_set_text_static(lv_obj_get_child(obj, nullptr), mode);
return;
}
Expand Down Expand Up @@ -624,8 +636,8 @@ void Sleep::SnoozeWakeAlarm() {

NRF_LOG_INFO("Snoozing alarm for %d minutes", SNOOZE_MINUTES);

uint16_t totalAlarmMinutes = infiniSleepController.GetCurrentHour() * 60 + infiniSleepController.GetCurrentMinute();
uint16_t newSnoozeMinutes = totalAlarmMinutes + SNOOZE_MINUTES;
const uint16_t totalAlarmMinutes = infiniSleepController.GetCurrentHour() * 60 + infiniSleepController.GetCurrentMinute();
const uint16_t newSnoozeMinutes = totalAlarmMinutes + SNOOZE_MINUTES;

infiniSleepController.SetPreSnoozeTime();
infiniSleepController.isSnoozing = true;
Expand Down Expand Up @@ -661,10 +673,10 @@ void Sleep::SetAlerting() {
if (!infiniSleepController.infiniSleepSettings.naturalWake) {
taskSnoozeWakeAlarm = lv_task_create(SnoozeAlarmTaskCallback, 120 * 1000, LV_TASK_PRIO_MID, this);
}
if (infiniSleepController.infiniSleepSettings.graddualWake) {
motorController.StartWakeAlarm();
} else if (infiniSleepController.infiniSleepSettings.naturalWake) {
if (infiniSleepController.infiniSleepSettings.naturalWake) {
motorController.StartNaturalWakeAlarm();
} else {
motorController.StartWakeAlarm();
}
if (!infiniSleepController.infiniSleepSettings.naturalWake) {
wakeLock.Lock();
Expand All @@ -686,10 +698,10 @@ void Sleep::RedrawSetAlerting() {

void Sleep::StopAlerting(bool setSwitch) {
infiniSleepController.StopAlerting();
if (infiniSleepController.infiniSleepSettings.graddualWake) {
motorController.StopWakeAlarm();
} else if (infiniSleepController.infiniSleepSettings.naturalWake) {
if (infiniSleepController.infiniSleepSettings.naturalWake) {
motorController.StopNaturalWakeAlarm();
} else {
motorController.StopWakeAlarm();
}
if (setSwitch) {
SetSwitchState(LV_ANIM_OFF);
Expand Down

0 comments on commit 37f81ba

Please sign in to comment.