I have started to work on a library to simplify and abstract displaying data on arduino systems.
Initially, this idea came out of a project to build a dashboard to display some sensor data on my motorcycle using a tft / oled.
Right now, I have achieved a state where I can flexibly display numeric and textual data in a way that is very convenient from the Arduino Sketche's point of view:
Adafruit_ILI9341 tft1 = Adafruit_ILI9341(_cs, _dc, _rst);
textIntegerGauge Gspeed = textIntegerGauge(&tft1, 20, 20, 75, 40);
instanciates an Gauge on an ILI9341 display (any display supported by Adafruit_Gfx can be used).
Gspeed.setAutoRedraw(true);
Gspeed.setFont(&digital7monoitalic18pt7b);
Gspeed.setFormatString(String("%3i"));
Gspeed.setFGColor(WHITE);
Gspeed.setBGColor(BLUE);
Gspeed.setBorder(2);
Gspeed.setBorderColor(GREEN);
Gspeed.setCursor(10, 26);
adding some configuration to the Gspeed Gauge.
After that, updating the reading on the screen is simply a matter of calling
Gspeed.setValue(variable);
If autoRedraw has been set to true, that will automatically trigger a redraw of that Gauge, and only that Gauge, leaving the rest of the screen intact (unless there is overlap).
The gauge can even be moved to another screen by calling
Gspeed.setDisplay(&the_other_display);
This is what I'm currently running on my motorcycle.
However, it's not even half of the functionality I am envisioning for this library, and this is where I might need some help.
In my current thinking, there are two base "things" that might be base classes:
- datatypes
- visualizations
There are a few concepts that I'm thinking about, but frankly, my c++ prowess is not quite up where it would have to be, it seens.
- Multiple inheritance
This was my initial approach, have a "visualization" class that knows how to take a value and display it in a certain fashion and have a "datayte" class that basically just acts as a container for an allowable datatype that can be displayed by a specific visualization class - Template classes
Potentially, this is the more flexible way to do things, in essence, the visualization classes would have to be implemented using templates for the actual data to be displayed. On the face of it, this sounds tempting, but: depending on the datatype, sometimes, different computations have to be performed inside the class, and I have found that difficult with templates. The prime example would be printf format strings inside class templates - external visualization functions
This would be the easiest for a user to change (just add a function to set a visualization function callback and provide solid defaults) but my initial attempt to do this made it seem that it's near impossible to come up with an abstract set of parameters that would allow this to work. After all, the different output classes have very different requirements (display with coordinates, color, size vs. servo with range, direction and pin)
So, if there's anyone out here having an idea or a concept, I would highly appreciate this.
In the medium term, whatever architecture is implemented, I want it to be simple to add additional visualization functions so people can contribute to the project without having to pick it all apart.
link to the project on gitub: GitHub - pljakobs/Arduino_Gauges: A set of gauges to work with Adafruit_GFX
thanks,
pj