mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-01 02:41:48 +00:00
[hal,wpilib] Add DS Display API (#8975)
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <functional>
|
||||
@@ -279,6 +280,10 @@ HAL_Bool HAL_GetSystemTimeValid(int32_t* status) {
|
||||
return systemTimeValid;
|
||||
}
|
||||
|
||||
void HAL_WriteDisplayAnsi(const struct WPI_String* data) {
|
||||
mrcLibDs->writeDisplayAnsi(data);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
namespace wpi::hal {
|
||||
|
||||
@@ -444,4 +444,19 @@ Java_org_wpilib_hardware_hal_DriverStationJNI_getOutputsActive
|
||||
{
|
||||
return HAL_GetOutputsEnabled();
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_wpilib_hardware_hal_DriverStationJNI
|
||||
* Method: writeDisplayAnsi
|
||||
* Signature: (Ljava/lang/String;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_wpilib_hardware_hal_DriverStationJNI_writeDisplayAnsi
|
||||
(JNIEnv* env, jclass, jstring data)
|
||||
{
|
||||
JStringRef dataStr{env, data};
|
||||
WPI_String dataWpiStr = dataStr.wpi_str();
|
||||
HAL_WriteDisplayAnsi(&dataWpiStr);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -242,6 +242,8 @@ class MrcLibDsImpl : public MrcLibDs {
|
||||
|
||||
int32_t getSystemTimeValid(bool* systemTimeValid) override;
|
||||
|
||||
int32_t writeDisplayAnsi(const struct WPI_String* line) override;
|
||||
|
||||
wpi::util::EventVector newDataEvents;
|
||||
|
||||
private:
|
||||
@@ -661,6 +663,11 @@ int32_t MrcLibDsImpl::getSystemTimeValid(bool* systemTimeValid) {
|
||||
return status;
|
||||
}
|
||||
|
||||
int32_t MrcLibDsImpl::writeDisplayAnsi(const struct WPI_String* line) {
|
||||
MRC_String mrcLine = WPIStringToMRCString(line);
|
||||
return MRC_DsCommsControl_WriteAnsi(&mrcLine);
|
||||
}
|
||||
|
||||
void MrcLibDsImpl::provideNewDataEventHandle(WPI_EventHandle handle) {
|
||||
newDataEvents.Add(handle);
|
||||
}
|
||||
|
||||
@@ -315,6 +315,13 @@ void HAL_ObserveUserProgramStarting(void);
|
||||
*/
|
||||
void HAL_ObserveUserProgram(HAL_ControlWord word);
|
||||
|
||||
/**
|
||||
* Writes ANSI text to the display.
|
||||
*
|
||||
* @param data the ANSI text to write
|
||||
*/
|
||||
void HAL_WriteDisplayAnsi(const struct WPI_String* data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
@@ -97,6 +97,14 @@ class MrcLibDs {
|
||||
virtual int32_t observeUserProgram(HAL_ControlWord controlWord) = 0;
|
||||
|
||||
virtual int32_t getSystemTimeValid(bool* systemTimeValid) = 0;
|
||||
|
||||
/**
|
||||
* Writes ANSI text to the Driver Station display.
|
||||
*
|
||||
* @param line the ANSI text to write
|
||||
* @return 0 on success, non-zero on error
|
||||
*/
|
||||
virtual int32_t writeDisplayAnsi(const struct WPI_String* line) = 0;
|
||||
};
|
||||
|
||||
MrcLibDs* GetMrcLibDs();
|
||||
|
||||
@@ -160,6 +160,8 @@ class MrcLibDsSimImpl : public MrcLibDs {
|
||||
|
||||
int32_t getSystemTimeValid(bool* systemTimeValid) override;
|
||||
|
||||
int32_t writeDisplayAnsi(const struct WPI_String* line) override;
|
||||
|
||||
wpi::util::EventVector newDataEvents;
|
||||
|
||||
void NewDriverStationData();
|
||||
@@ -506,6 +508,10 @@ int32_t MrcLibDsSimImpl::getSystemTimeValid(bool* systemTimeValid) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t MrcLibDsSimImpl::writeDisplayAnsi(const struct WPI_String* line) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MrcLibDsSimImpl::NewDriverStationData() {
|
||||
SimDriverStationData->dsAttached = true;
|
||||
cacheToUpdate->Update();
|
||||
|
||||
Reference in New Issue
Block a user