Home | History | Annotate | Download | only in java
      1 /*
      2  * Author: Stefan Andritoiu <stefan.andritoiu (at) intel.com>
      3  * Copyright (c) 2015 Intel Corporation.
      4  *
      5  * Permission is hereby granted, free of charge, to any person obtaining
      6  * a copy of this software and associated documentation files (the
      7  * "Software"), to deal in the Software without restriction, including
      8  * without limitation the rights to use, copy, modify, merge, publish,
      9  * distribute, sublicense, and/or sell copies of the Software, and to
     10  * permit persons to whom the Software is furnished to do so, subject to
     11  * the following conditions:
     12  *
     13  * The above copyright notice and this permission notice shall be
     14  * included in all copies or substantial portions of the Software.
     15  *
     16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
     17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
     19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
     20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
     21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
     22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     23  */
     24 
     25 //NOT TESTED!!!
     26 public class LSM303Sample {
     27 
     28 	static {
     29 		try {
     30 			System.loadLibrary("javaupm_lsm303");
     31 		} catch (UnsatisfiedLinkError e) {
     32 			System.err.println("error in loading native library");
     33 			System.exit(-1);
     34 		}
     35 	}
     36 
     37 	public static void main(String[] args) throws InterruptedException {
     38 		// ! [Interesting]
     39 		// Instantiate LSM303 compass on I2C
     40 		upm_lsm303.LSM303 sensor = new upm_lsm303.LSM303(0);
     41 
     42 		// Get the coordinate data
     43 		sensor.getCoordinates();
     44 		int[] coor = sensor.getRawCoorData(); // in XYZ order.
     45 		// The sensor returns XZY, but the driver compensates and makes it XYZ
     46 
     47 		// Print out the X, Y, and Z coordinate data using two different methods
     48 		System.out.println("coor: rX " + coor[0] + " - rY " + coor[1] + " - rZ " + coor[2]);
     49 		System.out.println("coor: gX " + sensor.getCoorX() + " - gY " + sensor.getCoorY()
     50 				+ " - gZ " + sensor.getCoorZ());
     51 
     52 		// Get and print out the heading
     53 		System.out.println("heading: " + sensor.getHeading());
     54 
     55 		// Get the acceleration
     56 		sensor.getAcceleration();
     57 		int[] accel = sensor.getRawAccelData();
     58 
     59 		// Print out the X, Y, and Z acceleration data using two different
     60 		// methods
     61 		System.out.println("acc: rX " + accel[0] + " - rY " + accel[1] + " - rZ " + accel[2]);
     62 		System.out.println("acc: gX " + sensor.getAccelX() + " - gY " + sensor.getAccelY()
     63 				+ " - gZ " + sensor.getAccelZ());
     64 
     65 		// ! [Interesting]
     66 	}
     67 
     68 }