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
7 changes: 5 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,12 @@ list(APPEND SOURCE_FILES
displayapp/screens/HeartRate.cpp
displayapp/screens/Motion.cpp
displayapp/screens/FlashLight.cpp
displayapp/screens/settings/SettingsList.cpp
displayapp/screens/List.cpp
displayapp/screens/BatteryInfo.cpp
displayapp/screens/Steps.cpp
displayapp/screens/Timer.cpp
displayapp/screens/Timer/Timer.cpp
displayapp/screens/Timer/TimerList.cpp

## Settings
displayapp/screens/settings/QuickSettings.cpp
Expand Down Expand Up @@ -593,7 +595,8 @@ set(INCLUDE_FILES
displayapp/screens/Notifications.h
displayapp/screens/HeartRate.h
displayapp/screens/Motion.h
displayapp/screens/Timer.h
displayapp/screens/Timer/Timer.h
displayapp/screens/Timer/TimerList.h
drivers/St7789.h
drivers/SpiNorFlash.h
drivers/SpiMaster.h
Expand Down
18 changes: 17 additions & 1 deletion src/components/timer/TimerController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,20 @@ void TimerController::StopTimer() {

bool TimerController::IsRunning() {
return timerRunning;
}
}

void TimerController::selectPreset(int8_t i) {
initialValue = presets[i];
}

void TimerController::setPreset(int8_t i) {
presets[i] = initialValue;
}

TimerController::TimerValue* TimerController::getInitialValue(){
return &initialValue;
}

const TimerController::TimerValue& TimerController::getPreset(uint8_t i) const {
return presets[i];
}
22 changes: 21 additions & 1 deletion src/components/timer/TimerController.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ namespace Pinetime {

class TimerController {
public:
struct TimerValue {
uint8_t minutes;
uint8_t seconds;
};

TimerController(Pinetime::System::SystemTask& systemTask);

void Init();
Expand All @@ -23,8 +28,23 @@ namespace Pinetime {
uint32_t GetTimeRemaining();

bool IsRunning();


void selectPreset(int8_t i);
void setPreset(int8_t i);

TimerValue* getInitialValue();
const TimerValue& getPreset(uint8_t i) const;

private:

TimerValue presets[3] = {
{15, 00},
{30, 00},
{00, 30}
};

TimerValue initialValue = {00, 00};

System::SystemTask& systemTask;

static void timerEnd(void* p_context);
Expand Down
1 change: 1 addition & 0 deletions src/displayapp/Apps.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Pinetime {
NotificationsPreview,
Notifications,
Timer,
TimerTemplates,
FlashLight,
BatteryInfo,
Music,
Expand Down
6 changes: 5 additions & 1 deletion src/displayapp/DisplayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
#include <libraries/log/nrf_log.h>
#include <displayapp/screens/HeartRate.h>
#include <displayapp/screens/Motion.h>
#include <displayapp/screens/Timer.h>
#include <displayapp/screens/Timer/Timer.h>
#include <displayapp/screens/Timer/TimerList.h>
#include "components/battery/BatteryController.h"
#include "components/ble/BleController.h"
#include "components/datetime/DateTimeController.h"
Expand Down Expand Up @@ -278,6 +279,9 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
case Apps::Timer:
currentScreen = std::make_unique<Screens::Timer>(this, timerController);
break;
case Apps::TimerTemplates:
currentScreen = std::make_unique<Screens::TimerList>( 0, 1, this,timerController);
break;

// Settings
case Apps::QuickSettings:
Expand Down
105 changes: 37 additions & 68 deletions src/displayapp/screens/List.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#include "List.h"
#include "../DisplayApp.h"
#include "Symbols.h"

using namespace Pinetime::Applications::Screens;

Expand All @@ -9,112 +7,83 @@ namespace {
List* screen = static_cast<List*>(obj->user_data);
screen->OnButtonEvent(obj, event);
}

}

List::List(uint8_t screenID,
uint8_t numScreens,
DisplayApp* app,
Controllers::Settings& settingsController,
std::array<Applications, MAXLISTITEMS>& applications)
: Screen(app), settingsController {settingsController} {

List::List(Pinetime::Applications::DisplayApp* app, uint8_t screenID, uint8_t numScreens)
: Screen(app) {
// Set the background to Black
lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_make(0, 0, 0));

settingsController.SetSettingsMenu(screenID);

//draw scroll bar if List has more than one Page
if (numScreens > 1) {
pageIndicatorBasePoints[0].x = 240 - 1;
pageIndicatorBasePoints[0].y = 6;
pageIndicatorBasePoints[1].x = 240 - 1;
pageIndicatorBasePoints[1].y = 240 - 6;

pageIndicatorBase = lv_line_create(lv_scr_act(), NULL);
lv_obj_set_style_local_line_width(pageIndicatorBase, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3);
lv_obj_set_style_local_line_color(pageIndicatorBase, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111));
lv_obj_set_style_local_line_rounded(pageIndicatorBase, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, true);
lv_line_set_points(pageIndicatorBase, pageIndicatorBasePoints, 2);

uint16_t indicatorSize = 228 / numScreens;
uint16_t indicatorPos = indicatorSize * screenID;

pageIndicatorPoints[0].x = 240 - 1;
pageIndicatorPoints[0].y = 6 + indicatorPos;
pageIndicatorPoints[1].x = 240 - 1;
pageIndicatorPoints[1].y = 6 + indicatorPos + indicatorSize;

pageIndicator = lv_line_create(lv_scr_act(), NULL);
lv_obj_set_style_local_line_width(pageIndicator, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3);
lv_obj_set_style_local_line_color(pageIndicator, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
lv_obj_set_style_local_line_rounded(pageIndicator, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, true);
lv_line_set_points(pageIndicator, pageIndicatorPoints, 2);
}

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


//container for the buttons that will be created by createButtonNr
container1 = lv_cont_create(lv_scr_act(), nullptr);

// lv_obj_set_style_local_bg_color(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111));
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, 0, 0);
lv_obj_set_width(container1, LV_HOR_RES - 15);
lv_obj_set_height(container1, LV_VER_RES);
lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT);

lv_obj_t* labelBt;
lv_obj_t* labelBtIco;

for (int i = 0; i < MAXLISTITEMS; i++) {
apps[i] = applications[i].application;
if (applications[i].application != Apps::None) {

itemApps[i] = lv_btn_create(container1, nullptr);
lv_obj_set_style_local_bg_opa(itemApps[i], LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_20);
lv_obj_set_style_local_radius(itemApps[i], LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 20);
lv_obj_set_style_local_bg_color(itemApps[i], LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_AQUA);

lv_obj_set_width(itemApps[i], LV_HOR_RES - 25);
lv_obj_set_height(itemApps[i], 52);
lv_obj_set_event_cb(itemApps[i], ButtonEventHandler);
lv_btn_set_layout(itemApps[i], LV_LAYOUT_ROW_MID);
itemApps[i]->user_data = this;

labelBtIco = lv_label_create(itemApps[i], nullptr);
lv_obj_set_style_local_text_color(labelBtIco, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW);
lv_label_set_text_static(labelBtIco, applications[i].icon);

labelBt = lv_label_create(itemApps[i], nullptr);
lv_label_set_text_fmt(labelBt, " %s", applications[i].name);
}
}


lv_obj_t* backgroundLabel = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_long_mode(backgroundLabel, LV_LABEL_LONG_CROP);
lv_obj_set_size(backgroundLabel, LV_HOR_RES, LV_VER_RES);
lv_obj_set_pos(backgroundLabel, 0, 0);
lv_label_set_text_static(backgroundLabel, "");
}

List::~List() {
lv_obj_clean(lv_scr_act());
}

bool List::Refresh() {

return running;
}

void List::OnButtonEvent(lv_obj_t* object, lv_event_t event) {
if (event == LV_EVENT_RELEASED) {
for (int i = 0; i < MAXLISTITEMS; i++) {
if (apps[i] != Apps::None && object == itemApps[i]) {
app->StartApp(apps[i], DisplayApp::FullRefreshDirections::Up);
running = false;
return;
}
}
}
//Derived Classes shall call this in their constructor to create the buttons
void List::createButtonNr(int i, Item& item) {

lv_obj_t* labelBt;
lv_obj_t* labelBtIco;

buttons[i] = lv_btn_create(container1, nullptr);
lv_obj_set_style_local_bg_opa(buttons[i], LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_20);
lv_obj_set_style_local_radius(buttons[i], LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 20);
lv_obj_set_style_local_bg_color(buttons[i], LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_AQUA);

lv_obj_set_width(buttons[i], LV_HOR_RES - 25);
lv_obj_set_height(buttons[i], 52);
lv_obj_set_event_cb(buttons[i], ButtonEventHandler);
lv_btn_set_layout(buttons[i], LV_LAYOUT_ROW_MID);
buttons[i]->user_data = this;

labelBtIco = lv_label_create(buttons[i], nullptr);
lv_obj_set_style_local_text_color(labelBtIco, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW);
lv_label_set_text_static(labelBtIco, item.icon);

labelBt = lv_label_create(buttons[i], nullptr);
lv_label_set_text_fmt(labelBt, " %s", item.name);
}
38 changes: 15 additions & 23 deletions src/displayapp/screens/List.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#pragma once

#include <lvgl/lvgl.h>
#include <cstdint>
#include <memory>
#include <array>
#include "Screen.h"
#include "../Apps.h"
#include "components/settings/Settings.h"

#define MAXLISTITEMS 4

Expand All @@ -14,29 +11,24 @@ namespace Pinetime {
namespace Screens {
class List : public Screen {
public:
struct Applications {
struct Item {
const char* icon;
const char* name;
Pinetime::Applications::Apps application;
void* data;
};

explicit List(uint8_t screenID,
uint8_t numScreens,
DisplayApp* app,
Controllers::Settings& settingsController,
std::array<Applications, MAXLISTITEMS>& applications);
~List() override;

bool Refresh() override;

void OnButtonEvent(lv_obj_t* object, lv_event_t event);


virtual void OnButtonEvent(lv_obj_t* object, lv_event_t event) = 0;

protected:
explicit List(Pinetime::Applications::DisplayApp* app, uint8_t screenID, uint8_t numScreens);

lv_obj_t* buttons[MAXLISTITEMS];
lv_obj_t* container1;

void createButtonNr(int i, Item& item);

private:
Controllers::Settings& settingsController;
Pinetime::Applications::Apps apps[MAXLISTITEMS];

lv_obj_t* itemApps[MAXLISTITEMS];


lv_point_t pageIndicatorBasePoints[2];
lv_point_t pageIndicatorPoints[2];
lv_obj_t* pageIndicatorBase;
Expand Down
4 changes: 2 additions & 2 deletions src/displayapp/screens/ScreenList.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include <array>
#include <functional>
#include <memory>
#include "Screen.h"
#include "../DisplayApp.h"
#include "displayapp/screens/Screen.h"
#include "displayapp/DisplayApp.h"

namespace Pinetime {
namespace Applications {
Expand Down
Loading