b0c6539cf48a29673b36b5c68b5ec6ef75d16ce2
[fw/altos] / altosdroid / src / org / altusmetrum / AltosDroid / TabDescent.java
1 /*
2  * Copyright © 2013 Mike Beattie <mike@ethernal.org>
3  *
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.
7  *
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.
12  *
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.
16  */
17
18 package org.altusmetrum.AltosDroid;
19
20 import org.altusmetrum.altoslib_1.*;
21
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
31 public class TabDescent extends Fragment implements AltosDroidTab {
32         AltosDroid mAltosDroid;
33
34         private TextView mSpeedView;
35         private TextView mHeightView;
36         private TextView mElevationView;
37         private TextView mRangeView;
38         private TextView mBearingView;
39         private TextView mCompassView;
40         private TextView mDistanceView;
41         private TextView mLatitudeView;
42         private TextView mLongitudeView;
43         private TextView mApogeeVoltageView;
44         private GoNoGoLights mApogeeLights;
45         private TextView mMainVoltageView;
46         private GoNoGoLights mMainLights;
47
48
49         @Override
50         public void onAttach(Activity activity) {
51                 super.onAttach(activity);
52                 mAltosDroid = (AltosDroid) activity;
53                 mAltosDroid.registerTab(this);
54         }
55
56         @Override
57         public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
58                 View v = inflater.inflate(R.layout.tab_descent, container, false);
59
60                 mSpeedView     = (TextView) v.findViewById(R.id.speed_value);
61                 mHeightView    = (TextView) v.findViewById(R.id.height_value);
62                 mElevationView = (TextView) v.findViewById(R.id.elevation_value);
63                 mRangeView     = (TextView) v.findViewById(R.id.range_value);
64                 mBearingView   = (TextView) v.findViewById(R.id.bearing_value);
65                 mCompassView   = (TextView) v.findViewById(R.id.compass_value);
66                 mDistanceView  = (TextView) v.findViewById(R.id.distance_value);
67                 mLatitudeView  = (TextView) v.findViewById(R.id.lat_value);
68                 mLongitudeView = (TextView) v.findViewById(R.id.lon_value);
69
70                 mApogeeVoltageView = (TextView) v.findViewById(R.id.apogee_voltage_value);
71                 mApogeeLights = new GoNoGoLights((ImageView) v.findViewById(R.id.apogee_redled),
72                                                  (ImageView) v.findViewById(R.id.apogee_greenled),
73                                                  getResources());
74
75                 mMainVoltageView = (TextView) v.findViewById(R.id.main_voltage_value);
76                 mMainLights = new GoNoGoLights((ImageView) v.findViewById(R.id.main_redled),
77                                                (ImageView) v.findViewById(R.id.main_greenled),
78                                                getResources());
79
80                 return v;
81         }
82
83
84         @Override
85         public void onDestroy() {
86                 super.onDestroy();
87                 mAltosDroid.unregisterTab(this);
88                 mAltosDroid = null;
89         }
90
91         public void update_ui(AltosState state, AltosGreatCircle from_receiver) {
92                 mSpeedView.setText(String.format("%6.0f m/s", state.speed()));
93                 mHeightView.setText(String.format("%6.0f m", state.height));
94                 if (from_receiver != null) {
95                         mElevationView.setText(String.format("%3.0f°", from_receiver.elevation));
96                         mRangeView.setText(String.format("%6.0f m", from_receiver.range));
97                         mBearingView.setText(String.format("%3.0f°", from_receiver.bearing));
98                         mCompassView.setText(from_receiver.bearing_words(AltosGreatCircle.BEARING_LONG));
99                         mDistanceView.setText(String.format("%6.0f m", from_receiver.distance));
100                 } else { 
101                         mElevationView.setText("<unknown>");
102                         mRangeView.setText("<unknown>");
103                         mBearingView.setText("<unknown>");
104                         mCompassView.setText("<unknown>");
105                         mDistanceView.setText("<unknown>");
106                 }
107                 mLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S"));
108                 mLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E"));
109
110                 mApogeeVoltageView.setText(String.format("%4.2f V", state.drogue_sense));
111                 mApogeeLights.set(state.drogue_sense > 3.2);
112
113                 mMainVoltageView.setText(String.format("%4.2f V", state.main_sense));
114                 mMainLights.set(state.main_sense > 3.2);
115         }
116
117 }