Moved pictures out of source code and added ability to draw XBM from RAM

This commit is contained in:
Dirk Jahnke 2018-01-23 13:39:01 +01:00
parent fabcca06fb
commit 429a42f4f4
3 changed files with 142 additions and 53 deletions

41
src/fremo_logo.xbm Normal file
View File

@ -0,0 +1,41 @@
#define FREMO_LOGO_width 64
#define FREMO_LOGO_height 47
static char FREMO_LOGO_bits[] = {
0x00, 0x00, 0x00, 0x5A, 0x59, 0x00, 0x00, 0x00,
0x00, 0x00, 0x60, 0x00, 0x00, 0x0C, 0x00, 0x00,
0x00, 0x00, 0x06, 0x68, 0x99, 0x20, 0x00, 0x00,
0x00, 0x80, 0x40, 0x4D, 0x5B, 0x86, 0x01, 0x00,
0x00, 0x20, 0x5A, 0x09, 0x88, 0x36, 0x04, 0x00,
0x00, 0x00, 0x35, 0x50, 0x03, 0x94, 0x10, 0x00,
0x00, 0x44, 0x82, 0x02, 0x40, 0x40, 0x21, 0x00,
0x00, 0xC1, 0x10, 0x00, 0x00, 0x0C, 0x83, 0x00,
0x80, 0x00, 0x04, 0x00, 0x00, 0x20, 0x00, 0x01,
0x40, 0x00, 0x01, 0xF8, 0x3F, 0x80, 0x00, 0x02,
0x20, 0x40, 0x00, 0xFC, 0x3F, 0x00, 0x02, 0x04,
0x00, 0x20, 0x00, 0xFC, 0x3F, 0x00, 0x04, 0x00,
0x00, 0x10, 0x00, 0xFC, 0x3F, 0x00, 0x08, 0x00,
0x08, 0x08, 0x00, 0xFC, 0x3F, 0x00, 0x10, 0x10,
0x04, 0x00, 0x00, 0xFE, 0x7F, 0x00, 0x00, 0x20,
0x00, 0x02, 0x00, 0xFE, 0x7F, 0x00, 0x40, 0x00,
0x02, 0x01, 0x00, 0xFC, 0x3F, 0x00, 0x80, 0x40,
0x00, 0x00, 0x00, 0xF0, 0x07, 0x00, 0x00, 0x00,
0x80, 0x00, 0x00, 0xC0, 0x03, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0x01, 0xF8, 0xFD, 0xB8, 0x33, 0x0C, 0x0F, 0x80,
0x40, 0x10, 0x11, 0x11, 0x62, 0xC4, 0x18, 0x00, 0x01, 0x50, 0x11, 0x91,
0x50, 0x4E, 0x10, 0x02, 0x40, 0x70, 0xF0, 0xF0, 0x60, 0x44, 0x10, 0x82,
0x01, 0x50, 0x90, 0x91, 0x82, 0x45, 0x10, 0x00, 0x40, 0x10, 0x10, 0x11,
0x92, 0xC5, 0x18, 0x82, 0x01, 0x38, 0x38, 0xF9, 0xB1, 0x0E, 0x07, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x80,
0x03, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x40,
0x22, 0x01, 0x00, 0x80, 0x03, 0x00, 0x80, 0x04, 0x30, 0x02, 0x00, 0xC0,
0x03, 0x00, 0x40, 0x26, 0x54, 0x00, 0x00, 0xE0, 0x0F, 0x00, 0x00, 0x24,
0x08, 0x09, 0x00, 0xFC, 0x3F, 0x00, 0x90, 0x13, 0xC0, 0x01, 0xC0, 0xFF,
0xFF, 0x07, 0x80, 0x02, 0x10, 0x23, 0xF0, 0xFF, 0xFF, 0x0F, 0xC4, 0x09,
0x20, 0x4E, 0xB0, 0xBF, 0xFF, 0x07, 0x62, 0x04, 0x40, 0x10, 0x01, 0x00,
0x00, 0x80, 0x10, 0x02, 0x80, 0x14, 0x04, 0x00, 0x00, 0x20, 0x14, 0x01,
0x00, 0xB1, 0x20, 0x00, 0x00, 0x88, 0x8D, 0x00, 0x00, 0xC4, 0x82, 0x12,
0xA0, 0xA0, 0x23, 0x00, 0x00, 0x08, 0x27, 0x40, 0x02, 0x08, 0x11, 0x00,
0x00, 0x20, 0x9C, 0x06, 0xD0, 0x5A, 0x04, 0x00, 0x00, 0x80, 0xA0, 0x75,
0x2F, 0x87, 0x01, 0x00, 0x00, 0x00, 0x04, 0x16, 0xF7, 0x20, 0x00, 0x00,
0x00, 0x00, 0x70, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x99,
0x2A, 0x00, 0x00, 0x00, };

View File

@ -31,42 +31,8 @@
Adafruit_SSD1306 *d1 = nullptr, *d2 = nullptr;
static void timer_cb(void *arg);
#define FREMO_LOGO_WIDTH 64
#define FREMO_LOGO_HEIGHT 48
const PROGMEM uint8_t fremo_logo[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x5A, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x06, 0x68, 0x99, 0x20, 0x00, 0x00,
0x00, 0x80, 0x40, 0x4D, 0x5B, 0x86, 0x01, 0x00, 0x00, 0x20, 0x5A, 0x09,
0x88, 0x36, 0x04, 0x00, 0x00, 0x00, 0x35, 0x50, 0x03, 0x94, 0x10, 0x00,
0x00, 0x44, 0x82, 0x02, 0x40, 0x40, 0x21, 0x00, 0x00, 0xC1, 0x10, 0x00,
0x00, 0x0C, 0x83, 0x00, 0x80, 0x00, 0x04, 0x00, 0x00, 0x20, 0x00, 0x01,
0x40, 0x00, 0x01, 0xF8, 0x3F, 0x80, 0x00, 0x02, 0x20, 0x40, 0x00, 0xFC,
0x3F, 0x00, 0x02, 0x04, 0x00, 0x20, 0x00, 0xFC, 0x3F, 0x00, 0x04, 0x00,
0x00, 0x10, 0x00, 0xFC, 0x3F, 0x00, 0x08, 0x00, 0x08, 0x08, 0x00, 0xFC,
0x3F, 0x00, 0x10, 0x10, 0x04, 0x00, 0x00, 0xFE, 0x7F, 0x00, 0x00, 0x20,
0x00, 0x02, 0x00, 0xFE, 0x7F, 0x00, 0x40, 0x00, 0x02, 0x01, 0x00, 0xFC,
0x3F, 0x00, 0x80, 0x40, 0x00, 0x00, 0x00, 0xF0, 0x07, 0x00, 0x00, 0x00,
0x80, 0x00, 0x00, 0xC0, 0x03, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0x01, 0xF8, 0xFD, 0xB8, 0x33, 0x0C, 0x0F, 0x80,
0x40, 0x10, 0x11, 0x11, 0x62, 0xC4, 0x18, 0x00, 0x01, 0x50, 0x11, 0x91,
0x50, 0x4E, 0x10, 0x02, 0x40, 0x70, 0xF0, 0xF0, 0x60, 0x44, 0x10, 0x82,
0x01, 0x50, 0x90, 0x91, 0x82, 0x45, 0x10, 0x00, 0x40, 0x10, 0x10, 0x11,
0x92, 0xC5, 0x18, 0x82, 0x01, 0x38, 0x38, 0xF9, 0xB1, 0x0E, 0x07, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x80,
0x03, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x40,
0x22, 0x01, 0x00, 0x80, 0x03, 0x00, 0x80, 0x04, 0x30, 0x02, 0x00, 0xC0,
0x03, 0x00, 0x40, 0x26, 0x54, 0x00, 0x00, 0xE0, 0x0F, 0x00, 0x00, 0x24,
0x08, 0x09, 0x00, 0xFC, 0x3F, 0x00, 0x90, 0x13, 0xC0, 0x01, 0xC0, 0xFF,
0xFF, 0x07, 0x80, 0x02, 0x10, 0x23, 0xF0, 0xFF, 0xFF, 0x0F, 0xC4, 0x09,
0x20, 0x4E, 0xB0, 0xBF, 0xFF, 0x07, 0x62, 0x04, 0x40, 0x10, 0x01, 0x00,
0x00, 0x80, 0x10, 0x02, 0x80, 0x14, 0x04, 0x00, 0x00, 0x20, 0x14, 0x01,
0x00, 0xB1, 0x20, 0x00, 0x00, 0x88, 0x8D, 0x00, 0x00, 0xC4, 0x82, 0x12,
0xA0, 0xA0, 0x23, 0x00, 0x00, 0x08, 0x27, 0x40, 0x02, 0x08, 0x11, 0x00,
0x00, 0x20, 0x9C, 0x06, 0xD0, 0x5A, 0x04, 0x00, 0x00, 0x80, 0xA0, 0x75,
0x2F, 0x87, 0x01, 0x00, 0x00, 0x00, 0x04, 0x16, 0xF7, 0x20, 0x00, 0x00,
0x00, 0x00, 0x70, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x99,
0x2A, 0x00, 0x00, 0x00, };
#include "fremo_logo.xbm"
#include "test_pattern.xbm"
static void printTextPattern(Adafruit_SSD1306 *d) {
d->setTextSize(1);
@ -91,10 +57,6 @@ static void show_num(Adafruit_SSD1306 *d, const char *s, int i) {
d->setCursor(0, 0);
d->printf("%s%d", s, i);
printTextPattern(d1);
// draw frame
d->writeFastVLine(d->width()-1, 0, d->height(), WHITE);
d->writeFastHLine(0, d->height()-1, d->width(), WHITE);
d->display();
}
static void show_msg(Adafruit_SSD1306 *d, const char *s) {
@ -104,7 +66,6 @@ static void show_msg(Adafruit_SSD1306 *d, const char *s) {
// d->printf("%s", " ");
d->setCursor(0, 9);
d->printf("%s", s);
d->display();
}
static void print_message_handler(struct mg_rpc_request_info *ri, void *cb_arg,
@ -122,7 +83,10 @@ static void print_message_handler(struct mg_rpc_request_info *ri, void *cb_arg,
}
// mgos_gpio_toggle(LED_GPIO);
if (d1 != nullptr) show_msg(d1, msg);
if (d1 != nullptr) {
show_msg(d1, msg);
d1->display();
}
printf("msg = %s\n", msg);
@ -135,6 +99,28 @@ static void print_message_handler(struct mg_rpc_request_info *ri, void *cb_arg,
(void) fi;
}
// Draw RAM-resident XBitMap Files (*.xbm), exported from GIMP,
// Usage: Export from GIMP to *.xbm, rename *.xbm to *.c and open in editor.
// C Array can be directly used with this function.
void drawXBitmap(Adafruit_SSD1306 *display, int16_t x, int16_t y,
const uint8_t bitmap[], int16_t w, int16_t h, uint16_t color, uint16_t bg) {
int16_t byteWidth = (w + 7) / 8; // Bitmap scanline pad = whole byte
uint8_t byte = 0;
display->startWrite();
for (int16_t j=0; j<h; j++, y++) {
for (int16_t i=0; i<w; i++ ) {
if (i & 7) byte >>= 1;
else byte = bitmap[j * byteWidth + i / 8];
// Nearly identical to drawBitmap(), only the bit order
// is reversed here (left-to-right = LSB to MSB):
display->writePixel(x+i, y, (byte & 0x01) ? color:bg);
}
}
display->endWrite();
}
void setup(void) {
// I2C
@ -151,28 +137,53 @@ void setup(void) {
struct mg_rpc *c = mgos_rpc_get_global();
mg_rpc_add_handler(c, "Display.Message", "{msg: %s}", print_message_handler, NULL);
mgos_set_timer(1000 /* ms */, true /* repeat */, timer_cb, NULL);
mgos_set_timer(3000 /* ms */, true /* repeat */, timer_cb, NULL);
}
static void timer_cb(void *arg) {
static int i = 0, j = 0;
static int startupStep = 0;
int posCenterX = d1->width()/2;
int posCenterY = d1->height()/2;
startupStep++;
switch (startupStep) {
case 0: startupStep++; break;
case 1:
case 1: break;
case 2:
d1->clearDisplay();
d1->drawBitmap(0, 0, fremo_logo, FREMO_LOGO_WIDTH, FREMO_LOGO_HEIGHT, BLACK, WHITE);
d1->display();
startupStep++;
drawXBitmap(d1, 0, 0, (uint8_t *) FREMO_LOGO_bits, FREMO_LOGO_width, FREMO_LOGO_height, WHITE, BLACK);
break;
case 2: startupStep++; break;
case 3: startupStep ++; break;
case 4:
case 3: break;
case 4: break;
case 5:
d1->clearDisplay();
show_msg(d1, "*Init´ed*");
startupStep++;
d1->drawBitmap(0, 0, (uint8_t *) TEST_PATTERN_bits, TEST_PATTERN_width, TEST_PATTERN_height, WHITE, BLACK);
break;
case 6: break;
case 7: break;
case 8: break;
case 9:
d1->clearDisplay();
show_msg(d1, "*Init'ed*");
break;
case 10:
d1->writeFastVLine(d1->width()-1, 0, d1->height(), WHITE);
break;
case 11:
d1->writeFastHLine(0, d1->height()-1, d1->width(), WHITE);
break;
case 12:
d1->clearDisplay();
d1->fillCircle(posCenterX, posCenterY, 20, WHITE);
d1->fillCircle(posCenterX, posCenterY, 10, BLACK);
break;
case 13:
d1->drawLine(0, 0, d1->width()-1, d1->height()-1, WHITE);
break;
case 14:
d1->drawLine(d1->width()-1, 0, 0, d1->height()-1, WHITE);
break;
case 15: break;
default:
show_num(d1, "i = ", i);
LOG(LL_INFO, ("i = %d, j = %d", i, j));
@ -188,6 +199,7 @@ static void timer_cb(void *arg) {
i++;
j++;
}
d1->display();
(void) arg;
}

36
src/test_pattern.xbm Normal file
View File

@ -0,0 +1,36 @@
#define TEST_PATTERN_width 64
#define TEST_PATTERN_height 32
static char TEST_PATTERN_bits[] = {
0x0f, 0x0f, 0x00, 0xf0, 0xf0, 0x00, 0xaa, 0xaa,
0x0f, 0x0f, 0x00, 0xf0, 0xf0, 0x00, 0xaa, 0xaa,
0xf0, 0xf0, 0x00, 0x0f, 0x0f, 0x00, 0x55, 0x55,
0xf0, 0xf0, 0x00, 0x0f, 0x0f, 0x00, 0x55, 0x55,
0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff,
0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff,
0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff,
0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff,
0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff,
0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff,
0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff,
0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff,
0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff,
0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff,
0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff,
0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff,
0xff, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0x00,
0xff, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0x00,
0xff, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0x00,
0xff, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0x00,
0xff, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0x00,
0xff, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0x00,
0xff, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0x00,
0xff, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0x00,
0xff, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0x00,
0xff, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0x00,
0xff, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0x00,
0xff, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0x00,
0xff, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0x00,
0xff, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0x00,
0xff, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0x00,
0xff, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0x00,
};