From 0e3150e577cdeb18d093135d2366b69c34f3b05d Mon Sep 17 00:00:00 2001 From: Frank Mori Hess Date: Wed, 26 Mar 2008 19:22:38 +0000 Subject: [PATCH] Made comedi::calibration default constructible. Added wrapper classes for comedi_to/from_physical. --- c++/include/comedilib.hpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/c++/include/comedilib.hpp b/c++/include/comedilib.hpp index 70eb752..b34099e 100644 --- a/c++/include/comedilib.hpp +++ b/c++/include/comedilib.hpp @@ -32,6 +32,36 @@ namespace comedi { class subdevice; + // wrapper for comedi_to_physical() + class to_physical + { + public: + to_physical(const comedi_polynomial_t &polynomial): + _polynomial(polynomial) + {} + double operator()(lsampl_t data) const + { + return comedi_to_physical(data, &_polynomial); + } + private: + comedi_polynomial_t _polynomial + }; + + // wrapper for comedi_from_physical() + class from_physical + { + public: + from_physical(const comedi_polynomial_t &polynomial): + _polynomial(polynomial) + {} + lsampl_t operator()(double physical_value) const + { + return comedi_from_physical(physical_value, &_polynomial); + } + private: + comedi_polynomial_t _polynomial + }; + class device { public: device() {} @@ -175,6 +205,7 @@ namespace comedi class calibration { public: + calibration() {} calibration(const device &dev) { init(dev.default_calibration_path()); @@ -222,6 +253,7 @@ namespace comedi } void apply_hard_calibration(unsigned channel, unsigned range, unsigned aref, const calibration &cal) { + if(cal.c_calibration() == 0) throw std::invalid_argument(__PRETTY_FUNCTION__); int retval = comedi_apply_parsed_calibration(comedi_handle(), index(), channel, range, aref, cal.c_calibration()); if(retval < 0) @@ -456,6 +488,7 @@ namespace comedi comedi_polynomial_t softcal_converter(unsigned channel, unsigned range, enum comedi_conversion_direction direction, const calibration &cal) { + if(cal.c_calibration() == 0) throw std::invalid_argument(__PRETTY_FUNCTION__); comedi_polynomial_t result; int retval = comedi_get_softcal_converter(index(), channel, range, direction, cal.c_calibration(), &result); -- 2.26.2