altosui: Add telemetry format menu and preferences
[fw/altos] / altosui / AltosPreferences.java
index d4df4e163efecaf18462fc0f49fce012564f138a..5f82765569dae85f0a69211c41bc0d1ed04b119f 100644 (file)
@@ -34,6 +34,9 @@ class AltosPreferences {
        /* channel preference name */
        final static String channelPreferenceFormat = "CHANNEL-%d";
 
+       /* telemetry format preference name */
+       final static String telemetryPreferenceFormat = "TELEMETRY-%d";
+
        /* voice preference name */
        final static String voicePreference = "VOICE";
 
@@ -61,6 +64,9 @@ class AltosPreferences {
        /* Channel (map serial to channel) */
        static Hashtable<Integer, Integer> channels;
 
+       /* Telemetry (map serial to telemetry format) */
+       static Hashtable<Integer, Integer> telemetries;
+
        /* Voice preference */
        static boolean voice;
 
@@ -94,6 +100,8 @@ class AltosPreferences {
 
                channels = new Hashtable<Integer,Integer>();
 
+               telemetries = new Hashtable<Integer,Integer>();
+
                voice = preferences.getBoolean(voicePreference, true);
 
                callsign = preferences.get(callsignPreference,"N0CALL");
@@ -189,6 +197,23 @@ class AltosPreferences {
                return channel;
        }
 
+       public static void set_telemetry(int serial, int new_telemetry) {
+               telemetries.put(serial, new_telemetry);
+               synchronized (preferences) {
+                       preferences.putInt(String.format(telemetryPreferenceFormat, serial), new_telemetry);
+                       flush_preferences();
+               }
+       }
+
+       public static int telemetry(int serial) {
+               if (telemetries.containsKey(serial))
+                       return telemetries.get(serial);
+               int telemetry = preferences.getInt(String.format(telemetryPreferenceFormat, serial),
+                                                  Altos.ao_telemetry_full);
+               telemetries.put(serial, telemetry);
+               return telemetry;
+       }
+
        public static void set_voice(boolean new_voice) {
                voice = new_voice;
                synchronized (preferences) {