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_ENHANCED_IO_H__
|
| 8 | #define __DRIVER_STATION_ENHANCED_IO_H__
|
| 9 |
|
| 10 | #include "ErrorBase.h"
|
| 11 | #include "NetworkCommunication/FRCComm.h"
|
| 12 | #include <stack>
|
| 13 | #include <vector>
|
| 14 | #include <vxWorks.h>
|
| 15 |
|
| 16 | #define kAnalogInputResolution ((double)((1<<14)-1))
|
| 17 | #define kAnalogInputReference 3.3
|
| 18 | #define kAnalogOutputResolution ((double)((1<<8)-1))
|
| 19 | #define kAnalogOutputReference 4.0
|
| 20 | #define kAccelOffset 8300
|
| 21 | #define kAccelScale 3300.0
|
| 22 | #define kSupportedAPIVersion 1
|
| 23 |
|
| 24 | /**
|
| 25 | * Interact with the more complete I/O available from the
|
| 26 | * newest driver station. Get a reference to an object
|
| 27 | * of this type by calling GetEnhancedIO() on the DriverStation object.
|
| 28 | */
|
| 29 | class DriverStationEnhancedIO : public ErrorBase
|
| 30 | {
|
| 31 | // Can only be constructed by the DriverStation class.
|
| 32 | friend class DriverStation;
|
| 33 |
|
| 34 | #pragma pack(push,1)
|
| 35 | // BEGIN: Definitions from the Cypress firmware
|
| 36 | typedef struct
|
| 37 | {
|
| 38 | UINT16 digital;
|
| 39 | UINT16 digital_oe;
|
| 40 | UINT16 digital_pe;
|
| 41 | UINT16 pwm_compare[4];
|
| 42 | UINT16 pwm_period[2];
|
| 43 | UINT8 dac[2];
|
| 44 | UINT8 leds;
|
| 45 | union
|
| 46 | {
|
| 47 | struct
|
| 48 | {
|
| 49 | // Bits are inverted from cypress fw because of big-endian!
|
| 50 | UINT8 pwm_enable : 4;
|
| 51 | UINT8 comparator_enable : 2;
|
| 52 | UINT8 quad_index_enable : 2;
|
| 53 | };
|
| 54 | UINT8 enables;
|
| 55 | };
|
| 56 | UINT8 fixed_digital_out;
|
| 57 | } output_t; //data to IO (23 bytes)
|
| 58 |
|
| 59 | typedef struct
|
| 60 | {
|
| 61 | UINT8 api_version;
|
| 62 | UINT8 fw_version;
|
| 63 | INT16 analog[8];
|
| 64 | UINT16 digital;
|
| 65 | INT16 accel[3];
|
| 66 | INT16 quad[2];
|
| 67 | UINT8 buttons;
|
| 68 | UINT8 capsense_slider;
|
| 69 | UINT8 capsense_proximity;
|
| 70 | } input_t; //data from IO (33 bytes)
|
| 71 | // END: Definitions from the Cypress firmware
|
| 72 |
|
| 73 | // Dynamic block definitions
|
| 74 | typedef struct
|
| 75 | {
|
| 76 | UINT8 size; // Must be 25 (size remaining in the block not counting the size variable)
|
| 77 | UINT8 id; // Must be 18
|
| 78 | output_t data;
|
| 79 | UINT8 flags;
|
| 80 | } status_block_t;
|
| 81 |
|
| 82 | typedef struct
|
| 83 | {
|
| 84 | UINT8 size; // Must be 34
|
| 85 | UINT8 id; // Must be 17
|
| 86 | input_t data;
|
| 87 | } control_block_t;
|
| 88 | #pragma pack(pop)
|
| 89 |
|
| 90 | enum tBlockID
|
| 91 | {
|
| 92 | kInputBlockID = kFRC_NetworkCommunication_DynamicType_DSEnhancedIO_Input,
|
| 93 | kOutputBlockID = kFRC_NetworkCommunication_DynamicType_DSEnhancedIO_Output,
|
| 94 | };
|
| 95 | enum tStatusFlags {kStatusValid = 0x01, kStatusConfigChanged = 0x02, kForceEnhancedMode = 0x04};
|
| 96 |
|
| 97 | public:
|
| 98 | enum tDigitalConfig {kUnknown, kInputFloating, kInputPullUp, kInputPullDown, kOutput, kPWM, kAnalogComparator};
|
| 99 | enum tAccelChannel {kAccelX = 0, kAccelY = 1, kAccelZ = 2};
|
| 100 | enum tPWMPeriodChannels {kPWMChannels1and2, kPWMChannels3and4};
|
| 101 |
|
| 102 | double GetAcceleration(tAccelChannel channel);
|
| 103 | double GetAnalogIn(UINT32 channel);
|
| 104 | double GetAnalogInRatio(UINT32 channel);
|
| 105 | double GetAnalogOut(UINT32 channel);
|
| 106 | void SetAnalogOut(UINT32 channel, double value);
|
| 107 | bool GetButton(UINT32 channel);
|
| 108 | UINT8 GetButtons();
|
| 109 | void SetLED(UINT32 channel, bool value);
|
| 110 | void SetLEDs(UINT8 value);
|
| 111 | bool GetDigital(UINT32 channel);
|
| 112 | UINT16 GetDigitals();
|
| 113 | void SetDigitalOutput(UINT32 channel, bool value);
|
| 114 | tDigitalConfig GetDigitalConfig(UINT32 channel);
|
| 115 | void SetDigitalConfig(UINT32 channel, tDigitalConfig config);
|
| 116 | double GetPWMPeriod(tPWMPeriodChannels channels);
|
| 117 | void SetPWMPeriod(tPWMPeriodChannels channels, double period);
|
| 118 | bool GetFixedDigitalOutput(UINT32 channel);
|
| 119 | void SetFixedDigitalOutput(UINT32 channel, bool value);
|
| 120 | INT16 GetEncoder(UINT32 encoderNumber);
|
| 121 | void ResetEncoder(UINT32 encoderNumber);
|
| 122 | bool GetEncoderIndexEnable(UINT32 encoderNumber);
|
| 123 | void SetEncoderIndexEnable(UINT32 encoderNumber, bool enable);
|
| 124 | double GetTouchSlider();
|
| 125 | double GetPWMOutput(UINT32 channel);
|
| 126 | void SetPWMOutput(UINT32 channel, double value);
|
| 127 | UINT8 GetFirmwareVersion();
|
| 128 |
|
| 129 | private:
|
| 130 | DriverStationEnhancedIO();
|
| 131 | virtual ~DriverStationEnhancedIO();
|
| 132 | void UpdateData();
|
| 133 | void MergeConfigIntoOutput(const status_block_t &dsOutputBlock, status_block_t &localCache);
|
| 134 | bool IsConfigEqual(const status_block_t &dsOutputBlock, const status_block_t &localCache);
|
| 135 |
|
| 136 | // Usage Guidelines...
|
| 137 | DISALLOW_COPY_AND_ASSIGN(DriverStationEnhancedIO);
|
| 138 |
|
| 139 | control_block_t m_inputData;
|
| 140 | status_block_t m_outputData;
|
| 141 | SEM_ID m_inputDataSemaphore;
|
| 142 | SEM_ID m_outputDataSemaphore;
|
| 143 | bool m_inputValid;
|
| 144 | bool m_outputValid;
|
| 145 | bool m_configChanged;
|
| 146 | bool m_requestEnhancedEnable;
|
| 147 | INT16 m_encoderOffsets[2];
|
| 148 | };
|
| 149 |
|
| 150 | #endif
|
| 151 |
|