Compare commits

...

2 Commits

Author SHA1 Message Date
interfisch 421b4e1068 add text display 2023-11-25 12:23:15 +01:00
interfisch 7024eb09fb mirror column data. msbfirst. bit 0 is now top row. 2023-11-25 12:22:05 +01:00
5 changed files with 123 additions and 9 deletions

View File

@ -26,7 +26,7 @@ private:
//buffer is 16 bit because of 16 Rows //buffer is 16 bit because of 16 Rows
uint16_t frontBuffer[COLUMNS]; //1 is bright dot / set dot. 0 is black / cleared 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_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 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_byString(String data,String& error);
void setBuffer_byInt(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_Image1();
void setBuffer_Image2(); void setBuffer_Image2();
void setBuffer_Image3(); void setBuffer_Image3();

View File

@ -144,8 +144,9 @@ bool Flipdot::HBridgeOK() {
void Flipdot::shiftDataRow() { //send out all data to shift registers void Flipdot::shiftDataRow() { //send out all data to shift registers
//select Rows via shift registers on own controller board //select Rows via shift registers on own controller board
shiftOutSlow(PIN_SR_DATA, PIN_SR_CLK, LSBFIRST, row&0xff); //lower byte //LSBFIRST= LSB is QH, bit 8 is QA. //upper byte
shiftOutSlow(PIN_SR_DATA, PIN_SR_CLK, LSBFIRST, row>>8); //LSBFIRST= LSB is QH, bit 8 is QA. //upper byte shiftOutSlow(PIN_SR_DATA, PIN_SR_CLK, MSBFIRST, row>>8); //MSBFIRST= LSB is QH, bit 8 is QA
shiftOutSlow(PIN_SR_DATA, PIN_SR_CLK, MSBFIRST, row&0xff); //lower byte
digitalWrite(PIN_SR_LATCH, HIGH); digitalWrite(PIN_SR_LATCH, HIGH);
delayMicroseconds(MICROS_SHIFT_LATCH); delayMicroseconds(MICROS_SHIFT_LATCH);
digitalWrite(PIN_SR_LATCH, LOW); digitalWrite(PIN_SR_LATCH, LOW);
@ -169,7 +170,7 @@ void Flipdot::resetColumns() {
} }
void Flipdot::setRow(uint16_t _row){ void Flipdot::setRow(uint16_t _row){
row=_row; row=_row; //data for one column
} }
uint16_t Flipdot::getRow() { uint16_t Flipdot::getRow() {

View File

@ -1,11 +1,10 @@
#include "image.h" #include "image.h"
#include "fonts.h"
Image::Image() Image::Image()
{ {
} }
void Image::serialPrintInt(uint16_t source) void Image::serialPrintInt(uint16_t source)
@ -46,6 +45,24 @@ void Image::setBuffer_solid(bool set)
flag_updating=true; //make update run 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 void Image::setBuffer_Image1() //Bumblebee
{ {
@ -1039,9 +1056,6 @@ void Image::loop_drawClearTest() {
init=false; init=false;
} }
} }

View File

@ -220,6 +220,9 @@ bool presetHandler(const HomieRange& range, const String& value) {
Homie.getLogger() << "Preset is Image8" << endl; Homie.getLogger() << "Preset is Image8" << endl;
}else if(value == "random"){ }else if(value == "random"){
flip.setBuffer_random(50); flip.setBuffer_random(50);
}else if(value == "text") {
flip.setBuffer_solid(0);
flip.addBuffer_text("Test",0,0);
}else{ }else{
error="preset \""+value+"\" not found"; error="preset \""+value+"\" not found";
return false; 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()