Merge remote-tracking branch 'mjb/altosdroid'
[fw/altos] / altosdroid / src / org / altusmetrum / AltosDroid / TabAscent.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.AltosState;
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 TabAscent extends Fragment implements AltosDroidTab {
32         AltosDroid mAltosDroid;
33
34         private TextView mHeightView;
35         private TextView mMaxHeightView;
36         private TextView mSpeedView;
37         private TextView mMaxSpeedView;
38         private TextView mAccelView;
39         private TextView mMaxAccelView;
40         private TextView mLatitudeView;
41         private TextView mLongitudeView;
42         private TextView mApogeeVoltageView;
43         private GoNoGoLights mApogeeLights;
44         private TextView mMainVoltageView;
45         private GoNoGoLights mMainLights;
46
47         @Override
48         public void onAttach(Activity activity) {
49                 super.onAttach(activity);
50                 mAltosDroid = (AltosDroid) activity;
51                 mAltosDroid.registerTab(this);
52         }
53
54         @Override
55         public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
56                 View v = inflater.inflate(R.layout.tab_ascent, container, false);
57
58                 mHeightView    = (TextView) v.findViewById(R.id.height_value);
59                 mMaxHeightView = (TextView) v.findViewById(R.id.max_height_value);
60                 mSpeedView     = (TextView) v.findViewById(R.id.speed_value);
61                 mMaxSpeedView  = (TextView) v.findViewById(R.id.max_speed_value);
62                 mAccelView     = (TextView) v.findViewById(R.id.accel_value);
63                 mMaxAccelView  = (TextView) v.findViewById(R.id.max_accel_value);
64                 mLatitudeView  = (TextView) v.findViewById(R.id.lat_value);
65                 mLongitudeView = (TextView) v.findViewById(R.id.lon_value);
66
67                 mApogeeVoltageView = (TextView) v.findViewById(R.id.apogee_voltage_value);
68                 mApogeeLights = new GoNoGoLights((ImageView) v.findViewById(R.id.apogee_redled),
69                                                  (ImageView) v.findViewById(R.id.apogee_greenled),
70                                                  getResources());
71
72                 mMainVoltageView = (TextView) v.findViewById(R.id.main_voltage_value);
73                 mMainLights = new GoNoGoLights((ImageView) v.findViewById(R.id.main_redled),
74                                                (ImageView) v.findViewById(R.id.main_greenled),
75                                                getResources());
76
77                 return v;
78         }
79
80         @Override
81         public void onDestroy() {
82                 super.onDestroy();
83                 mAltosDroid.unregisterTab(this);
84                 mAltosDroid = null;
85         }
86
87         public void update_ui(AltosState state) {
88                 mHeightView.setText(String.format("%6.0f m", state.height));
89                 mMaxHeightView.setText(String.format("%6.0f m", state.max_height));
90                 mSpeedView.setText(String.format("%6.0f m/s", state.speed()));
91                 mMaxSpeedView.setText(String.format("%6.0f m/s", state.max_speed()));
92                 mAccelView.setText(String.format("%6.0f m/s²", state.acceleration));
93                 mMaxAccelView.setText(String.format("%6.0f m/s²", state.max_acceleration));
94
95                 mLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S"));
96                 mLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E"));
97
98                 mApogeeVoltageView.setText(String.format("%4.2f V", state.drogue_sense));
99                 mApogeeLights.set(state.drogue_sense > 3.2);
100
101                 mMainVoltageView.setText(String.format("%4.2f V", state.main_sense));
102                 mMainLights.set(state.main_sense > 3.2);
103         }
104 }