2009:Correct Dashboard Update Function: Difference between revisions
From 1511Wookiee
Jump to navigationJump to search
(Initial checkin) |
|
(No difference)
|
Latest revision as of 19:42, 30 December 2009
This function should be used if/when WPILib is updated
#include "WPILib.h" #include "ThunderDrive.h" #include "DashboardDataFormat.h" #include "AnalogModule.h" #include "DigitalModule.h" #include "iomap.h" //This function requires you to modify WPIlib/DigitalModule.h and // make m_fpgaDIO a public member instead of private. The reason is // that there are no publicly accessible ways of reading the value of // a digital output or the output enables. Exposing m_fpgaDIO lets you use // the ChipObject functions readDI, readDO, and readOutputEnable. The bitmasking // of the DI and DO vectors versus the OE ensure that DIO's that are not inputs are // not falsely set because those specific bits are actually outputs, and vice versa. // // The same lack of ability to get() the status of the relayFWD and relayREV bits // requires exposing m_fpgaDIO to use the readSlowValue_Relay[Fwd|Rev] function void UpdateDashboard(void) { tRioStatusCode status = 0; UINT16 channum = 0; //analog/digital channel number AnalogModule *amodule = AnalogModule::GetInstance(1); DigitalModule *dmodule = DigitalModule::GetInstance(4); for (channum = 1; channum <= SensorBase::kAnalogChannels; channum++) { dashboardDataFormat.m_AnalogChannels[0][channum-1] = amodule->GetValue(channum); } for (channum = 1; channum <= SensorBase::kPwmChannels; channum++) { dashboardDataFormat.m_PWMChannels[0][channum-1] = dmodule->GetPWM(channum); } unsigned short digin = 0, digout = 0, dio = 0; unsigned short dio_oe = dmodule->m_fpgaDIO->readOutputEnable(&status); digin = dmodule->m_fpgaDIO->readDI(&status); digin &= ~dio_oe; digout = dmodule->m_fpgaDIO->readDO(&status); digout &= dio_oe; dio = digin | digout; dashboardDataFormat.m_DIOChannels[0] = dio; //cast from ushort to UINT16 dashboardDataFormat.m_DIOChannelsOutputEnable[0] = dio_oe; //another ushort to UINT16 cast dashboardDataFormat.m_RelayFwd[0] = dmodule->m_fpgaDIO->readSlowValue_RelayFwd(&status); dashboardDataFormat.m_RelayRev[0] = dmodule->m_fpgaDIO->readSlowValue_RelayRev(&status); //no solenoid feedback - we're not using it. dashboardDataFormat.PackAndSend(); }