Efficient Coding Considerations

Deouss
Posts: 425
Joined: Tue Mar 20, 2018 11:36 am

Efficient Coding Considerations

Postby Deouss » Thu Mar 14, 2019 2:42 pm

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

ESP_igrr
Posts: 2067
Joined: Tue Dec 01, 2015 8:37 am

Re: Efficient Coding Considerations

Postby ESP_igrr » Thu Mar 14, 2019 3:18 pm

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.

Deouss
Posts: 425
Joined: Tue Mar 20, 2018 11:36 am

Re: Efficient Coding Considerations

Postby Deouss » Thu Mar 14, 2019 11:06 pm

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

Who is online

Users browsing this forum: Majestic-12 [Bot] and 150 guests