Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix off by 1 error in Displaypart code on Arduino with 7in5_V2 #345

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions Arduino/epd7in5_V2/epd7in5_V2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,20 +238,26 @@ void Epd::DisplayFrame(const unsigned char* frame_buffer) {
WaitUntilIdle();
}

void Epd::Displaypart(const unsigned char* pbuffer, unsigned long xStart, unsigned long yStart,unsigned long Picture_Width,unsigned long Picture_Height) {
void Epd::Displaypart(const unsigned char* pbuffer, unsigned long xStart, unsigned long yStart, unsigned long Picture_Width, unsigned long Picture_Height) {
SendCommand(0x13);
// xStart = xStart/8;
// xStart = xStart*8;

// Ensure xStart is byte-aligned
unsigned long xStart_byte = xStart / 8;

// Iterate over the entire display area and see if the bytes fit within the starts and width/height bounds
for (unsigned long j = 0; j < height; j++) {
for (unsigned long i = 0; i < width/8; i++) {
if( (j>=yStart) && (j<yStart+Picture_Height) && (i*8>=xStart) && (i*8<xStart+Picture_Width)){
SendData(~(pgm_read_byte(&(pbuffer[i-xStart/8 + (Picture_Width)/8*(j-yStart)]))) );
// SendData(0xff);
}else {
SendData(0x00);
for (unsigned long i = 0; i < width / 8; i++) {
// Check if the current byte is within the part to be displayed
if ((j >= yStart) && (j < yStart + Picture_Height) && (i >= xStart_byte) && (i < xStart_byte + Picture_Width / 8)) {
// Correctly calculate the buffer index
unsigned long buffer_index = (i - xStart_byte) + (Picture_Width / 8) * (j - yStart);
SendData(~(pgm_read_byte(&(pbuffer[buffer_index]))));
} else {
SendData(~0xFF); // ~ inverts the bytes
}
}
}

SendCommand(0x12);
DelayMs(100);
WaitUntilIdle();
Expand Down