index.js
/*
* Enables IMU sampling and registers the handler to receive data when available
*/
Enables IMU sampling and registers the handler to receive data when available
Enables IMU sampling and registers the handler to receive data when available
function enableAndReadSensor(control_characteristic, data_characteristic, imu_sampling_rate) {
	logger.info("Received two UUIDs: " + control_characteristic.uuid + " and " + data_characteristic.uuid)
	var start = getStartSamplingCommand(imu_sampling_rate);
	control_characteristic.write(start, false, function (err) {
		if (!err) {
			logger.info("Written successfully to characteristic: " + control_characteristic.uuid)
			data_characteristic.subscribe(function (err) {
				if (!err) {
					sensor_notification_handler = function (data, isNotification) {
						if (utils.checkCheckSum(data, 2) == true) {
							var readings = utils.getSensorReadings(data);
							io.sockets.emit('gyro', {
								x: utils.convertGyroADCToDegPerSecond(readings[0], gyro_factor) - gx_offset,
								y: utils.convertGyroADCToDegPerSecond(readings[1], gyro_factor) - gy_offset,
								z: utils.convertGyroADCToDegPerSecond(readings[2], gyro_factor) - gz_offset
							});
							io.sockets.emit('acc', {
								x: utils.convertAccelADCToG(readings[3], acc_factor) - ax_offset,
								y: utils.convertAccelADCToG(readings[4], acc_factor) - ay_offset,
								z: utils.convertAccelADCToG(readings[5], acc_factor) - az_offset
							});
						} else {
							logger.error("Checksum failed!");
						}
					};
					data_characteristic.on('data', sensor_notification_handler);
				}
			});
		}
		else logger.error("Error when starting IMU sampling");
	})
}
function enableAndReadSensor ( control_characteristic , data_characteristic , imu_sampling_rate ) { logger . info ( "Received two UUIDs: " + control_characteristic . uuid + " and " + data_characteristic . uuid ) var start = getStartSamplingCommand ( imu_sampling_rate ) ; control_characteristic . write ( start , false , function ( err ) { if ( ! err ) { logger . info ( "Written successfully to characteristic: " + control_characteristic . uuid ) data_characteristic . subscribe ( function ( err ) { if ( ! err ) { sensor_notification_handler = function ( data , isNotification ) { if ( utils . checkCheckSum ( data , 2 ) == true ) { var readings = utils . getSensorReadings ( data ) ; io . sockets . emit ( 'gyro' , { x : utils . convertGyroADCToDegPerSecond ( readings [ 0 ] , gyro_factor ) - gx_offset , y : utils . convertGyroADCToDegPerSecond ( readings [ 1 ] , gyro_factor ) - gy_offset , z : utils . convertGyroADCToDegPerSecond ( readings [ 2 ] , gyro_factor ) - gz_offset } ) ; io . sockets . emit ( 'acc' , { x : utils . convertAccelADCToG ( readings [ 3 ] , acc_factor ) - ax_offset , y : utils . convertAccelADCToG ( readings [ 4 ] , acc_factor ) - ay_offset , z : utils . convertAccelADCToG ( readings [ 5 ] , acc_factor ) - az_offset } ) ; } else { logger . error ( "Checksum failed!" ) ; } } ; data_characteristic . on ( 'data' , sensor_notification_handler ) ; } } ) ; } else logger . error ( "Error when starting IMU sampling" ) ; } ) }
Enables IMU sampling and registers the handler to receive data when available
Enables IMU sampling and registers the handler to receive data when available