Merge branch 'chime' into motor_pattern

This commit is contained in:
tofasthacker 2023-10-09 16:49:59 -04:00
commit ecbcce41d7
4 changed files with 62 additions and 11 deletions

View File

@ -389,7 +389,18 @@ void DisplayApp::Refresh() {
break;
case Messages::Chime:
LoadNewScreen(Apps::Clock, DisplayApp::FullRefreshDirections::None);
motorController.RunForDuration(35);
time_var = dateTimeController.Minutes();
if (time_var == 30){
NRF_LOG_INFO("Short: %d", time_var);
motorController.RunForDuration(25);
}
else
{
NRF_LOG_INFO("Long: %d", time_var);
motorController.RunForDuration(200);
}
break;
case Messages::OnChargingEvent:
RestoreBrightness();
@ -545,7 +556,7 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
touchPanel);
break;
case Apps::FlashLight:
currentScreen = std::make_unique<Screens::FlashLight>(*systemTask, brightnessController);
currentScreen = std::make_unique<Screens::FlashLight>(*systemTask, brightnessController, dateTimeController);
break;
case Apps::StopWatch:
currentScreen = std::make_unique<Screens::StopWatch>(*systemTask);

View File

@ -128,6 +128,7 @@ namespace Pinetime {
Utility::StaticStack<Apps, returnAppStackSize> returnAppStack;
Utility::StaticStack<FullRefreshDirections, returnAppStackSize> appStackDirections;
int time_var;
bool isDimmed = false;
};
}

View File

@ -2,6 +2,7 @@
#include "displayapp/DisplayApp.h"
#include "displayapp/screens/Symbols.h"
#include "displayapp/InfiniTimeTheme.h"
#include <libraries/log/nrf_log.h>
using namespace Pinetime::Applications::Screens;
@ -14,11 +15,24 @@ namespace {
}
}
FlashLight::FlashLight(System::SystemTask& systemTask, Controllers::BrightnessController& brightnessController)
: systemTask {systemTask}, brightnessController {brightnessController} {
FlashLight::FlashLight(System::SystemTask& systemTask, Controllers::BrightnessController& brightnessController, Controllers::DateTime& dateTimeController)
: systemTask {systemTask}, brightnessController {brightnessController}, dateTimeController {dateTimeController} {
brightnessController.Set(Controllers::BrightnessController::Levels::Low);
int time_var = dateTimeController.Hours();
if(time_var > 21 || time_var < 6){
State_l = 1;
NRF_LOG_INFO("Loop Hour Red: %d", time_var);
}
else {
State_l = 0;
NRF_LOG_INFO("Loop Hour White: %d", time_var);
}
flashLight = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_font(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_sys_48);
lv_label_set_text_static(flashLight, Symbols::flashlight);
@ -58,8 +72,17 @@ FlashLight::~FlashLight() {
}
void FlashLight::SetColors() {
lv_color_t bgColor = isOn ? LV_COLOR_WHITE : LV_COLOR_BLACK;
lv_color_t fgColor = isOn ? Colors::lightGray : LV_COLOR_WHITE;
lv_color_t bgColor = LV_COLOR_BLACK;
if(State_l == 0){
bgColor = LV_COLOR_BLACK;
} else if (State_l == 1){
bgColor = LV_COLOR_WHITE;
}
else {
bgColor = lv_color_hex(0xff0000);
}
lv_color_t fgColor = State_l ? Colors::lightGray : LV_COLOR_WHITE;
lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, bgColor);
lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, fgColor);
@ -86,9 +109,11 @@ void FlashLight::SetIndicators() {
}
void FlashLight::Toggle() {
isOn = !isOn;
State_l++;
if(State_l > 2)
State_l = 0;
SetColors();
if (isOn) {
if (State_l) {
brightnessController.Set(brightnessLevel);
} else {
brightnessController.Set(Controllers::BrightnessController::Levels::Low);
@ -99,7 +124,7 @@ bool FlashLight::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
using namespace Pinetime::Controllers;
auto SetState = [this]() {
if (isOn) {
if (State_l) {
brightnessController.Set(brightnessLevel);
}
SetIndicators();
@ -128,3 +153,15 @@ bool FlashLight::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
return false;
}
/*
time_var = dateTimeController.Minutes();
if (time_var == 30){
NRF_LOG_INFO("Short: %d", time_var);
motorController.RunForDuration(25);
}
else
{
NRF_LOG_INFO("Long: %d", time_var);
motorController.RunForDuration(200);
}
*/

View File

@ -2,6 +2,7 @@
#include "displayapp/screens/Screen.h"
#include "components/brightness/BrightnessController.h"
#include "components/datetime/DateTimeController.h"
#include "systemtask/SystemTask.h"
#include <cstdint>
#include <lvgl/lvgl.h>
@ -13,7 +14,7 @@ namespace Pinetime {
class FlashLight : public Screen {
public:
FlashLight(System::SystemTask& systemTask, Controllers::BrightnessController& brightness);
FlashLight(System::SystemTask& systemTask, Controllers::BrightnessController& brightness, Controllers::DateTime& dateTimeController);
~FlashLight() override;
bool OnTouchEvent(Pinetime::Applications::TouchEvents event) override;
@ -25,13 +26,14 @@ namespace Pinetime {
Pinetime::System::SystemTask& systemTask;
Controllers::BrightnessController& brightnessController;
Controllers::DateTime& dateTimeController;
Controllers::BrightnessController::Levels brightnessLevel = Controllers::BrightnessController::Levels::High;
lv_obj_t* flashLight;
lv_obj_t* backgroundAction;
lv_obj_t* indicators[3];
bool isOn = false;
int State_l = 1;
};
}
}