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_13;
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 System.out.printf("adxl parse line %s\n", line);
35 String[] items = line.split("\\s+");
36 if (axis == AltosLib.MISSING)
37 throw new NumberFormatException("No ADXL375 axis specified");
38 if (items.length >= 3) {
39 accel = Integer.parseInt(items[2 + axis]);
40 System.out.printf("accel %d\n", accel);
47 public AltosAdxl375 clone() {
48 AltosAdxl375 n = new AltosAdxl375(axis);
54 static public void provide_data(AltosDataListener listener, AltosLink link) throws InterruptedException, AltosUnknownProduct {
56 AltosCalData cal_data = listener.cal_data();
57 AltosAdxl375 adxl375 = new AltosAdxl375(link, cal_data.adxl375_axis);
59 if (adxl375 != null) {
60 int accel = adxl375.accel;
61 if (cal_data.adxl375_inverted)
63 if (cal_data.pad_orientation == 1)
65 listener.set_acceleration(cal_data.acceleration(accel));
67 } catch (TimeoutException te) {
68 } catch (NumberFormatException ne) {
72 public AltosAdxl375() {
73 accel = AltosLib.MISSING;
74 axis = AltosLib.MISSING;
77 public AltosAdxl375(int axis) {
82 public AltosAdxl375(AltosLink link, int axis) throws InterruptedException, TimeoutException, NumberFormatException {
86 String line = link.get_reply_no_dialog(5000);
88 throw new TimeoutException();