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

[WIP/RFC] Remove watchface enum #2040

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 2 additions & 8 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ endif ()
set(CMAKE_OSX_SYSROOT "/")
set(CMAKE_OSX_DEPLOYMENT_TARGET "")

add_subdirectory(displayapp)

set(SDK_SOURCE_FILES
# Startup
Expand Down Expand Up @@ -420,12 +421,7 @@ list(APPEND SOURCE_FILES
displayapp/screens/settings/SettingBluetooth.cpp

## Watch faces
displayapp/screens/WatchFaceAnalog.cpp
displayapp/screens/WatchFaceDigital.cpp
displayapp/screens/WatchFaceInfineat.cpp
displayapp/screens/WatchFaceTerminal.cpp
displayapp/screens/WatchFacePineTimeStyle.cpp
displayapp/screens/WatchFaceCasioStyleG7710.cpp
${WATCHFACE_SOURCES}

##

Expand Down Expand Up @@ -848,8 +844,6 @@ target_compile_options(infinitime_fonts PUBLIC
$<$<COMPILE_LANGUAGE:ASM>: ${ASM_FLAGS}>
)

add_subdirectory(displayapp/apps)

# NRF SDK
add_library(nrf-sdk STATIC ${SDK_SOURCE_FILES})
target_include_directories(nrf-sdk SYSTEM PUBLIC . ../)
Expand Down
20 changes: 13 additions & 7 deletions src/components/settings/Settings.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#pragma once
#include <cstdint>
#include <bitset>
#include <cstring>
#include <array>
#include "components/brightness/BrightnessController.h"
#include "components/fs/FS.h"
#include "displayapp/apps/Apps.h"
#include "displayapp/Apps.h"
#include "displayapp/WatchFaces.h"

namespace Pinetime {
namespace Controllers {
Expand Down Expand Up @@ -60,15 +63,18 @@ namespace Pinetime {
void Init();
void SaveSettings();

void SetWatchFace(Pinetime::Applications::WatchFace face) {
if (face != settings.watchFace) {
void SetWatchFace(const char* face) {
const char* currentWatchFace = settings.watchFace.data();
if (std::strcmp(face, currentWatchFace) != 0) {
settingsChanged = true;
auto len = std::min(std::strlen(face), Pinetime::Applications::MaxWatchFaceNameSize);
std::memcpy(settings.watchFace.data(), face, len);
settings.watchFace[len] = 0;
}
settings.watchFace = face;
};

Pinetime::Applications::WatchFace GetWatchFace() const {
return settings.watchFace;
const char* GetWatchFace() const {
return settings.watchFace.data();
};

void SetChimeOption(ChimesOption chimeOption) {
Expand Down Expand Up @@ -297,7 +303,7 @@ namespace Pinetime {
WeatherFormat weatherFormat = WeatherFormat::Metric;
Notification notificationStatus = Notification::On;

Pinetime::Applications::WatchFace watchFace = Pinetime::Applications::WatchFace::Digital;
std::array<char, Pinetime::Applications::MaxWatchFaceNameSize + 1> watchFace = {0};
ChimesOption chimesOption = ChimesOption::None;

PineTimeStyle PTS;
Expand Down
21 changes: 0 additions & 21 deletions src/displayapp/apps/Apps.h.in → src/displayapp/Apps.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -45,35 +45,14 @@ namespace Pinetime {
Error
};

enum class WatchFace : uint8_t {
Digital,
Analog,
PineTimeStyle,
Terminal,
Infineat,
CasioStyleG7710,
};

template <Apps>
struct AppTraits {};

template <WatchFace>
struct WatchFaceTraits {};

template <Apps... As>
struct TypeList {
static constexpr size_t Count = sizeof...(As);
};

using UserAppTypes = TypeList<@USERAPP_TYPES@>;

template <WatchFace... Ws>
struct WatchFaceTypeList {
static constexpr size_t Count = sizeof...(Ws);
};

using UserWatchFaceTypes = WatchFaceTypeList<@WATCHFACE_TYPES@>;

static_assert(UserWatchFaceTypes::Count >= 1);
}
}
66 changes: 66 additions & 0 deletions src/displayapp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
if(DEFINED ENABLE_USERAPPS)
set(USERAPP_TYPES ${ENABLE_USERAPPS} CACHE STRING "List of user apps to build into the firmware")
else ()
set(DEFAULT_USER_APP_TYPES "Apps::StopWatch")
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Alarm")
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Timer")
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Steps")
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::HeartRate")
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Music")
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Paint")
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Paddle")
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Twos")
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Dice")
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Metronome")
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Navigation")
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Weather")
#set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Motion")
set(USERAPP_TYPES "${DEFAULT_USER_APP_TYPES}" CACHE STRING "List of user apps to build into the firmware")
endif ()

if(NOT DEFINED DEFAULT_WATCHFACE_NAMES )
set(DEFAULT_WATCHFACE_NAMES "digital;analog;pinetimestyle;terminal;infineat;casioStyleG7710")
endif()
message("WATCH FACES\n-----------")
foreach(item ${DEFAULT_WATCHFACE_NAMES})
if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/watchfaces/${item})
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/watchfaces/${item})
message(" * Watch face ${INFINITIME_WATCHFACE_NAME} enabled!")
list(APPEND DEFAULT_WATCHFACE_TYPES "${INFINITIME_WATCHFACE_NAMESPACE}")
list(APPEND WATCHFACE_SOURCES_LIST "${INFINITIME_WATCHFACE_SOURCES}")
string(APPEND WATCHFACE_INCLUDE "#include \"${INFINITIME_WATCHFACE_INCLUDES}\"\n")
endif()
endforeach()
set(WATCHFACE_SOURCES ${WATCHFACE_SOURCES_LIST} PARENT_SCOPE)

# Generate the list of watchface types necessary to instantiate WatchFaceTypeList<> needed in WatchFace.h
set(FIRST_ITERATION TRUE)
foreach (watchface IN LISTS DEFAULT_WATCHFACE_TYPES)
if (${FIRST_ITERATION})
string(APPEND WATCHFACE_TYPES "${watchface}")
set(FIRST_ITERATION FALSE)
else ()
string(APPEND WATCHFACE_TYPES ", ${watchface}")
endif ()
endforeach ()

# Generate the forward declarations needed in WatchFace.h
foreach (w IN LISTS DEFAULT_WATCHFACE_TYPES)
string(FIND ${w} "::" classIndex REVERSE)
string(LENGTH ${w} watchfaceFullLength)
math(EXPR watchfaceLength "${watchfaceFullLength} - (${classIndex} + 2)")
math(EXPR beginIndex "${classIndex}+2")
string(SUBSTRING ${w} ${beginIndex} ${watchfaceLength} className)
string(SUBSTRING ${w} 0 ${classIndex} namespaceName)
string(APPEND WATCHFACE_NAMESPACE "namespace ${namespaceName} { class ${className}; }\n")
endforeach ()

add_library(infinitime_apps INTERFACE)
target_sources(infinitime_apps INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/Apps.h")
target_include_directories(infinitime_apps INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/")
target_include_directories(infinitime_apps INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/../")

# Generate the list of user apps to be compiled into the firmware
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Apps.h.in ${CMAKE_CURRENT_BINARY_DIR}/Apps.h)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/WatchFaces.h.in ${CMAKE_CURRENT_BINARY_DIR}/WatchFaces.h)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/UserApps.h.in ${CMAKE_CURRENT_BINARY_DIR}/UserApps.h)
5 changes: 2 additions & 3 deletions src/displayapp/DisplayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
case Apps::Clock: {
const auto* watchFace =
std::find_if(userWatchFaces.begin(), userWatchFaces.end(), [this](const WatchFaceDescription& watchfaceDescription) {
return watchfaceDescription.watchFace == settingsController.GetWatchFace();
return std::strcmp(watchfaceDescription.name, settingsController.GetWatchFace()) == 0;
});
if (watchFace != userWatchFaces.end())
currentScreen.reset(watchFace->create(controllers));
Expand Down Expand Up @@ -494,8 +494,7 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
std::array<Screens::SettingWatchFace::Item, UserWatchFaceTypes::Count> items;
int i = 0;
for (const auto& userWatchFace : userWatchFaces) {
items[i++] =
Screens::SettingWatchFace::Item {userWatchFace.name, userWatchFace.watchFace, userWatchFace.isAvailable(controllers.filesystem)};
items[i++] = Screens::SettingWatchFace::Item {userWatchFace.name, userWatchFace.isAvailable(controllers.filesystem)};
}
currentScreen = std::make_unique<Screens::SettingWatchFace>(this, std::move(items), settingsController, filesystem);
} break;
Expand Down
2 changes: 1 addition & 1 deletion src/displayapp/DisplayApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <task.h>
#include <memory>
#include <systemtask/Messages.h>
#include "displayapp/apps/Apps.h"
#include "displayapp/Apps.h"
#include "displayapp/LittleVgl.h"
#include "displayapp/TouchEvents.h"
#include "components/brightness/BrightnessController.h"
Expand Down
21 changes: 8 additions & 13 deletions src/displayapp/UserApps.h → src/displayapp/UserApps.h.in
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
#pragma once
#include "displayapp/apps/Apps.h"
#include "Controllers.h"
#include "displayapp/Apps.h"
#include "displayapp/Controllers.h"

#include "displayapp/screens/Alarm.h"
#include "displayapp/screens/Dice.h"
#include "displayapp/screens/Timer.h"
#include "displayapp/screens/Twos.h"
#include "displayapp/screens/Tile.h"
#include "displayapp/screens/ApplicationList.h"
#include "displayapp/screens/WatchFaceDigital.h"
#include "displayapp/screens/WatchFaceAnalog.h"
#include "displayapp/screens/WatchFaceCasioStyleG7710.h"
#include "displayapp/screens/WatchFaceInfineat.h"
#include "displayapp/screens/WatchFacePineTimeStyle.h"
#include "displayapp/screens/WatchFaceTerminal.h"
@WATCHFACE_INCLUDE@

namespace Pinetime {
namespace Applications {
Expand All @@ -28,7 +22,6 @@ namespace Pinetime {
};

struct WatchFaceDescription {
WatchFace watchFace;
const char* name;
Screens::Screen* (*create)(AppControllers& controllers);
bool (*isAvailable)(Controllers::FS& fileSystem);
Expand All @@ -39,17 +32,19 @@ namespace Pinetime {
return {AppTraits<t>::app, AppTraits<t>::icon, &AppTraits<t>::Create};
}

template <WatchFace t>
template <class t>
consteval WatchFaceDescription CreateWatchFaceDescription() {
return {WatchFaceTraits<t>::watchFace, WatchFaceTraits<t>::name, &WatchFaceTraits<t>::Create, &WatchFaceTraits<t>::IsAvailable};
static_assert(std::char_traits<char>::length(WatchFaceTraits<t>::name) < 16,
"The name of the watch faces is limited to 15 characters max");
return {WatchFaceTraits<t>::name, &WatchFaceTraits<t>::Create, &WatchFaceTraits<t>::IsAvailable};
}

template <template <Apps...> typename T, Apps... ts>
consteval std::array<AppDescription, sizeof...(ts)> CreateAppDescriptions(T<ts...>) {
return {CreateAppDescription<ts>()...};
}

template <template <WatchFace...> typename T, WatchFace... ts>
template <template <class...> typename T, class... ts>
consteval std::array<WatchFaceDescription, sizeof...(ts)> CreateWatchFaceDescriptions(T<ts...>) {
return {CreateWatchFaceDescription<ts>()...};
}
Expand Down
22 changes: 22 additions & 0 deletions src/displayapp/WatchFaces.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once
#include <cstddef>
#include <cstdint>

@WATCHFACE_NAMESPACE@
namespace Pinetime {
namespace Applications {
static constexpr size_t MaxWatchFaceNameSize = 15;

template <class T>
struct WatchFaceTraits {};

template <class... Ws>
struct WatchFaceTypeList {
static constexpr size_t Count = sizeof...(Ws);
};

using UserWatchFaceTypes = WatchFaceTypeList<@WATCHFACE_TYPES@>;

static_assert(UserWatchFaceTypes::Count >= 1);
}
}
38 changes: 0 additions & 38 deletions src/displayapp/apps/CMakeLists.txt

This file was deleted.

2 changes: 1 addition & 1 deletion src/displayapp/screens/Alarm.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
#pragma once

#include "displayapp/apps/Apps.h"
#include "displayapp/Apps.h"
#include "components/settings/Settings.h"
#include "displayapp/screens/Screen.h"
#include "displayapp/widgets/Counter.h"
Expand Down
1 change: 0 additions & 1 deletion src/displayapp/screens/ApplicationList.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <array>
#include <memory>
#include "displayapp/apps/Apps.h"
#include "Screen.h"
#include "ScreenList.h"
#include "displayapp/Controllers.h"
Expand Down
1 change: 0 additions & 1 deletion src/displayapp/screens/CheckboxList.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include "displayapp/apps/Apps.h"
#include "displayapp/screens/Screen.h"
#include <array>
#include <cstdint>
Expand Down
2 changes: 1 addition & 1 deletion src/displayapp/screens/Dice.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "displayapp/apps/Apps.h"
#include "displayapp/Apps.h"
#include "displayapp/screens/Screen.h"
#include "displayapp/widgets/Counter.h"
#include "displayapp/Controllers.h"
Expand Down
2 changes: 1 addition & 1 deletion src/displayapp/screens/InfiniPaint.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "displayapp/screens/Screen.h"
#include "components/motor/MotorController.h"
#include "Symbols.h"
#include "displayapp/apps/Apps.h"
#include "displayapp/Apps.h"
#include <displayapp/Controllers.h>

namespace Pinetime {
Expand Down
1 change: 0 additions & 1 deletion src/displayapp/screens/List.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <array>
#include "displayapp/screens/Screen.h"
#include "displayapp/widgets/PageIndicator.h"
#include "displayapp/apps/Apps.h"
#include "components/settings/Settings.h"

#define MAXLISTITEMS 4
Expand Down
2 changes: 1 addition & 1 deletion src/displayapp/screens/Motion.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <lvgl/src/lv_core/lv_obj.h>
#include <components/motion/MotionController.h>
#include "displayapp/Controllers.h"
#include "displayapp/apps/Apps.h"
#include "displayapp/Apps.h"

namespace Pinetime {
namespace Applications {
Expand Down
2 changes: 1 addition & 1 deletion src/displayapp/screens/Music.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <lvgl/src/lv_core/lv_obj.h>
#include <string>
#include "displayapp/screens/Screen.h"
#include "displayapp/apps/Apps.h"
#include "displayapp/Apps.h"
#include "displayapp/Controllers.h"
#include "Symbols.h"

Expand Down
Loading
Loading