I would like to create a Display lambda C++ method for displaying Green-Yellow-Red bars.
Using the existing lambda “it.horizontal_line(…)” I have shown one bar, but I really would like to create an extra method for the Display class, so it could be called something like: it.GYR_bar(… …).
I have found the C++ source code for the Display class, but I am struggling with C++ in my “cpp-file.h” file that I include in the YAML syntax. Below is a first attempt, that doesn’t compile. Any pointers to examples I can borrow from?
In my YAML:
includes:
- cpp-file.h
In my cpp-file.h:
#include "display.h"
#include "esphome.h"
namespace esphome {
namespace display {
// DEMO declaration to get basics running
void Display::GYR_bar(int x1, int y1, int width, int height, Color color) {
//
// This is the C++ code from the existing rectangle method to check
// the basic include and namespace settings
//
// vvvv DEMO CODE vvvv
this->horizontal_line(x1, y1, width, color);
this->horizontal_line(x1, y1 + height - 1, width, color);
this->vertical_line(x1, y1, height, color);
this->vertical_line(x1 + width - 1, y1, height, color);
// ^^^^ DEMO CODE ^^^^
}
}
}
Thanks!