From 69f5726d7027ef45ccbb1a568ff33e91bd742654 Mon Sep 17 00:00:00 2001 From: Thomas Gubler Date: Sun, 8 Feb 2015 12:35:10 +0100 Subject: make subscriber example use the new param api --- src/examples/subscriber/subscriber_example.cpp | 24 +++++++++++------------- src/examples/subscriber/subscriber_example.h | 7 +++---- 2 files changed, 14 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/examples/subscriber/subscriber_example.cpp b/src/examples/subscriber/subscriber_example.cpp index e1292f788..496e1dcd8 100644 --- a/src/examples/subscriber/subscriber_example.cpp +++ b/src/examples/subscriber/subscriber_example.cpp @@ -49,20 +49,18 @@ void rc_channels_callback_function(const px4_rc_channels &msg) { SubscriberExample::SubscriberExample() : _n(), - _p_sub_interv(PX4_PARAM_INIT(SUB_INTERV)), - _interval(0), - _p_test_float(PX4_PARAM_INIT(SUB_TESTF)), - _test_float(0.0f) + _p_sub_interv("SUB_INTERV", PARAM_SUB_INTERV_DEFAULT), + _p_test_float("SUB_TESTF", PARAM_SUB_TESTF_DEFAULT) { /* Read the parameter back as example */ - PX4_PARAM_GET(_p_sub_interv, &_interval); - PX4_INFO("Param SUB_INTERV = %d", _interval); - PX4_PARAM_GET(_p_test_float, &_test_float); - PX4_INFO("Param SUB_TESTF = %.3f", (double)_test_float); + _p_sub_interv.update(); + _p_test_float.update(); + PX4_INFO("Param SUB_INTERV = %d", _p_sub_interv.get()); + PX4_INFO("Param SUB_TESTF = %.3f", (double)_p_test_float.get()); /* Do some subscriptions */ /* Function */ - _n.subscribe(rc_channels_callback_function, _interval); + _n.subscribe(rc_channels_callback_function, _p_sub_interv.get()); /* No callback */ _sub_rc_chan = _n.subscribe(500); @@ -98,8 +96,8 @@ void SubscriberExample::vehicle_attitude_callback(const px4_vehicle_attitude &ms void SubscriberExample::parameter_update_callback(const px4_parameter_update &msg) { PX4_INFO("parameter_update_callback (method): [%llu]", msg.data().timestamp); - PX4_PARAM_GET(_p_sub_interv, &_interval); - PX4_INFO("Param SUB_INTERV = %d", _interval); - PX4_PARAM_GET(_p_test_float, &_test_float); - PX4_INFO("Param SUB_TESTF = %.3f", (double)_test_float); + _p_sub_interv.update(); + PX4_INFO("Param SUB_INTERV = %d", _p_sub_interv.get()); + _p_test_float.update(); + PX4_INFO("Param SUB_TESTF = %.3f", (double)_p_test_float.get()); } diff --git a/src/examples/subscriber/subscriber_example.h b/src/examples/subscriber/subscriber_example.h index 9b6d890e3..686fed023 100644 --- a/src/examples/subscriber/subscriber_example.h +++ b/src/examples/subscriber/subscriber_example.h @@ -52,12 +52,11 @@ public: void spin() {_n.spin();} protected: px4::NodeHandle _n; - px4_param_t _p_sub_interv; - int32_t _interval; - px4_param_t _p_test_float; - float _test_float; + px4::ParameterInt _p_sub_interv; + px4::ParameterFloat _p_test_float; px4::Subscriber * _sub_rc_chan; + void rc_channels_callback(const px4_rc_channels &msg); void vehicle_attitude_callback(const px4_vehicle_attitude &msg); void parameter_update_callback(const px4_parameter_update &msg); -- cgit v1.2.3