Skip to content

Instantly share code, notes, and snippets.

@MaBecker
Created December 5, 2018 19:28
Show Gist options
  • Save MaBecker/dfcd3908005f3cafa2b9a5ab5156e3d8 to your computer and use it in GitHub Desktop.
Save MaBecker/dfcd3908005f3cafa2b9a5ab5156e3d8 to your computer and use it in GitHub Desktop.
Espruino: store FontHaxorNarrow7x17 in storage and print single and double size without using any RAM for font and widths
var s = require('Storage');
/* use this code only once to save font and widths in Storage
s.write('fHN7x17',atob("AAAAAAAAAAAB/MAAAJAAcAAAABIADgAAAAACAAngB4AeeAHgB5AAQAAAAHEAREAiID/4CIgERAEcAAAAwMCQgEmAGTADJAISBgYAAAAHgHQgRBAjCA5kAAwAPQAAAkABwAAAAAfADBgIAggAgAACACCAIDBgB8AAAAEgAGAA/AAYABIAAAABAACAAEAB/AAQAAgABAAAAAAkABwAAAAgABAACAAEAAIAAAAADAAGAAAAAIABgAMABgAMABgAAAAB/AEBAQxAjCAgIA/gAAACAAIAAgAB/8AAACBwIMgQhAiCA4EAAACAgIAgQhAhCA94AAAAGAA0ACIAYQB/8ABAAAAPhARBAiCBEECHwAAAH/ARBAiCBEEBHwAAAIAAQPAhgBMADgAAAAHvAQhAhCBCEB7wAAAHhAQhAhCBCEB/wAAADDAGGAAAAYUAwwAAAAQABQAEQAQQBAQAAABEACIAEQAIgARAAiAAAAICAIIAIgAKAAIAAAAIAAgABBMCEAEQAHAAAAAf8BAECOIEiQJEgP4AAAAP8BiAEEAGIAD/AAAB/8CEIEIQIQgPeAAAA/4CAIEAQIAgICAAAB/8CAIEAQEBAH8AAAB/8CEIEIQIQgQBAAAB/8CIAEQAIgAQAAAAA/4CAIEAQIQgI+AAAB/8AEAAIAAQAf/AAABAED/4EAQAAAQGAgCBAECAIH/gAAAf/ABAAFAAxgGAwAAAf/AACAAEAAIAAQAAAf/AYAAMABgAH/wAAAf/AYAAMAAGAH/wAAAP+AgCBAECAID/gAAAf/AhABCACEADwAAAAP+AgCBAUCAQD/QAAAf/AhABCACHADxwAAA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AAAAQAH/gBAkCBwECAAAA"));
s.write('wHN7x17',atob("AwIGCAgICAMFBQYIAwYDBwcFBgYHBgYGBgYDAwYHBgcHBgYGBgYGBgYEBgYGBgYGBgYGBgYGBggGBgYEBwQGBwQGBgYGBgYHBgYGBgYGBgYGBgYGBgYGBgYGBgQCBAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABwAHCAYGBgAGBgYGAAYGBQYABgMGBgQABgYHBgAGBgYGBgYGBgYGBgYGBgYEBAYGBgYGBgYGAAYGBgYGBgYHBgYGBgYGBgYGBgYGBgYGBwcGBgYGBgYABgYGBgYGBg=="));
*/
Graphics.prototype.setFontHN7x17 = function() {
var fHN7x17 = require('Storage').read('fHN7x17');
var wHN7x17 = require('Storage').read('wHN7x17');
this.setFontCustom(fHN7x17, 32, wHN7x17, 17);
};
Graphics.prototype.drawStringDbl = (txt,px,py,h)=>{
var g2 = Graphics.createArrayBuffer(128,h,2,{msb:true});
// set your custom font here if you need to
g2.setFontHN7x17();
var w = g2.stringWidth(txt);
var c = (w+3)>>2;
g2.drawString(txt);
var img = {width:w*2,height:1,transparent:0,buffer:new ArrayBuffer(c)};
var a = new Uint8Array(img.buffer);
for (var y=0;y<h;y++) {
a.set(new Uint8Array(g2.buffer,32*y,c));
this.drawImage(img,px,py+y*2);
this.drawImage(img,px,py+1+y*2);
}
};
function ds(text){
g.clear();
g.setFontHN7x17();
g.drawString(text,0,0);
g.drawStringDbl(text,0,20,17);
g.flip();
}
function start(){
ds('01234äüöß');
g.flip();
}
I2C1.setup({sda:NodeMCU.D1,scl:NodeMCU.D2});
var g = require("SSD1306").connect(I2C1,start);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment