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
48 changes: 30 additions & 18 deletions src/components/settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "components/brightness/BrightnessController.h"
#include "components/fs/FS.h"
#include "drivers/Cst816s.h"

#include <displayapp/Colors.h>
namespace Pinetime {
namespace Controllers {
class Settings {
Expand All @@ -17,13 +17,11 @@ namespace Pinetime {
DoubleTap = 1,
RaiseWrist = 2,
};
enum class Colors : uint8_t {
White, Silver, Gray, Black, Red, Maroon, Yellow, Olive, Lime, Green, Cyan, Teal, Blue, Navy, Magenta, Purple, Orange
};

struct PineTimeStyle {
Colors ColorTime = Colors::Teal;
Colors ColorBar = Colors::Teal;
Colors ColorBG = Colors::Black;
Applications::Colors ColorTime = Applications::Colors::Teal;
Applications::Colors ColorBar = Applications::Colors::Teal;
Applications::Colors ColorBG = Applications::Colors::Black;
};

Settings(Pinetime::Controllers::FS& fs);
Expand All @@ -41,30 +39,40 @@ namespace Pinetime {
return settings.clockFace;
};

void SetPTSColorTime(Colors colorTime) {
void setLastTorchColorIndex(uint8_t lastTorchColorIndex) {
if (lastTorchColorIndex != settings.lastTourchColorIndex) {
settingsChanged = true;
}
settings.lastTourchColorIndex = lastTorchColorIndex;
};
uint8_t getLastTorchColorIndex() {
return settings.lastTourchColorIndex;
};

void SetPTSColorTime(Applications::Colors colorTime) {
if (colorTime != settings.PTS.ColorTime)
settingsChanged = true;
settings.PTS.ColorTime = colorTime;
};
Colors GetPTSColorTime() const {
Applications::Colors GetPTSColorTime() const {
return settings.PTS.ColorTime;
};

void SetPTSColorBar(Colors colorBar) {
void SetPTSColorBar(Applications::Colors colorBar) {
if (colorBar != settings.PTS.ColorBar)
settingsChanged = true;
settings.PTS.ColorBar = colorBar;
};
Colors GetPTSColorBar() const {
Applications::Colors GetPTSColorBar() const {
return settings.PTS.ColorBar;
};

void SetPTSColorBG(Colors colorBG) {
void SetPTSColorBG(Applications::Colors colorBG) {
if (colorBG != settings.PTS.ColorBG)
settingsChanged = true;
settings.PTS.ColorBG = colorBG;
};
Colors GetPTSColorBG() const {
Applications::Colors GetPTSColorBG() const {
return settings.PTS.ColorBG;
};

Expand Down Expand Up @@ -151,14 +159,16 @@ namespace Pinetime {
return settings.brightLevel;
};

void SetStepsGoal( uint32_t goal ) {
if ( goal != settings.stepsGoal ) {
void SetStepsGoal(uint32_t goal) {
if (goal != settings.stepsGoal) {
settingsChanged = true;
}
settings.stepsGoal = goal;
settings.stepsGoal = goal;
};

uint32_t GetStepsGoal() const {
return settings.stepsGoal;
};

uint32_t GetStepsGoal() const { return settings.stepsGoal; };

private:
Pinetime::Controllers::FS& fs;
Expand All @@ -179,6 +189,8 @@ namespace Pinetime {
std::bitset<3> wakeUpMode {0};

Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium;

u_int8_t lastTourchColorIndex = 0;
};

SettingsData settings;
Expand Down
57 changes: 37 additions & 20 deletions src/displayapp/Colors.cpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,44 @@
#include "Colors.h"

using namespace Pinetime::Applications;
using namespace Pinetime::Controllers;

lv_color_t Pinetime::Applications::Convert(Pinetime::Controllers::Settings::Colors color) {
lv_color_t Pinetime::Applications::Convert(Colors color) {
switch (color) {
case Pinetime::Controllers::Settings::Colors::White: return LV_COLOR_WHITE;
case Pinetime::Controllers::Settings::Colors::Silver: return LV_COLOR_SILVER;
case Pinetime::Controllers::Settings::Colors::Gray: return LV_COLOR_GRAY;
case Pinetime::Controllers::Settings::Colors::Black: return LV_COLOR_BLACK;
case Pinetime::Controllers::Settings::Colors::Red: return LV_COLOR_RED;
case Pinetime::Controllers::Settings::Colors::Maroon: return LV_COLOR_MAROON;
case Pinetime::Controllers::Settings::Colors::Yellow: return LV_COLOR_YELLOW;
case Pinetime::Controllers::Settings::Colors::Olive: return LV_COLOR_OLIVE;
case Pinetime::Controllers::Settings::Colors::Lime: return LV_COLOR_LIME;
case Pinetime::Controllers::Settings::Colors::Green: return LV_COLOR_GREEN;
case Pinetime::Controllers::Settings::Colors::Cyan: return LV_COLOR_CYAN;
case Pinetime::Controllers::Settings::Colors::Teal: return LV_COLOR_TEAL;
case Pinetime::Controllers::Settings::Colors::Blue: return LV_COLOR_BLUE;
case Pinetime::Controllers::Settings::Colors::Navy: return LV_COLOR_NAVY;
case Pinetime::Controllers::Settings::Colors::Magenta: return LV_COLOR_MAGENTA;
case Pinetime::Controllers::Settings::Colors::Purple: return LV_COLOR_PURPLE;
case Pinetime::Controllers::Settings::Colors::Orange: return LV_COLOR_ORANGE;
default: return LV_COLOR_WHITE;
case Colors::White:
return LV_COLOR_WHITE;
case Colors::Silver:
return LV_COLOR_SILVER;
case Colors::Gray:
return LV_COLOR_GRAY;
case Colors::Black:
return LV_COLOR_BLACK;
case Colors::Red:
return LV_COLOR_RED;
case Colors::Maroon:
return LV_COLOR_MAROON;
case Colors::Yellow:
return LV_COLOR_YELLOW;
case Colors::Olive:
return LV_COLOR_OLIVE;
case Colors::Lime:
return LV_COLOR_LIME;
case Colors::Green:
return LV_COLOR_GREEN;
case Colors::Cyan:
return LV_COLOR_CYAN;
case Colors::Teal:
return LV_COLOR_TEAL;
case Colors::Blue:
return LV_COLOR_BLUE;
case Colors::Navy:
return LV_COLOR_NAVY;
case Colors::Magenta:
return LV_COLOR_MAGENTA;
case Colors::Purple:
return LV_COLOR_PURPLE;
case Colors::Orange:
return LV_COLOR_ORANGE;
default:
return LV_COLOR_WHITE;
}
}
25 changes: 23 additions & 2 deletions src/displayapp/Colors.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
#pragma once

#include <lvgl/src/lv_misc/lv_color.h>
#include <components/settings/Settings.h>
//#include <components/settings/Settings.h>

namespace Pinetime {
namespace Applications {
lv_color_t Convert(Controllers::Settings::Colors color);

enum class Colors : uint8_t {
White,
Silver,
Gray,
Black,
Red,
Maroon,
Yellow,
Olive,
Lime,
Green,
Cyan,
Teal,
Blue,
Navy,
Magenta,
Purple,
Orange
};

lv_color_t Convert(Colors color);
}
}
2 changes: 1 addition & 1 deletion src/displayapp/DisplayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,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
75 changes: 41 additions & 34 deletions src/displayapp/screens/FlashLight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,67 +4,74 @@

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)
Controllers::BrightnessController& brightness,
Pinetime::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));

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);

currentColorIndex = settingsController.getLastTorchColorIndex();
lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, Convert(torchColors[currentColorIndex]));
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() {
settingsController.setLastTorchColorIndex(currentColorIndex);
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));
lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, Convert(Applications::Colors::Black));
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));
bool FlashLight::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
switch (event) {
case TouchEvents::SwipeLeft:
currentColorIndex--;
if (currentColorIndex <= 0) {
currentColorIndex = 11;
}
lv_obj_set_style_local_bg_color(lv_scr_act(), LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Convert(torchColors[currentColorIndex]));
break;
case TouchEvents::SwipeRight:
currentColorIndex++;
if (currentColorIndex >= 11) {
currentColorIndex = 0;
}
lv_obj_set_style_local_bg_color(lv_scr_act(), LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Convert(torchColors[currentColorIndex]));
break;
case TouchEvents::SwipeUp:
brightness.Higher();
break;
case TouchEvents::SwipeDown:
brightness.Lower();
break;
case TouchEvents::DoubleTap:
if (brightness.Level() == Pinetime::Controllers::BrightnessController::Levels::Off) {
brightness.Set(Pinetime::Controllers::BrightnessController::Levels::Medium);
} 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));
brightness.Set(Pinetime::Controllers::BrightnessController::Levels::Off);
}
}
break;
case TouchEvents::LongTap:
currentColorIndex = 0;
lv_obj_set_style_local_bg_color(lv_scr_act(), LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Convert(torchColors[currentColorIndex]));
break;
default:
break;
}
}

bool FlashLight::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
return false;
}
20 changes: 15 additions & 5 deletions src/displayapp/screens/FlashLight.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,37 @@
#include <lvgl/lvgl.h>
#include "systemtask/SystemTask.h"
#include "components/brightness/BrightnessController.h"

#include <displayapp/Colors.h>
namespace Pinetime {

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;
void OnClickEvent(lv_obj_t* obj, lv_event_t event);

private:
Pinetime::System::SystemTask& systemTask;
Controllers::BrightnessController& brightness;
Controllers::Settings& settingsController;

lv_obj_t* flashLight;
lv_obj_t* backgroundAction;
bool isOn = true;
Colors torchColors[11] = {Colors::White,
Colors::Gray,
Colors::Red,
Colors::Yellow,
Colors::Green,
Colors::Cyan,
Colors::Teal,
Colors::Navy,
Colors::Magenta,
Colors::Orange,
Colors::Black};
int8_t currentColorIndex;
};
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/displayapp/screens/PineTimeStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ PineTimeStyle::PineTimeStyle(DisplayApp* app,
displayedChar[3] = 0;
displayedChar[4] = 0;

//Create a 200px wide background rectangle
// Create a 200px wide background rectangle
timebar = lv_obj_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_bg_color(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Convert(settingsController.GetPTSColorBG()));
lv_obj_set_style_local_radius(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 0);
Expand Down Expand Up @@ -257,7 +257,7 @@ void PineTimeStyle::Refresh() {
char hoursChar[3];
char ampmChar[5];
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24) {
sprintf(hoursChar, "%02d", hour);
sprintf(hoursChar, "%02d", hour);
} else {
if (hour == 0 && hour != 12) {
hour = 12;
Expand Down
Loading