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