Subversion Repositories seema-scanner

Rev

Blame | Last modification | View Log | RSS feed

#include "mex.h"
#include "class_handle.hpp"

// Output printf statements in the Matlab workspace
#define printf mexPrintf

// The class that we are interfacing to
#include "RotationStage.h"

using namespace std;

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){
    
    //mexPrintf("nlhs: %d , nrhs: %d\n", nlhs, nrhs);
    
    // Get the command string
    char cmd[64];
        if (nrhs < 1 || mxGetString(prhs[0], cmd, sizeof(cmd)))
                mexErrMsgTxt("First input should be a command string less than 64 characters long.");
    
    // Static methods
    
    // Class methods
    
    // New
    if (!strcmp("new", cmd)) {
        // Check parameters
        if (nlhs != 1)
            mexErrMsgTxt("New: One output expected.");
        if (nrhs > 2)
            mexErrMsgTxt("New: Expected no arguments.");
        // Return a handle to a new C++ instance
        plhs[0] = convertPtr2Mat<RotationStage>(new RotationStage());
        return;
    }
    
    // Check if there is a second input, which should be the class instance handle
    if (nrhs < 2)
                mexErrMsgTxt("Second input should be a class instance handle.");
    
    // Delete
    if (!strcmp("delete", cmd)) {
        // Destroy the C++ object
        destroyObject<RotationStage>(prhs[1]);
        // Warn if other commands were ignored
        if (nlhs != 0 || nrhs != 2)
            mexWarnMsgTxt("Delete: Unexpected arguments ignored.");
        return;
    }
    
    // Get the class instance pointer from the second input
    RotationStage *RotationStage_instance = convertMat2Ptr<RotationStage>(prhs[1]);
    
    // Call the various class methods
    // moveAbsolute
    if (!strcmp("moveAbsolute", cmd)) {
        // Check parameters
        if (nlhs > 0 || nrhs > 3)
            mexErrMsgTxt("moveAbsolute: Unexpected arguments.");
        // Call the method
        float angle = (unsigned int)mxGetScalar(prhs[2]);
        RotationStage_instance->moveAbsolute(angle);
        return;
    }

    // moveRelative
    if (!strcmp("moveRelative", cmd)) {
        // Check parameters
        if (nlhs > 0 || nrhs > 3)
            mexErrMsgTxt("moveRelative: Unexpected arguments.");
        // Call the method
        float angle = (unsigned int)mxGetScalar(prhs[2]);
        RotationStage_instance->moveRelative(angle);
        return;
    }
    
        // getAngle
    if (!strcmp("getAngle", cmd)) {
        // Check parameters
        if (nlhs > 1 || nrhs > 2)
            mexErrMsgTxt("getAngle: Unexpected arguments.");
        // Call the method
        float angle = RotationStage_instance->getAngle();
        plhs[0] = mxCreateNumericMatrix(1, 1, mxSINGLE_CLASS, mxREAL);
        float *data = (float *) mxGetData(plhs[0]);
        *data = angle;
        return;
    }
    
        // wait
    if (!strcmp("wait", cmd)) {
        // Check parameters
        if (nlhs > 0 || nrhs > 2)
            mexErrMsgTxt("wait: Unexpected arguments.");
        // Call the method
        RotationStage_instance->wait();
        return;
    }
    
//    // Test
//    if (!strcmp("test", cmd)) {
//        // Check parameters
//        if (nlhs < 0 || nrhs < 2)
//            mexErrMsgTxt("Test: Unexpected arguments.");
//        // Call the method
//        PatternProjector_instance->test();
//        return;
//    }
    
    // Got here, so command not recognized
    mexErrMsgTxt("Command not recognized.");
}