diff --git a/Arduino/epd7in5_V2/epd7in5_V2.cpp b/Arduino/epd7in5_V2/epd7in5_V2.cpp index 242ed006a..64cd8f304 100644 --- a/Arduino/epd7in5_V2/epd7in5_V2.cpp +++ b/Arduino/epd7in5_V2/epd7in5_V2.cpp @@ -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=xStart) && (i*8= 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();