we render a point!!!

This commit is contained in:
Emanuele Trabattoni
2021-05-26 23:38:07 +02:00
parent 9f1990b977
commit 8325dcfdd8
6 changed files with 122 additions and 62 deletions

View File

@@ -11,15 +11,16 @@ namespace Render {
_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);
_bufferDim = (_screenSize.x >> 3) * _screenSize.y;
_screenBufferBackground = (uint8_t*)malloc(sizeof(uint8_t)* _bufferDim);
_screenBufferForeground = (uint8_t*)malloc(sizeof(uint8_t)* _bufferDim);
clearBuffer(_screenBufferForeground, _bufferDim, Color::White);
clearBuffer(_screenBufferBackground, _bufferDim, Color::White);
// init display
DEV_Delay_ms(500);
if((rv=DEV_Module_Init())!=0){
printf("Init Failed, %d",rv);
printf("Init Failed, %d\n",rv);
return;
}
EPD_2IN9_V2_Init();
@@ -38,24 +39,11 @@ namespace Render {
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){
clearBuffer(_screenBufferBackground, _bufferDim, Color::White);
for (auto d: _drawables) {
if (d != nullptr)
d->render();
} else {
printf("Drawable is expired");
}
}
EPD_2IN9_V2_Display_Partial(_screenBufferBackground);
}
@@ -63,14 +51,14 @@ namespace Render {
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;
img += (sizeof(uint8_t)*y*(_screenSize.x/8) + sizeof(uint8_t)*(x/8));
if (value) *img &= ~(0x80 >> (x%8));
else *img |= (0x80 >> (x%8));
}
void clearBuffer(uint8_t* buffer, Color col){
void Mare::clearBuffer(uint8_t* buffer, uint16_t len, Color col){
assert(buffer != nullptr);
std::memset(buffer, col == Color::White ? 0xff : 0x00, sizeof(buffer));
std::memset(buffer, col == Color::White ? 0xff : 0x00, len);
}
}