This commit is contained in:
2020-06-11 11:25:19 +02:00
parent 5cb02880b3
commit 5177cd5cbd
15 changed files with 1090 additions and 411 deletions

View File

@@ -41,7 +41,8 @@ public:
/** get the pixel-width of the given char */
uint8_t getCharWidht(char c) const {
if (c == 32) {return 3;} // whitespace
return offsets[c-off+1] - offsets[c-off];
const int i = c-off;
return offsets[i+1] - offsets[i];
}
uint8_t getHeight() const {
@@ -57,8 +58,8 @@ public:
return sum;
}
/** draw the given char at the given position */
template <typename Scalar, typename Destination> void draw(const char* c, Scalar dx, Scalar dy, Destination& dst) {
/** draw the given string at the given position */
template <typename Scalar, typename Destination> void draw(const char* c, Scalar dx, Scalar dy, Destination& dst) const {
while(*c) {
draw(*c, dx, dy, dst);
dx += getCharWidht(*c);// + 1;
@@ -67,11 +68,10 @@ public:
}
/** draw the given char at the given position */
template <typename Scalar, typename Destination> void draw(unsigned char c, Scalar dx, Scalar dy, Destination& dst) {
template <typename Scalar, typename Destination> void draw(unsigned char c, Scalar dx, Scalar dy, Destination& dst) const {
if (c == 32) {return;} // skip whitespace
const uint16_t x1 = offsets[c-off];
const uint16_t x2 = offsets[c-off+1];
const uint16_t y1 = 0;
@@ -80,8 +80,8 @@ public:
for (uint16_t y = y1; y < y2; ++y) {
for (uint16_t x = x1; x < x2; ++x) {
const uint16_t idx = (x/8) + (y*this->w/8);
const uint8_t pixel = data[idx] & (1<<(x&7));
if (pixel) {
const uint8_t pxInFont = data[idx] & (1<<(x&7)); // pixel from font glyph
if (pxInFont) {
dst.setPixel(dx+x-x1, dy+y);
}
}

View File

@@ -70,17 +70,23 @@
class SSD1306 {
template <typename I2C> class SSD1306 {
private:
static constexpr uint8_t ADDR7 = 0b0111100;
bool inited = false;
I2C& i2c;
public:
SSD1306(I2C& i2c) : i2c(i2c) {
}
bool isPresent() {
return i2c::query(ADDR7);
return i2c.query(ADDR7);
}
void initOnce() {
@@ -137,15 +143,15 @@ public:
// i2c::stop();
// }
i2c::startWrite(ADDR7);
bool ok = i2c::writeByteAndCheck(0x40);
i2c.startWrite(ADDR7);
bool ok = i2c.writeByteAndCheck(0x40);
if (!ok) {os_printf("failed write data\n");}
for (uint16_t i=0; i < (SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8); i++) {
i2c::writeByteAndCheck(data[i]);
i2c.writeByteAndCheck(data[i]);
}
i2c::stop();
i2c.stop();
}
@@ -240,13 +246,13 @@ private:
void sendCommand(uint8_t cmd) {
bool ok;
ok = i2c::startWrite(ADDR7);
ok = i2c.startWrite(ADDR7);
if (!ok) {os_printf("failed start write\n");}
ok = i2c::writeByteAndCheck(0x00); // command
ok = i2c.writeByteAndCheck(0x00); // command
if (!ok) {os_printf("failed command mode\n");}
ok = i2c::writeByteAndCheck(cmd);
ok = i2c.writeByteAndCheck(cmd);
if (!ok) {os_printf("failed command\n");}
i2c::stop();
i2c.stop();
}
};