Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ list(APPEND SOURCE_FILES
displayapp/screens/settings/SettingDisplay.cpp
displayapp/screens/settings/SettingSteps.cpp
displayapp/screens/settings/SettingPineTimeStyle.cpp
displayapp/screens/settings/SettingFlashlight.cpp

## Watch faces
displayapp/icons/bg_clock.c
Expand Down
13 changes: 13 additions & 0 deletions src/components/settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ namespace Pinetime {
Colors ColorBar = Colors::Teal;
Colors ColorBG = Colors::Black;
};
struct FlashlightColor {
Colors ColorFlashlight = Colors::White;
};

Settings(Pinetime::Controllers::FS& fs);

Expand Down Expand Up @@ -68,6 +71,15 @@ namespace Pinetime {
return settings.PTS.ColorBG;
};

void SetFlashlightColor(Colors colorFlashlight) {
if (colorFlashlight != settings.Flash.ColorFlashlight)
settingsChanged = true;
settings.Flash.ColorFlashlight = colorFlashlight;
};
Colors GetFlashlightColor() const {
return settings.Flash.ColorFlashlight;
};

void SetAppMenu(uint8_t menu) {
appMenu = menu;
};
Expand Down Expand Up @@ -175,6 +187,7 @@ namespace Pinetime {
uint8_t clockFace = 0;

PineTimeStyle PTS;
FlashlightColor Flash;

std::bitset<3> wakeUpMode {0};

Expand Down
3 changes: 2 additions & 1 deletion src/displayapp/Apps.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ namespace Pinetime {
SettingDisplay,
SettingWakeUp,
SettingSteps,
SettingPineTimeStyle
SettingPineTimeStyle,
SettingFlashlight
};
}
}
7 changes: 6 additions & 1 deletion src/displayapp/DisplayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "displayapp/screens/settings/SettingDisplay.h"
#include "displayapp/screens/settings/SettingSteps.h"
#include "displayapp/screens/settings/SettingPineTimeStyle.h"
#include "displayapp/screens/settings/SettingFlashlight.h"

#include "libs/lv_conf.h"

Expand Down Expand Up @@ -375,6 +376,10 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
currentScreen = std::make_unique<Screens::SettingPineTimeStyle>(this, settingsController);
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
case Apps::SettingFlashlight:
currentScreen = std::make_unique<Screens::SettingFlashlight>(this, settingsController);
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
case Apps::BatteryInfo:
currentScreen = std::make_unique<Screens::BatteryInfo>(this, batteryController);
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
Expand All @@ -385,7 +390,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
case Apps::FlashLight:
currentScreen = std::make_unique<Screens::FlashLight>(this, *systemTask, brightnessController);
currentScreen = std::make_unique<Screens::FlashLight>(this, *systemTask, brightnessController, settingsController);
ReturnApp(Apps::Clock, FullRefreshDirections::Down, TouchEvents::None);
break;
case Apps::StopWatch:
Expand Down
15 changes: 9 additions & 6 deletions src/displayapp/screens/FlashLight.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "FlashLight.h"
#include "../DisplayApp.h"
#include "Symbols.h"
#include "components/settings/Settings.h"
#include <displayapp/Colors.h>

using namespace Pinetime::Applications::Screens;

Expand All @@ -13,16 +15,17 @@ namespace {

FlashLight::FlashLight(Pinetime::Applications::DisplayApp* app,
System::SystemTask& systemTask,
Controllers::BrightnessController& brightness)
Controllers::BrightnessController& brightness,
Controllers::Settings& settingsController)
: Screen(app),
systemTask {systemTask},
brightness {brightness}
brightness {brightness},
settingsController {settingsController} {

{
brightness.Backup();
brightness.Set(Controllers::BrightnessController::Levels::High);
// Set the background
lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFFFFF));
lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, Convert(settingsController.GetFlashlightColor()));

flashLight = lv_label_create(lv_scr_act(), NULL);
lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000));
Expand Down Expand Up @@ -55,11 +58,11 @@ void FlashLight::OnClickEvent(lv_obj_t* obj, lv_event_t event) {
isOn = !isOn;

if (isOn) {
lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFFFFF));
lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, Convert(settingsController.GetFlashlightColor()));
lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000));
} else {
lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000));
lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFFFFF));
lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Convert(settingsController.GetFlashlightColor()));
}
}
}
Expand Down
74 changes: 74 additions & 0 deletions src/displayapp/screens/FlashLight.cpp~
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include "FlashLight.h"
#include "../DisplayApp.h"
#include "Symbols.h"

using namespace Pinetime::Applications::Screens;

namespace {
static void event_handler(lv_obj_t* obj, lv_event_t event) {
FlashLight* screen = static_cast<FlashLight*>(obj->user_data);
screen->OnClickEvent(obj, event);
}
}

FlashLight::FlashLight(Pinetime::Applications::DisplayApp* app,
System::SystemTask& systemTask,
Controllers::BrightnessController& brightness)
: Screen(app),
systemTask {systemTask},
brightness {brightness}

{
brightness.Backup();
brightness.Set(Controllers::BrightnessController::Levels::High);
// Set the background
lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFFFFF));

flashLight = lv_label_create(lv_scr_act(), NULL);
lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000));
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::highlight);
lv_obj_align(flashLight, NULL, LV_ALIGN_CENTER, 0, 0);

backgroundAction = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_long_mode(backgroundAction, LV_LABEL_LONG_CROP);
lv_obj_set_size(backgroundAction, 240, 240);
lv_obj_set_pos(backgroundAction, 0, 0);
lv_label_set_text(backgroundAction, "");
lv_obj_set_click(backgroundAction, true);
backgroundAction->user_data = this;
lv_obj_set_event_cb(backgroundAction, event_handler);

systemTask.PushMessage(Pinetime::System::Messages::DisableSleeping);
}

FlashLight::~FlashLight() {
lv_obj_clean(lv_scr_act());
lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000));
brightness.Restore();
systemTask.PushMessage(Pinetime::System::Messages::EnableSleeping);
}

void FlashLight::OnClickEvent(lv_obj_t* obj, lv_event_t event) {
if (obj == backgroundAction) {
if (event == LV_EVENT_CLICKED) {
isOn = !isOn;

if (isOn) {
lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFFFFF));
lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000));
} else {
lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000));
lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFFFFF));
}
}
}
}

bool FlashLight::Refresh() {
return running;
}

bool FlashLight::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
return false;
}
11 changes: 10 additions & 1 deletion src/displayapp/screens/FlashLight.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,22 @@
#include "systemtask/SystemTask.h"
#include "components/brightness/BrightnessController.h"


namespace Pinetime {

namespace Controllers {
class Settings;
}

namespace Applications {
namespace Screens {

class FlashLight : public Screen {
public:
FlashLight(DisplayApp* app, System::SystemTask& systemTask, Controllers::BrightnessController& brightness);
FlashLight(DisplayApp* app,
System::SystemTask& systemTask,
Controllers::BrightnessController& brightness,
Controllers::Settings& settingsController);
~FlashLight() override;

bool OnTouchEvent(Pinetime::Applications::TouchEvents event) override;
Expand All @@ -22,6 +30,7 @@ namespace Pinetime {
private:
Pinetime::System::SystemTask& systemTask;
Controllers::BrightnessController& brightness;
Controllers::Settings& settingsController;

lv_obj_t* flashLight;
lv_obj_t* backgroundAction;
Expand Down
110 changes: 110 additions & 0 deletions src/displayapp/screens/settings/SettingFlashlight.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#include "SettingFlashlight.h"
#include <lvgl/lvgl.h>
#include "displayapp/DisplayApp.h"
#include "displayapp/Messages.h"
#include "displayapp/screens/Screen.h"
#include "displayapp/screens/Symbols.h"
#include <displayapp/Colors.h>

using namespace Pinetime::Applications::Screens;

namespace {
static void event_handler(lv_obj_t* obj, lv_event_t event) {
SettingFlashlight* screen = static_cast<SettingFlashlight*>(obj->user_data);
screen->UpdateSelected(obj, event);
}
}

SettingFlashlight::SettingFlashlight(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController)
: Screen(app), settingsController {settingsController} {

lv_obj_t* container1 = lv_cont_create(lv_scr_act(), nullptr);

lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP);
lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10);
lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5);
lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0);

lv_obj_set_pos(container1, 10, 60);
lv_obj_set_width(container1, LV_HOR_RES - 20);
lv_obj_set_height(container1, LV_VER_RES - 50);
lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT);

lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_text_static(title, "Flashlight");
lv_label_set_align(title, LV_LABEL_ALIGN_CENTER);
lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 10, 15);

lv_obj_t* icon = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE);
lv_label_set_text_static(icon, Symbols::highlight);
lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER);
lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0);

optionsTotal = 0;
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
lv_checkbox_set_text_static(cbOption[optionsTotal], " White");
cbOption[optionsTotal]->user_data = this;
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
if (settingsController.GetFlashlightColor() == Pinetime::Controllers::Settings::Colors::White) {
lv_checkbox_set_checked(cbOption[optionsTotal], true);
}
optionsTotal++;
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
lv_checkbox_set_text_static(cbOption[optionsTotal], " Red");
cbOption[optionsTotal]->user_data = this;
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
if (settingsController.GetFlashlightColor() == Pinetime::Controllers::Settings::Colors::Red) {
lv_checkbox_set_checked(cbOption[optionsTotal], true);
}
optionsTotal++;
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
lv_checkbox_set_text_static(cbOption[optionsTotal], " Green");
cbOption[optionsTotal]->user_data = this;
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
if (settingsController.GetFlashlightColor() == Pinetime::Controllers::Settings::Colors::Green) {
lv_checkbox_set_checked(cbOption[optionsTotal], true);
}
optionsTotal++;
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
lv_checkbox_set_text_static(cbOption[optionsTotal], " Blue");
cbOption[optionsTotal]->user_data = this;
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
if (settingsController.GetFlashlightColor() == Pinetime::Controllers::Settings::Colors::Blue) {
lv_checkbox_set_checked(cbOption[optionsTotal], true);
}
optionsTotal++;
}

SettingFlashlight::~SettingFlashlight() {
lv_obj_clean(lv_scr_act());
settingsController.SaveSettings();
}

void SettingFlashlight::UpdateSelected(lv_obj_t* object, lv_event_t event) {
if (event == LV_EVENT_CLICKED) {
for (int i = 0; i < optionsTotal; i++) {
if (object == cbOption[i]) {
lv_checkbox_set_checked(cbOption[i], true);

if (i == 0) {
settingsController.SetFlashlightColor(Pinetime::Controllers::Settings::Colors::White);
};
if (i == 1) {
settingsController.SetFlashlightColor(Pinetime::Controllers::Settings::Colors::Red);
};
if (i == 2) {
settingsController.SetFlashlightColor(Pinetime::Controllers::Settings::Colors::Green);
};
if (i == 3) {
settingsController.SetFlashlightColor(Pinetime::Controllers::Settings::Colors::Blue);
};

app->PushMessage(Applications::Display::Messages::UpdateTimeOut);

} else {
lv_checkbox_set_checked(cbOption[i], false);
}
}
}
}
28 changes: 28 additions & 0 deletions src/displayapp/screens/settings/SettingFlashlight.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include <cstdint>
#include <lvgl/lvgl.h>
#include "components/settings/Settings.h"
#include "displayapp/screens/Screen.h"
#include <displayapp/Colors.h>

namespace Pinetime {

namespace Applications {
namespace Screens {

class SettingFlashlight : public Screen {
public:
SettingFlashlight(DisplayApp* app, Pinetime::Controllers::Settings& settingsController);
~SettingFlashlight() override;

void UpdateSelected(lv_obj_t* object, lv_event_t event);

private:
Controllers::Settings& settingsController;
uint8_t optionsTotal;
lv_obj_t* cbOption[4];
};
}
}
}
2 changes: 1 addition & 1 deletion src/displayapp/screens/settings/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ std::unique_ptr<Screen> Settings::CreateScreen3() {

std::array<Screens::List::Applications, 4> applications {{
{Symbols::paintbrush, "PTS Colors", Apps::SettingPineTimeStyle},
{Symbols::none, "None", Apps::None},
{Symbols::highlight, "Flashlight", Apps::SettingFlashlight},
{Symbols::none, "None", Apps::None},
{Symbols::none, "None", Apps::None},
}};
Expand Down