Skip to content

Commit

Permalink
navigation: Add is available (InfiniTimeOrg#1847)
Browse files Browse the repository at this point in the history
Navigation app now needs 2 images to be loaded from the resources on the external filesystem. This PR adds an 'enabled' field to the Applications struct. This field is true for all applications expect for Navigation which calls Navigation::IsAvailable(). This methods returns true if the 2 files are available in the resources.

The application list disables the application (draws it in grey, disables the touch callback) if the enable flag is not set.
  • Loading branch information
JF002 authored Sep 2, 2023
1 parent 44d1798 commit 0aead42
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/displayapp/DisplayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
switch (app) {
case Apps::Launcher:
currentScreen =
std::make_unique<Screens::ApplicationList>(this, settingsController, batteryController, bleController, dateTimeController);
std::make_unique<Screens::ApplicationList>(this, settingsController, batteryController, bleController, dateTimeController, filesystem);
break;
case Apps::Motion:
// currentScreen = std::make_unique<Screens::Motion>(motionController);
Expand Down
6 changes: 3 additions & 3 deletions src/displayapp/screens/ApplicationList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

using namespace Pinetime::Applications::Screens;

constexpr std::array<Tile::Applications, ApplicationList::applications.size()> ApplicationList::applications;

auto ApplicationList::CreateScreenList() const {
std::array<std::function<std::unique_ptr<Screen>()>, nScreens> screens;
for (size_t i = 0; i < screens.size(); i++) {
Expand All @@ -22,12 +20,14 @@ ApplicationList::ApplicationList(Pinetime::Applications::DisplayApp* app,
Pinetime::Controllers::Settings& settingsController,
const Pinetime::Controllers::Battery& batteryController,
const Pinetime::Controllers::Ble& bleController,
Controllers::DateTime& dateTimeController)
Controllers::DateTime& dateTimeController,
Pinetime::Controllers::FS& filesystem)
: app {app},
settingsController {settingsController},
batteryController {batteryController},
bleController {bleController},
dateTimeController {dateTimeController},
filesystem{filesystem},
screens {app, settingsController.GetAppMenu(), CreateScreenList(), Screens::ScreenListModes::UpDown} {
}

Expand Down
33 changes: 18 additions & 15 deletions src/displayapp/screens/ApplicationList.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "components/battery/BatteryController.h"
#include "displayapp/screens/Symbols.h"
#include "displayapp/screens/Tile.h"
#include "displayapp/screens/Navigation.h"

namespace Pinetime {
namespace Applications {
Expand All @@ -20,7 +21,8 @@ namespace Pinetime {
Pinetime::Controllers::Settings& settingsController,
const Pinetime::Controllers::Battery& batteryController,
const Pinetime::Controllers::Ble& bleController,
Controllers::DateTime& dateTimeController);
Controllers::DateTime& dateTimeController,
Pinetime::Controllers::FS& filesystem);
~ApplicationList() override;
bool OnTouchEvent(TouchEvents event) override;

Expand All @@ -33,26 +35,27 @@ namespace Pinetime {
const Pinetime::Controllers::Battery& batteryController;
const Pinetime::Controllers::Ble& bleController;
Controllers::DateTime& dateTimeController;
Pinetime::Controllers::FS& filesystem;

static constexpr int appsPerScreen = 6;

// Increment this when more space is needed
static constexpr int nScreens = 2;

static constexpr std::array<Tile::Applications, appsPerScreen * nScreens> applications {{
{Symbols::stopWatch, Apps::StopWatch},
{Symbols::clock, Apps::Alarm},
{Symbols::hourGlass, Apps::Timer},
{Symbols::shoe, Apps::Steps},
{Symbols::heartBeat, Apps::HeartRate},
{Symbols::music, Apps::Music},

{Symbols::paintbrush, Apps::Paint},
{Symbols::paddle, Apps::Paddle},
{"2", Apps::Twos},
{Symbols::drum, Apps::Metronome},
{Symbols::map, Apps::Navigation},
{Symbols::none, Apps::None},
std::array<Tile::Applications, appsPerScreen * nScreens> applications {{
{Symbols::stopWatch, Apps::StopWatch, true},
{Symbols::clock, Apps::Alarm, true},
{Symbols::hourGlass, Apps::Timer, true},
{Symbols::shoe, Apps::Steps, true},
{Symbols::heartBeat, Apps::HeartRate, true},
{Symbols::music, Apps::Music, true},

{Symbols::paintbrush, Apps::Paint, true},
{Symbols::paddle, Apps::Paddle, true},
{"2", Apps::Twos, true},
{Symbols::drum, Apps::Metronome, true},
{Symbols::map, Apps::Navigation, Applications::Screens::Navigation::IsAvailable(filesystem)},
{Symbols::none, Apps::None, false},

// {"M", Apps::Motion},
}};
Expand Down
16 changes: 16 additions & 0 deletions src/displayapp/screens/Navigation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,19 @@ void Navigation::Refresh() {
}
}
}

bool Navigation::IsAvailable(Pinetime::Controllers::FS& filesystem) {
lfs_file file = {};

if (filesystem.FileOpen(&file, "/images/navigation0.bin", LFS_O_RDONLY) < 0) {
return false;
}
filesystem.FileClose(&file);

if (filesystem.FileOpen(&file, "/images/navigation1.bin", LFS_O_RDONLY) < 0) {
return false;
}
filesystem.FileClose(&file);

return true;
}
2 changes: 2 additions & 0 deletions src/displayapp/screens/Navigation.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
namespace Pinetime {
namespace Controllers {
class NavigationService;
class FS;
}

namespace Applications {
Expand All @@ -36,6 +37,7 @@ namespace Pinetime {
~Navigation() override;

void Refresh() override;
static bool IsAvailable(Pinetime::Controllers::FS& filesystem);

private:
lv_obj_t* imgFlag;
Expand Down
2 changes: 1 addition & 1 deletion src/displayapp/screens/Tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Tile::Tile(uint8_t screenID,

for (uint8_t i = 0; i < 6; i++) {
lv_btnmatrix_set_btn_ctrl(btnm1, i, LV_BTNMATRIX_CTRL_CLICK_TRIG);
if (applications[i].application == Apps::None) {
if (applications[i].application == Apps::None || !applications[i].enabled) {
lv_btnmatrix_set_btn_ctrl(btnm1, i, LV_BTNMATRIX_CTRL_DISABLED);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/displayapp/screens/Tile.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace Pinetime {
struct Applications {
const char* icon;
Pinetime::Applications::Apps application;
bool enabled;
};

explicit Tile(uint8_t screenID,
Expand Down

0 comments on commit 0aead42

Please sign in to comment.