/* If null is passed then we return the base function, otherwise we return the named subfuction or NULL if we can't find it. Also we store a pointer to the current function name string or set that pointer to NULL if we are returning the project base function. */ PsychFunctionPtr PsychGetProjectFunction(char *command) { int i; //return the project base function if(command==NULL){ currentFunctionNameREGISTER = NULL; return(baseFunctionREGISTER); } // See if help is being requested if (command[strlen(command)-1] == '?') { PsychSetGiveHelp(); command[strlen(command)-1]=0; }else PsychClearGiveHelp(); //lookup the function in the table for(i=0;i<numFunctionsREGISTER;i++){ if(PsychMatch(functionTableREGISTER[i].name, command)){ currentFunctionNameREGISTER = functionTableREGISTER[i].name; return(functionTableREGISTER[i].function); } } // Unknown command. return NULL; }
/* This function is called by the special subfunction 'DescribeModuleFunctionsHelper'. * It returns the full table of registered subfunction names as an array. * Useful for automatic documentation generators... * */ PsychError PsychDescribeModuleFunctions(void) { static char useString[] = "subfunctionNames = Modulename('DescribeModuleFunctionsHelper' [, mode] [, subfunctionName]);"; static char synopsisString[] = "Return a cell array of strings naming all subfunctions supported by this module if " "the optional 'subfunctionName' argument is omitted. If 'subfunctionName' is a " "string with a valid subfunction name for the module, and 'mode' is 1, return a 3 element cell " "array of strings which describe the detailed syntax, help and see also strings " "for that function - the text you'd get for Modulename('subfunctionName?'); "; static char seeAlsoString[] = ""; char* subfname; int i; PsychGenericScriptType *cellVector; PsychFunctionPtr fcn; //all subfunctions should have these two lines. PsychPushHelp(useString, synopsisString, seeAlsoString); if(PsychIsGiveHelp()){PsychGiveHelp();return(PsychError_none);}; // Check for valid number of arguments PsychErrorExit(PsychCapNumInputArgs(2)); PsychErrorExit(PsychCapNumOutputArgs(1)); PsychCopyInIntegerArg(1, FALSE, &i); subfname = NULL; PsychAllocInCharArg(2, FALSE, &subfname); if (subfname) { // Find named subfunction in functin table: fcn = PsychGetProjectFunction(subfname); if (fcn) { // This will trigger the subfunction 'fcn' to execute its PsychGiveHelp() method, then // return. PsychGiveHelp() will return the help text to Runtime as cell array of strings, // instead of printing to runtimes console: PsychSetGiveHelp(); PsychOneShotReturnHelp(); (*fcn)(); PsychClearGiveHelp(); } } else { // Generate a cell array to return PsychAllocOutCellVector(1, FALSE, numFunctionsREGISTER, &cellVector); for(i=0; i < numFunctionsREGISTER; i++) PsychSetCellVectorStringElement(i, functionTableREGISTER[i].name, cellVector); } return(PsychError_none); }
/* PsychHIDCleanup() Cleanup before flushing the mex file. */ PsychError PsychHIDCleanup(void) { long error; pRecDevice curdev = NULL; // Disable online help system: PsychClearGiveHelp(); // Disable any kind of low-level stdin<->tty magic for character reception // or suppression in console mode (for octave and matlab -nojvm): ConsoleInputHelper(-10); // Shutdown USB-HID report low-level functions, e.g., for DAQ toolbox on OS/X: error = PsychHIDReceiveReportsCleanup(); // PsychHIDReceiveReport.c // Shutdown os specific interfaces and routines: PsychHIDShutdownHIDStandardInterfaces(); // Release all other HID device data structures: #if PSYCH_SYSTEM == PSYCH_OSX // Via Apple HIDUtils: #if (PSYCH_SYSTEM == PSYCH_OSX) && defined(__LP64__) int i; for (i = 0; i < MAXDEVICEINDEXS; i++) { if (deviceInterfaces[i]) { IOHIDDeviceInterface** interface = (IOHIDDeviceInterface**) deviceInterfaces[i]; (*interface)->close(interface); (*interface)->Release(interface); deviceInterfaces[i] = NULL; } } #endif if(HIDHaveDeviceList()) HIDReleaseDeviceList(); #else // Then our high-level list: while (hid_devices) { // Get current device record to release: curdev = hid_devices; // Advance to the next one for next loop iteration: hid_devices = hid_devices->pNext; // Interface attached aka device opened? If so we need to close the device handle: if (curdev->interface) hid_close((hid_device*) curdev->interface); // Release: free(curdev); } // Reset last hid device for error handling: last_hid_device = NULL; // Release the HIDLIB low-level device list: if (hidlib_devices) hid_free_enumeration(hidlib_devices); hidlib_devices = NULL; // Shutdown HIDAPI: hid_exit(); #endif // Close and release all open generic USB devices: PsychHIDCloseAllUSBDevices(); return(PsychError_none); }