Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Favorite Apps on swipe left #487 #9

Open
wants to merge 10 commits into
base: 0mywatch
Choose a base branch
from
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.10)
project(pinetime VERSION 1.4.0 LANGUAGES C CXX ASM)
project(pinetime VERSION 1.6.0 LANGUAGES C CXX ASM)

set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 14)
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ list(APPEND SOURCE_FILES
displayapp/screens/settings/SettingDisplay.cpp
displayapp/screens/settings/SettingSteps.cpp
displayapp/screens/settings/SettingPineTimeStyle.cpp
displayapp/screens/settings/SettingFavoriteApp.cpp

## Watch faces
displayapp/icons/bg_clock.c
Expand Down
8 changes: 0 additions & 8 deletions src/components/ble/NotificationManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,6 @@ bool NotificationManager::AreNewNotificationsAvailable() {
return newNotification;
}

bool NotificationManager::IsVibrationEnabled() {
return vibrationEnabled;
}

void NotificationManager::ToggleVibrations() {
vibrationEnabled = !vibrationEnabled;
}

bool NotificationManager::ClearNewNotificationFlag() {
return newNotification.exchange(false);
}
Expand Down
5 changes: 1 addition & 4 deletions src/components/ble/NotificationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ namespace Pinetime {
Notification GetPrevious(Notification::Id id);
bool ClearNewNotificationFlag();
bool AreNewNotificationsAvailable();
bool IsVibrationEnabled();
void ToggleVibrations();

static constexpr size_t MaximumMessageSize() {
return MessageSize;
Expand All @@ -60,7 +58,6 @@ namespace Pinetime {
uint8_t writeIndex = 0;
bool empty = true;
std::atomic<bool> newNotification {false};
bool vibrationEnabled = true;
};
}
}
}
10 changes: 0 additions & 10 deletions src/components/motor/MotorController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ APP_TIMER_DEF(longVibTimer);

using namespace Pinetime::Controllers;

MotorController::MotorController(Controllers::Settings& settingsController) : settingsController {settingsController} {
}

void MotorController::Init() {
nrf_gpio_cfg_output(PinMap::Motor);
nrf_gpio_pin_set(PinMap::Motor);
Expand All @@ -27,18 +24,11 @@ void MotorController::Ring(void* p_context) {
}

void MotorController::RunForDuration(uint8_t motorDuration) {
if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::OFF) {
return;
}

nrf_gpio_pin_clear(PinMap::Motor);
app_timer_start(shortVibTimer, APP_TIMER_TICKS(motorDuration), nullptr);
}

void MotorController::StartRinging() {
if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::OFF) {
return;
}
Ring(this);
app_timer_start(longVibTimer, APP_TIMER_TICKS(1000), this);
}
Expand Down
5 changes: 2 additions & 3 deletions src/components/motor/MotorController.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
#pragma once

#include <cstdint>
#include "components/settings/Settings.h"

namespace Pinetime {
namespace Controllers {

class MotorController {
public:
MotorController(Controllers::Settings& settingsController);
MotorController() = default;

void Init();
void RunForDuration(uint8_t motorDuration);
void StartRinging();
static void StopRinging();

private:
static void Ring(void* p_context);
Controllers::Settings& settingsController;
static void StopMotor(void* p_context);
};
}
Expand Down
28 changes: 21 additions & 7 deletions src/components/settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
#include "components/brightness/BrightnessController.h"
#include "components/fs/FS.h"
#include "drivers/Cst816s.h"
#include "displayapp/Apps.h"

namespace Pinetime {
namespace Controllers {
class Settings {
public:
enum class ClockType : uint8_t { H24, H12 };
enum class Vibration : uint8_t { ON, OFF };
enum class Notification : uint8_t { ON, OFF };
enum class WakeUpMode : uint8_t {
SingleTap = 0,
DoubleTap = 1,
Expand All @@ -31,6 +32,17 @@ namespace Pinetime {
void Init();
void SaveSettings();

void SetFavoriteApp(Applications::Apps app){
if (app != settings.favoriteApp) {
settingsChanged = true;
}
settings.favoriteApp = app;
}

Applications::Apps GetFavoriteApp(){
return settings.favoriteApp;
}

void SetClockFace(uint8_t face) {
if (face != settings.clockFace) {
settingsChanged = true;
Expand Down Expand Up @@ -93,14 +105,14 @@ namespace Pinetime {
return settings.clockType;
};

void SetVibrationStatus(Vibration status) {
if (status != settings.vibrationStatus) {
void SetNotificationStatus(Notification status) {
if (status != settings.notificationStatus) {
settingsChanged = true;
}
settings.vibrationStatus = status;
settings.notificationStatus = status;
};
Vibration GetVibrationStatus() const {
return settings.vibrationStatus;
Notification GetNotificationStatus() const {
return settings.notificationStatus;
};

void SetScreenTimeOut(uint32_t timeout) {
Expand Down Expand Up @@ -170,7 +182,7 @@ namespace Pinetime {
uint32_t screenTimeOut = 15000;

ClockType clockType = ClockType::H24;
Vibration vibrationStatus = Vibration::ON;
Notification notificationStatus = Notification::ON;

uint8_t clockFace = 0;

Expand All @@ -179,6 +191,8 @@ namespace Pinetime {
std::bitset<3> wakeUpMode {0};

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

Applications::Apps favoriteApp = Applications::Apps::None;
};

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

#include "libs/lv_conf.h"
#include "displayapp/screens/settings/SettingFavoriteApp.h"

using namespace Pinetime::Applications;
using namespace Pinetime::Applications::Display;
Expand Down Expand Up @@ -232,6 +233,13 @@ void DisplayApp::Refresh() {
case TouchEvents::SwipeRight:
LoadApp(Apps::QuickSettings, DisplayApp::FullRefreshDirections::RightAnim);
break;
case TouchEvents::SwipeLeft:
favoriteApp = settingsController.GetFavoriteApp();
if (favoriteApp == Apps::None)
LoadApp(Apps::SettingFavoriteApp, DisplayApp::FullRefreshDirections::LeftAnim);
else
LoadApp(favoriteApp, DisplayApp::FullRefreshDirections::LeftAnim);
break;
case TouchEvents::DoubleTap:
PushMessageToSystemTask(System::Messages::GoToSleep);
break;
Expand Down Expand Up @@ -380,6 +388,8 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
break;
case Apps::SettingPineTimeStyle:
currentScreen = std::make_unique<Screens::SettingPineTimeStyle>(this, settingsController);
case Apps::SettingFavoriteApp:
currentScreen = std::make_unique<Screens::SettingFavoriteApp>(this, settingsController);
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
case Apps::BatteryInfo:
Expand Down
1 change: 1 addition & 0 deletions src/displayapp/DisplayApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ namespace Pinetime {

Apps currentApp = Apps::None;
Apps returnToApp = Apps::None;
Apps favoriteApp = Apps::None;
FullRefreshDirections returnDirection = FullRefreshDirections::None;
TouchEvents returnTouchEvent = TouchEvents::None;

Expand Down
4 changes: 0 additions & 4 deletions src/displayapp/screens/Notifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,6 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
alertNotificationService);
}
return true;
case Pinetime::Applications::TouchEvents::LongTap: {
// notificationManager.ToggleVibrations();
return true;
}
default:
return false;
}
Expand Down
47 changes: 36 additions & 11 deletions src/displayapp/screens/Tile.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "Tile.h"
#include "../DisplayApp.h"
#include "BatteryIcon.h"
#include "Symbols.h"

using namespace Pinetime::Applications::Screens;

Expand All @@ -11,12 +12,15 @@ namespace {
}

static void event_handler(lv_obj_t* obj, lv_event_t event) {
if (event != LV_EVENT_VALUE_CHANGED) return;

Tile* screen = static_cast<Tile*>(obj->user_data);
auto* eventDataPtr = (uint32_t*) lv_event_get_data();
uint32_t eventData = *eventDataPtr;
screen->OnValueChangedEvent(obj, eventData);
switch(event){
case LV_EVENT_VALUE_CHANGED:
case LV_EVENT_LONG_PRESSED:
Tile* screen = static_cast<Tile*>(obj->user_data);
auto* eventDataPtr = (uint32_t*) lv_event_get_data();
uint32_t eventData = *eventDataPtr;
screen->OnValueChangedEvent(obj, eventData, event);
break;
}
}
}

Expand All @@ -27,7 +31,7 @@ Tile::Tile(uint8_t screenID,
Pinetime::Controllers::Battery& batteryController,
Controllers::DateTime& dateTimeController,
std::array<Applications, 6>& applications)
: Screen(app), batteryController {batteryController}, dateTimeController {dateTimeController} {
: Screen(app), batteryController {batteryController}, dateTimeController {dateTimeController}, settingsController {settingsController} {

settingsController.SetAppMenu(screenID);

Expand Down Expand Up @@ -74,7 +78,12 @@ Tile::Tile(uint8_t screenID,
if (applications[i].application == Apps::None) {
btnmMap[btIndex] = " ";
} else {
btnmMap[btIndex] = applications[i].icon;
if (applications[i].application == settingsController.GetFavoriteApp()){
btnmMap[btIndex] = Pinetime::Applications::Screens::Symbols::eye;
}
else{
btnmMap[btIndex] = applications[i].icon;
}
}
btIndex++;
apps[i] = applications[i].application;
Expand Down Expand Up @@ -123,9 +132,25 @@ void Tile::UpdateScreen() {
lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryController.PercentRemaining()));
}

void Tile::OnValueChangedEvent(lv_obj_t* obj, uint32_t buttonId) {
void Tile::OnValueChangedEvent(lv_obj_t* obj, uint32_t buttonId, lv_event_t event) {
if(obj != btnm1) return;
switch(event){
case LV_EVENT_VALUE_CHANGED:
if(apps[buttonId] != Pinetime::Applications::Apps::None){
app->StartApp(apps[buttonId], DisplayApp::FullRefreshDirections::Up);
running = false;
}
break;
case LV_EVENT_LONG_PRESSED:
currentFavoriteApp = settingsController.GetFavoriteApp();
if(currentFavoriteApp == apps[buttonId]){
settingsController.SetFavoriteApp(Pinetime::Applications::Apps::None);
}
else{
settingsController.SetFavoriteApp(apps[buttonId]);
}
//motorController.RunForDuration(35);
break;
}

app->StartApp(apps[buttonId], DisplayApp::FullRefreshDirections::Up);
running = false;
}
5 changes: 4 additions & 1 deletion src/displayapp/screens/Tile.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "components/settings/Settings.h"
#include "components/datetime/DateTimeController.h"
#include "components/battery/BatteryController.h"
#include "components/motor/MotorController.h"

namespace Pinetime {
namespace Applications {
Expand All @@ -31,11 +32,12 @@ namespace Pinetime {
~Tile() override;

void UpdateScreen();
void OnValueChangedEvent(lv_obj_t* obj, uint32_t buttonId);
void OnValueChangedEvent(lv_obj_t* obj, uint32_t buttonId, lv_event_t event);

private:
Pinetime::Controllers::Battery& batteryController;
Controllers::DateTime& dateTimeController;
Controllers::Settings& settingsController;

lv_task_t* taskUpdate;

Expand All @@ -49,6 +51,7 @@ namespace Pinetime {

const char* btnmMap[8];
Pinetime::Applications::Apps apps[6];
Pinetime::Applications::Apps currentFavoriteApp = Pinetime::Applications::Apps::None;
};
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/displayapp/screens/settings/QuickSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ QuickSettings::QuickSettings(Pinetime::Applications::DisplayApp* app,
btn3_lvl = lv_label_create(btn3, nullptr);
lv_obj_set_style_local_text_font(btn3_lvl, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_sys_48);

if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::ON) {
if (settingsController.GetNotificationStatus() == Controllers::Settings::Notification::ON) {
lv_obj_add_state(btn3, LV_STATE_CHECKED);
lv_label_set_text_static(btn3_lvl, Symbols::notificationsOn);
} else {
Expand Down Expand Up @@ -142,11 +142,11 @@ void QuickSettings::OnButtonEvent(lv_obj_t* object, lv_event_t event) {
} else if (object == btn3 && event == LV_EVENT_VALUE_CHANGED) {

if (lv_obj_get_state(btn3, LV_BTN_PART_MAIN) & LV_STATE_CHECKED) {
settingsController.SetVibrationStatus(Controllers::Settings::Vibration::ON);
settingsController.SetNotificationStatus(Controllers::Settings::Notification::ON);
motorController.RunForDuration(35);
lv_label_set_text_static(btn3_lvl, Symbols::notificationsOn);
} else {
settingsController.SetVibrationStatus(Controllers::Settings::Vibration::OFF);
settingsController.SetNotificationStatus(Controllers::Settings::Notification::OFF);
lv_label_set_text_static(btn3_lvl, Symbols::notificationsOff);
}

Expand Down
Loading