Skip to content

Commit 466a4a5

Browse files
authored
[wpilibc] Fix missing symbols on Windows (wpilibsuite#7140)
Windows doesn't support direct static variable access across library boundaries in a mixed static/shared environment, so change to accessor functions.
1 parent fe80d72 commit 466a4a5

File tree

5 files changed

+35
-19
lines changed

5 files changed

+35
-19
lines changed

wpilibc/src/main/native/cpp/DigitalOutput.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ void DigitalOutput::DisablePWM() {
135135
int32_t status = 0;
136136

137137
// Disable the output by routing to a dead bit.
138-
HAL_SetDigitalPWMOutputChannel(m_pwmGenerator, SensorUtil::kDigitalChannels,
139-
&status);
138+
HAL_SetDigitalPWMOutputChannel(m_pwmGenerator,
139+
SensorUtil::GetNumDigitalChannels(), &status);
140140
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
141141

142142
HAL_FreeDigitalPWM(m_pwmGenerator);

wpilibc/src/main/native/cpp/LEDPattern.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ LEDPattern LEDPattern::Blink(units::second_t onTime, units::second_t offTime) {
104104
if (wpi::Now() % totalMicros < onMicros) {
105105
self.ApplyTo(data, writer);
106106
} else {
107-
LEDPattern::kOff.ApplyTo(data, writer);
107+
LEDPattern::Off().ApplyTo(data, writer);
108108
}
109109
}};
110110
}
@@ -118,7 +118,7 @@ LEDPattern LEDPattern::SynchronizedBlink(std::function<bool()> signal) {
118118
if (signal()) {
119119
self.ApplyTo(data, writer);
120120
} else {
121-
LEDPattern::kOff.ApplyTo(data, writer);
121+
LEDPattern::Off().ApplyTo(data, writer);
122122
}
123123
}};
124124
}
@@ -198,7 +198,9 @@ LEDPattern LEDPattern::AtBrightness(double relativeBrightness) {
198198

199199
// Static constants and functions
200200

201-
LEDPattern LEDPattern::kOff = LEDPattern::Solid(Color::kBlack);
201+
LEDPattern LEDPattern::Off() {
202+
return LEDPattern::Solid(Color::kBlack);
203+
}
202204

203205
LEDPattern LEDPattern::Solid(const Color color) {
204206
return LEDPattern{[=](auto data, auto writer) {
@@ -228,7 +230,7 @@ LEDPattern LEDPattern::ProgressMaskLayer(
228230
LEDPattern LEDPattern::Steps(std::span<const std::pair<double, Color>> steps) {
229231
if (steps.size() == 0) {
230232
// no colors specified
231-
return LEDPattern::kOff;
233+
return LEDPattern::Off();
232234
}
233235
if (steps.size() == 1 && steps[0].first == 0) {
234236
// only one color specified, just show a static color
@@ -264,7 +266,7 @@ LEDPattern LEDPattern::Steps(
264266
LEDPattern LEDPattern::Gradient(std::span<const Color> colors) {
265267
if (colors.size() == 0) {
266268
// no colors specified
267-
return LEDPattern::kOff;
269+
return LEDPattern::Off();
268270
}
269271
if (colors.size() == 1) {
270272
// only one color specified, just show a static color

wpilibc/src/main/native/cpp/SensorUtil.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@
1313

1414
using namespace frc;
1515

16-
const int SensorUtil::kDigitalChannels = HAL_GetNumDigitalChannels();
17-
const int SensorUtil::kAnalogInputs = HAL_GetNumAnalogInputs();
18-
const int SensorUtil::kAnalogOutputs = HAL_GetNumAnalogOutputs();
19-
const int SensorUtil::kPwmChannels = HAL_GetNumPWMChannels();
20-
const int SensorUtil::kRelayChannels = HAL_GetNumRelayHeaders();
21-
2216
int SensorUtil::GetDefaultCTREPCMModule() {
2317
return 0;
2418
}
@@ -46,3 +40,23 @@ bool SensorUtil::CheckAnalogInputChannel(int channel) {
4640
bool SensorUtil::CheckAnalogOutputChannel(int channel) {
4741
return HAL_CheckAnalogOutputChannel(channel);
4842
}
43+
44+
int SensorUtil::GetNumDigitalChannels() {
45+
return HAL_GetNumDigitalChannels();
46+
}
47+
48+
int SensorUtil::GetNumAnalogInputs() {
49+
return HAL_GetNumAnalogInputs();
50+
}
51+
52+
int SensorUtil::GetNumAnalogOuputs() {
53+
return HAL_GetNumAnalogOutputs();
54+
}
55+
56+
int SensorUtil::GetNumPwmChannels() {
57+
return HAL_GetNumPWMChannels();
58+
}
59+
60+
int SensorUtil::GetNumRelayChannels() {
61+
return HAL_GetNumRelayHeaders();
62+
}

wpilibc/src/main/native/include/frc/LEDPattern.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ class LEDPattern {
246246
LEDPattern AtBrightness(double relativeBrightness);
247247

248248
/** A pattern that turns off all LEDs. */
249-
static LEDPattern kOff;
249+
static LEDPattern Off();
250250

251251
/**
252252
* Creates a pattern that displays a single static color along the entire

wpilibc/src/main/native/include/frc/SensorUtil.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ class SensorUtil final {
7878
*/
7979
static bool CheckAnalogOutputChannel(int channel);
8080

81-
static const int kDigitalChannels;
82-
static const int kAnalogInputs;
83-
static const int kAnalogOutputs;
84-
static const int kPwmChannels;
85-
static const int kRelayChannels;
81+
static int GetNumDigitalChannels();
82+
static int GetNumAnalogInputs();
83+
static int GetNumAnalogOuputs();
84+
static int GetNumPwmChannels();
85+
static int GetNumRelayChannels();
8686
};
8787

8888
} // namespace frc

0 commit comments

Comments
 (0)