add text display

This commit is contained in:
interfisch 2023-11-25 12:23:15 +01:00
parent 7024eb09fb
commit 421b4e1068
4 changed files with 119 additions and 6 deletions

View File

@ -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();

View File

@ -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<text.length();textpos++){
char currentchar=text.charAt(textpos);
Serial.print("Current Char "); Serial.print((uint8_t)currentchar); Serial.print(":"); Serial.println(currentchar);
for (uint8_t x=0;x<6;x++) {
uint16_t addBuffer=(font_minecraftia[(uint8_t)currentchar-font_offset][x]>>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;
}
}

View File

@ -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;

View File

@ -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 (x<pixelsW-1):
file.write(",")
comment_character=chr(ascii)
if comment_character=='\\':
comment_character="Backslash"
file.write("}, // "+str(ascii)+"="+comment_character+"\n")
ascii+=1
if (ascii>asciiend):
done=True
pygame.display.flip()
clock.tick(30)
file.write("};")
file.close()