Made comedi::calibration default constructible. Added wrapper classes
authorFrank Mori Hess <fmhess@speakeasy.net>
Wed, 26 Mar 2008 19:22:38 +0000 (19:22 +0000)
committerFrank Mori Hess <fmhess@speakeasy.net>
Wed, 26 Mar 2008 19:22:38 +0000 (19:22 +0000)
for comedi_to/from_physical.

c++/include/comedilib.hpp

index 70eb752eaf200aa4a920e48999b4fb629f7f1050..b34099e06846afcabc712cb0e9c5a38f40a0fb4d 100644 (file)
@@ -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);