Go Down

Topic: DMD (Freetronics) read string from an external source (Read 152 times) previous topic - next topic

ChristopherBadenhorst

Apr 05, 2019, 09:37 am Last Edit: Apr 05, 2019, 09:42 am by ChristopherBadenhorst Reason: Added attachment
Trying to get the DMD library working with an external txt file with info (2 digit numbers). All running on a Yun Rev2.

I have it working when I use the standard 'drawChar' in the script, but somehow the stuff messes up in the drawString method written into the script.

Is there anyone who can help? I've been trying for about a week now, but can't get it to work.

This is the start
Code: [Select]
void loop() {

   // Initialize the client library
  HttpClient client;
  HttpClient client2;

  // Make a HTTP request:
  client.get("http://www.fake.nl/t/1.txt");
  client2.get("http://www.fake.nl/t/2.txt");
  

  // if there are incoming bytes available
  // from the server, read them and print them:
  while (client.available()) {
    const char *t = client.read();
    const char *b = client2.read();
 
  dmd.clearScreen( true );
   dmd.selectFont(MyGraphicsFont);
   dmd.drawChar(  0,  0,  (t), GRAPHICS_NORMAL );
   dmd.drawChar(  0,  16,  (b), GRAPHICS_NORMAL );
   delay( 5000 );

  dmd.clearScreen( true );
   dmd.selectFont(System5x7);
   dmd.drawString(  0,  0, (t), 3, GRAPHICS_NORMAL );
   dmd.drawString(  0,  16, (b), 3, GRAPHICS_NORMAL );
   delay( 5000 );
  }
}


This works like a charm:
Code: [Select]
dmd.clearScreen( true );
   dmd.selectFont(System5x7);
   dmd.drawChar(  0,  0,  (t), GRAPHICS_NORMAL );
   dmd.drawChar(  0,  16,  (b), GRAPHICS_NORMAL );
   delay( 5000 );



But this shows a . on the screen and nothing else:
Code: [Select]
dmd.clearScreen( true );
   dmd.selectFont(System5x7);
   dmd.drawString(  0,  0, (t), 3, GRAPHICS_NORMAL );
   dmd.drawString(  0,  16, (b), 3, GRAPHICS_NORMAL );
   delay( 5000 );



Dit some research already, these are the steps I see;
Code: [Select]
Step1:
  HttpClient client;
Step2:
  client.get("http://www.fake.nl/t/1.txt");
Step3:
  char t = client.read();
Step4:
  dmd.drawChar(  0,  0,  (t), GRAPHICS_NORMAL );



With usage of these lines in following files;

DMD.h
Code: [Select]
//Draw a string
  void drawString( int bX, int bY, const char* bChars, byte length, byte bGraphicsMode);


DMD.ccp
Code: [Select]
void DMD::drawString(int bX, int bY, const char *bChars, byte length,
     byte bGraphicsMode)
{
    if (bX >= (DMD_PIXELS_ACROSS*DisplaysWide) || bY >= DMD_PIXELS_DOWN * DisplaysHigh)
 return;
    uint8_t height = pgm_read_byte(this->Font + FONT_HEIGHT);
    if (bY+height<0) return;

    int strWidth = 0;
 this->drawLine(bX -1 , bY, bX -1 , bY + height, GRAPHICS_INVERSE);

    for (int i = 0; i < length; i++) {
        int charWide = this->drawChar(bX+strWidth, bY, bChars[i], bGraphicsMode);
    if (charWide > 0) {
        strWidth += charWide ;
        this->drawLine(bX + strWidth , bY, bX + strWidth , bY + height, GRAPHICS_INVERSE);
            strWidth++;
        } else if (charWide < 0) {
            return;
        }
        if ((bX + strWidth) >= DMD_PIXELS_ACROSS * DisplaysWide || bY >= DMD_PIXELS_DOWN * DisplaysHigh) return;
    }
}


Anyone who can help?

Go Up