SPKDisplay - A mbed display class and processing imaging tools for 128x64 OLEDs using the SSD1305 driver, connected via SPI.
Dependents: SPK-DVIMXR SPK-DMXer
Diff: spk_oled_ssd1305.cpp
- Revision:
- 1:dd3faa2ab1dd
- Parent:
- 0:76bb084fa033
- Child:
- 3:ade83210ecf6
--- a/spk_oled_ssd1305.cpp Sun Apr 15 16:51:01 2012 +0000 +++ b/spk_oled_ssd1305.cpp Sun Apr 15 19:39:17 2012 +0000 @@ -1,7 +1,7 @@ // *spark audio-visual // OLED display using SSD1305 driver // Copyright *spark audio-visual 2012 - + #include "spk_oled_ssd1305.h" #include "mbed.h" @@ -9,6 +9,10 @@ { bufferHasChanged = false; + fontStartCharacter = NULL; + fontEndCharacter = NULL; + fontCharacters = NULL; + spi = new SPI(mosiPin, NC, clkPin); spi->format(8,3); spi->frequency(2000000); @@ -34,7 +38,7 @@ bufferHasChanged = true; } -void SPKDisplay::imageToBuffer() +void SPKDisplay::imageToBuffer(const uint8_t* image) { memcpy(buffer, image, bufferCount); bufferHasChanged = true; @@ -84,6 +88,10 @@ void SPKDisplay::textToBuffer(std::string message, int row) { + // Font check + if (NULL == fontCharacters) return; + if (NULL == fontStartCharacter || NULL == fontEndCharacter) return; + // Range check if (row >= 8) row = 7; int bStart = row*bufferWidth; @@ -95,7 +103,7 @@ char character = message.at(i); // Is it outside the range we have glyphs for? - if ((character < characterBytesStartChar) || (character > characterBytesEndChar)) + if ((character < *fontStartCharacter) || (character > *fontEndCharacter)) { // Treat as a space for (int j = 0; j < 5; j++) @@ -114,13 +122,13 @@ else { // Shift into our array's indexing - character -= characterBytesStartChar; + character -= *fontStartCharacter; // Write each byte's vertical column of 8bits into the buffer. - for (int j = 0; j < characterBytes[character][0]; j++) + for (int j = 0; j < fontCharacters[character][0]; j++) { if (bPos >= bEnd) break; - buffer[bPos++] = characterBytes[character][j+1]; + buffer[bPos++] = fontCharacters[character][j+1]; } // Put 1px letter spacing at end