2 * Copyright © 2012 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 package org.altusmetrum.altoslib_14;
21 import java.util.concurrent.*;
23 public class AltosAdxl375 implements Cloneable {
28 public static final int X_AXIS = 0;
29 public static final int Y_AXIS = 1;
30 public static final int Z_AXIS = 2;
32 public boolean parse_line(String line) throws NumberFormatException {
33 if (line.startsWith("ADXL375 value")) {
34 String[] items = line.split("\\s+");
35 if (axis == AltosLib.MISSING)
36 throw new NumberFormatException("No ADXL375 axis specified");
37 if (items.length >= 3) {
38 accel = Integer.parseInt(items[2 + axis]);
45 public AltosAdxl375 clone() {
46 AltosAdxl375 n = new AltosAdxl375(axis);
52 static public void provide_data(AltosDataListener listener, AltosLink link) throws InterruptedException, AltosUnknownProduct {
54 AltosCalData cal_data = listener.cal_data();
55 AltosAdxl375 adxl375 = new AltosAdxl375(link, cal_data.adxl375_axis);
57 if (adxl375 != null) {
58 int accel = adxl375.accel;
59 if (cal_data.adxl375_inverted)
61 if (cal_data.pad_orientation == 1)
63 listener.set_acceleration(cal_data.acceleration(accel));
65 } catch (TimeoutException te) {
66 } catch (NumberFormatException ne) {
70 public AltosAdxl375() {
71 accel = AltosLib.MISSING;
72 axis = AltosLib.MISSING;
75 public AltosAdxl375(int axis) {
80 public AltosAdxl375(AltosLink link, int axis) throws InterruptedException, TimeoutException, NumberFormatException {
84 String line = link.get_reply_no_dialog(5000);
86 throw new TimeoutException();