altos/stm32f4: Wrong value for CK48MSEL_PLL_Q
[fw/altos] / altosui / AltosCompanionInfo.java
1 /*
2  * Copyright © 2010 Keith Packard <keithp@keithp.com>
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; either version 2 of the License, or
7  * (at your option) any later version.
8  *
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.
13  *
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.
17  */
18
19 package altosui;
20
21 import java.awt.*;
22 import javax.swing.*;
23 import org.altusmetrum.altoslib_13.*;
24 import org.altusmetrum.altosuilib_13.*;
25
26 public class AltosCompanionInfo extends JTable implements AltosFlightDisplay {
27         private AltosFlightInfoTableModel model;
28
29         static final int info_columns = 2;
30         static final int info_rows = 17;
31
32         int desired_row_height() {
33                 FontMetrics     infoValueMetrics = getFontMetrics(Altos.table_value_font);
34                 return (infoValueMetrics.getHeight() + infoValueMetrics.getLeading()) * 18 / 10;
35         }
36
37         public void font_size_changed(int font_size) {
38                 setFont(Altos.table_value_font);
39                 setRowHeight(desired_row_height());
40                 doLayout();
41         }
42
43         public void units_changed(boolean imperial_units) {
44         }
45
46         public AltosCompanionInfo() {
47                 super(new AltosFlightInfoTableModel(info_rows, info_columns));
48                 model = (AltosFlightInfoTableModel) getModel();
49                 setAutoResizeMode(AUTO_RESIZE_ALL_COLUMNS);
50                 setShowGrid(true);
51                 font_size_changed(AltosUIPreferences.font_size());
52         }
53
54         public Dimension getPreferredScrollableViewportSize() {
55                 return getPreferredSize();
56         }
57
58         public void reset() {
59                 model.reset();
60         }
61
62         void info_add_row(int col, String name, String value) {
63                 model.addRow(col, name, value);
64         }
65
66         void info_add_row(int col, String name, String format, Object... parameters) {
67                 info_add_row (col, name, String.format(format, parameters));
68         }
69
70         void info_finish() {
71                 model.finish();
72         }
73
74         public void clear() {
75                 model.clear();
76         }
77
78         AltosCompanion  companion;
79
80         public String board_name() {
81                 if (companion == null)
82                         return "None";
83                 switch (companion.board_id) {
84                 case AltosCompanion.board_id_telescience:
85                         return "TeleScience";
86                 default:
87                         return String.format("%02x\n", companion.board_id);
88                 }
89         }
90
91         public String getName() { return "Companion"; }
92
93         public void show(AltosState state, AltosListenerState listener_state) {
94                 if (state == null)
95                         return;
96                 if (state.companion != null)
97                         companion = state.companion;
98                 reset();
99                 info_add_row(0, "Companion board", "%s", board_name());
100                 if (companion != null) {
101                         info_add_row(0, "Last Data", "%5d", companion.tick);
102                         info_add_row(0, "Update period", "%5.2f s",
103                                      companion.update_period / 100.0);
104                         info_add_row(0, "Channels", "%3d", companion.channels);
105
106                         for (int i = 0; i < companion.channels; i++)
107                                 info_add_row(1, String.format("Channel %2d", i),
108                                              "%6d", companion.companion_data[i]);
109                 }
110                 info_finish();
111         }
112 }