You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: doc/code/Apps.md
+90-32
Original file line number
Diff line number
Diff line change
@@ -9,59 +9,114 @@ This page will teach you:
9
9
10
10
The user interface of InfiniTime is made up of **screens**.
11
11
Screens that are opened from the app launcher are considered **apps**.
12
-
Every app in InfiniTime is it's own class.
12
+
Every app in InfiniTime is its own class.
13
13
An instance of the class is created when the app is launched, and destroyed when the user exits the app.
14
-
Apps run inside the "displayapp" task (briefly discussed [here](./Intro.md)).
14
+
Apps run inside the `DisplayApp` task (briefly discussed [here](./Intro.md)).
15
15
Apps are responsible for everything drawn on the screen when they are running.
16
-
By default, apps only do something (as in a function is executed) when they are created or when a touch event is detected.
16
+
Apps can be refreshed periodically and reacts to external events (touch or button).
17
17
18
18
## Interface
19
19
20
-
Every app class has to be inside the namespace `Pinetime::Applications::Screens` and inherit from `Screen`.
21
-
The constructor should have at least one parameter `DisplayApp* app`, which it needs for the constructor of its parent class Screen.
22
-
Other parameters should be references to controllers that the app needs.
23
-
A destructor is needed to clean up LVGL and restore any changes (for example re-enable sleeping).
24
-
App classes can override `bool OnButtonPushed()`, `bool OnTouchEvent(TouchEvents event)` and `bool OnTouchEvent(uint16_t x, uint16_t y)` to implement their own functionality for those events.
25
-
If an app only needs to display some text and do something upon a touch screen button press,
26
-
it does not need to override any of these functions, as LVGL can also handle touch events for you.
27
-
If you have any doubts, you can always look at how the other apps function for reference.
20
+
Every app class is declared inside the namespace `Pinetime::Applications::Screens`
21
+
and inherits
22
+
from [`Pinetime::Applications::Screens::Screen`](https://github.com/InfiniTimeOrg/InfiniTime/blob/main/src/displayapp/screens/Screen.h).
28
23
29
-
### Continuous updating
24
+
Each app defines its own constructor.
25
+
The constructors mostly take references to InfiniTime `Controllers` (ex: Alarm, DateTime, BLE services, Settings,...)
26
+
the app needs for its operations. The constructor is responsible for initializing the UI of the app.
30
27
31
-
If your app needs to be updated continuously, you can do so by overriding the `Refresh()` function in your class
32
-
and calling `lv_task_create` inside the constructor.
28
+
The **destructor** cleans up LVGL and restores any changes (for example re-enable sleeping).
33
29
34
-
An example call could look like this:
30
+
App classes can override `bool OnButtonPushed()`, `bool OnTouchEvent(TouchEvents event)`
31
+
and `bool OnTouchEvent(uint16_t x, uint16_t y)` to implement their own functionality for those events.
lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr);
79
133
lv_label_set_text_static(title, "My test application");
80
134
lv_label_set_align(title, LV_LABEL_ALIGN_CENTER);
@@ -86,20 +140,24 @@ MyApp::~MyApp() {
86
140
}
87
141
```
88
142
89
-
Both of these files should be in [displayapp/screens/](/src/displayapp/screens/)
90
-
or [displayapp/screens/settings/](/src/displayapp/screens/settings/) if it's a setting app.
143
+
Both of these files should be in [displayapp/screens/](/src/displayapp/screens/).
91
144
92
145
Now we have our very own app, but InfiniTime does not know about it yet.
93
-
The first step is to include your MyApp.cpp (or any new cpp files for that matter)
146
+
The first step is to include your `MyApp.cpp` (or any new cpp files for that matter)
94
147
in the compilation by adding it to [CMakeLists.txt](/CMakeLists.txt).
95
-
The next step to making it launchable is to give your app an id.
148
+
The next step to making it launch-able is to give your app an id.
96
149
To do this, add an entry in the enum class `Pinetime::Applications::Apps` ([displayapp/Apps.h](/src/displayapp/Apps.h)).
97
-
Name this entry after your app. Add `#include "displayapp/screens/MyApp.h"` to the file [displayapp/DisplayApp.cpp](/src/displayapp/DisplayApp.cpp).
98
-
Now, go to the function `DisplayApp::LoadScreen` and add another case to the switch statement.
150
+
Name this entry after your app. Add `#include "displayapp/screens/MyApp.h"`
151
+
to the file [displayapp/DisplayApp.cpp](/src/displayapp/DisplayApp.cpp).
152
+
153
+
If your application is a **system** application, go to the function `DisplayApp::LoadScreen`
154
+
and add another case to the switch statement.
99
155
The case will be the id you gave your app earlier.
100
156
If your app needs any additional arguments, this is the place to pass them.
101
157
102
-
If you want to add your app in the app launcher, add your app in [displayapp/screens/ApplicationList.h](/src/displayapp/screens/ApplicationList.h) to the array containing the applications and their corresponding symbol. If your app is a setting, do the same procedure in [displayapp/screens/settings/Settings.h](/src/displayapp/screens/settings/Settings.h).
158
+
If your application is a **user** application, you don't need to add anything in DisplayApp,
159
+
everything will be automatically generated for you.
160
+
The user application will also be automatically be added to the app launcher menu.
103
161
104
162
You should now be able to [build](../buildAndProgram.md) the firmware
0 commit comments