2 * Copyright © 2013 Mike Beattie <mike@ethernal.org>
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; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
18 package org.altusmetrum.AltosDroid;
20 import org.altusmetrum.altoslib_1.*;
22 import android.app.Activity;
23 import android.os.Bundle;
24 import android.support.v4.app.Fragment;
25 import android.view.LayoutInflater;
26 import android.view.View;
27 import android.view.ViewGroup;
28 import android.widget.ImageView;
29 import android.widget.TextView;
31 public class TabPad extends Fragment implements AltosDroidTab {
32 AltosDroid mAltosDroid;
34 private TextView mBatteryVoltageView;
35 private GoNoGoLights mBatteryLights;
36 private TextView mApogeeVoltageView;
37 private GoNoGoLights mApogeeLights;
38 private TextView mMainVoltageView;
39 private GoNoGoLights mMainLights;
40 private TextView mDataLoggingView;
41 private GoNoGoLights mDataLoggingLights;
42 private TextView mGPSLockedView;
43 private GoNoGoLights mGPSLockedLights;
44 private TextView mGPSReadyView;
45 private GoNoGoLights mGPSReadyLights;
46 private TextView mPadLatitudeView;
47 private TextView mPadLongitudeView;
48 private TextView mPadAltitudeView;
51 public void onAttach(Activity activity) {
52 super.onAttach(activity);
53 mAltosDroid = (AltosDroid) activity;
54 mAltosDroid.registerTab(this);
58 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
59 View v = inflater.inflate(R.layout.tab_pad, container, false);
60 mBatteryVoltageView = (TextView) v.findViewById(R.id.battery_voltage_value);
61 mBatteryLights = new GoNoGoLights((ImageView) v.findViewById(R.id.battery_redled),
62 (ImageView) v.findViewById(R.id.battery_greenled),
65 mApogeeVoltageView = (TextView) v.findViewById(R.id.apogee_voltage_value);
66 mApogeeLights = new GoNoGoLights((ImageView) v.findViewById(R.id.apogee_redled),
67 (ImageView) v.findViewById(R.id.apogee_greenled),
70 mMainVoltageView = (TextView) v.findViewById(R.id.main_voltage_value);
71 mMainLights = new GoNoGoLights((ImageView) v.findViewById(R.id.main_redled),
72 (ImageView) v.findViewById(R.id.main_greenled),
75 mDataLoggingView = (TextView) v.findViewById(R.id.logging_value);
76 mDataLoggingLights = new GoNoGoLights((ImageView) v.findViewById(R.id.logging_redled),
77 (ImageView) v.findViewById(R.id.logging_greenled),
80 mGPSLockedView = (TextView) v.findViewById(R.id.gps_locked_value);
81 mGPSLockedLights = new GoNoGoLights((ImageView) v.findViewById(R.id.gps_locked_redled),
82 (ImageView) v.findViewById(R.id.gps_locked_greenled),
85 mGPSReadyView = (TextView) v.findViewById(R.id.gps_ready_value);
86 mGPSReadyLights = new GoNoGoLights((ImageView) v.findViewById(R.id.gps_ready_redled),
87 (ImageView) v.findViewById(R.id.gps_ready_greenled),
90 mPadLatitudeView = (TextView) v.findViewById(R.id.pad_lat_value);
91 mPadLongitudeView = (TextView) v.findViewById(R.id.pad_lon_value);
92 mPadAltitudeView = (TextView) v.findViewById(R.id.pad_alt_value);
97 public void onDestroy() {
99 mAltosDroid.unregisterTab(this);
103 public void update_ui(AltosState state) {
104 mBatteryVoltageView.setText(String.format("%4.2f V", state.battery));
105 mBatteryLights.set(state.battery > 3.7);
107 mApogeeVoltageView.setText(String.format("%4.2f V", state.drogue_sense));
108 mApogeeLights.set(state.drogue_sense > 3.2);
110 mMainVoltageView.setText(String.format("%4.2f V", state.main_sense));
111 mMainLights.set(state.main_sense > 3.2);
113 if (state.data.flight != 0) {
114 if (state.data.state <= AltosLib.ao_flight_pad)
115 mDataLoggingView.setText("Ready to record");
116 else if (state.data.state < AltosLib.ao_flight_landed)
117 mDataLoggingView.setText("Recording data");
119 mDataLoggingView.setText("Recorded data");
121 mDataLoggingView.setText("Storage full");
123 mDataLoggingLights.set(state.data.flight != 0);
125 mGPSLockedView.setText(String.format("%4d sats", state.gps.nsat));
126 mGPSLockedLights.set(state.gps.locked && state.gps.nsat >= 4);
129 mGPSReadyView.setText("Ready");
131 mGPSReadyView.setText(String.format("Waiting %d", state.gps_waiting));
132 mGPSReadyLights.set(state.gps_ready);
134 mPadLatitudeView.setText(AltosDroid.pos(state.pad_lat, "N", "S"));
135 mPadLongitudeView.setText(AltosDroid.pos(state.pad_lon, "W", "E"));
136 mPadAltitudeView.setText(String.format("%4.0f m", state.pad_alt));