|
Lamp-Da 0.1
A compact lantern project
|
This document can be viewed as an introduction to development on the project, as well as a way for beginners to write a new "lighting mode" for one of the boards specified in this project.
First, the directory structure:
src/modessrc/systemsrc/userThe examples used in this guide are provided in modes/examples.
We will start with reading the 00_intro_mode.hpp example:
We recommend that you put your modes inside a modes:: namespace.
For example, if you are going to write some games for this board, feel free to create a new modes/custom/games/ directory, then a modes/custom/games/my_game_mode.hpp file, with the following content:
There are several rules while writing a mode:
public BasicModestaticstatic constexprWhat you will observe as you experiment, is that mode structures such as IntroMode and MyGameMode are completely state-less and are never actually constructed during the runtime of the program. Hence, all the following usages are strongly discouraged:
You can view that structure as a collection of static callbacks that implements your mode.
Note that only these callbacks will be called at runtime.
For example, if we look at the default BasicMode implementation of the void loop(auto& ctx) callback:
We see that by default, the .loop() callback does nothing.
Coming back at 00_intro_mode.hpp we see that it implements it as follows:
Here the ctx object makes available two important members:
ctx.lamp object that exposes to you user the lamp hardwarectx.state object that exposes to you your own mode stateWe will later see how to make your mode stateful by defining a custom StateTy.
Here, looking at the LampTy documentation, we see the following:
The IntroMode loop function thus fills the lamp with colors::Chartreuse (see documentation for modes/include/colors/palettes.hpp) and then, vary the brightness of the lamp depending on the current tick number.
One remark here, is that "colors" are meaningful only if the board is set up with an RGB LED strip, meaning that this mode will fail if make simple or make cct have been used during build.
To support multiple board flavors within a mode, use the following:
If you tried to modify modes/examples/00_intro_mode.hpp by yourself during this guide, you may have noticed that it is not compiled / not included at all.
This is because you need to enable the mode inside the global mode manager.
In order to do that, you can edit src/user/indexable_functions.cpp as follows:
Here, we declare a mode group named IntroGroup that contains only one mode, our new modes::examples::IntroMode and nothing else. We are then able to pass a list to the manager of all the groups we want to include in our configuration, here our IntroGroup that only includes IntroMode.
It can be needed to have extra groups not accessible by standard actions. The template option hiddenGroupCnt allows the programmer to add groups that wont be accessible by standard user inputs.
Be aware that once entered, those groups can be circulated by standard user commands. Modes in thoses groups can also be saved as favorites and other standard actions. The only difference with the standard groups will be the way to go to those groups.
A manager can only be created with at least one accessible group.
Enter an hidden group simply using the enter_group method of the manager, with the id of the hidden group as a parameter.
The types to use for managers with hidden groups is ManagerFoHiddenConfig and ManagerForHiddenGroups.
Example: