Skip to content

Latest commit

 

History

History
105 lines (79 loc) · 4.01 KB

ESPHOME.md

File metadata and controls

105 lines (79 loc) · 4.01 KB

espmake

cppdash can be used by esphome projects to allows espmhome.yaml files to repeat map keys declarations such as sensor: or switch: across files and merges them. It also allows the C preprocessor to operate on yaml.

cpphash assists with managing multiple esphome project variants that share yaml source files. It also enables the sharing of pin definitions and configuration definitions between yaml and C / C++ files by enabling the use of C preprocessor directives inside espmake.yaml files. See lily.yaml, config.h and pins.h in the example directory.

cpphash generates reads, for example, esphome.yaml and generates and output file, for example espmake.yaml for each project variant.

Project variants are built in the build/ directory by default. Project variants are selected using the PRJ make variable and named after the file specified without the suffix. For example, for "make PRJ=lily.yaml", the output file, which defaults to "espmake.yaml" file will be found in build/lily. If the PRJ file is set to esphome.yaml, the build for it will be in build/esphome.

The reason a new espmake.yaml is generated is because espmake runs the original esphome project's yaml files through the C-preprocessor (cpp) and leaves it there available for review. And the generated CPP output needs a new name. Hence, it is, by default, called espmake.yaml. esphome itself will operate on the output file espmake.yaml.

Once a yaml file is generated by the Makefile, esphome commands can be issued upon it, such as:

 esphome compile espmake.yaml
 esphome upload  espmake.yaml
 esphome logs    espmake.yaml

See 'esphome -h' for more details on esphome commands. There are also some convenience aliases that can be found in Bashrc.

Installation

To add cpphash support to an existing esphome project directory, just git clone htpps://github.com/maartenSXM/cpphash.git from that directory and then run ./cpphash/install.sh.

Then cpphash/Makefile.esphome can be copied to the esphome project directory like this: cp -i cpphash/Makefile.esphome ./Makefile

Note, do not do this is there is already a Makefile in the esphome project directory as it will be overwritten. Save it first.

Before building, do this to activate the esphome virtual environment: source cpphash/Bashrc

cpphash/Bashrc will set CH_HOME and will define some convenience aliases.

Makefile User variables

These Makefile variables can be changed from their defaults by either editting the Makefile or overriding them with an argument to make such as

make PRJ=init.yaml

cpphash will remember the PRJ setting by storing it in .cpphash_prj so that it does not have to be specified afterwards.

PRJ

The initial yaml file that #includes the others. It defaults to "esphome.yaml". To quickly get started using cpphash, clone it, run cpphash/install.sh and the source cpphash/Bashrc and then copy Makefile.esphome to the same directory as your esphome.yaml and type make.

If your esphome yaml file is called something else, use "make PRJ=. After specifying PRJ= once, espmake will remember it since it stashes it in $ESPMAKE_HOME/.cpphash_prj.

Generated files

Generated yaml can be deleted using 'make clean'. To remove the binary build created by esphome, use 'make realclean'.

Other

There are some additional comments describing Makefile.esphome features in Makefile.esphome.

There are some aliases in file Bashrc which may be helpful for issuing esphome commands. To dump the esphome cpphash config, try 'make print-config'.

cpphash leverages yq to merge multiple declaration of esphome sections such as "sensor:" or "switch:". This allows #ifdefs to declare them in separate files conditionally and cpphash will merge them together for processing by esphome.

Credits

Thank you to Landon Rohatensky for the exemplary espmake.yaml file https://github.com/landonr/lilygo-tdisplays3-esphome used to demonstrate espmake configuration, build and also as used in the test subdirectory.

Thank you Mike Farah for yq. It is at https://github.com/mikefarah/yq.