@@ -31,7 +31,7 @@ var CC2650SensorTag = function(peripheral) {
31
31
this . mpu9250mask = 0 ;
32
32
this . mpu9250notifyCount = 0 ;
33
33
34
- this . onMPU9250ChangeBinded = this . onMPU9250Change . bind ( this ) ;
34
+ this . onMPU9250ChangeBinded = this . onMPU9250Change . bind ( this ) ;
35
35
this . onLuxometerChangeBinded = this . onLuxometerChange . bind ( this ) ;
36
36
} ;
37
37
@@ -98,20 +98,27 @@ CC2650SensorTag.prototype.setMPU9250Period = function(period, callback) {
98
98
CC2650SensorTag . prototype . enableMPU9250 = function ( mask , callback ) {
99
99
this . mpu9250mask |= mask ;
100
100
101
- this . writeUInt16LECharacteristic ( MPU9250_UUID , MPU9250_CONFIG_UUID , this . mpu9250mask , callback ) ;
101
+ // for now, always write 0x007f, magnetometer does not seem to notify is specific mask is used
102
+ this . writeUInt16LECharacteristic ( MPU9250_UUID , MPU9250_CONFIG_UUID , 0x007f , callback ) ;
102
103
} ;
103
104
104
105
CC2650SensorTag . prototype . disableMPU9250 = function ( mask , callback ) {
105
106
this . mpu9250mask &= ~ mask ;
106
107
107
- this . writeUInt16LECharacteristic ( MPU9250_UUID , MPU9250_CONFIG_UUID , this . mpu9250mask , callback ) ;
108
+ if ( this . mpu9250mask === 0 ) {
109
+ this . writeUInt16LECharacteristic ( MPU9250_UUID , MPU9250_CONFIG_UUID , 0x0000 , callback ) ;
110
+ } else if ( typeof ( callback ) === 'function' ) {
111
+ callback ( ) ;
112
+ }
108
113
} ;
109
114
110
115
CC2650SensorTag . prototype . notifyMPU9250 = function ( callback ) {
111
116
this . mpu9250notifyCount ++ ;
112
117
113
118
if ( this . mpu9250notifyCount === 1 ) {
114
119
this . notifyCharacteristic ( MPU9250_UUID , MPU9250_DATA_UUID , true , this . onMPU9250ChangeBinded , callback ) ;
120
+ } else if ( typeof ( callback ) === 'function' ) {
121
+ callback ( ) ;
115
122
}
116
123
} ;
117
124
@@ -120,6 +127,8 @@ CC2650SensorTag.prototype.unnotifyMPU9250 = function(callback) {
120
127
121
128
if ( this . mpu9250notifyCount === 0 ) {
122
129
this . notifyCharacteristic ( MPU9250_UUID , MPU9250_DATA_UUID , false , this . onMPU9250ChangeBinded , callback ) ;
130
+ } else if ( typeof ( callback ) === 'function' ) {
131
+ callback ( ) ;
123
132
}
124
133
} ;
125
134
@@ -170,10 +179,10 @@ CC2650SensorTag.prototype.convertMPU9250Data = function(data, callback) {
170
179
var y = data . readInt16LE ( 8 ) * 2.0 / 32768.0 ;
171
180
var z = data . readInt16LE ( 10 ) * 2.0 / 32768.0 ;
172
181
173
- // magnetometer
174
- var xM = data . readInt16LE ( 12 ) ;
175
- var yM = data . readInt16LE ( 14 ) ;
176
- var zM = data . readInt16LE ( 16 ) ;
182
+ // magnetometer (page 50 of http://www.invensense.com/mems/gyro/documents/RM-MPU-9250A-00.pdf)
183
+ var xM = data . readInt16LE ( 12 ) * 4912.0 / 32760.0 ;
184
+ var yM = data . readInt16LE ( 14 ) * 4912.0 / 32760.0 ;
185
+ var zM = data . readInt16LE ( 16 ) * 4912.0 / 32760.0 ;
177
186
178
187
callback ( x , y , z , xG , yG , zG , xM , yM , zM ) ;
179
188
} ;
0 commit comments