00001 /*---------------------------------------------------------------------------- 00002 MoMu: A Mobile Music Toolkit 00003 Copyright (c) 2010 Nicholas J. Bryan, Jorge Herrera, Jieun Oh, and Ge Wang 00004 All rights reserved. 00005 http://momu.stanford.edu/toolkit/ 00006 00007 Mobile Music Research @ CCRMA 00008 Music, Computing, Design Group 00009 Stanford University 00010 http://momu.stanford.edu/ 00011 http://ccrma.stanford.edu/groups/mcd/ 00012 00013 MoMu is distributed under the following BSD style open source license: 00014 00015 Permission is hereby granted, free of charge, to any person obtaining a 00016 copy of this software and associated documentation files (the 00017 "Software"), to deal in the Software without restriction, including 00018 without limitation the rights to use, copy, modify, merge, publish, 00019 distribute, sublicense, and/or sell copies of the Software, and to 00020 permit persons to whom the Software is furnished to do so, subject to 00021 the following conditions: 00022 00023 The authors encourage users of MoMu to include this copyright notice, 00024 and to let us know that you are using MoMu. Any person wishing to 00025 distribute modifications to the Software is encouraged to send the 00026 modifications to the original authors so that they can be incorporated 00027 into the canonical version. 00028 00029 The Software is provided "as is", WITHOUT ANY WARRANTY, express or implied, 00030 including but not limited to the warranties of MERCHANTABILITY, FITNESS 00031 FOR A PARTICULAR PURPOSE and NONINFRINGEMENT. In no event shall the authors 00032 or copyright holders by liable for any claim, damages, or other liability, 00033 whether in an actino of a contract, tort or otherwise, arising from, out of 00034 or in connection with the Software or the use or other dealings in the 00035 software. 00036 -----------------------------------------------------------------------------*/ 00037 00038 /*----------------------------------------------------------------------------*/ 00049 /*----------------------------------------------------------------------------*/ 00050 #ifndef __MO_COMPASS_H__ 00051 #define __MO_COMPASS_H__ 00052 00053 #import "mo_def.h" 00054 #import <vector> 00055 #import <CoreLocation/CoreLocation.h> 00056 00057 /*----------------------------------------------------------------------------*/ 00062 /*----------------------------------------------------------------------------*/ 00063 @interface CompassDelegate : NSObject <CLLocationManagerDelegate> 00064 { 00065 CLLocationManager *locationManager; 00066 } 00067 @property (nonatomic, retain) CLLocationManager *locationManager; 00068 00069 @end 00070 00071 00072 /*----------------------------------------------------------------------------*/ 00080 /*----------------------------------------------------------------------------*/ 00081 typedef void (* MoCompassCallback)( CLHeading * heading, void * data ); 00082 00083 00084 00085 //----------------------------------------------------------------------------- 00086 // name: class MoLocation 00087 // desc: location stuff, GPS/Edge/Wifi + Compass 00088 //----------------------------------------------------------------------------- 00089 /*----------------------------------------------------------------------------*/ 00100 /*----------------------------------------------------------------------------*/ 00101 class MoCompass 00102 { 00103 public: // setting values 00104 00106 static void setOffset(); 00107 00109 static void clearOffset(); 00110 00112 static double getMagneticOffset(); 00113 00115 static double getTrueOffset(); 00116 00117 public: // getting values 00118 00120 static double getMagneticHeading(); 00121 00123 static double getTrueHeading(); 00124 00126 static double getAccuracy(); 00127 00129 static NSDate * getTimestamp(); 00130 00131 00133 static void addCallback( const MoCompassCallback & callback, void * data ); 00134 00136 static void removeCallback( const MoCompassCallback & callback ); 00137 00138 public: 00140 static void update( CLHeading * heading ); // do not call outside of mo_compass.mm... 00141 00142 00143 private: 00144 // current values; 00145 static CLHeading * m_heading; 00146 static double m_magneticHeading; 00147 static double m_trueHeading; 00148 static CLLocationDirection m_accuracy; 00149 // store an offset 00150 static double m_trueOffset; 00151 static double m_magneticOffset; 00152 static CompassDelegate * compassDelegate; 00153 00154 // queue of callbacks 00155 static std::vector< MoCompassCallback > m_clients; 00156 static std::vector<void *> m_clientData; 00157 00158 // internal setup of the compass 00159 static void checkSetup(); 00160 }; 00161 00162 00163 #endif