Before you start to write code, you must first understand the basic structure of a FlyThings project, and then you can know where your code should be added.
For a basic FlyThings project, its directory structure is like this:
It is roughly divided into three folders: jni, resources, ui. The role of each folder is explained below.
Expand ui folder
You can see that a main.ftu file is included by default. ftu is the suffix of the UI file of the FlyThings project. Each ftu file corresponds to an application interface. Usually, an application contains multiple interfaces, so you need to create multiple ftu files in the ui folder. To add a new ftu file, please refer to How to create a new FlyThings UI file. For the convenience of description, in the following tutorials, the ftu file will be referred to as the UI file.
You can double-click to open the UI file, edit it, and preview the effect instantly. For the specific steps of editing the UI file, please refer to the tutorial of Introduction to Controls.
After editing, you can start "compile" (How to compile）
[!Note] Note: The compilation mentioned here not only compiles the source code, but also includes a series of operations such as the preprocessing of the ui file and the generation of template code, but these are all automated, and you do not need to manually operate. For all the specific operations behind compiling this action, please refer to The specific compilation process and the correspondence between UI files and source code, After reading, I believe you will be easier to understand and get started quickly
The content of this folder is relatively simple, mainly used to store various resource files of the project, including pictures, fonts, input method configuration files, etc. If you have other resource files you can also add to this folder, the folder will be completely copied to the machine. However, due to the limitation of the machine's own storage space, it is not recommended to store large files in this directory. It is recommended that you store large resource files in the TF card.
We can get the absolute path of a file in the resources directory in the code. For example: The following code can obtain the absolute path of resources/test.txt.
std::string resPath = CONFIGMANAGER->getResFilePathEx("test.txt");
This folder is mainly for storing code files, and it also contains multiple parts of code. We expand the jni folder
As you can see, it contains 6 parts of activity, include, logic, uart, Main.cpp, Makefile, each The functions of each part are as follows:
Store the basic class code of the UI file. After each UI file is compiled, an
Activityclass and a
Logic.ccfile with the same prefix name will be generated. For example: there is a main.ftu in the ui folder, then after compilation,
mainLogic.ccwill be generated, and the
mainActivityclass will be stored in In the activity folder, the
mainLogic.ccfile will be stored in the logic folder.
[!Warning] It is strongly recommended not to manually modify the code under the activity folder, except in special circumstances
Store specific logic codes. Same as the description above, each UI file will generate a Logic.cc file with the corresponding prefix name after compilation.Note: Our custom code is mainly added to these Logic.cc files.
After the compilation is passed, the libs directory and the obj directory will be generated under the project, which are the compiled target storage directory and the compiled intermediate file directory, both of which can be cleaned up or deleted directly It doesn't matter.