render line with rotation method, still some bugs

This commit is contained in:
Emanuele Trabattoni
2021-06-02 18:04:23 +02:00
parent 7116885f2d
commit 60c6ca83c1
6 changed files with 109 additions and 73 deletions

View File

@@ -19,14 +19,17 @@ namespace Render {
clearBuffer(_screenBufferBackground, _bufferDim, Color::White);
// init display
DEV_Delay_ms(500);
sleep_ms(500);
if((rv=DEV_Module_Init())!=0){
printf("Init Failed, %d\n",rv);
__breakpoint();
return;
}
EPD_2IN9_V2_Init();
EPD_2IN9_V2_Clear();
printf("Mare render engine created\n");
EPD_2IN9_V2_Display(_screenBufferBackground);
sleep_ms(500);
}
Mare::~Mare(){
@@ -45,7 +48,7 @@ namespace Render {
for (auto d: _drawables) {
if (d != nullptr)
d->render();
}
};
EPD_2IN9_V2_Display_Partial(_screenBufferBackground);
}
@@ -54,17 +57,15 @@ namespace Render {
std::memset(buffer, col == Color::White ? 0xff : 0x00, len);
}
bool Mare::applyRotation(uint16_t* x, uint16_t* y) {
bool Mare::applyScreenRotation(uint16_t* x, uint16_t* y) {
uint16_t ax,ay;
switch(_rotation){
case ScreenRotation::Rot0 :
{
if (*x >= _screenSize.x || *y >= _screenSize.y) return false;
break;
}
case ScreenRotation::Rot90 :
{
if (*x >= _screenSize.y || *y >= _screenSize.x) return false;
ax = *x; ay = *y;
*x = _screenSize.x - ay;
*y = ax;
@@ -72,21 +73,20 @@ namespace Render {
}
case ScreenRotation::Rot180 :
{
if (*x >= _screenSize.x || *y >= _screenSize.y) return false;
ax = *x; ay = *y;
*x = _screenSize.x - ax;
*y = _screenSize.y - ay;
*y = _screenSize.y - ay;
break;
}
case ScreenRotation::Rot270 :
{
if (*x >= _screenSize.y || *y >= _screenSize.x) return false;
ax = *x; ay = *y;
*x = ay;
*y = _screenSize.y - ax;
break;
}
}
if (*x >= _screenSize.x || *y >= _screenSize.y) return false;
if (*x < 0 || *y < 0) return false;
return true;
}
@@ -105,12 +105,22 @@ namespace Render {
return rv;
}
void Mare::setPixel(uint8_t* img, uint16_t x, uint16_t y, bool value) {
if (!applyRotation(&x,&y)) return;
void Mare::setPixel(uint8_t* img, uint16_t x, uint16_t y, BlendMode bm) {
if (!applyScreenRotation(&x,&y)) return;
// from here the coordinates are natural for the screen
img += (sizeof(uint8_t)*y*(_screenSize.x>>3) + sizeof(uint8_t)*(x>>3));
if (value) *img &= ~(0x80 >> (x%8));
else *img |= (0x80 >> (x%8));
if (bm == BlendMode::Add) *img &= ~(0x80 >> (x%8));
else if (bm == BlendMode::Intersect) *img = ~*img ^ ~(0x80 >> (x%8));
}
spos_t Mare::rotateXY(int16_t x, int16_t y, float rot){
// apply rotation matrix xy
spos_t rv;
float cx,sx;
sincosf(rot, &sx, &cx);
rv.x = x*cx - y*sx;
rv.y = x*sx + y*cx;
return rv;
}
void Mare::clearScreen() {