Sylaina/oled-display

Incorrect drawing when display's height is different than 64

heikete opened this issue · 1 comments

When display has only 32 pixels high the primitives are torn apart.
The reason for this is calculation in this function:

void lcd_drawPixel(uint8_t x, uint8_t y, uint8_t color){
    if( x > DISPLAY_WIDTH-1 || y > (DISPLAY_HEIGHT-1)) return; // out of Display
    if( color == WHITE){
        displayBuffer[(y / (DISPLAY_HEIGHT/8))][x] |= (1 << (y % (DISPLAY_HEIGHT/8)));
    } else {
        displayBuffer[(y / (DISPLAY_HEIGHT/8))][x] &= ~(1 << (y % (DISPLAY_HEIGHT/8)));
    }
}

The y offset has nothing to do with DISPLAY_HEIGHT it has to be divided by 8, because
the memory is organized this way even in infinitely large displays of this kind.

So the correct function looks like this:

void lcd_drawPixel(uint8_t x, uint8_t y, uint8_t color){
    if( x > DISPLAY_WIDTH-1 || y > (DISPLAY_HEIGHT-1)) return; // out of Display
    if( color == WHITE){
        displayBuffer[(y / 8)][x] |= (1 << (y % 8));
    } else {
        displayBuffer[(y / 8)][x] &= ~(1 << (y % 8));
    }
}

// Tested with 128x32 oled display.

fixed, thanks for info. This calculation was from an old display-size check and it was obsolet by adding if-statement at the begin of drawPixel