implementation continues...
This commit is contained in:
@@ -5,8 +5,68 @@
|
|||||||
|
|
||||||
namespace Render {
|
namespace Render {
|
||||||
|
|
||||||
Mare::Mare(){
|
Mare::Mare(dim_t size) :
|
||||||
|
_screenSize(size),
|
||||||
|
_screenBufferBackground(nullptr),
|
||||||
|
_screenBufferForeground(nullptr)
|
||||||
|
{
|
||||||
|
int rv;
|
||||||
|
_screenBufferBackground = (uint8_t*)malloc(sizeof(uint8_t)* (_screenSize.x * _screenSize.y));
|
||||||
|
_screenBufferForeground = (uint8_t*)malloc(sizeof(uint8_t)* (_screenSize.x * _screenSize.y));
|
||||||
|
clearBuffer(_screenBufferBackground, Color::White);
|
||||||
|
clearBuffer(_screenBufferBackground, Color::White);
|
||||||
|
|
||||||
|
// init display
|
||||||
|
DEV_Delay_ms(500);
|
||||||
|
if((rv=DEV_Module_Init())!=0){
|
||||||
|
printf("Init Failed, %d",rv);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
EPD_2IN9_V2_Init();
|
||||||
|
EPD_2IN9_V2_Clear();
|
||||||
|
printf("Mare render engine created\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
Mare::~Mare(){
|
||||||
|
for (auto &d :_drawables) {
|
||||||
|
d.reset();
|
||||||
|
}
|
||||||
|
for (auto &p : _pages){
|
||||||
|
p.reset();
|
||||||
|
}
|
||||||
|
free(_screenBufferBackground);
|
||||||
|
free(_screenBufferForeground);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void Mare::addDrawable(T){
|
||||||
|
static size_t lastDrawableIndex(0);
|
||||||
|
auto newD = std::make_shared<T>(lastDrawableIndex++, )
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Mare::render() {
|
||||||
|
clearBuffer(_screenBufferBackground, Color::White);
|
||||||
|
for (auto &d: _drawables) {
|
||||||
|
if (d != nullptr){
|
||||||
|
d->render();
|
||||||
|
} else {
|
||||||
|
printf("Drawable is expired");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mare::setPixel(uint8_t* img, uint16_t x, uint16_t y, bool value){
|
||||||
|
assert(x <= _screenSize.x);
|
||||||
|
assert(y <= _screenSize.y);
|
||||||
|
img += (sizeof(uint8_t)*x*(_screenSize.y>>3)+ sizeof(uint8_t)*(y>>3));
|
||||||
|
if (value) *img &= ~0x01 << (y%8);
|
||||||
|
else *img |= 0x01 << y%8;
|
||||||
|
}
|
||||||
|
|
||||||
|
void clearBuffer(uint8_t* buffer, Color col){
|
||||||
|
assert(buffer != nullptr);
|
||||||
|
std::memset(buffer, col == Color::White ? 0xff : 0x00, sizeof(buffer));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
139
libs/mare/mare.h
139
libs/mare/mare.h
@@ -5,12 +5,14 @@
|
|||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <DEV_Config.h>
|
#include <DEV_Config.h>
|
||||||
#include <EPD_2in9b_V3.h>
|
#include <EPD_2in9_V2.h>
|
||||||
#include <fonts.h>
|
#include <fonts.h>
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <cstring>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace Render{
|
namespace Render{
|
||||||
|
|
||||||
@@ -36,56 +38,64 @@ namespace Render{
|
|||||||
Intersect
|
Intersect
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class Color {
|
||||||
|
White,
|
||||||
|
Black
|
||||||
|
};
|
||||||
|
|
||||||
class Page;
|
class Page;
|
||||||
class Drawable;
|
class Drawable;
|
||||||
|
|
||||||
typedef pos_t dim_t;
|
typedef pos_t dim_t;
|
||||||
typedef std::vector<Page*> Pages;
|
typedef std::vector<std::shared_ptr<Page>> Pages;
|
||||||
typedef std::vector<Drawable*> Drawables;
|
typedef std::vector<std::shared_ptr<Drawable>> Drawables;
|
||||||
|
|
||||||
class Mare {
|
class Mare {
|
||||||
Mare();
|
friend class Drawable;
|
||||||
virtual ~Mare();
|
|
||||||
|
Mare(dim_t size);
|
||||||
|
~Mare();
|
||||||
|
|
||||||
// getters, setters
|
// getters, setters
|
||||||
public:
|
public:
|
||||||
void setSize(const uint16_t x, const uint16_t y);
|
void setSize(const dim_t size);
|
||||||
const dim_t getSize();
|
const dim_t getSize();
|
||||||
void setRotation(const ScreenRotation r);
|
void setRotation(const ScreenRotation r);
|
||||||
const ScreenRotation getRotation();
|
const ScreenRotation getRotation();
|
||||||
|
|
||||||
const Pages& getPages();
|
|
||||||
const uint8_t getCurrentPage();
|
|
||||||
void setCurrentPage(const uint8_t p);
|
void setCurrentPage(const uint8_t p);
|
||||||
|
const Page& getCurrentPage();
|
||||||
const Drawables& getDrawables();
|
|
||||||
|
|
||||||
// drawables, pages
|
// drawables, pages
|
||||||
public:
|
public:
|
||||||
void addDrawable();
|
template <class T>
|
||||||
void removeDrawable(size_t id);
|
void addDrawable(T);
|
||||||
void addPage(uint8_t num);
|
void removeDrawable(const size_t id);
|
||||||
void removePage(uint8_t num);
|
void addPage();
|
||||||
|
void removePage(const uint8_t num);
|
||||||
|
const Drawables& getDrawables();
|
||||||
|
const Pages& getPages();
|
||||||
|
|
||||||
private:
|
//render
|
||||||
void visitDrawables(Drawable* parent);
|
private:
|
||||||
void render();
|
void render();
|
||||||
void setPixel(uint16_t x, uint16_t y, bool value);
|
void clearBuffer(uint8_t* buffer, Color col);
|
||||||
|
void visitDrawables(Drawable* parent);
|
||||||
|
void setPixel(uint8_t* img, uint16_t x, uint16_t y, bool value);
|
||||||
|
|
||||||
// members
|
// members
|
||||||
private:
|
private:
|
||||||
uint8_t* _screenBufferForeground;
|
|
||||||
uint8_t* _screenBufferBackgrund;
|
|
||||||
dim_t _screenSize;
|
dim_t _screenSize;
|
||||||
Pages _pages;
|
Pages _pages;
|
||||||
Drawables _drawables;
|
uint8_t* _screenBufferForeground;
|
||||||
|
uint8_t* _screenBufferBackground;
|
||||||
|
Drawables _drawables; // background drawables for all the pages
|
||||||
ScreenRotation _rotation;
|
ScreenRotation _rotation;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Drawable {
|
class Drawable {
|
||||||
|
public:
|
||||||
Drawable(const size_t id, const pos_t position, const Drawable* parent);
|
Drawable(const size_t id, const Drawable* parent, const Mare* engine);
|
||||||
virtual ~Drawable();
|
~Drawable();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual void render();
|
virtual void render();
|
||||||
@@ -100,27 +110,30 @@ namespace Render{
|
|||||||
const BlendMode getBlendMode();
|
const BlendMode getBlendMode();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
const Drawable* _parent;
|
||||||
|
const Mare* _engine;
|
||||||
bool _dirty;
|
bool _dirty;
|
||||||
size_t _id;
|
size_t _id;
|
||||||
pos_t _origin;
|
pos_t _origin;
|
||||||
bbox2d_t _bbox;
|
bbox2d_t _bbox;
|
||||||
Drawables _children;
|
Drawables _children;
|
||||||
Drawable* _parent;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class DrawablePoint: public Drawable {
|
class DrawablePoint: public Drawable {
|
||||||
|
|
||||||
DrawablePoint();
|
DrawablePoint(const size_t id, const Drawable* parent, const Mare* engine, dim_t size);
|
||||||
~DrawablePoint();
|
~DrawablePoint();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
void setSize(dim_t size);
|
||||||
|
const dim_t getSize();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
// members
|
// members
|
||||||
private:
|
private:
|
||||||
|
dim_t _size;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DrawableLine: public Drawable {
|
class DrawableLine: public Drawable {
|
||||||
@@ -129,12 +142,21 @@ namespace Render{
|
|||||||
~DrawableLine();
|
~DrawableLine();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
void setThickness(uint16_t thickness);
|
||||||
|
const uint16_t getThickness();
|
||||||
|
void setRotation(float rotation);
|
||||||
|
const float getRotation();
|
||||||
|
void setLength(uint16_t length);
|
||||||
|
const uint16_t getLength();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void render() {};
|
void render(); // difficult business
|
||||||
|
|
||||||
// members
|
// members
|
||||||
private:
|
private:
|
||||||
|
uint16_t _thickness;
|
||||||
|
uint16_t _lenght;
|
||||||
|
float _rotation;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DrawableRectangle: public Drawable {
|
class DrawableRectangle: public Drawable {
|
||||||
@@ -151,6 +173,63 @@ namespace Render{
|
|||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class DrawableCircle: public Drawable {
|
||||||
|
|
||||||
|
DrawableCircle();
|
||||||
|
~DrawableCircle();
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
private:
|
||||||
|
void render() {};
|
||||||
|
|
||||||
|
// members
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
class DrawableChar: public Drawable {
|
||||||
|
|
||||||
|
DrawableChar();
|
||||||
|
~DrawableChar();
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
private:
|
||||||
|
void render() {};
|
||||||
|
|
||||||
|
// members
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
class DrawableString: public Drawable {
|
||||||
|
|
||||||
|
DrawableString();
|
||||||
|
~DrawableString();
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
private:
|
||||||
|
void render() {};
|
||||||
|
|
||||||
|
// members
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
class DrawableCustom: public Drawable {
|
||||||
|
|
||||||
|
DrawableCustom();
|
||||||
|
~DrawableCustom();
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
private:
|
||||||
|
void render() {};
|
||||||
|
|
||||||
|
// members
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class Page {
|
class Page {
|
||||||
|
|
||||||
Page();
|
Page();
|
||||||
@@ -159,6 +238,8 @@ namespace Render{
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Drawables _backDrawables;
|
||||||
|
Drawables _frontDrawables;
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -2,12 +2,22 @@
|
|||||||
|
|
||||||
namespace Render {
|
namespace Render {
|
||||||
|
|
||||||
Drawable::Drawable(const size_t id, const pos_t position, const Drawable* parent) {
|
Drawable::Drawable(const size_t id, const Drawable* parent, const Mare* engine):
|
||||||
|
_id(id),
|
||||||
|
_parent(parent),
|
||||||
|
_engine(engine)
|
||||||
|
{
|
||||||
|
printf("Created Drawable id: %d\n", _id);
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------+--------+--------+--------+--------+--------+--------+--------+--------+--------//
|
//--------+--------+--------+--------+--------+--------+--------+--------+--------+--------//
|
||||||
//Point
|
//Point
|
||||||
|
DrawablePoint::DrawablePoint(const size_t id, const Drawable* parent, const Mare* engine, dim_t size):
|
||||||
|
Drawable(id, parent,engine),
|
||||||
|
_size(size)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//--------+--------+--------+--------+--------+--------+--------+--------+--------+--------//
|
//--------+--------+--------+--------+--------+--------+--------+--------+--------+--------//
|
||||||
|
|||||||
41
src/main.cpp
41
src/main.cpp
@@ -31,48 +31,9 @@ int main(){
|
|||||||
gpio_init(LED_PIN);
|
gpio_init(LED_PIN);
|
||||||
gpio_set_dir(LED_PIN, GPIO_OUT);
|
gpio_set_dir(LED_PIN, GPIO_OUT);
|
||||||
bool s=false;
|
bool s=false;
|
||||||
uint32_t i=0;
|
uint i(0);
|
||||||
uint8_t img[EPD_2IN9_V2_HEIGHT/8*EPD_2IN9_V2_WIDTH];
|
|
||||||
|
|
||||||
for (int x=0; x < EPD_2IN9_V2_HEIGHT/8*EPD_2IN9_V2_WIDTH; ++x){
|
|
||||||
img[x] = 0xff;
|
|
||||||
}
|
|
||||||
|
|
||||||
int rv;
|
|
||||||
DEV_Delay_ms(500);
|
|
||||||
if((rv=DEV_Module_Init())!=0){
|
|
||||||
printf("Init Failed, %d",rv);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
EPD_2IN9_V2_Init();
|
|
||||||
EPD_2IN9_V2_Clear();
|
|
||||||
|
|
||||||
//clear delta memory
|
|
||||||
uint8_t delta[EPD_2IN9_V2_HEIGHT][EPD_2IN9_V2_WIDTH/8];
|
|
||||||
for(auto i(0); i < EPD_2IN9B_V3_HEIGHT; ++i){
|
|
||||||
for (auto j(0); j< EPD_2IN9B_V3_WIDTH/8; ++j){
|
|
||||||
delta[i][j]=0xff;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
uint8_t dot(8);
|
|
||||||
bool col(false);
|
|
||||||
while(true){
|
while(true){
|
||||||
EPD_2IN9_V2_Display_Base((uint8_t*)img);
|
|
||||||
for(auto k(0); k<2; ++k){
|
|
||||||
col = col ? false : true;
|
|
||||||
for (auto x(0); x <= EPD_2IN9_V2_WIDTH-dot;x+=dot){
|
|
||||||
for(auto y(0); y <= EPD_2IN9_V2_HEIGHT-dot;y+=dot){
|
|
||||||
drawSquare((uint8_t*)delta,y,EPD_2IN9_V2_WIDTH-x-dot,dot,dot,col);
|
|
||||||
EPD_2IN9_V2_Display_Partial((uint8_t*)delta);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(auto i(0); i < EPD_2IN9B_V3_HEIGHT; ++i){
|
|
||||||
for (auto j(0); j< EPD_2IN9B_V3_WIDTH/8; ++j){
|
|
||||||
delta[i][j]=0xff;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
printf("[%u] Hello, world!\n",i++);
|
printf("[%u] Hello, world!\n",i++);
|
||||||
gpio_put(LED_PIN,s);
|
gpio_put(LED_PIN,s);
|
||||||
s = s ? false : true;
|
s = s ? false : true;
|
||||||
|
|||||||
Reference in New Issue
Block a user