Skip to content

Commit

Permalink
Merge branch 'InfiniTimeOrg:develop' into dice
Browse files Browse the repository at this point in the history
  • Loading branch information
yusufmte authored Oct 2, 2022
2 parents 349e63a + 7b115fe commit 11067bc
Show file tree
Hide file tree
Showing 16 changed files with 595 additions and 19 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Fast open-source firmware for the [PineTime smartwatch](https://www.pine64.org/p
- [Generate the fonts and symbols](src/displayapp/fonts/README.md)
- [Tips on designing an app UI](doc/ui_guidelines.md)
- [Bootloader, OTA and DFU](bootloader/README.md)
- [External resources](doc/ExternalResources.md)
- [Versioning](doc/versioning.md)
- [Project branches](doc/branches.md)
- [Files included in the release notes](doc/filesInReleaseNotes.md)
Expand Down
70 changes: 70 additions & 0 deletions doc/ExternalResources.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# External resources
Since InfiniTime 1.11 apps and watchfaces can benefit from the external flash memory to store images and fonts.
This external memory is a lot bigger (4MB) than the internal memory that contains the firmware (512KB).

This page describes how the resources are integrated in InfiniTime from a developer perspective. [This page](gettingStarted/updating-software.md) explains how to install and update the external resources using companion apps.

## Resources generation

Resources are generated at build time via the [CMake target `Generate Resources`](https://github.com/InfiniTimeOrg/InfiniTime/blob/develop/src/resources/CMakeLists.txt#L19).
It runs 3 Python scripts that respectively convert the fonts to binary format, convert the images to binary format and package everything in a .zip file.

The resulting file `infinitime-resources-x.y.z.zip` contains the images and fonts converted in binary `.bin` files and a JSON file `resources.json`.

Companion apps use this file to upload the files to the watch.

```
{
"resources": [
{
"filename": "lv_font_dots_40.bin",
"path": "/fonts/lv_font_dots_40.bin"
}
],
"obsolete_files": [
{
"path": "/example-of-obsolete-file.bin",
"since": "1.11.0"
}
]
}
```

The resource JSON file describes an array of resources and an array of obsolete files :

- `resources` : a resource is a file that must be flashed to the watch
- `filename`: name of the resources in the zip file.
- `path` : file path and name where the file must be flashed in the watch FS.

- `obsolete_files` : files that are not needed anymore in the memory of the watch that can be deleted during the update procedure.
- `path` : path of the file in the watch FS
- `since` : version of InfiniTime that made this file obsolete.

## Resources update procedure

The update procedure is based on the [BLE FS API](BLEFS.md). The companion app simply write the binary files to the watch FS using information from the file `resources.json`.

## Working with external resources in the code

Load a picture from the external resources:

```
lv_obj_t* logo = lv_img_create(lv_scr_act(), nullptr);
lv_img_set_src(logo, "F:/images/logo.bin");
```

Load a font from the external resources: you first need to check that the file actually exists. LVGL will crash when trying to open a font that doesn't exist.

```
lv_font_t* font_teko = nullptr;
if (filesystem.FileOpen(&f, "/fonts/font.bin", LFS_O_RDONLY) >= 0) {
filesystem.FileClose(&f);
font_teko = lv_font_load("F:/fonts/font.bin");
}
if(font != nullptr) {
lv_obj_set_style_local_text_font(label, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, font);
}
```

Binary file added doc/gettingStarted/itd-external-resources.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions doc/gettingStarted/updating-software.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,35 @@ You can validate your updated firmware on InfiniTime >= 1.0 by following this si
- Open settings by tapping the cogwheel on the bottom right
- Swipe up until you find an entry named **Firmware** and tap on it
- If the firmware is not validated yet, you can either validate the running firmware, or reset and revert to the previous firmware version

# Updating resources

Since InfiniTime 1.11 apps and watchfaces can take benefit of the external flash memory to store their pictures and fonts.
This external memory is a lot bigger (4MB) than the internal memory where the firmware is flashed (512KB).
Since those resources are not part of the firmware, they need to be flashed and updated separately.

Resources are packaged into a single .zip file named `infinitime-resources-x.y.z.zip` (where `x`, `y` and `z` are the version numbers of InfiniTime).
You can use the companion app of your choice to flash the resources.

**Note : at the time of writing this page, [Amazfish](https://github.com/piggz/harbour-amazfish) and [ITD](https://gitea.arsenm.dev/Arsen6331/itd) have already integrated this functionality. Other companion apps will hopefully implement it soon!*

## Amazfish
Use the `Download file` functionality of Amazfish.

![Update resources with Amazfish - Download file](amazfish-external-resources-1.png)

Amazfish automatically detects the file type (firmware or resources) and apply the corresponding flash procedure when you hit the button **Send file**.

![Update resources with Amazfish](amazfish-external-resources-2.png)

## ITD

Run `itctl` with the `res` command:

```
itctl res load infinitime-resources-1.10.0.zip
```

Example:

![Update resources using itctl](itd-external-resources.png)
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ list(APPEND SOURCE_FILES
displayapp/screens/WatchFaceInfineat.cpp
displayapp/screens/WatchFaceTerminal.cpp
displayapp/screens/WatchFacePineTimeStyle.cpp
displayapp/screens/WatchFaceCasioStyleG7710.cpp

##

Expand Down
2 changes: 1 addition & 1 deletion src/components/motor/MotorController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void MotorController::Ring(TimerHandle_t xTimer) {
}

void MotorController::RunForDuration(uint8_t motorDuration) {
if (xTimerChangePeriod(shortVib, pdMS_TO_TICKS(motorDuration), 0) == pdPASS && xTimerStart(shortVib, 0) == pdPASS) {
if (motorDuration > 0 && xTimerChangePeriod(shortVib, pdMS_TO_TICKS(motorDuration), 0) == pdPASS && xTimerStart(shortVib, 0) == pdPASS) {
nrf_gpio_pin_clear(PinMap::Motor);
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/components/settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ namespace Pinetime {
appMenu = menu;
};

void SetWatchfacesMenu(uint8_t menu) {
watchFacesMenu = menu;
};

uint8_t GetWatchfacesMenu() const {
return watchFacesMenu;
};

uint8_t GetAppMenu() const {
return appMenu;
};
Expand All @@ -134,14 +142,6 @@ namespace Pinetime {
return settingsMenu;
};

void SetWatchfacesMenu(uint8_t menu) {
watchFacesMenu = menu;
};

uint8_t GetWatchfacesMenu() const {
return watchFacesMenu;
};

void SetClockType(ClockType clocktype) {
if (clocktype != settings.clockType) {
settingsChanged = true;
Expand Down
17 changes: 13 additions & 4 deletions src/displayapp/DisplayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void DisplayApp::Process(void* instance) {

void DisplayApp::InitHw() {
brightnessController.Init();
brightnessController.Set(settingsController.GetBrightness());
ApplyBrightness();
}

void DisplayApp::Refresh() {
Expand Down Expand Up @@ -159,7 +159,7 @@ void DisplayApp::Refresh() {
brightnessController.Set(Controllers::BrightnessController::Levels::Low);
break;
case Messages::RestoreBrightness:
brightnessController.Set(settingsController.GetBrightness());
ApplyBrightness();
break;
case Messages::GoToSleep:
while (brightnessController.Level() != Controllers::BrightnessController::Levels::Off) {
Expand All @@ -170,7 +170,7 @@ void DisplayApp::Refresh() {
state = States::Idle;
break;
case Messages::GoToRunning:
brightnessController.Set(settingsController.GetBrightness());
ApplyBrightness();
state = States::Running;
break;
case Messages::UpdateTimeOut:
Expand Down Expand Up @@ -304,7 +304,7 @@ void DisplayApp::ReturnApp(Apps app, DisplayApp::FullRefreshDirections direction

void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) {
touchHandler.CancelTap();
brightnessController.Set(settingsController.GetBrightness());
ApplyBrightness();

currentScreen.reset(nullptr);
SetFullRefresh(direction);
Expand Down Expand Up @@ -534,3 +534,12 @@ void DisplayApp::PushMessageToSystemTask(Pinetime::System::Messages message) {
void DisplayApp::Register(Pinetime::System::SystemTask* systemTask) {
this->systemTask = systemTask;
}
void DisplayApp::ApplyBrightness() {
auto brightness = settingsController.GetBrightness();
if(brightness != Controllers::BrightnessController::Levels::Low &&
brightness != Controllers::BrightnessController::Levels::Medium &&
brightness != Controllers::BrightnessController::Levels::High) {
brightness = Controllers::BrightnessController::Levels::High;
}
brightnessController.Set(brightness);
}
1 change: 1 addition & 0 deletions src/displayapp/DisplayApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ namespace Pinetime {
Apps nextApp = Apps::None;
DisplayApp::FullRefreshDirections nextDirection;
System::BootErrors bootError;
void ApplyBrightness();
};
}
}
1 change: 0 additions & 1 deletion src/displayapp/screens/CheckboxList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ CheckboxList::CheckboxList(const uint8_t screenID,

CheckboxList::~CheckboxList() {
lv_obj_clean(lv_scr_act());
settingsController.SaveSettings();
}

void CheckboxList::UpdateSelected(lv_obj_t* object, lv_event_t event) {
Expand Down
18 changes: 17 additions & 1 deletion src/displayapp/screens/Clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "displayapp/screens/WatchFaceInfineat.h"
#include "displayapp/screens/WatchFaceAnalog.h"
#include "displayapp/screens/WatchFacePineTimeStyle.h"
#include "displayapp/screens/WatchFaceCasioStyleG7710.h"

using namespace Pinetime::Applications::Screens;

Expand Down Expand Up @@ -51,6 +52,9 @@ Clock::Clock(DisplayApp* app,
case 4:
return WatchFaceInfineatScreen();
break;
case 5:
return WatchFaceCasioStyleG7710();
break;
}
return WatchFaceDigitalScreen();
}()} {
Expand Down Expand Up @@ -115,8 +119,20 @@ std::unique_ptr<Screen> Clock::WatchFaceInfineatScreen() {
dateTimeController,
batteryController,
bleController,
notificatioManager,
notificationManager,
settingsController,
motionController,
filesystem);
}

std::unique_ptr<Screen> Clock::WatchFaceCasioStyleG7710() {
return std::make_unique<Screens::WatchFaceCasioStyleG7710>(app,
dateTimeController,
batteryController,
bleController,
notificationManager,
settingsController,
heartRateController,
motionController,
filesystem);
}
1 change: 1 addition & 0 deletions src/displayapp/screens/Clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ namespace Pinetime {
std::unique_ptr<Screen> WatchFacePineTimeStyleScreen();
std::unique_ptr<Screen> WatchFaceTerminalScreen();
std::unique_ptr<Screen> WatchFaceInfineatScreen();
std::unique_ptr<Screen> WatchFaceCasioStyleG7710();
};
}
}
Expand Down
Loading

0 comments on commit 11067bc

Please sign in to comment.