Compare commits
2 Commits
b8ef6b7231
...
9f1990b977
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9f1990b977 | ||
|
|
f5ce925153 |
@@ -10,4 +10,4 @@ include_directories(../epaper/Fonts)
|
||||
|
||||
# Generate the link library
|
||||
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)
|
||||
@@ -5,8 +5,72 @@
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
155
libs/mare/mare.h
155
libs/mare/mare.h
@@ -1,16 +1,19 @@
|
||||
/*******************************************
|
||||
* Most Awesome Renderer Ever
|
||||
*******************************************/
|
||||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
#include <pico/stdlib.h>
|
||||
|
||||
extern "C" {
|
||||
#include <DEV_Config.h>
|
||||
#include <EPD_2in9b_V3.h>
|
||||
#include <fonts.h>
|
||||
#include <EPD_2in9_V2.h>
|
||||
}
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
||||
namespace Render{
|
||||
|
||||
@@ -36,56 +39,72 @@ namespace Render{
|
||||
Intersect
|
||||
};
|
||||
|
||||
enum class Color {
|
||||
White,
|
||||
Black
|
||||
};
|
||||
|
||||
class Page;
|
||||
class Drawable;
|
||||
|
||||
typedef pos_t dim_t;
|
||||
typedef std::vector<Page*> Pages;
|
||||
typedef std::vector<Drawable*> Drawables;
|
||||
typedef std::vector<std::shared_ptr<Page>> Pages;
|
||||
typedef std::vector<std::shared_ptr<Drawable>> Drawables;
|
||||
|
||||
class Mare {
|
||||
Mare();
|
||||
virtual ~Mare();
|
||||
friend class Drawable;
|
||||
friend class Page;
|
||||
|
||||
public:
|
||||
Mare(dim_t size);
|
||||
~Mare();
|
||||
|
||||
// getters, setters
|
||||
public:
|
||||
void setSize(const uint16_t x, const uint16_t y);
|
||||
void setSize(const dim_t size);
|
||||
const dim_t getSize();
|
||||
void setRotation(const ScreenRotation r);
|
||||
const ScreenRotation getRotation();
|
||||
|
||||
const Pages& getPages();
|
||||
const uint8_t getCurrentPage();
|
||||
void setCurrentPage(const uint8_t p);
|
||||
|
||||
const Drawables& getDrawables();
|
||||
const Page& getCurrentPage();
|
||||
|
||||
// drawables, pages
|
||||
public:
|
||||
void addDrawable();
|
||||
void removeDrawable(size_t id);
|
||||
void addPage(uint8_t num);
|
||||
void removePage(uint8_t num);
|
||||
template <class T, class ... Args>
|
||||
T* addDrawable(Args&&... args);
|
||||
void removeDrawable(const size_t id);
|
||||
void addPage();
|
||||
void removePage(const uint8_t num);
|
||||
const Drawables& getDrawables();
|
||||
const Pages& getPages();
|
||||
|
||||
private:
|
||||
//render
|
||||
private:
|
||||
void clearBuffer(uint8_t* buffer, Color col);
|
||||
void visitDrawables(Drawable* parent);
|
||||
|
||||
public:
|
||||
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
|
||||
private:
|
||||
uint8_t* _screenBufferForeground;
|
||||
uint8_t* _screenBufferBackgrund;
|
||||
dim_t _screenSize;
|
||||
Pages _pages;
|
||||
Drawables _drawables;
|
||||
uint8_t* _screenBufferForeground;
|
||||
uint8_t* _screenBufferBackground;
|
||||
Drawables _drawables; // background drawables for all the pages
|
||||
ScreenRotation _rotation;
|
||||
|
||||
public:
|
||||
uint8_t* bBuffer() {return _screenBufferBackground;}
|
||||
uint8_t* fBuffer() {return _screenBufferForeground;}
|
||||
};
|
||||
|
||||
class Drawable {
|
||||
|
||||
Drawable(const size_t id, const pos_t position, const Drawable* parent);
|
||||
virtual ~Drawable();
|
||||
public:
|
||||
Drawable(const size_t id, Drawable* parent, Mare* engine);
|
||||
~Drawable();
|
||||
|
||||
public:
|
||||
virtual void render();
|
||||
@@ -96,31 +115,38 @@ namespace Render{
|
||||
void setDirty();
|
||||
void setBlendMode(const BlendMode mode);
|
||||
|
||||
const pos_t getOrigin();
|
||||
const bbox2d_t getBBox();
|
||||
const BlendMode getBlendMode();
|
||||
|
||||
Mare* engine() { return _engine; };
|
||||
Drawable* parent() { return _parent; };
|
||||
|
||||
private:
|
||||
Drawable* _parent;
|
||||
Mare* _engine;
|
||||
bool _dirty;
|
||||
size_t _id;
|
||||
pos_t _origin;
|
||||
bbox2d_t _bbox;
|
||||
Drawables _children;
|
||||
Drawable* _parent;
|
||||
|
||||
};
|
||||
|
||||
class DrawablePoint: public Drawable {
|
||||
|
||||
DrawablePoint();
|
||||
DrawablePoint(const size_t id, Drawable* parent, Mare* engine, dim_t size);
|
||||
~DrawablePoint();
|
||||
|
||||
public:
|
||||
void setSize(dim_t size);
|
||||
const dim_t getSize();
|
||||
|
||||
private:
|
||||
void render();
|
||||
|
||||
// members
|
||||
private:
|
||||
dim_t _size;
|
||||
};
|
||||
|
||||
class DrawableLine: public Drawable {
|
||||
@@ -129,12 +155,21 @@ namespace Render{
|
||||
~DrawableLine();
|
||||
|
||||
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:
|
||||
void render() {};
|
||||
void render(); // difficult business
|
||||
|
||||
// members
|
||||
private:
|
||||
uint16_t _thickness;
|
||||
uint16_t _lenght;
|
||||
float _rotation;
|
||||
};
|
||||
|
||||
class DrawableRectangle: public Drawable {
|
||||
@@ -151,6 +186,63 @@ namespace Render{
|
||||
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 {
|
||||
|
||||
Page();
|
||||
@@ -159,6 +251,7 @@ namespace Render{
|
||||
public:
|
||||
|
||||
private:
|
||||
|
||||
Drawables _backDrawables;
|
||||
Drawables _frontDrawables;
|
||||
};
|
||||
}
|
||||
@@ -2,12 +2,37 @@
|
||||
|
||||
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
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------+--------+--------+--------+--------+--------+--------+--------+--------+--------//
|
||||
|
||||
@@ -18,11 +18,6 @@ pico_add_extra_outputs(emon)
|
||||
|
||||
# Pull in our pico_stdlib which aggregates commonly used features
|
||||
target_link_libraries(emon
|
||||
hardware_spi
|
||||
pico_stdlib
|
||||
Config
|
||||
ePaper
|
||||
GUI
|
||||
Fonts
|
||||
MyLibs
|
||||
Mare
|
||||
)
|
||||
|
||||
72
src/main.cpp
72
src/main.cpp
@@ -2,80 +2,34 @@
|
||||
#include <pico/stdlib.h>
|
||||
|
||||
// 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>
|
||||
|
||||
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(){
|
||||
stdio_init_all();
|
||||
const uint LED_PIN = PICO_DEFAULT_LED_PIN;
|
||||
gpio_init(LED_PIN);
|
||||
gpio_set_dir(LED_PIN, GPIO_OUT);
|
||||
bool s=false;
|
||||
uint32_t i=0;
|
||||
uint8_t img[EPD_2IN9_V2_HEIGHT/8*EPD_2IN9_V2_WIDTH];
|
||||
uint i(0);
|
||||
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){
|
||||
img[x] = 0xff;
|
||||
}
|
||||
auto viewer = Render::Mare(ssize);
|
||||
|
||||
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){
|
||||
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++);
|
||||
gpio_put(LED_PIN,s);
|
||||
s = s ? false : true;
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user