Now you can download a copy of these docs so you can use them offline! Download now
DriverStationLCD.cpp
00001 /*----------------------------------------------------------------------------*/ 00002 /* Copyright (c) FIRST 2008. All Rights Reserved. */ 00003 /* Open Source Software - may be modified and shared by FRC teams. The code */ 00004 /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ 00005 /*----------------------------------------------------------------------------*/ 00006 00007 #include "DriverStationLCD.h" 00008 #include "NetworkCommunication/FRCComm.h" 00009 #include "Synchronized.h" 00010 #include "WPIErrors.h" 00011 #include <strLib.h> 00012 00013 const UINT32 DriverStationLCD::kSyncTimeout_ms; 00014 const UINT16 DriverStationLCD::kFullDisplayTextCommand; 00015 const INT32 DriverStationLCD::kLineLength; 00016 const INT32 DriverStationLCD::kNumLines; 00017 DriverStationLCD* DriverStationLCD::m_instance = NULL; 00018 00024 DriverStationLCD::DriverStationLCD() 00025 : m_textBuffer (NULL) 00026 , m_textBufferSemaphore (NULL) 00027 { 00028 m_textBuffer = new char[USER_DS_LCD_DATA_SIZE]; 00029 memset(m_textBuffer, ' ', USER_DS_LCD_DATA_SIZE); 00030 00031 *((UINT16 *)m_textBuffer) = kFullDisplayTextCommand; 00032 00033 m_textBufferSemaphore = semMCreate(SEM_DELETE_SAFE | SEM_INVERSION_SAFE); 00034 00035 AddToSingletonList(); 00036 } 00037 00038 DriverStationLCD::~DriverStationLCD() 00039 { 00040 semDelete(m_textBufferSemaphore); 00041 delete [] m_textBuffer; 00042 m_instance = NULL; 00043 } 00044 00048 DriverStationLCD* DriverStationLCD::GetInstance() 00049 { 00050 if (m_instance == NULL) 00051 { 00052 m_instance = new DriverStationLCD(); 00053 } 00054 return m_instance; 00055 } 00056 00060 void DriverStationLCD::UpdateLCD() 00061 { 00062 Synchronized sync(m_textBufferSemaphore); 00063 setUserDsLcdData(m_textBuffer, USER_DS_LCD_DATA_SIZE, kSyncTimeout_ms); 00064 } 00065 00075 void DriverStationLCD::Printf(Line line, INT32 startingColumn, const char *writeFmt, ...) 00076 { 00077 va_list args; 00078 UINT32 start = startingColumn - 1; 00079 INT32 maxLength = kLineLength - start; 00080 char lineBuffer[kLineLength + 1]; 00081 00082 if (startingColumn < 1 || startingColumn > kLineLength) 00083 { 00084 wpi_setWPIErrorWithContext(ParameterOutOfRange, "startingColumn"); 00085 return; 00086 } 00087 00088 if (line < kMain_Line6 || line > kUser_Line6) 00089 { 00090 wpi_setWPIErrorWithContext(ParameterOutOfRange, "line"); 00091 return; 00092 } 00093 00094 va_start (args, writeFmt); 00095 { 00096 Synchronized sync(m_textBufferSemaphore); 00097 // snprintf appends NULL to its output. Therefore we can't write directly to the buffer. 00098 INT32 length = vsnprintf(lineBuffer, kLineLength + 1, writeFmt, args); 00099 if (length < 0) length = kLineLength; 00100 00101 memcpy(m_textBuffer + start + line * kLineLength + sizeof(UINT16), lineBuffer, std::min(maxLength,length)); 00102 } 00103 00104 va_end (args); 00105 } 00106 00116 void DriverStationLCD::PrintfLine(Line line, const char *writeFmt, ...) 00117 { 00118 va_list args; 00119 char lineBuffer[kLineLength + 1]; 00120 00121 if (line < kMain_Line6 || line > kUser_Line6) 00122 { 00123 wpi_setWPIErrorWithContext(ParameterOutOfRange, "line"); 00124 return; 00125 } 00126 00127 va_start (args, writeFmt); 00128 { 00129 Synchronized sync(m_textBufferSemaphore); 00130 // snprintf appends NULL to its output. Therefore we can't write directly to the buffer. 00131 INT32 length = std::min(vsnprintf(lineBuffer, kLineLength + 1, writeFmt, args), kLineLength); 00132 if (length < 0) length = kLineLength; 00133 00134 // Fill the rest of the buffer 00135 if (length < kLineLength) 00136 { 00137 memset(lineBuffer + length, ' ', kLineLength - length); 00138 } 00139 00140 memcpy(m_textBuffer + line * kLineLength + sizeof(UINT16), lineBuffer, kLineLength); 00141 } 00142 00143 va_end (args); 00144 } 00145 00149 void DriverStationLCD::Clear() 00150 { 00151 Synchronized sync(m_textBufferSemaphore); 00152 memset(m_textBuffer + sizeof(UINT16), ' ', kLineLength*kNumLines); 00153 } 00154
Generated on Thu Jan 12 2012 22:35:19 for WPILibC++ by
1.7.1