From 693adf5ac19297680eb5d9dca3cc01bd3ba70754 Mon Sep 17 00:00:00 2001 From: Fisch Date: Tue, 9 Jan 2024 22:15:54 +0100 Subject: [PATCH] add large font --- flipcontrol_esp32/include/fonts.h | 113 +++++++++++- flipcontrol_esp32/include/image.h | 5 +- flipcontrol_esp32/src/image.cpp | 283 +++--------------------------- flipcontrol_esp32/src/main.cpp | 28 +-- fontconverter/fontconverter.py | 56 ++++-- 5 files changed, 195 insertions(+), 290 deletions(-) diff --git a/flipcontrol_esp32/include/fonts.h b/flipcontrol_esp32/include/fonts.h index 5d7faa2..dacafc5 100644 --- a/flipcontrol_esp32/include/fonts.h +++ b/flipcontrol_esp32/include/fonts.h @@ -2,12 +2,15 @@ #define FONTS_H #include - -const uint8_t font_width=6; uint8_t font_spacing=1; + +const uint8_t font_normal_width=6; + + const uint8_t font_offset=33; -const uint8_t font_minecraftia[94][font_width]= { +const uint8_t font_normal_mean_width=5; +const uint8_t font_normal[94][font_normal_width]= { //minecraftia {95,0,0,0,0,0}, // 33 ! {3,0,3,0,0,0}, // 34 " {20,127,20,127,20,0}, // 35 # @@ -104,4 +107,106 @@ const uint8_t font_minecraftia[94][font_width]= { {2,1,1,2,2,1}, // 126 ~ }; -#endif \ No newline at end of file + + +const uint8_t font_large_width=9; +const uint8_t font_large_offset=33; +const uint8_t font_large_mean_width=6; +const uint16_t font_large[94][9]= { +{0,0,0,1790,0,0,0,0,0}, // 33=! +{0,0,14,0,14,0,0,0,0}, // 34=" +{0,272,2044,272,272,2044,272,0,0}, // 35=# +{0,796,1058,3107,1058,972,0,0,0}, // 36=$ +{524,274,140,64,1568,2320,1544,0,0}, // 37=% +{896,1116,1058,1122,668,896,1120,0,0}, // 38=& +{0,0,0,8,6,0,0,0,0}, // 39=' +{0,0,1016,1028,2050,0,0,0,0}, // 40=( +{0,0,2050,1028,1016,0,0,0,0}, // 41=) +{0,64,336,224,224,336,64,0,0}, // 42=* +{0,64,64,496,64,64,0,0,0}, // 43=+ +{0,0,0,2048,1536,0,0,0,0}, // 44=, +{0,0,64,64,64,64,0,0,0}, // 45=- +{0,0,0,1536,0,0,0,0,0}, // 46=. +{0,1536,384,96,24,6,0,0,0}, // 47=/ +{0,1020,1282,1218,1074,1034,1020,0,0}, // 48=0 +{0,0,16,8,4,2046,0,0,0}, // 49=1 +{0,1796,1154,1090,1058,1042,1036,0,0}, // 50=2 +{0,516,1026,1058,1058,1058,988,0,0}, // 51=3 +{0,96,80,72,68,2046,64,0,0}, // 52=4 +{0,574,1058,1058,1058,1058,962,0,0}, // 53=5 +{0,1016,1060,1058,1058,1058,960,0,0}, // 54=6 +{0,2,2,1922,66,34,30,0,0}, // 55=7 +{0,988,1058,1058,1058,1058,988,0,0}, // 56=8 +{0,540,1058,1058,1058,1058,1020,0,0}, // 57=9 +{0,0,0,1584,0,0,0,0,0}, // 58=: +{0,0,0,2048,1584,0,0,0,0}, // 59=; +{0,64,160,272,520,1028,0,0,0}, // 60=< +{0,160,160,160,160,160,160,0,0}, // 61== +{0,1028,520,272,160,64,0,0,0}, // 62=> +{0,12,2,1666,66,34,28,0,0}, // 63=? +{496,520,1156,1364,1364,1508,1288,240,0}, // 64=@ +{0,2044,66,66,66,66,2044,0,0}, // 65=A +{0,2046,1058,1058,1058,1058,988,0,0}, // 66=B +{0,1020,1026,1026,1026,1026,516,0,0}, // 67=C +{0,2046,1026,1026,1026,516,504,0,0}, // 68=D +{0,2046,1058,1058,1058,1026,1026,0,0}, // 69=E +{0,2046,34,34,34,2,2,0,0}, // 70=F +{0,1020,1026,1026,1090,1090,964,0,0}, // 71=G +{0,2046,32,32,32,32,2046,0,0}, // 72=H +{0,1026,1026,2046,1026,1026,0,0,0}, // 73=I +{0,768,1024,1024,1024,1024,1022,0,0}, // 74=J +{0,2046,32,32,80,136,1798,0,0}, // 75=K +{0,2046,1024,1024,1024,1024,1024,0,0}, // 76=L +{2046,4,8,48,8,4,2046,0,0}, // 77=M +{0,2046,4,8,16,32,2046,0,0}, // 78=N +{0,1020,1026,1026,1026,1026,1020,0,0}, // 79=O +{0,2046,34,34,34,34,28,0,0}, // 80=P +{0,1020,1026,1026,1282,1538,4092,0,0}, // 81=Q +{0,2046,34,34,34,98,1948,0,0}, // 82=R +{0,524,1042,1058,1058,1090,900,0,0}, // 83=S +{2,2,2,2046,2,2,2,0,0}, // 84=T +{0,1022,1024,1024,1024,1024,1022,0,0}, // 85=U +{30,96,384,1536,384,96,30,0,0}, // 86=V +{2046,512,256,224,256,512,2046,0,0}, // 87=W +{0,1806,144,96,96,144,1806,0,0}, // 88=X +{6,24,32,1984,32,24,6,0,0}, // 89=Y +{0,1794,1154,1090,1058,1042,1038,0,0}, // 90=Z +{0,0,4094,2050,2050,0,0,0,0}, // 91=[ +{0,6,24,96,384,1536,0,0,0}, // 92=Backslash +{0,0,2050,2050,4094,0,0,0,0}, // 93=] +{0,4,2,1,2,4,0,0,0}, // 94=^ +{0,4096,4096,4096,4096,4096,4096,0,0}, // 95=_ +{0,0,0,6,8,0,0,0,0}, // 96=` +{0,896,1104,1104,1104,1104,2016,0,0}, // 97=a +{0,2046,1040,1040,1040,1040,992,0,0}, // 98=b +{0,992,1040,1040,1040,1040,544,0,0}, // 99=c +{0,992,1040,1040,1040,1040,2046,0,0}, // 100=d +{0,992,1168,1168,1168,1168,736,0,0}, // 101=e +{0,32,2044,34,34,2,4,0,0}, // 102=f +{0,5088,9232,9232,9232,8720,8160,0,0}, // 103=g +{0,2046,16,16,16,16,2016,0,0}, // 104=h +{0,1040,1040,2036,1024,1024,0,0,0}, // 105=i +{0,6144,8192,8192,8192,8180,0,0,0}, // 106=j +{0,2046,128,128,128,320,1584,0,0}, // 107=k +{0,1026,1026,2046,1024,1024,0,0,0}, // 108=l +{2032,16,16,992,16,16,2016,0,0}, // 109=m +{0,2032,16,16,16,16,2016,0,0}, // 110=n +{0,992,1040,1040,1040,1040,992,0,0}, // 111=o +{0,16368,1040,1040,1040,1040,992,0,0}, // 112=p +{0,992,1040,1040,1040,1040,16368,0,0}, // 113=q +{0,2032,32,16,16,16,0,0,0}, // 114=r +{0,608,1168,1168,1168,1168,800,0,0}, // 115=s +{0,16,16,1020,1040,1040,0,0,0}, // 116=t +{0,1008,1024,1024,1024,1024,2032,0,0}, // 117=u +{48,192,768,1024,768,192,48,0,0}, // 118=v +{1008,1024,512,448,512,1024,1008,0,0}, // 119=w +{1040,544,320,128,320,544,1040,0,0}, // 120=x +{0,9200,9216,9216,9216,4608,4080,0,0}, // 121=y +{0,1552,1296,1168,1104,1072,1040,0,0}, // 122=z +{0,64,64,1980,2050,2050,0,0,0}, // 123={ +{0,0,0,2014,0,0,0,0,0}, // 124=| +{0,2050,2050,1980,64,64,0,0,0}, // 125=} +{0,4,2,2,4,4,2,0,0}, // 126=~ +}; + +#endif diff --git a/flipcontrol_esp32/include/image.h b/flipcontrol_esp32/include/image.h index 8ec02da..b37b8bf 100644 --- a/flipcontrol_esp32/include/image.h +++ b/flipcontrol_esp32/include/image.h @@ -65,13 +65,10 @@ public: void setBuffer_byString(String data,String& error); void setBuffer_byInt(String data,String& error); - void addBuffer_text(String text,uint8_t xoffset, uint8_t yoffset); + void addBuffer_text(String text,uint8_t xoffset, uint8_t yoffset, uint8_t pfont=0); void setBuffer_Preset_Bumblebee(); - void setBuffer_Preset_CTDO(); void setBuffer_Preset_Datamatrixctdo(); - void setBuffer_Preset_1337(); - void setBuffer_Preset_1359(); void loop_testDots(); diff --git a/flipcontrol_esp32/src/image.cpp b/flipcontrol_esp32/src/image.cpp index 973fcb1..8e3a841 100644 --- a/flipcontrol_esp32/src/image.cpp +++ b/flipcontrol_esp32/src/image.cpp @@ -45,8 +45,27 @@ void Image::setBuffer_solid(bool set) flag_updating=true; //make update run } -void Image::addBuffer_text(String text,uint8_t xoffset, uint8_t yoffset) + + +void Image::addBuffer_text(String text,uint8_t xoffset, uint8_t yoffset, uint8_t pfont) { + uint8_t font_width; + uint8_t font_spacing; + switch (pfont){ + case 0: + font_width=font_normal_width; + if (xoffset=255) { //centering? + xoffset=(COLUMNS-text.length()*(font_normal_mean_width+font_spacing))/2; + } + break; + case 1: + font_width=font_large_width; + if (xoffset=255) { //centering? + xoffset=(COLUMNS-text.length()*(font_large_mean_width+font_spacing))/2; + } + break; + } + uint8_t bufferxpos=xoffset; for (uint8_t textpos=0;textpos=COLUMNS) { diff --git a/flipcontrol_esp32/src/main.cpp b/flipcontrol_esp32/src/main.cpp index a7b89a1..e130cb7 100644 --- a/flipcontrol_esp32/src/main.cpp +++ b/flipcontrol_esp32/src/main.cpp @@ -28,6 +28,7 @@ bool orderHandler(const HomieRange& range, const String& value); bool dataHandler(const HomieRange& range, const String& value); bool controlHandler(const HomieRange& range, const String& value); bool textHandler(const HomieRange& range, const String& value) ; +bool textLargeHandler(const HomieRange& range, const String& value) ; bool clearFirstHandler(const HomieRange& range, const String& value); bool optimizeClearHandler(const HomieRange& range, const String& value); @@ -47,12 +48,13 @@ void setup() { Serial.begin(115200); //Setup Homie - Homie_setFirmware("flipdot", "0.1.1"); + Homie_setFirmware("flipdot", "0.1.2"); displayNode.advertise("preset").settable(presetHandler); displayNode.advertise("data").settable(dataHandler); displayNode.advertise("order").settable(orderHandler); displayNode.advertise("control").settable(controlHandler); displayNode.advertise("text").settable(textHandler); + displayNode.advertise("textlarge").settable(textLargeHandler); settingsNode.advertise("clearfirst").settable(clearFirstHandler); settingsNode.advertise("optimizeclear").settable(optimizeClearHandler); settingsNode.advertise("optimizeset").settable(optimizeSetHandler); @@ -199,18 +201,9 @@ bool presetHandler(const HomieRange& range, const String& value) { }else if(value == "bumblebee"){ flip.setBuffer_Preset_Bumblebee(); Homie.getLogger() << "Preset is bumblebee" << endl; - }else if(value == "ctdo"){ - flip.setBuffer_Preset_CTDO(); - Homie.getLogger() << "Preset is ctdo" << endl; }else if(value == "datamatrixctdo"){ flip.setBuffer_Preset_Datamatrixctdo(); Homie.getLogger() << "Preset is datamatrixctdo" << endl; - }else if(value == "1337"){ - flip.setBuffer_Preset_1337(); - Homie.getLogger() << "Preset is 1337" << endl; - }else if(value == "1359"){ - flip.setBuffer_Preset_1359(); - Homie.getLogger() << "Preset is 1359" << endl; }else if(value == "random"){ flip.setBuffer_random(50); }else if(value == "uptime") { @@ -373,5 +366,20 @@ bool textHandler(const HomieRange& range, const String& value) { } + return true; +} + + +bool textLargeHandler(const HomieRange& range, const String& value) { + Serial.print("Text Large payload="); Serial.println(value); + + String row1=value; + + Serial.print("Row="); Serial.println(row1); + + flip.setBuffer_solid(0); //clear + + flip.addBuffer_text(row1,255,0,1); //large font, centered + return true; } \ No newline at end of file diff --git a/fontconverter/fontconverter.py b/fontconverter/fontconverter.py index 2396713..d012657 100644 --- a/fontconverter/fontconverter.py +++ b/fontconverter/fontconverter.py @@ -5,29 +5,46 @@ screen = pygame.display.set_mode((640, 480)) clock = pygame.time.Clock() done = False +persistance=False +fps=10 + pixelsize=8 -#font = pygame.font.SysFont("comicsansms", 72) -font = pygame.font.Font("Minecraftia-Regular.ttf", 8*pixelsize); +#fontname="font_normal" +#font = pygame.font.Font("Minecraftia-Regular.ttf", fontsize*pixelsize); +#fontsize=8 +#pixelsW=6 +#pixelsH=8 +#offset=(0,0) + +fontname="font_large" +fontsize=16 +pixelsW=9 +pixelsH=8*2 +offset=(0,8) +font = pygame.font.Font("Sweet16mono.ttf", fontsize*pixelsize); # https://github.com/kmar/Sweet16Font + -pixelsW=6 -pixelsH=8 asciioffset=33 asciiend=126 ascii = asciioffset -fontname="font_minecraftia" + file = open("output.txt", "w") # write mode -file.write("const uint8_t font_width="+str(pixelsW)+";\n"); -file.write("const uint8_t font_offset="+str(asciioffset)+";\n"); +file.write("const uint8_t "+fontname+"_width="+str(pixelsW)+";\n"); +file.write("const uint8_t "+fontname+"_offset="+str(asciioffset)+";\n"); #file.write("uint8_t "+fontname+"["+str(asciiend-asciioffset+1)+"]["+str(pixelsW)+"];\n") -file.write("const uint8_t "+fontname+"["+str(asciiend-asciioffset+1)+"]["+str(pixelsW)+"]= {\n") +file.write("const uint"+str(pixelsH)+"_t "+fontname+"["+str(asciiend-asciioffset+1)+"]["+str(pixelsW)+"]= {\n") + +screen.fill((255, 255, 255)) + +screencleared=False while not done: for event in pygame.event.get(): @@ -36,17 +53,20 @@ while not done: if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: done = True - screen.fill((255, 255, 255)) - for y in range(pixelsH): - for x in range(pixelsW): - color=(250,250,250) - if (x+y)%2==0: - color=(200,200,200) - pygame.draw.rect(screen, color, pygame.Rect(pixelsize*x, pixelsize*y, pixelsize, pixelsize)) + if not screencleared or not persistance: + screencleared=True + screen.fill((255, 255, 255)) + + for y in range(pixelsH): + for x in range(pixelsW): + color=(250,250,250) + if (x+y)%2==0: + color=(200,200,200) + pygame.draw.rect(screen, color, pygame.Rect(pixelsize*x, pixelsize*y, pixelsize, pixelsize)) text = font.render(chr(ascii), True, (0, 0, 0)) - screen.blit(text,(0,-pixelsize*2)) + screen.blit(text,(0+offset[0],-pixelsize*2+offset[1])) print("ascii="+str(ascii)+" char="+chr(ascii)) ''' @@ -90,7 +110,7 @@ while not done: done=True pygame.display.flip() - clock.tick(30) + clock.tick(fps) file.write("};") -file.close() \ No newline at end of file +file.close()