diff --git a/flipcontrol_esp32/include/image.h b/flipcontrol_esp32/include/image.h index 9b7c24a..3039e5a 100644 --- a/flipcontrol_esp32/include/image.h +++ b/flipcontrol_esp32/include/image.h @@ -26,7 +26,7 @@ private: //buffer is 16 bit because of 16 Rows uint16_t frontBuffer[COLUMNS]; //1 is bright dot / set dot. 0 is black / cleared - uint16_t backBuffer[COLUMNS]; + uint16_t backBuffer[COLUMNS]; //least significant bit is bottom dot. bool flag_updating; //when true, display flip is in progress. frontBuffer does not match backBuffer bool flag_redraw; //when set true, settings for updating are overwritten such that all dots are cleared and set @@ -63,6 +63,8 @@ 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 setBuffer_Image1(); void setBuffer_Image2(); void setBuffer_Image3(); diff --git a/flipcontrol_esp32/src/image.cpp b/flipcontrol_esp32/src/image.cpp index 0119dfd..3a791cb 100644 --- a/flipcontrol_esp32/src/image.cpp +++ b/flipcontrol_esp32/src/image.cpp @@ -1,11 +1,10 @@ #include "image.h" - +#include "fonts.h" Image::Image() { - } void Image::serialPrintInt(uint16_t source) @@ -46,6 +45,24 @@ void Image::setBuffer_solid(bool set) flag_updating=true; //make update run } +void Image::addBuffer_text(String text,uint8_t xoffset, uint8_t yoffset) +{ + uint8_t bufferxpos=xoffset; + for (uint8_t textpos=0;textpos>yoffset); + backBuffer[bufferxpos]|= addBuffer; + Serial.print("Buffer at "); Serial.print(bufferxpos); Serial.print(" add ");Serial.print(addBuffer,2); Serial.print(" result="); Serial.println(backBuffer[bufferxpos],2); + bufferxpos++; //TODO: do not increment when font column is empty + } + } + Serial.println("Finished Text"); +} + void Image::setBuffer_Image1() //Bumblebee { @@ -1039,9 +1056,6 @@ void Image::loop_drawClearTest() { init=false; } - - - } diff --git a/flipcontrol_esp32/src/main.cpp b/flipcontrol_esp32/src/main.cpp index a0e7b16..d7b5d01 100644 --- a/flipcontrol_esp32/src/main.cpp +++ b/flipcontrol_esp32/src/main.cpp @@ -220,6 +220,9 @@ bool presetHandler(const HomieRange& range, const String& value) { Homie.getLogger() << "Preset is Image8" << endl; }else if(value == "random"){ flip.setBuffer_random(50); + }else if(value == "text") { + flip.setBuffer_solid(0); + flip.addBuffer_text("Test",0,0); }else{ error="preset \""+value+"\" not found"; return false; diff --git a/fontconverter/fontconverter.py b/fontconverter/fontconverter.py new file mode 100644 index 0000000..cd03129 --- /dev/null +++ b/fontconverter/fontconverter.py @@ -0,0 +1,94 @@ +import pygame + +pygame.init() +screen = pygame.display.set_mode((640, 480)) +clock = pygame.time.Clock() +done = False + +pixelsize=8 + +#font = pygame.font.SysFont("comicsansms", 72) +font = pygame.font.Font("Minecraftia-Regular.ttf", 8*pixelsize); + +pixelsW=6 +pixelsH=8 + +asciioffset=33 +asciiend=126 +ascii = asciioffset + +fontname="font_minecraftia" + + +file = open("output.txt", "w") # write mode + +file.write("uint8_t font_offset="+str(asciioffset)+";\n"); + +#file.write("uint8_t "+fontname+"["+str(asciiend-asciioffset+1)+"]["+str(pixelsW)+"];\n") +file.write("uint8_t "+fontname+"["+str(asciiend-asciioffset+1)+"]["+str(pixelsW)+"]= {\n") + +while not done: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + done = True + 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)) + + text = font.render(chr(ascii), True, (0, 0, 0)) + screen.blit(text,(0,-pixelsize*2)) + print("ascii="+str(ascii)+" char="+chr(ascii)) + + ''' + uint16_t font[COLUMNS]; + font[ascii][column]=0b00000000; + + int a[2][3] = { + {0, 2, 1} , /* row at index 0 */ + {4, 3, 7} , /* row at index 1 */ + }; + ''' + + file.write("{") + for x in range(pixelsW): + int8number=0 + string8="" + for y in range(pixelsH): + readcolor = screen.get_at(((int)(pixelsize*x+pixelsize/2),(int)(pixelsize*y+pixelsize/2))) + if (readcolor==(0,0,0)): + int8number+=pow(2,y) + string8+='1' + else: + string8+='0' + + #file.write(fontname+"["+str(ascii-asciioffset)+"]["+str(x)+"]=0b"+string8+";\n") + file.write(str(int8number)) + if (xasciiend): + done=True + + pygame.display.flip() + clock.tick(30) + +file.write("};") +file.close() \ No newline at end of file