View Full Version : Printing over other text
ekapalka
13-01-2013, 21:50
Hello! I'm having a small bit of trouble. Nothing critical, but I was wondering if someone could quickly clear something up for me. How do I print text (to the driver station) which completely replaces the previous line? Here is my code:
if (joyTrigger)
{
dsLCD->Printf(DriverStationLCD::kUser_Line1, 1, "Trigger");
dsLCD->UpdateLCD();
Wait(0.1);
}
else if (Button2)
{
dsLCD->Printf(DriverStationLCD::kUser_Line1, 11, "BottomThumbButton");
dsLCD->UpdateLCD();
Wait(0.1);
}
What it outputs is the current button (on the joystick). When I press a different button, it overwrites only the space it needs, so if I had it print something like "1111111111" and then something like "22222", it would end up printing "2222211111". I'm pretty sure it's just taking over the spaces, and not pushing the old text to the end of the line where it disappears. I know I could fix it by adding a bunch of spaces after each print, but is there another way? Thanks!
inkspell4
13-01-2013, 22:01
In the past I've had similar problems.
Even though my team is using java I'm interested to see what the fix is.
Greg McKaskle
13-01-2013, 22:05
The DriverStaion LCD duplicates the functionality of the old blue KwickByte DS. This means that the characters are written into a display buffer and you need to pad them with spaces if you wish to write the entire line.
The good part of its behavior is that you can pretty easily make columns on the same line, but it complicates simple debugging printfs.
Greg McKaskle
Radical Pi
13-01-2013, 22:17
There's no mechanism to clear a single line other than using spaces, however if you're willing to erase the whole screen, you can use dsLCD->Clear(), which is just a shortcut for writing spaces to all of the lines.
EDIT: I spoke without looking. Use dsLCD->PrintfLine(), which pads spaces as necessary to clear the rest of the line
ekapalka
13-01-2013, 22:36
I assume that there is some sort of syntax alteration? Adding "Line" to the end causes an error. I'll look into WPI....
Radical Pi
13-01-2013, 22:37
Drop the "1" argument when you switch to that. PrintfLine assumes you're starting at the front of the line
dsLCD->PrintfLine(DriverStationLCD::kUser_Line1, "Trigger");
dsLCD->UpdateLCD();
ekapalka
13-01-2013, 23:04
Thanks! I have one more question...
When I run a program that prints to the dashboard, then run one that doesn't (or doesn't immediately), the text from the previous program remains on the dashboard until it is either replaced by something else or the driver station is restarted. Is it good practice to use dsLCD->Clear() at the end of the program, or is this not supposed to happen?
Radical Pi
13-01-2013, 23:38
The data on the driver station is only updated when you call dsLCD->UpdateLCD(). Clear() doesn't make that call, so by calling Clear() you're only clearing out the robot-side buffer, but not updating the screen with it.
I personally don't mind having the stale data on the DS, especially since it leaves a snapshot of the robot's state from right before the connection was lost. Whenever I'm using the DriverStationLCD class though (which isn't as common now that SmartDashboard is available) I put in a call to Clear() before any Printf()s, just so that I can be sure I'm not forgetting to blank out any lines. It's all up to you though
cjlane1138
14-01-2013, 11:40
Last year, I developed a simple header and class file that has a few methods for simple printing to the LCD. Here it is:
http://www.filedropper.com/printtodslcd
Let me know how it works for you!
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.