Page 1 of 1

Efficient Coding Considerations

Posted: Thu Mar 14, 2019 2:42 pm
by Deouss
I am trying to develop some kind of display graphic library or class that's uniform across devices.
I noticed every time the new display is added it involves basically rewriting or ugly renaming the functions and variables which makes a big mess if we deal with larger number of devices or their variations.
So why not create a class in OOP style in C++ that has virtual methods which could be overwritten in future for newer displays, sensors, etc.
F.ex: class for display could be

Code: Select all

class DisplayBase
{
public:
 	display_type_t DisplayType;
 	DisplayGraphicbase Graphics;
 	
	virtual int InitDisplay(){}	
	virtual int GetDisplayType()
	....
}

class DisplayGraphicsBase
{
public:
 
	virtual void Clear() {}
	virtual void DrawArc
	virtual void DrawBezier
	virtual void DrawBeziers
	virtual void DrawClosedCurve
	virtual void DrawCurve
	virtual void DrawEllipse
	virtual void DrawIcon
.......
	virtual void DrawImage
	virtual void DrawImageUnscaled
	virtual void DrawImageUnscaledAndClipped
	virtual void DrawLine
	virtual void DrawLines
	virtual void DrawPath
	virtual void DrawPie
....
	virtual void ScaleTransform
	virtual void SetClip
	virtual void TransformPoints
	virtual void TranslateClip
	virtual void TranslateTransform
}
So in such way we can execute same function for drawing f.ex text or icon on two different displays without too much coding
This could be applied not only to displays but all kinds of sensors or modules
I am just thinking loud here and wonder if anyone has tried similar coding for embedded stuff
I think it would be much faster and easier coding this way

Re: Efficient Coding Considerations

Posted: Thu Mar 14, 2019 3:18 pm
by ESP_igrr
Adafruit GFX library is one such example. It supports many kinds of displays through their other libraries, each display class is derived from the same base class.

Re: Efficient Coding Considerations

Posted: Thu Mar 14, 2019 11:06 pm
by Deouss
Maybe some people would be interested in non-Adafruit graphics library project just for ESP
I also like the idea of RTOS on ESP8266 which will make those MCUs very attractive on market and practical for engineers
For now however there is no CMake for 8266