Skip to content
This repository has been archived by the owner on Jul 21, 2021. It is now read-only.

change writeScreenBuffer #46

Merged
merged 8 commits into from
May 11, 2018
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions inc/BrainPadDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ namespace codal {
public:
BrainPadDisplay(codal::I2C& _i2c);

void flush();
void drawPoint(int x, int y, bool set);
void writeScreenBuffer(uint8_t* buffer);
};
}
Expand Down
18 changes: 3 additions & 15 deletions samples/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,28 +103,16 @@ uint8_t* font = new uint8_t[95 * 5] {
0x08, 0x08, 0x2a, 0x1c, 0x08 /* ~ */
};

void DrawPoint(int x, int y, bool set) {
if (x >= 0 && x < 128 && y >= 0 && y < 64) {
int offset = y * 16 + x / 8;
int mask = 0x80 >> (x & 7);

if (set)
vram[offset] |= mask;
else
vram[offset] &= ~mask;
}
}

void DrawText(int x, int y, char letter) {
int index = 5 * (letter - 32);

for (int h = 0; h < 5; h++)
for (int v = 0; v < 8; v++)
DrawPoint(x + h, y + v, (font[index + h] & (1 << v)) != 0);
brain.lcd.drawPoint(x + h, y + v, (font[index + h] & (1 << v)) != 0);

// clear the space between characters
for (int i = 0; i < 8; i++)
DrawPoint(x + 5, y + i, 0);
brain.lcd.drawPoint(x + 5, y + i, 0);
}

void DrawString(int x, int y, std::string text) {
Expand Down Expand Up @@ -248,7 +236,7 @@ int main() {
while (true) {
TestAccelerometer();

brain.lcd.writeScreenBuffer(vram);
brain.lcd.flush();
}

return 0;
Expand Down
10 changes: 1 addition & 9 deletions source/BrainPadDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,6 @@ void BrainPadDisplay::flush() {
}

void BrainPadDisplay::writeScreenBuffer(uint8_t* buffer) {
for (int x = 0; x < 128; x++) {
for (int y = 0; y < 64; y++) {
int offset = y * 16 + x / 8;
int mask = 0x80 >> (x & 7);

drawNativePixel(x, y, (buffer[offset] & mask) > 0);
}
}

memcpy(vram + 1, buffer, vramSize - 1);
flush();
}