7 #include "DriverStationLCD.h"
8 #include "NetworkCommunication/FRCComm.h"
9 #include "NetworkCommunication/UsageReporting.h"
10 #include "Synchronized.h"
11 #include "WPIErrors.h"
14 const uint32_t DriverStationLCD::kSyncTimeout_ms;
15 const uint16_t DriverStationLCD::kFullDisplayTextCommand;
16 const int32_t DriverStationLCD::kLineLength;
17 const int32_t DriverStationLCD::kNumLines;
27 , m_textBufferSemaphore (NULL)
29 m_textBuffer =
new char[USER_DS_LCD_DATA_SIZE];
30 memset(m_textBuffer,
' ', USER_DS_LCD_DATA_SIZE);
32 *((uint16_t *)m_textBuffer) = kFullDisplayTextCommand;
34 m_textBufferSemaphore = semMCreate(SEM_DELETE_SAFE);
36 nUsageReporting::report(nUsageReporting::kResourceType_DriverStationLCD, 0);
41 DriverStationLCD::~DriverStationLCD()
43 semDelete(m_textBufferSemaphore);
44 delete [] m_textBuffer;
53 if (m_instance == NULL)
66 setUserDsLcdData(m_textBuffer, USER_DS_LCD_DATA_SIZE, kSyncTimeout_ms);
81 va_start (args, writeFmt);
82 VPrintf(line, startingColumn, writeFmt, args);
86 void DriverStationLCD::VPrintf(
Line line, int32_t startingColumn,
const char *writeFmt, va_list args)
88 uint32_t start = startingColumn - 1;
89 int32_t maxLength = kLineLength - start;
90 char lineBuffer[kLineLength + 1];
92 if (startingColumn < 1 || startingColumn > kLineLength)
94 wpi_setWPIErrorWithContext(ParameterOutOfRange,
"startingColumn");
98 if (line < kMain_Line6 || line > kUser_Line6)
100 wpi_setWPIErrorWithContext(ParameterOutOfRange,
"line");
107 int32_t length = vsnprintf(lineBuffer, kLineLength + 1, writeFmt, args);
108 if (length < 0) length = kLineLength;
110 memcpy(m_textBuffer + start + line * kLineLength +
sizeof(uint16_t), lineBuffer, std::min(maxLength,length));
126 va_start (args, writeFmt);
127 VPrintfLine(line, writeFmt, args);
131 void DriverStationLCD::VPrintfLine(
Line line,
const char *writeFmt, va_list args)
133 char lineBuffer[kLineLength + 1];
135 if (line < kMain_Line6 || line > kUser_Line6)
137 wpi_setWPIErrorWithContext(ParameterOutOfRange,
"line");
144 int32_t length = std::min(vsnprintf(lineBuffer, kLineLength + 1, writeFmt, args), (
int)kLineLength);
145 if (length < 0) length = kLineLength;
148 if (length < kLineLength)
150 memset(lineBuffer + length,
' ', kLineLength - length);
153 memcpy(m_textBuffer + line * kLineLength +
sizeof(uint16_t), lineBuffer, kLineLength);
163 memset(m_textBuffer +
sizeof(uint16_t),
' ', kLineLength*kNumLines);
static DriverStationLCD * GetInstance()
void AddToSingletonList()
void Printf(Line line, int32_t startingColumn, const char *writeFmt,...)
void PrintfLine(Line line, const char *writeFmt,...)