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_7.*;
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;
30 import android.location.Location;
32 public class TabPad extends AltosDroidTab {
33 private TextView mBatteryVoltageView;
34 private TextView mBatteryVoltageLabel;
35 private GoNoGoLights mBatteryLights;
36 private TextView mApogeeVoltageView;
37 private TextView mApogeeVoltageLabel;
38 private GoNoGoLights mApogeeLights;
39 private TextView mMainVoltageView;
40 private TextView mMainVoltageLabel;
41 private GoNoGoLights mMainLights;
42 private TextView mDataLoggingView;
43 private GoNoGoLights mDataLoggingLights;
44 private TextView mGPSLockedView;
45 private GoNoGoLights mGPSLockedLights;
46 private TextView mGPSReadyView;
47 private GoNoGoLights mGPSReadyLights;
48 private TextView mPadLatitudeView;
49 private TextView mPadLongitudeView;
50 private TextView mPadAltitudeView;
53 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
54 View v = inflater.inflate(R.layout.tab_pad, container, false);
55 mBatteryVoltageView = (TextView) v.findViewById(R.id.battery_voltage_value);
56 mBatteryVoltageLabel = (TextView) v.findViewById(R.id.battery_voltage_label);
57 mBatteryLights = new GoNoGoLights((ImageView) v.findViewById(R.id.battery_redled),
58 (ImageView) v.findViewById(R.id.battery_greenled),
61 mApogeeVoltageView = (TextView) v.findViewById(R.id.apogee_voltage_value);
62 mApogeeVoltageLabel = (TextView) v.findViewById(R.id.apogee_voltage_label);
63 mApogeeLights = new GoNoGoLights((ImageView) v.findViewById(R.id.apogee_redled),
64 (ImageView) v.findViewById(R.id.apogee_greenled),
67 mMainVoltageView = (TextView) v.findViewById(R.id.main_voltage_value);
68 mMainVoltageLabel = (TextView) v.findViewById(R.id.main_voltage_label);
69 mMainLights = new GoNoGoLights((ImageView) v.findViewById(R.id.main_redled),
70 (ImageView) v.findViewById(R.id.main_greenled),
73 mDataLoggingView = (TextView) v.findViewById(R.id.logging_value);
74 mDataLoggingLights = new GoNoGoLights((ImageView) v.findViewById(R.id.logging_redled),
75 (ImageView) v.findViewById(R.id.logging_greenled),
78 mGPSLockedView = (TextView) v.findViewById(R.id.gps_locked_value);
79 mGPSLockedLights = new GoNoGoLights((ImageView) v.findViewById(R.id.gps_locked_redled),
80 (ImageView) v.findViewById(R.id.gps_locked_greenled),
83 mGPSReadyView = (TextView) v.findViewById(R.id.gps_ready_value);
84 mGPSReadyLights = new GoNoGoLights((ImageView) v.findViewById(R.id.gps_ready_redled),
85 (ImageView) v.findViewById(R.id.gps_ready_greenled),
88 mPadLatitudeView = (TextView) v.findViewById(R.id.pad_lat_value);
89 mPadLongitudeView = (TextView) v.findViewById(R.id.pad_lon_value);
90 mPadAltitudeView = (TextView) v.findViewById(R.id.pad_alt_value);
94 public String tab_name() { return "pad"; }
96 public void show(TelemetryState telem_state, AltosState state, AltosGreatCircle from_receiver, Location receiver) {
98 mBatteryVoltageView.setText(AltosDroid.number("%4.2f V", state.battery_voltage));
99 mBatteryLights.set(state.battery_voltage >= AltosLib.ao_battery_good, state.battery_voltage == AltosLib.MISSING);
100 if (state.apogee_voltage == AltosLib.MISSING) {
101 mApogeeVoltageView.setVisibility(View.GONE);
102 mApogeeVoltageLabel.setVisibility(View.GONE);
104 mApogeeVoltageView.setText(AltosDroid.number("%4.2f V", state.apogee_voltage));
105 mApogeeVoltageView.setVisibility(View.VISIBLE);
106 mApogeeVoltageLabel.setVisibility(View.VISIBLE);
108 mApogeeLights.set(state.apogee_voltage >= AltosLib.ao_igniter_good, state.apogee_voltage == AltosLib.MISSING);
109 if (state.main_voltage == AltosLib.MISSING) {
110 mMainVoltageView.setVisibility(View.GONE);
111 mMainVoltageLabel.setVisibility(View.GONE);
113 mMainVoltageView.setText(AltosDroid.number("%4.2f V", state.main_voltage));
114 mMainVoltageView.setVisibility(View.VISIBLE);
115 mMainVoltageLabel.setVisibility(View.VISIBLE);
117 mMainLights.set(state.main_voltage >= AltosLib.ao_igniter_good, state.main_voltage == AltosLib.MISSING);
119 if (state.flight != 0) {
120 if (state.state <= AltosLib.ao_flight_pad)
121 mDataLoggingView.setText("Ready to record");
122 else if (state.state < AltosLib.ao_flight_landed)
123 mDataLoggingView.setText("Recording data");
125 mDataLoggingView.setText("Recorded data");
127 mDataLoggingView.setText("Storage full");
129 mDataLoggingLights.set(state.flight != 0, state.flight == AltosLib.MISSING);
131 if (state.gps != null) {
132 int soln = state.gps.nsat;
133 int nsat = state.gps.cc_gps_sat != null ? state.gps.cc_gps_sat.length : 0;
134 mGPSLockedView.setText(String.format("%4d in soln, %4d in view", soln, nsat));
135 mGPSLockedLights.set(state.gps.locked && state.gps.nsat >= 4, false);
137 mGPSReadyView.setText("Ready");
139 mGPSReadyView.setText(AltosDroid.integer("Waiting %d", state.gps_waiting));
141 mGPSLockedLights.set(false, true);
142 mGPSReadyLights.set(state.gps_ready, state.gps == null);
145 if (receiver != null) {
146 double altitude = AltosLib.MISSING;
147 if (receiver.hasAltitude())
148 altitude = receiver.getAltitude();
149 mPadLatitudeView.setText(AltosDroid.pos(receiver.getLatitude(), "N", "S"));
150 mPadLongitudeView.setText(AltosDroid.pos(receiver.getLongitude(), "E", "W"));
151 set_value(mPadAltitudeView, AltosConvert.height, 6, altitude);