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 AltosMma655x implements Cloneable {
27 public boolean parse_line(String line) throws NumberFormatException {
28 if (line.startsWith("MMA655X value")) {
29 String[] items = line.split("\\s+");
30 if (items.length >= 3) {
31 accel = Integer.parseInt(items[2]);
38 public AltosMma655x() {
39 accel = AltosLib.MISSING;
42 public AltosMma655x clone() {
43 AltosMma655x n = new AltosMma655x();
49 static public void provide_data(AltosDataListener listener, AltosLink link) throws InterruptedException, AltosUnknownProduct {
51 AltosMma655x mma655x = new AltosMma655x(link);
52 AltosCalData cal_data = listener.cal_data();
54 if (mma655x != null) {
55 int accel = mma655x.accel;
56 if (cal_data.mma655x_inverted)
58 if (cal_data.pad_orientation == AltosLib.AO_PAD_ORIENTATION_ANTENNA_DOWN)
60 listener.set_acceleration(cal_data.acceleration(accel));
62 } catch (TimeoutException te) {
63 } catch (NumberFormatException ne) {
67 public AltosMma655x(AltosLink link) throws InterruptedException, TimeoutException, NumberFormatException {
71 String line = link.get_reply_no_dialog(5000);
73 throw new TimeoutException();