|
|||||||
![]() |
Forum Index > Projects > LED Pegboard and Matrix Projects | ||
Peggy2LE doesn't like snprintf? |
|||
| | | Printable Version |
|
adambomb | ||||||||
|
I've got a peggy2le (v2.31le) that I'm trying to program to dynamically update (twitter feeds, baseball scores, news, etc.), but I've hit some snags. I'm using the Peggy2 and PeggyWriter libraries, downloaded two days ago, from here. Using this library gives me four usable rows for text. I'm displaying static text on the top three rows right now and scrolling text for the bottom row. (This may change later.) Here's what's happening: PHP Formatted Code char textstrHeader[] = "SET NEW MESSAGE"; char textstrScroller[] = "INITIALIZING 0123456789:;<=>?@ "; void setup() { frame1.HardwareInit(); myScroller.init(&frame1, &myWriter, 18, textstrScroller); }
PHP Formatted Code char textstrHeader[BUFFER_SIZE]; char textstrScroller[BUFFER_SIZE]; void setup() { snprintf(textstrHeader, BUFFER_SIZE, "%s", "SET NEW MESSAGE"); snprintf(textstrScroller, BUFFER_SIZE, "%s", "INITIALIZING 0123456789:;<=>?@ "); frame1.HardwareInit(); myScroller.init(&frame1, &myWriter, 18, textstrScroller); }
PHP Formatted Code #include <Peggy2.h> #include <PeggyWriter.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define BUFFER_SIZE 8192 Peggy2 frame1; PeggyWriter myWriter; PeggyScroller myScroller; //char textstrHeader[BUFFER_SIZE]; //char textstrScroller[BUFFER_SIZE]; char textstrHeader[] = "SET NEW MESSAGE"; char textstrScroller[] = "INITIALIZING 0123456789:;<=>?@ "; void setup() { // snprintf(textstrHeader, BUFFER_SIZE, "%s", "SET NEW MESSAGE"); // snprintf(textstrScroller, BUFFER_SIZE, "%s", "INITIALIZING 0123456789:;<=>?@ "); frame1.HardwareInit(); myScroller.init(&frame1, &myWriter, 18, textstrScroller); } void loop() { long delayCount = 0; char messageFinished; // strip_nonvalid_characters(textstrHeader); // strip_nonvalid_characters(textstrScroller); // pull all the "myWriter.drawCharacter calls into a separate function writeStaticDisplay(frame1, myWriter, textstrHeader); messageFinished = myScroller.scrollLeft(); while (delayCount < 200) { frame1.RefreshAll(1); delayMicroseconds(50); delayCount++; } delayCount = 0; if (messageFinished == 0) { // refresh so we make another call to reset the messages refresh(); } } void refresh() { snprintf(textstrHeader, BUFFER_SIZE, "%s", "BUGGY AS HELL"); snprintf(textstrScroller, BUFFER_SIZE, "%s", "SETTING NEW MESSAGE "); // find a way to definitively clear the screen to get around static overlap problem // frame1.HardwareInit(); // <- doesn't seem to make a difference on subsequent calls myScroller.init(&frame1, &myWriter, 18, textstrScroller); } void strip_nonvalid_characters(char *textstr) { int i, j; int textstr_length = strlen(textstr); char temp_textstr[BUFFER_SIZE]; for (i = 0, j = 0; i < textstr_length; i++) { if ((textstr[i] > 96) && (textstr[i] < 123)) { textstr[i] = textstr[i] - 32; } // ascii characters between 0 and Z and the space on http://www.asciitable.com/ if (((textstr[i] > 47) && (textstr[i] < 91)) || (textstr[i] == 32)) { temp_textstr[j++] = textstr[i]; } // ascii character for / turns into ; if (textstr[i] == 47) { temp_textstr[j++] = 59; } // ascii character for # turns into < if (textstr[i] == 35) { temp_textstr[j++] = 60; } // ascii character for . turns into > if (textstr[i] == 46) { temp_textstr[j++] = 62; } // ascii characters for ' ` " turns into ; if ((textstr[i] == 34) || (textstr[i] == 39) || (textstr[i] == 44)) { temp_textstr[j++] = 59; } // ascii character for ! turns into : if (textstr[i] == 33) { temp_textstr[j++] = 58; temp_textstr[j++] = 58; } } temp_textstr[j] = '\0'; snprintf(textstr, BUFFER_SIZE, "%s", temp_textstr); strncpy(textstr, temp_textstr, strlen(temp_textstr)); } void writeStaticDisplay(Peggy2 frame, PeggyWriter msg, char *textline) { int x = 0; int y = 0; int count; for (count = 0; textline[count] != '\0'; count++) { if (textline[count] == ' ') { if ((x + 1) <= 25) { x += 2; } else { x = 0; y += 6; } } else if ((textline[count] == 'I') || (textline[count] == ':')) { if ((x + 1) > 25) { x = 0; y += 6; } msg.drawCharacter(textline[count], &frame, x, y); x += 2; } else if ((textline[count] == 'E') || (textline[count] == 'F') || (textline[count] == 'L') || (textline[count] == 'T') || (textline[count] == 'Z') || (textline[count] == '1') || (textline[count] == '<') || (textline[count] == '>') || (textline[count] == '=') || (textline[count] == ';')) { if ((x + 3) > 25) { x = 0; y += 6; } msg.drawCharacter(textline[count], &frame, x, y); x += 4; } else if ((textline[count] == 'M') || (textline[count] == 'N') || (textline[count] == 'V') || (textline[count] == 'W') || (textline[count] == 'X') || (textline[count] == 'Y')) { if ((x + 5) > 25) { x = 0; y += 6; } msg.drawCharacter(textline[count], &frame, x, y); x += 6; } else { if ((x + 4) > 25) { x = 0; y += 6; } msg.drawCharacter(textline[count], &frame, x, y); x += 5; } } }
|
![]() Apprentice Status: offline
Registered: 05/26/10 |
||||||||
|
|||||||||
|
adambomb | ||||||||
|
Okay, I'm a real idiot sometimes. Shouldn't wait until it was so late to work on this. Turns out I should've read this page a bit more carefully. Issuing frame1.Clear() wipes the display clean properly. PHP Formatted Code void strip_nonvalid_characters(char *textstr) { int i, j; int textstr_length = strlen(textstr); char temp_textstr[BUFFER_SIZE]; for (i = 0, j = 0; i < textstr_length; i++) { if ((textstr[i] > 96) && (textstr[i] < 123)) { textstr[i] = textstr[i] - 32; } // ascii characters between 0 and Z and the space on http://www.asciitable.com/ if (((textstr[i] > 47) && (textstr[i] < 91)) || (textstr[i] == 32)) { temp_textstr[j++] = textstr[i]; } // ascii character for / turns into ; if (textstr[i] == 47) { temp_textstr[j++] = 59; } // ascii character for # turns into < if (textstr[i] == 35) { temp_textstr[j++] = 60; } // ascii character for . turns into > if (textstr[i] == 46) { temp_textstr[j++] = 62; } // ascii characters for ' ` " turns into ; if ((textstr[i] == 34) || (textstr[i] == 39) || (textstr[i] == 44)) { temp_textstr[j++] = 59; } // ascii character for ! turns into : if (textstr[i] == 33) { temp_textstr[j++] = 58; temp_textstr[j++] = 58; } } temp_textstr[j] = '\0'; snprintf(textstr, BUFFER_SIZE, "%s", temp_textstr); // strncpy(textstr, temp_textstr, strlen(temp_textstr)); } |
![]() Apprentice Status: offline
Registered: 05/26/10 |
||||||||
|
|||||||||
|
Windell | ||||||||
1. Somebody needs to update the libraries to use all ASCII characters. Having to work around that is a major pain in the butt.
2. How I assign values to the display strings determines whether or not the string for static display will be displayed. If I use snprintf, either a single line of LEDs lights up or nothing at all on the entire board. No scrolling text either. If I set up my strings like this, everything initially works fine:
3. Finally, what's the best way to completely wipe the display so I can change the text? After the scrolling text is finished, I make a call to a refresh function (that uses snprintf, by the way) that results in the old static text remaining after the new static text is displayed. More frustrating: the scrolling text changes just fine!
Windell H. Oskay drwho(at)evilmadscientist.com http://www.evilmadscientist.com/ |
![]() Evil Scientist ![]() Status: offline
Registered: 06/15/06 |
||||||||
|
|||||||||
|
adambomb | ||||||||
|
Aw, jeez. That did it. Changing my default buffer size down to 256 fixed my string scrubbing. Damn. ![]() CHARACTERS SUPPORTED Only a limited subset of ASCII characters are supported. These run from '0' through to 'Z' in the standard ASCII table. Specifically: - Numbers '0' up to '9' - punctuation marks: < > = : ; ? @ - Capital letters: 'A' through to 'Z' - You can also output spaces If you tell these functions to output characters outside of this set, the behaviour is undefined, and likely to crash.
|
![]() Apprentice Status: offline
Registered: 05/26/10 |
||||||||
|
|||||||||
|
Windell | ||||||||
|
>Okay, last thing then is just this from the PeggyWriter readme.txt file: Windell H. Oskay drwho(at)evilmadscientist.com http://www.evilmadscientist.com/ |
![]() Evil Scientist ![]() Status: offline
Registered: 06/15/06 |
||||||||
|
|||||||||
|
|
| All times are PDT. The time is now 07:37 PM. |
|
|
Octolively
Interactive LED kits
Meggy Jr RGB
LED matrix game
development kit.
Business-card sized
AVR target boards
Peggy 2
LED Pegboard kits