Efficient Coding Considerations
Posted: 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
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
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
}
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