forked from haui/InfiniTime_mirror
Compare commits
4 commits
main
...
remove-wat
Author | SHA1 | Date | |
---|---|---|---|
6f146fc0cd | |||
7c2ead9054 | |||
45f0d9880c | |||
73b22aaaa4 |
|
@ -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/WatchFaces.h"
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Controllers {
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
|
@ -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;
|
||||
|
|
|
@ -1,19 +1,13 @@
|
|||
#pragma once
|
||||
#include "displayapp/apps/Apps.h"
|
||||
#include "Controllers.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 {
|
||||
|
@ -28,7 +22,6 @@ namespace Pinetime {
|
|||
};
|
||||
|
||||
struct WatchFaceDescription {
|
||||
WatchFace watchFace;
|
||||
const char* name;
|
||||
Screens::Screen* (*create)(AppControllers& controllers);
|
||||
bool (*isAvailable)(Controllers::FS& fileSystem);
|
||||
|
@ -39,9 +32,11 @@ 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>
|
||||
|
@ -49,7 +44,7 @@ namespace Pinetime {
|
|||
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>()...};
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,20 +19,47 @@ else ()
|
|||
endif ()
|
||||
|
||||
if(DEFINED ENABLE_WATCHFACES)
|
||||
set(WATCHFACE_TYPES ${ENABLE_WATCHFACES} CACHE STRING "List of watch faces to build into the firmware")
|
||||
else()
|
||||
set(DEFAULT_WATCHFACE_TYPES "WatchFace::Digital")
|
||||
set(DEFAULT_WATCHFACE_TYPES "${DEFAULT_WATCHFACE_TYPES}, WatchFace::Analog")
|
||||
set(DEFAULT_WATCHFACE_TYPES "${DEFAULT_WATCHFACE_TYPES}, WatchFace::PineTimeStyle")
|
||||
set(DEFAULT_WATCHFACE_TYPES "${DEFAULT_WATCHFACE_TYPES}, WatchFace::Terminal")
|
||||
set(DEFAULT_WATCHFACE_TYPES "${DEFAULT_WATCHFACE_TYPES}, WatchFace::Infineat")
|
||||
set(DEFAULT_WATCHFACE_TYPES "${DEFAULT_WATCHFACE_TYPES}, WatchFace::CasioStyleG7710")
|
||||
set(WATCHFACE_TYPES "${DEFAULT_WATCHFACE_TYPES}" CACHE STRING "List of watch faces to build into the firmware")
|
||||
endif()
|
||||
set(DEFAULT_WATCHFACE_TYPES ${ENABLE_WATCHFACES})
|
||||
else ()
|
||||
list(APPEND DEFAULT_WATCHFACE_TYPES "Pinetime::Applications::Screens::WatchFaceDigital")
|
||||
list(APPEND DEFAULT_WATCHFACE_TYPES "Pinetime::Applications::Screens::WatchFaceAnalog")
|
||||
list(APPEND DEFAULT_WATCHFACE_TYPES "Pinetime::Applications::Screens::WatchFacePineTimeStyle")
|
||||
list(APPEND DEFAULT_WATCHFACE_TYPES "Pinetime::Applications::Screens::WatchFaceTerminal")
|
||||
list(APPEND DEFAULT_WATCHFACE_TYPES "Pinetime::Applications::Screens::WatchFaceInfineat")
|
||||
list(APPEND DEFAULT_WATCHFACE_TYPES "Pinetime::Applications::Screens::WatchFaceCasioStyleG7710")
|
||||
endif ()
|
||||
|
||||
# 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")
|
||||
|
||||
# TODO the include path should be specified by the CMake file of the watchface
|
||||
string(APPEND WATCHFACE_INCLUDE "#include \"displayapp/screens/${className}.h\"\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)
|
||||
|
|
22
src/displayapp/apps/WatchFaces.h.in
Normal file
22
src/displayapp/apps/WatchFaces.h.in
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include "displayapp/apps/Apps.h"
|
||||
#include "Screen.h"
|
||||
#include "ScreenList.h"
|
||||
#include "displayapp/Controllers.h"
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#include "displayapp/apps/Apps.h"
|
||||
#include "displayapp/screens/Screen.h"
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include "displayapp/screens/Screen.h"
|
||||
#include "displayapp/apps/Apps.h"
|
||||
#include "components/datetime/DateTimeController.h"
|
||||
#include "components/settings/Settings.h"
|
||||
#include "components/battery/BatteryController.h"
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "components/ble/NotificationManager.h"
|
||||
#include "displayapp/screens/BatteryIcon.h"
|
||||
#include "utility/DirtyValue.h"
|
||||
#include "displayapp/apps/WatchFaces.h"
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Controllers {
|
||||
|
@ -90,8 +91,7 @@ namespace Pinetime {
|
|||
}
|
||||
|
||||
template <>
|
||||
struct WatchFaceTraits<WatchFace::Analog> {
|
||||
static constexpr WatchFace watchFace = WatchFace::Analog;
|
||||
struct WatchFaceTraits<Screens::WatchFaceAnalog> {
|
||||
static constexpr const char* name = "Analog face";
|
||||
|
||||
static Screens::Screen* Create(AppControllers& controllers) {
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include "components/datetime/DateTimeController.h"
|
||||
#include "components/ble/BleController.h"
|
||||
#include "utility/DirtyValue.h"
|
||||
#include "displayapp/apps/Apps.h"
|
||||
#include "displayapp/apps/WatchFaces.h"
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Controllers {
|
||||
|
@ -104,8 +104,7 @@ namespace Pinetime {
|
|||
}
|
||||
|
||||
template <>
|
||||
struct WatchFaceTraits<WatchFace::CasioStyleG7710> {
|
||||
static constexpr WatchFace watchFace = WatchFace::CasioStyleG7710;
|
||||
struct WatchFaceTraits<Screens::WatchFaceCasioStyleG7710> {
|
||||
static constexpr const char* name = "Casio G7710";
|
||||
|
||||
static Screens::Screen* Create(AppControllers& controllers) {
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include "components/ble/BleController.h"
|
||||
#include "displayapp/widgets/StatusIcons.h"
|
||||
#include "utility/DirtyValue.h"
|
||||
#include "displayapp/apps/Apps.h"
|
||||
#include "displayapp/apps/WatchFaces.h"
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Controllers {
|
||||
|
@ -81,8 +81,7 @@ namespace Pinetime {
|
|||
}
|
||||
|
||||
template <>
|
||||
struct WatchFaceTraits<WatchFace::Digital> {
|
||||
static constexpr WatchFace watchFace = WatchFace::Digital;
|
||||
struct WatchFaceTraits<Screens::WatchFaceDigital> {
|
||||
static constexpr const char* name = "Digital face";
|
||||
|
||||
static Screens::Screen* Create(AppControllers& controllers) {
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include "displayapp/screens/Screen.h"
|
||||
#include "components/datetime/DateTimeController.h"
|
||||
#include "utility/DirtyValue.h"
|
||||
#include "displayapp/apps/Apps.h"
|
||||
#include "displayapp/apps/WatchFaces.h"
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Controllers {
|
||||
|
@ -102,8 +102,7 @@ namespace Pinetime {
|
|||
}
|
||||
|
||||
template <>
|
||||
struct WatchFaceTraits<WatchFace::Infineat> {
|
||||
static constexpr WatchFace watchFace = WatchFace::Infineat;
|
||||
struct WatchFaceTraits<Screens::WatchFaceInfineat> {
|
||||
static constexpr const char* name = "Infineat face";
|
||||
|
||||
static Screens::Screen* Create(AppControllers& controllers) {
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "components/ble/SimpleWeatherService.h"
|
||||
#include "components/ble/BleController.h"
|
||||
#include "utility/DirtyValue.h"
|
||||
#include "displayapp/apps/WatchFaces.h"
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Controllers {
|
||||
|
@ -122,8 +123,7 @@ namespace Pinetime {
|
|||
}
|
||||
|
||||
template <>
|
||||
struct WatchFaceTraits<WatchFace::PineTimeStyle> {
|
||||
static constexpr WatchFace watchFace = WatchFace::PineTimeStyle;
|
||||
struct WatchFaceTraits<Screens::WatchFacePineTimeStyle> {
|
||||
static constexpr const char* name = "PineTimeStyle";
|
||||
|
||||
static Screens::Screen* Create(AppControllers& controllers) {
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "displayapp/screens/Screen.h"
|
||||
#include "components/datetime/DateTimeController.h"
|
||||
#include "utility/DirtyValue.h"
|
||||
#include "displayapp/apps/WatchFaces.h"
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Controllers {
|
||||
|
@ -71,8 +72,7 @@ namespace Pinetime {
|
|||
}
|
||||
|
||||
template <>
|
||||
struct WatchFaceTraits<WatchFace::Terminal> {
|
||||
static constexpr WatchFace watchFace = WatchFace::Terminal;
|
||||
struct WatchFaceTraits<Screens::WatchFaceTerminal> {
|
||||
static constexpr const char* name = "Terminal";
|
||||
|
||||
static Screens::Screen* Create(AppControllers& controllers) {
|
||||
|
|
|
@ -12,12 +12,12 @@ constexpr const char* SettingWatchFace::symbol;
|
|||
namespace {
|
||||
uint32_t IndexOf(const std::array<Pinetime::Applications::Screens::SettingWatchFace::Item,
|
||||
Pinetime::Applications::UserWatchFaceTypes::Count>& watchfaces,
|
||||
Pinetime::Applications::WatchFace watchface) {
|
||||
const char* watchface) {
|
||||
size_t index = 0;
|
||||
auto found = std::find_if(watchfaces.begin(),
|
||||
watchfaces.end(),
|
||||
[&index, &watchface](const Pinetime::Applications::Screens::SettingWatchFace::Item& item) {
|
||||
const bool result = item.watchface == watchface;
|
||||
[&index, watchface](const Pinetime::Applications::Screens::SettingWatchFace::Item& item) {
|
||||
const bool result = (std::strcmp(item.name, watchface) == 0);
|
||||
if (!result) {
|
||||
index++;
|
||||
}
|
||||
|
@ -30,13 +30,13 @@ namespace {
|
|||
return index;
|
||||
}
|
||||
|
||||
Pinetime::Applications::WatchFace IndexToWatchFace(const std::array<Pinetime::Applications::Screens::SettingWatchFace::Item,
|
||||
Pinetime::Applications::UserWatchFaceTypes::Count>& watchfaces,
|
||||
const char* IndexToWatchFace(const std::array<Pinetime::Applications::Screens::SettingWatchFace::Item,
|
||||
Pinetime::Applications::UserWatchFaceTypes::Count>& watchfaces,
|
||||
size_t index) {
|
||||
if (index >= watchfaces.size()) {
|
||||
return watchfaces[0].watchface;
|
||||
return watchfaces[0].name;
|
||||
}
|
||||
return watchfaces[index].watchface;
|
||||
return watchfaces[index].name;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "displayapp/screens/CheckboxList.h"
|
||||
#include "displayapp/screens/WatchFaceInfineat.h"
|
||||
#include "displayapp/screens/WatchFaceCasioStyleG7710.h"
|
||||
#include "displayapp/apps/WatchFaces.h"
|
||||
|
||||
namespace Pinetime {
|
||||
|
||||
|
@ -21,7 +22,6 @@ namespace Pinetime {
|
|||
public:
|
||||
struct Item {
|
||||
const char* name;
|
||||
WatchFace watchface;
|
||||
bool enabled;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue