made stuff actually work
diff --git a/aos/crio/hardware/digital_source.cc b/aos/crio/hardware/digital_source.cc
index 1ed6e1c..3bb6e26 100644
--- a/aos/crio/hardware/digital_source.cc
+++ b/aos/crio/hardware/digital_source.cc
@@ -6,13 +6,12 @@
namespace crio {
namespace hardware {
-AnalogTriggerOutput::AnalogTriggerOutput(const unique_ptr< ::AnalogTrigger>
- &trigger,
+AnalogTriggerOutput::AnalogTriggerOutput(unique_ptr< ::AnalogTrigger> trigger,
::AnalogTriggerOutput::Type type,
float lowerVoltage,
float upperVoltage)
- : output_(trigger->CreateOutput(type)) {
- trigger->SetLimitsVoltage(lowerVoltage, upperVoltage);
+ : trigger_(::std::move(trigger)), output_(trigger_->CreateOutput(type)) {
+ trigger_->SetLimitsVoltage(lowerVoltage, upperVoltage);
}
} // namespace hardware
diff --git a/aos/crio/hardware/digital_source.h b/aos/crio/hardware/digital_source.h
index 3767508..52a50ba 100644
--- a/aos/crio/hardware/digital_source.h
+++ b/aos/crio/hardware/digital_source.h
@@ -39,7 +39,9 @@
static const float kDefaultUpperVoltage = 4;
// Will set up the voltages on trigger.
- AnalogTriggerOutput(const ::std::unique_ptr< ::AnalogTrigger> &trigger,
+ // Takes ownership of trigger to make sure it stays around so that the output
+ // it creates won't blow up (because it holds on to and uses it).
+ AnalogTriggerOutput(::std::unique_ptr< ::AnalogTrigger> trigger,
::AnalogTriggerOutput::Type type,
float lowerVoltage = kDefaultLowerVoltage,
float upperVoltage = kDefaultUpperVoltage);
@@ -50,6 +52,8 @@
virtual ::DigitalSource *source() const { return output_.get(); }
private:
+ // Might be NULL.
+ const ::std::unique_ptr< ::AnalogTrigger> trigger_;
const ::std::unique_ptr< ::AnalogTriggerOutput> output_;
};
diff --git a/aos/crio/shared_libs/limit_encoder_reader.cc b/aos/crio/shared_libs/limit_encoder_reader.cc
index dbbc88d..7292867 100644
--- a/aos/crio/shared_libs/limit_encoder_reader.cc
+++ b/aos/crio/shared_libs/limit_encoder_reader.cc
@@ -8,13 +8,15 @@
namespace aos {
namespace crio {
-LimitEncoderReader::LimitEncoderReader(const unique_ptr<::hardware::Counter>
+LimitEncoderReader::LimitEncoderReader(const unique_ptr< ::hardware::Counter>
&counter,
- unique_ptr<::hardware::DigitalSource>
+ unique_ptr< ::hardware::DigitalSource>
source,
bool posEdge, bool negEdge)
- : counter_(counter), source(::std::move(source)),
- notifier_(ReadValueStatic, source_->source(), this) {
+ : counter_(counter), source_(::std::move(source)),
+ notifier_(new InterruptNotifier<LimitEncoderReader>(ReadValueStatic,
+ source_->source(),
+ this)) {
source_->source()->SetUpSourceEdge(posEdge, negEdge);
}