jerrym | f157933 | 2013-02-07 01:56:28 +0000 | [diff] [blame] | 1 | /*----------------------------------------------------------------------------*/
|
| 2 | /* Copyright (c) FIRST 2008. All Rights Reserved. */
|
| 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */
|
| 4 | /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
|
| 5 | /*----------------------------------------------------------------------------*/
|
| 6 |
|
| 7 | #ifndef __DRIVER_STATION_H__
|
| 8 | #define __DRIVER_STATION_H__
|
| 9 |
|
| 10 | #include "Dashboard.h"
|
| 11 | #include "DriverStationEnhancedIO.h"
|
| 12 | #include "SensorBase.h"
|
| 13 | #include "Task.h"
|
| 14 |
|
| 15 | struct FRCCommonControlData;
|
| 16 | class AnalogChannel;
|
| 17 |
|
| 18 | /**
|
| 19 | * Provide access to the network communication data to / from the Driver Station.
|
| 20 | */
|
| 21 | class DriverStation : public SensorBase
|
| 22 | {
|
| 23 | public:
|
| 24 | enum Alliance {kRed, kBlue, kInvalid};
|
| 25 |
|
| 26 | virtual ~DriverStation();
|
| 27 | static DriverStation *GetInstance();
|
| 28 |
|
| 29 | static const UINT32 kBatteryModuleNumber = 1;
|
| 30 | static const UINT32 kBatteryChannel = 8;
|
| 31 | static const UINT32 kJoystickPorts = 4;
|
| 32 | static const UINT32 kJoystickAxes = 6;
|
| 33 |
|
| 34 | float GetStickAxis(UINT32 stick, UINT32 axis);
|
| 35 | short GetStickButtons(UINT32 stick);
|
| 36 |
|
| 37 | float GetAnalogIn(UINT32 channel);
|
| 38 | bool GetDigitalIn(UINT32 channel);
|
| 39 | void SetDigitalOut(UINT32 channel, bool value);
|
| 40 | bool GetDigitalOut(UINT32 channel);
|
| 41 |
|
| 42 | bool IsEnabled();
|
| 43 | bool IsDisabled();
|
| 44 | bool IsAutonomous();
|
| 45 | bool IsOperatorControl();
|
| 46 | bool IsTest();
|
| 47 | bool IsNewControlData();
|
| 48 | bool IsFMSAttached();
|
| 49 |
|
| 50 | UINT32 GetPacketNumber();
|
| 51 | Alliance GetAlliance();
|
| 52 | UINT32 GetLocation();
|
| 53 | void WaitForData();
|
| 54 | double GetMatchTime();
|
| 55 | float GetBatteryVoltage();
|
| 56 | UINT16 GetTeamNumber();
|
| 57 |
|
| 58 | // Get the default dashboard packers. These instances stay around even after
|
| 59 | // a call to SetHigh|LowPriorityDashboardPackerToUse() changes which packer
|
| 60 | // is in use. You can restore the default high priority packer by calling
|
| 61 | // SetHighPriorityDashboardPackerToUse(&GetHighPriorityDashboardPacker()).
|
| 62 | Dashboard& GetHighPriorityDashboardPacker() { return m_dashboardHigh; }
|
| 63 | Dashboard& GetLowPriorityDashboardPacker() { return m_dashboardLow; }
|
| 64 |
|
| 65 | // Get/set the dashboard packers to use. This can sideline or restore the
|
| 66 | // default packers. Initializing SmartDashboard changes the high priority
|
| 67 | // packer in use so beware that the default packer will then be idle. These
|
| 68 | // methods support any kind of DashboardBase, e.g. a Dashboard or a
|
| 69 | // SmartDashboard.
|
| 70 | DashboardBase* GetHighPriorityDashboardPackerInUse() { return m_dashboardInUseHigh; }
|
| 71 | DashboardBase* GetLowPriorityDashboardPackerInUse() { return m_dashboardInUseLow; }
|
| 72 | void SetHighPriorityDashboardPackerToUse(DashboardBase* db) { m_dashboardInUseHigh = db; }
|
| 73 | void SetLowPriorityDashboardPackerToUse(DashboardBase* db) { m_dashboardInUseLow = db; }
|
| 74 |
|
| 75 | DriverStationEnhancedIO& GetEnhancedIO() { return m_enhancedIO; }
|
| 76 |
|
| 77 | void IncrementUpdateNumber() { m_updateNumber++; }
|
| 78 | SEM_ID GetUserStatusDataSem() { return m_statusDataSemaphore; }
|
| 79 |
|
| 80 | /** Only to be used to tell the Driver Station what code you claim to be executing
|
| 81 | * for diagnostic purposes only
|
| 82 | * @param entering If true, starting disabled code; if false, leaving disabled code */
|
| 83 | void InDisabled(bool entering) {m_userInDisabled=entering;}
|
| 84 | /** Only to be used to tell the Driver Station what code you claim to be executing
|
| 85 | * for diagnostic purposes only
|
| 86 | * @param entering If true, starting autonomous code; if false, leaving autonomous code */
|
| 87 | void InAutonomous(bool entering) {m_userInAutonomous=entering;}
|
| 88 | /** Only to be used to tell the Driver Station what code you claim to be executing
|
| 89 | * for diagnostic purposes only
|
| 90 | * @param entering If true, starting teleop code; if false, leaving teleop code */
|
| 91 | void InOperatorControl(bool entering) {m_userInTeleop=entering;}
|
| 92 | /** Only to be used to tell the Driver Station what code you claim to be executing
|
| 93 | * for diagnostic purposes only
|
| 94 | * @param entering If true, starting test code; if false, leaving test code */
|
| 95 | void InTest(bool entering) {m_userInTest=entering;}
|
| 96 |
|
| 97 | protected:
|
| 98 | DriverStation();
|
| 99 |
|
| 100 | void GetData();
|
| 101 | void SetData();
|
| 102 |
|
| 103 | private:
|
| 104 | static void InitTask(DriverStation *ds);
|
| 105 | static DriverStation *m_instance;
|
| 106 | static UINT8 m_updateNumber;
|
| 107 | ///< TODO: Get rid of this and use the semaphore signaling
|
| 108 | static const float kUpdatePeriod = 0.02;
|
| 109 |
|
| 110 | void Run();
|
| 111 |
|
| 112 | struct FRCCommonControlData *m_controlData;
|
| 113 | UINT8 m_digitalOut;
|
| 114 | AnalogChannel *m_batteryChannel;
|
| 115 | SEM_ID m_statusDataSemaphore;
|
| 116 | Task m_task;
|
| 117 | Dashboard m_dashboardHigh; // the default dashboard packers
|
| 118 | Dashboard m_dashboardLow;
|
| 119 | DashboardBase* m_dashboardInUseHigh; // the current dashboard packers in use
|
| 120 | DashboardBase* m_dashboardInUseLow;
|
| 121 | SEM_ID m_newControlData;
|
| 122 | SEM_ID m_packetDataAvailableSem;
|
| 123 | DriverStationEnhancedIO m_enhancedIO;
|
| 124 | SEM_ID m_waitForDataSem;
|
| 125 | double m_approxMatchTimeOffset;
|
| 126 | bool m_userInDisabled;
|
| 127 | bool m_userInAutonomous;
|
| 128 | bool m_userInTeleop;
|
| 129 | bool m_userInTest;
|
| 130 | };
|
| 131 |
|
| 132 | #endif
|
| 133 |
|