|
From: <ean...@us...> - 2012-09-23 15:47:22
|
Revision: 11090
http://octave.svn.sourceforge.net/octave/?rev=11090&view=rev
Author: eandrius
Date: 2012-09-23 15:47:11 +0000 (Sun, 23 Sep 2012)
Log Message:
-----------
instrument-control: i2c, fix for constructor argument parsing
Modified Paths:
--------------
trunk/octave-forge/main/instrument-control/src/i2c/i2c.cc
Modified: trunk/octave-forge/main/instrument-control/src/i2c/i2c.cc
===================================================================
--- trunk/octave-forge/main/instrument-control/src/i2c/i2c.cc 2012-09-23 15:40:53 UTC (rev 11089)
+++ trunk/octave-forge/main/instrument-control/src/i2c/i2c.cc 2012-09-23 15:47:11 UTC (rev 11090)
@@ -67,7 +67,7 @@
}
DEFUN_DLD (i2c, args, nargout,
-"-*- texinfo -*-\n\
+ "-*- texinfo -*-\n\
@deftypefn {Loadable Function} {@var{i2c} = } i2c ([@var{path}], [@var{address}])\n \
\n\
Open i2c interface.\n \
@@ -84,10 +84,6 @@
#endif
int nargin = args.length();
-
- // Default values
- int oflags = O_RDWR;
- string path("/dev/i2c-0");
// Do not open interface if return value is not assigned
if (nargout != 1)
@@ -96,6 +92,47 @@
return octave_value();
}
+ // Default values
+ int oflags = O_RDWR;
+ string path("/dev/i2c-0");
+ int addr = -1;
+
+ if (!type_loaded)
+ {
+ octave_i2c::register_type();
+ type_loaded = true;
+ }
+
+ // Parse the function arguments
+ if (args.length() > 0)
+ {
+ if (args(0).is_string())
+ {
+ path = args(0).string_value();
+ }
+ else
+ {
+ print_usage();
+ return octave_value();
+ }
+
+ }
+
+ // is_float_type() is or'ed to allow expression like ("", 123), without user
+ // having to use ("", int32(123)), as we still only take "int_value"
+ if (args.length() > 1)
+ {
+ if (args(1).is_integer_type() || args(1).is_float_type())
+ {
+ addr = args(1).int_value();
+ }
+ else
+ {
+ print_usage();
+ return octave_value();
+ }
+ }
+
// Open the interface
octave_i2c* retval = new octave_i2c(path, oflags);
@@ -105,5 +142,8 @@
return octave_value();
}
+ if (addr > 0)
+ retval->set_addr(addr);
+
return octave_value(retval);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|