more making the hardware stuff actually work...
diff --git a/aos/crio/hardware/README b/aos/crio/hardware/README
index 8974a52..a312613 100644
--- a/aos/crio/hardware/README
+++ b/aos/crio/hardware/README
@@ -5,5 +5,8 @@
qualify the names of these ones (and should do the same for WPILib ones too).
The wrappers only have the functionality that is missing from whatever WPILib
class they are wrapping (and can return pointer to). Use that pointer to do
- everything else. They also ahve the more useful constructors that forward to
- the WPILib ones.
+ everything else. They also have the more useful constructors that forward to
+ the WPILib ones. Some of them also have smart pointers named *_holder_. These
+ are only there to hold onto objects that WPILib needs held onto separately.
+ Many of them are sometimes left as NULL depending on how the wrapper is
+ created. They really should not be used for anything.
diff --git a/aos/crio/hardware/counter.cc b/aos/crio/hardware/counter.cc
index fc19f89..4665679 100644
--- a/aos/crio/hardware/counter.cc
+++ b/aos/crio/hardware/counter.cc
@@ -9,6 +9,13 @@
namespace crio {
namespace hardware {
+::DigitalSource *Counter::a() {
+ return a_wrapper_->source();
+}
+::DigitalSource *Counter::b() {
+ return b_wrapper_->source();
+}
+
int Counter::GetDenominator() {
switch (type_) {
case ::CounterBase::EncodingType::k1X:
@@ -30,8 +37,8 @@
LOG(FATAL, "bad ::CounterBase::EncodingType %d\n", static_cast<int>(type));
}
-unique_ptr<Counter> Counter::Create(unique_ptr< ::DigitalSource> a,
- unique_ptr< ::DigitalSource> b,
+unique_ptr<Counter> Counter::Create(unique_ptr<DigitalSource> a,
+ unique_ptr<DigitalSource> b,
::CounterBase::EncodingType type) {
switch (type) {
case ::CounterBase::EncodingType::k4X:
@@ -46,17 +53,17 @@
BadEncodingType(type);
}
-EncoderCounter::EncoderCounter(unique_ptr< ::DigitalSource> a_source,
- unique_ptr< ::DigitalSource> b_source)
- : Counter(::std::move(a_source), ::std::move(b_source),
+EncoderCounter::EncoderCounter(unique_ptr<DigitalSource> a_wrapper,
+ unique_ptr<DigitalSource> b_wrapper)
+ : Counter(::std::move(a_wrapper), ::std::move(b_wrapper),
::CounterBase::EncodingType::k4X),
- encoder_(new ::Encoder(a().get(), b().get())) {}
+ encoder_(new ::Encoder(a(), b())) {}
-CounterCounter::CounterCounter(unique_ptr< ::DigitalSource> a_source,
- unique_ptr< ::DigitalSource> b_source,
+CounterCounter::CounterCounter(unique_ptr<DigitalSource> a_wrapper,
+ unique_ptr<DigitalSource> b_wrapper,
::CounterBase::EncodingType type)
- : Counter(::std::move(a_source), ::std::move(b_source), type),
- counter_(new ::Counter(type, a().get(), b().get(), false /*inverted*/)) {
+ : Counter(::std::move(a_wrapper), ::std::move(b_wrapper), type),
+ counter_(new ::Counter(type, a(), b(), false /*inverted*/)) {
assert(type == ::CounterBase::EncodingType::k1X ||
type == ::CounterBase::EncodingType::k2X);
}
diff --git a/aos/crio/hardware/counter.h b/aos/crio/hardware/counter.h
index 23bf35d..610f65a 100644
--- a/aos/crio/hardware/counter.h
+++ b/aos/crio/hardware/counter.h
@@ -31,9 +31,8 @@
virtual int32_t Get() = 0;
// This object maintains ownership.
virtual ::CounterBase *counter_base() const = 0;
-
- const ::std::unique_ptr< ::DigitalSource> &a() { return a_; }
- const ::std::unique_ptr< ::DigitalSource> &b() { return b_; }
+ ::DigitalSource *a();
+ ::DigitalSource *b();
// Returns the denominator to convert from ticks to cycles.
int GetDenominator();
@@ -41,18 +40,16 @@
// Will create an instance of a subclass as appropriate for type.
// This should be used (except for special circumstances) for constructing all
// instances because it makes it much easier to change the encoding type.
- static ::std::unique_ptr<Counter> Create(::std::unique_ptr< ::DigitalSource>
- a,
- ::std::unique_ptr< ::DigitalSource>
- b,
+ static ::std::unique_ptr<Counter> Create(::std::unique_ptr<DigitalSource> a,
+ ::std::unique_ptr<DigitalSource> b,
::CounterBase::EncodingType type);
protected:
- Counter(::std::unique_ptr< ::DigitalSource> a,
- ::std::unique_ptr< ::DigitalSource> b,
+ Counter(::std::unique_ptr<DigitalSource> a_wrapper,
+ ::std::unique_ptr<DigitalSource> b_wrapper,
::CounterBase::EncodingType type)
- : a_(::std::move(a)),
- b_(::std::move(b)),
+ : a_wrapper_(::std::move(a_wrapper)),
+ b_wrapper_(::std::move(b_wrapper)),
type_(type) {}
// What to do at the end of functions that handle all encoding types to make
@@ -61,8 +58,8 @@
__attribute__((noreturn));
private:
- const ::std::unique_ptr< ::DigitalSource> a_;
- const ::std::unique_ptr< ::DigitalSource> b_;
+ const ::std::unique_ptr<DigitalSource> a_wrapper_;
+ const ::std::unique_ptr<DigitalSource> b_wrapper_;
// Because WPILib doesn't actually keep track of it...
const ::CounterBase::EncodingType type_;
@@ -74,8 +71,8 @@
// creates an internal ::Counter, which is really stupid.
class EncoderCounter : public Counter {
public:
- EncoderCounter(::std::unique_ptr< ::DigitalSource> a,
- ::std::unique_ptr< ::DigitalSource> b);
+ EncoderCounter(::std::unique_ptr<DigitalSource> a_wrapper,
+ ::std::unique_ptr<DigitalSource> b_wrapper);
virtual int32_t Get() { return encoder_->GetRaw(); }
virtual ::CounterBase *counter_base() const { return encoder_.get(); }
@@ -87,8 +84,8 @@
class CounterCounter : public Counter {
public:
- CounterCounter(::std::unique_ptr< ::DigitalSource> a,
- ::std::unique_ptr< ::DigitalSource> b,
+ CounterCounter(::std::unique_ptr<DigitalSource> a_wrapper,
+ ::std::unique_ptr<DigitalSource> b_wrapper,
::CounterBase::EncodingType type);
virtual int32_t Get() { return counter_->Get(); }
diff --git a/aos/crio/hardware/digital_source.cc b/aos/crio/hardware/digital_source.cc
index 3bb6e26..8849a3b 100644
--- a/aos/crio/hardware/digital_source.cc
+++ b/aos/crio/hardware/digital_source.cc
@@ -10,8 +10,9 @@
::AnalogTriggerOutput::Type type,
float lowerVoltage,
float upperVoltage)
- : trigger_(::std::move(trigger)), output_(trigger_->CreateOutput(type)) {
- trigger_->SetLimitsVoltage(lowerVoltage, upperVoltage);
+ : trigger_holder_(::std::move(trigger)),
+ output_(trigger_holder_->CreateOutput(type)) {
+ trigger_holder_->SetLimitsVoltage(lowerVoltage, upperVoltage);
}
} // namespace hardware
diff --git a/aos/crio/hardware/digital_source.h b/aos/crio/hardware/digital_source.h
index 52a50ba..9980bd0 100644
--- a/aos/crio/hardware/digital_source.h
+++ b/aos/crio/hardware/digital_source.h
@@ -52,8 +52,8 @@
virtual ::DigitalSource *source() const { return output_.get(); }
private:
- // Might be NULL.
- const ::std::unique_ptr< ::AnalogTrigger> trigger_;
+ const ::std::unique_ptr< ::AnalogTrigger> trigger_holder_;
+
const ::std::unique_ptr< ::AnalogTriggerOutput> output_;
};