hal/cocoa/smslib.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/hal/cocoa/smslib.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,159 @@
     1.4 +/*
     1.5 + * smslib.h
     1.6 + *
     1.7 + * SMSLib Sudden Motion Sensor Access Library
     1.8 + * Copyright (c) 2010 Suitable Systems
     1.9 + * All rights reserved.
    1.10 + * 
    1.11 + * Developed by: Daniel Griscom
    1.12 + *               Suitable Systems
    1.13 + *               http://www.suitable.com
    1.14 + * 
    1.15 + * Permission is hereby granted, free of charge, to any person obtaining a
    1.16 + * copy of this software and associated documentation files (the
    1.17 + * "Software"), to deal with the Software without restriction, including
    1.18 + * without limitation the rights to use, copy, modify, merge, publish,
    1.19 + * distribute, sublicense, and/or sell copies of the Software, and to
    1.20 + * permit persons to whom the Software is furnished to do so, subject to
    1.21 + * the following conditions:
    1.22 + * 
    1.23 + * - Redistributions of source code must retain the above copyright notice,
    1.24 + * this list of conditions and the following disclaimers.
    1.25 + * 
    1.26 + * - Redistributions in binary form must reproduce the above copyright
    1.27 + * notice, this list of conditions and the following disclaimers in the
    1.28 + * documentation and/or other materials provided with the distribution.
    1.29 + * 
    1.30 + * - Neither the names of Suitable Systems nor the names of its
    1.31 + * contributors may be used to endorse or promote products derived from
    1.32 + * this Software without specific prior written permission.
    1.33 + * 
    1.34 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
    1.35 + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    1.36 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    1.37 + * IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR
    1.38 + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
    1.39 + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    1.40 + * SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
    1.41 + *
    1.42 + * For more information about SMSLib, see
    1.43 + *		<http://www.suitable.com/tools/smslib.html>
    1.44 + * or contact
    1.45 + *		Daniel Griscom
    1.46 + *		Suitable Systems
    1.47 + *		1 Centre Street, Suite 204
    1.48 + *		Wakefield, MA 01880
    1.49 + *		(781) 665-0053
    1.50 + *
    1.51 + */
    1.52 +
    1.53 +#import <Foundation/Foundation.h>
    1.54 +
    1.55 +#define SMSLIB_VERSION "1.8"
    1.56 +
    1.57 +#pragma mark Structure definitions
    1.58 +
    1.59 +// Structure for specifying a 3-axis acceleration. 0.0 means "zero gravities",
    1.60 +// 1.0 means "one gravity".
    1.61 +typedef struct sms_acceleration {
    1.62 +	float x;		// Right-left acceleration (positive is rightwards)
    1.63 +	float y;		// Front-rear acceleration (positive is rearwards)
    1.64 +	float z;		// Up-down acceleration (positive is upwards)
    1.65 +} sms_acceleration;
    1.66 +
    1.67 +// Structure for specifying a calibration.
    1.68 +typedef struct sms_calibration {
    1.69 +	float zeros[3];	// Zero points for three axes (X, Y, Z)
    1.70 +	float onegs[3];	// One gravity values for three axes
    1.71 +} sms_calibration;
    1.72 +
    1.73 +#pragma mark Return value definitions
    1.74 +
    1.75 +// These are the return values for accelStartup(), giving the
    1.76 +// various stages where the most successful attempt at accessing
    1.77 +// the accelerometer failed. The higher the value, the further along the
    1.78 +// software progressed before failing. The options are:
    1.79 +//	- Didn't match model name
    1.80 +#define SMS_FAIL_MODEL			(-7)
    1.81 +//	- Failure getting dictionary matching desired services
    1.82 +#define SMS_FAIL_DICTIONARY		(-6)
    1.83 +//	- Failure getting list of services
    1.84 +#define SMS_FAIL_LIST_SERVICES	(-5)
    1.85 +//	- Failure if list of services is empty. The process generally fails
    1.86 +//		here if run on a machine without a Sudden Motion Sensor.
    1.87 +#define SMS_FAIL_NO_SERVICES	(-4)
    1.88 +//	- Failure if error opening device.
    1.89 +#define SMS_FAIL_OPENING		(-3)
    1.90 +//	- Failure if opened, but didn't get a connection
    1.91 +#define SMS_FAIL_CONNECTION		(-2)
    1.92 +//	- Failure if couldn't access connction using given function and size. This
    1.93 +//		is where the process would probably fail with a change in Apple's API.
    1.94 +//		Driver problems often also cause failures here.
    1.95 +#define SMS_FAIL_ACCESS			(-1)
    1.96 +//	- Success!
    1.97 +#define SMS_SUCCESS				(0)
    1.98 +
    1.99 +#pragma mark Function declarations
   1.100 +
   1.101 +// This starts up the accelerometer code, trying each possible sensor
   1.102 +// specification. Note that for logging purposes it
   1.103 +// takes an object and a selector; the object's selector is then invoked
   1.104 +// with a single NSString as argument giving progress messages. Example
   1.105 +// logging method:
   1.106 +//		- (void)logMessage: (NSString *)theString
   1.107 +// which would be used in accelStartup's invocation thusly:
   1.108 +//		result = accelStartup(self, @selector(logMessage:));
   1.109 +// If the object is nil, then no logging is done. Sets calibation from built-in
   1.110 +// value table. Returns ACCEL_SUCCESS for success, and other (negative)
   1.111 +// values for various failures (returns value indicating result of
   1.112 +// most successful trial).
   1.113 +int smsStartup(id logObject, SEL logSelector);
   1.114 +
   1.115 +// This starts up the library in debug mode, ignoring the actual hardware.
   1.116 +// Returned data is in the form of 1Hz sine waves, with the X, Y and Z
   1.117 +// axes 120 degrees out of phase; "calibrated" data has range +/- (1.0/5);
   1.118 +// "uncalibrated" data has range +/- (256/5). X and Y axes centered on 0.0,
   1.119 +// Z axes centered on 1 (calibrated) or 256 (uncalibrated). 
   1.120 +// Don't use smsGetBufferLength or smsGetBufferData. Always returns SMS_SUCCESS.
   1.121 +int smsDebugStartup(id logObject, SEL logSelector);
   1.122 +
   1.123 +// Returns the current calibration values.
   1.124 +void smsGetCalibration(sms_calibration *calibrationRecord);
   1.125 +
   1.126 +// Sets the calibration, but does NOT store it as a preference. If the argument
   1.127 +// is nil then the current calibration is set from the built-in value table.
   1.128 +void smsSetCalibration(sms_calibration *calibrationRecord);
   1.129 +
   1.130 +// Stores the current calibration values as a stored preference.
   1.131 +void smsStoreCalibration(void);
   1.132 +
   1.133 +// Loads the stored preference values into the current calibration.
   1.134 +// Returns YES if successful.
   1.135 +BOOL smsLoadCalibration(void);
   1.136 +
   1.137 +// Deletes any stored calibration, and then takes the current calibration values
   1.138 +// from the built-in value table.
   1.139 +void smsDeleteCalibration(void);
   1.140 +
   1.141 +// Fills in the accel record with calibrated acceleration data. Takes
   1.142 +// 1-2ms to return a value. Returns 0 if success, error number if failure.
   1.143 +int smsGetData(sms_acceleration *accel);
   1.144 +
   1.145 +// Fills in the accel record with uncalibrated acceleration data.
   1.146 +// Returns 0 if success, error number if failure.
   1.147 +int smsGetUncalibratedData(sms_acceleration *accel);
   1.148 +
   1.149 +// Returns the length of a raw block of data for the current type of sensor.
   1.150 +int smsGetBufferLength(void);
   1.151 +
   1.152 +// Takes a pointer to accelGetRawLength() bytes; sets those bytes
   1.153 +// to return value from sensor. Make darn sure the buffer length is right!
   1.154 +void smsGetBufferData(char *buffer);
   1.155 +
   1.156 +// This returns an NSString describing the current calibration in
   1.157 +// human-readable form. Also include a description of the machine.
   1.158 +NSString *smsGetCalibrationDescription(void);
   1.159 +
   1.160 +// Shuts down the accelerometer.
   1.161 +void smsShutdown(void);
   1.162 +

mercurial