Skip to content

Commit

Permalink
Fixed default state bug
Browse files Browse the repository at this point in the history
  • Loading branch information
idealemu committed Apr 30, 2024
1 parent 08e136c commit 8d67524
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/displayapp/screens/REM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ REM::REM(Controllers::MotorController& motorController):
lv_obj_set_size(btnToggle, 50, 50);
lv_obj_align(btnToggle, nullptr, LV_ALIGN_IN_TOP_LEFT, 10, 10);
btnToggleText = lv_label_create(btnToggle, nullptr);
lv_label_set_text(btnToggleText, "N"); // Night default value
lv_obj_set_user_data(btnToggle, this);
lv_obj_set_event_cb(btnToggle, btnToggleEventHandler);

setNight(); // Set default to night

motorController.Init();

taskRefresh = lv_task_create(RefreshTaskCallback, 100, LV_TASK_PRIO_MID, this);
Expand Down Expand Up @@ -124,17 +125,27 @@ void REM::btnToggleEventHandler(lv_obj_t* obj, lv_event_t event) {
screen->motorController.hapticFeedback(); // One pulse haptic feedback


if (screen->isNight) { // Toggle to DAY
screen->motorController.setPulseStrength(screen->DAY_TIME_PULSE_STRENGTH);
screen->motorController.setMaxPeriodCountInREM(screen->DAY_TIME_MAX_PERIOD_COUNT_IN_REM);
lv_label_set_text(screen->btnToggleText, "D");
screen->isNight = false;
} else { // Toggle to NIGHT
screen->motorController.setPulseStrength(screen->NIGHT_TIME_PULSE_TIME);
screen->motorController.setMaxPeriodCountInREM(screen->NIGHT_TIME_MAX_PERIOD_COUNT_IN_REM);
lv_label_set_text(screen->btnToggleText, "N");
screen->isNight = true;
if (screen->isNight) {
screen->setDay(); // Toggle to DAY
} else {
screen->setNight(); // Toggle to NIGHT
}
}
screen->updateInfoLabels();
}

void REM::setNight() {
motorController.setPulseStrength(NIGHT_TIME_PULSE_TIME);
motorController.setMaxPeriodCountInREM(NIGHT_TIME_MAX_PERIOD_COUNT_IN_REM);
lv_label_set_text(btnToggleText, "N");
isNight = true;
updateInfoLabels();
}

void REM::setDay() {
motorController.setPulseStrength(DAY_TIME_PULSE_STRENGTH);
motorController.setMaxPeriodCountInREM(DAY_TIME_MAX_PERIOD_COUNT_IN_REM);
lv_label_set_text(btnToggleText, "D");
isNight = false;
updateInfoLabels();
}
4 changes: 4 additions & 0 deletions src/displayapp/screens/REM.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ namespace Pinetime {
void Refresh() override;

bool isNight = true;

void setNight();
void setDay();

const uint8_t DAY_TIME_PULSE_STRENGTH = 50;
const uint8_t DAY_TIME_MAX_PERIOD_COUNT_IN_REM = 3;
const uint8_t NIGHT_TIME_PULSE_TIME = 5;
Expand Down

0 comments on commit 8d67524

Please sign in to comment.