Compare commits

..

2 Commits

Author SHA1 Message Date
Emanuele Trabattoni
9f1990b977 does not link, we are close.. 2021-05-25 22:35:25 +02:00
Emanuele Trabattoni
f5ce925153 implementation continues... 2021-05-22 20:41:51 +02:00
6 changed files with 231 additions and 100 deletions

View File

@@ -10,4 +10,4 @@ include_directories(../epaper/Fonts)
# Generate the link library # Generate the link library
add_library(Mare ${DIR_Config_SRCS}) add_library(Mare ${DIR_Config_SRCS})
target_link_libraries(Mare PUBLIC Config ePaper pico_stdlib hardware_spi) target_link_libraries(Mare PUBLIC Config ePaper Fonts pico_stdlib hardware_spi)

View File

@@ -5,8 +5,72 @@
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, class ... Args>
T* Mare::addDrawable(Args&&... args){
static size_t lastDrawableIndex(0);
static_assert(std::is_base_of_v<Drawable, T>, "Scene::createDrawable<T>() error, type T is not inherited from Drawable.");
auto newD = std::make_shared<T>(lastDrawableIndex++, nullptr, this, std::forward<Args>(args)...);
_drawables.push_back(newD);
return newD.get();
}
void Mare::render() {
clearBuffer(_screenBufferBackground, Color::White);
for (auto &d: _drawables) {
if (d != nullptr){
d->render();
} else {
printf("Drawable is expired");
}
}
EPD_2IN9_V2_Display_Partial(_screenBufferBackground);
}
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));
} }
} }

View File

@@ -1,16 +1,19 @@
/******************************************* /*******************************************
* Most Awesome Renderer Ever * Most Awesome Renderer Ever
*******************************************/ *******************************************/
#pragma once
#include <stdio.h>
#include <pico/stdlib.h>
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 <vector> #include <vector>
#include <string> #include <string>
#include <cstring>
#include <memory>
namespace Render{ namespace Render{
@@ -36,56 +39,72 @@ 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(); friend class Page;
public:
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, class ... Args>
void removeDrawable(size_t id); T* addDrawable(Args&&... args);
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();
//render
private: private:
void clearBuffer(uint8_t* buffer, Color col);
void visitDrawables(Drawable* parent); void visitDrawables(Drawable* parent);
public:
void render(); void render();
void setPixel(uint16_t x, uint16_t y, bool value); 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;
public:
uint8_t* bBuffer() {return _screenBufferBackground;}
uint8_t* fBuffer() {return _screenBufferForeground;}
}; };
class Drawable { class Drawable {
public:
Drawable(const size_t id, const pos_t position, const Drawable* parent); Drawable(const size_t id, Drawable* parent, Mare* engine);
virtual ~Drawable(); ~Drawable();
public: public:
virtual void render(); virtual void render();
@@ -96,31 +115,38 @@ namespace Render{
void setDirty(); void setDirty();
void setBlendMode(const BlendMode mode); void setBlendMode(const BlendMode mode);
const pos_t getOrigin();
const bbox2d_t getBBox(); const bbox2d_t getBBox();
const BlendMode getBlendMode(); const BlendMode getBlendMode();
Mare* engine() { return _engine; };
Drawable* parent() { return _parent; };
private: private:
Drawable* _parent;
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, Drawable* parent, 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 +155,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 +186,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 +251,7 @@ namespace Render{
public: public:
private: private:
Drawables _backDrawables;
Drawables _frontDrawables;
}; };
} }

View File

@@ -2,12 +2,37 @@
namespace Render { namespace Render {
Drawable::Drawable(const size_t id, const pos_t position, const Drawable* parent) { Drawable::Drawable(const size_t id, Drawable* parent, Mare* engine):
_id(id),
_parent(parent),
_engine(engine)
{
printf("Created Drawable id: %d\n", _id);
} }
//--------+--------+--------+--------+--------+--------+--------+--------+--------+--------// //--------+--------+--------+--------+--------+--------+--------+--------+--------+--------//
//Point //Point
DrawablePoint::DrawablePoint(const size_t id, Drawable* parent, Mare* engine, dim_t size):
Drawable(id, parent,engine),
_size(size)
{
}
void DrawablePoint::render() {
uint8_t *buf;
if (parent() == nullptr)
buf = engine()->bBuffer();
else
buf = engine()->fBuffer();
for (uint16_t xx(0); xx< _size.x; xx++){
for (uint16_t yy(0); yy < _size.y; yy++)
{
engine()->setPixel(buf,getOrigin().x+xx,getOrigin().y+yy,true);
}
}
}
//--------+--------+--------+--------+--------+--------+--------+--------+--------+--------// //--------+--------+--------+--------+--------+--------+--------+--------+--------+--------//

View File

@@ -18,11 +18,6 @@ pico_add_extra_outputs(emon)
# Pull in our pico_stdlib which aggregates commonly used features # Pull in our pico_stdlib which aggregates commonly used features
target_link_libraries(emon target_link_libraries(emon
hardware_spi
pico_stdlib pico_stdlib
Config Mare
ePaper
GUI
Fonts
MyLibs
) )

View File

@@ -2,80 +2,34 @@
#include <pico/stdlib.h> #include <pico/stdlib.h>
// Ricrdarsi di inserire cosi' tutte le lebrerie C altrimenti non LINKA, vaccamiseria // Ricrdarsi di inserire cosi' tutte le lebrerie C altrimenti non LINKA, vaccamiseria
extern "C" {
#include <EPD_2in9_V2.h>
}
#include <myclass.h>
#include <mare.h> #include <mare.h>
void setPixel(uint8_t* img, uint16_t x, uint16_t y, bool value){
img += (sizeof(uint8_t)*x*(EPD_2IN9_V2_WIDTH>>3)+ sizeof(uint8_t)*(y>>3));
if (value) *img &= ~0x01 << (y%8);
else *img |= 0x01 << y%8;
}
void drawSquare(uint8_t* img, uint16_t x, uint16_t y, uint16_t dimX, uint16_t dimY, bool col){
for (auto xx(0); xx< dimX; xx++){
for (auto yy(0); yy < dimY; yy++)
{
setPixel(img,x+xx,y+yy,col);
}
}
}
int main(){ int main(){
stdio_init_all(); stdio_init_all();
const uint LED_PIN = PICO_DEFAULT_LED_PIN; const uint LED_PIN = PICO_DEFAULT_LED_PIN;
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]; Render::dim_t ssize;
ssize.x = EPD_2IN9_V2_WIDTH;
ssize.y = EPD_2IN9_V2_HEIGHT;
for (int x=0; x < EPD_2IN9_V2_HEIGHT/8*EPD_2IN9_V2_WIDTH; ++x){ auto viewer = Render::Mare(ssize);
img[x] = 0xff;
} Render::dim_t ps;
ps.x=10;
ps.y=10;
auto point = viewer.addDrawable<Render::DrawablePoint>(ps);
point->setOrigin(ps);
viewer.render();
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;
} }
return 0; return 0;