setpixel function works as expected

true for black
false for white
This commit is contained in:
Emanuele Trabattoni
2021-05-18 23:06:27 +02:00
parent a8afa0ccdb
commit 263741519b

View File

@@ -9,6 +9,22 @@ extern "C" {
#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){
for (auto xx(0); xx< dimX; xx++){
for (auto yy(0); yy < dimY; yy++)
{
setPixel(img,x+xx,y+yy,true);
}
}
}
int main(){
stdio_init_all();
const uint LED_PIN = PICO_DEFAULT_LED_PIN;
@@ -19,7 +35,7 @@ int main(){
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] = 0x01;
img[x] = 0xff;
}
int rv;
@@ -31,10 +47,29 @@ int main(){
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(16);
while(true){
EPD_2IN9_V2_Display((uint8_t*)img);
sleep_ms(10000);
EPD_2IN9_V2_Clear();
EPD_2IN9_V2_Display_Base((uint8_t*)img);
//EPD_2IN9_V2_Clear();
for (auto x(0); x <= EPD_2IN9_V2_HEIGHT-dot;x+=dot){
for(auto y(0); y <= EPD_2IN9_V2_WIDTH-dot;y+=dot){
drawSquare((uint8_t*)delta,x,y,dot,dot);
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;