v4l2-ctl: Add support for printing band info to G_TUNER / G_MODULATOR code
authorHans de Goede <hdegoede@redhat.com>
Sun, 27 May 2012 08:33:21 +0000 (10:33 +0200)
committerHans de Goede <hdegoede@redhat.com>
Sat, 2 Jun 2012 11:32:10 +0000 (13:32 +0200)
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
utils/v4l2-ctl/v4l2-ctl.cpp

index 6033f47..061a7e6 100644 (file)
@@ -50,6 +50,8 @@
 #include <string>
 #include <algorithm>
 
+#define ARRAY_SIZE(arr) ((int)(sizeof(arr) / sizeof((arr)[0])))
+
 /* Short option list
 
    Please keep in alphabetical order.
@@ -1508,6 +1510,49 @@ static std::string txsubchans2s(int txsubchans)
        return s;
 }
 
+static const char *band_names[] = {
+       "default",
+       "fm-eur_us",
+       "fm-japan",
+       "fm-russian",
+       "fm-weather",
+       "am-mw",
+};
+
+static const char *band2s(unsigned band)
+{
+       if (band >= ARRAY_SIZE(band_names))
+               return "Unknown";
+
+       return band_names[band];
+}
+
+static int s2band(const char *s) {
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(band_names); i++) {
+               if (!strcmp(s, band_names[i]))
+                       return i;
+       }
+
+       return -1;
+}
+
+static std::string tcap2bands(unsigned cap) {
+       std::string s;
+       int i;
+
+       for (i = 1; i < ARRAY_SIZE(band_names); i++) {
+               if (cap & (V4L2_TUNER_CAP_BAND_FM_EUROPE_US << (i - 1))) {
+                       if (s.length())
+                               s += " ";
+                       s += band_names[i];
+               }
+       }
+
+       return s;
+}
+
 static std::string tcap2s(unsigned cap)
 {
        std::string s;
@@ -3940,6 +3985,12 @@ int main(int argc, char **argv)
                        printf("Tuner %d:\n", vt.index);
                        printf("\tName                 : %s\n", vt.name);
                        printf("\tCapabilities         : %s\n", tcap2s(vt.capability).c_str());
+                       if (vt.capability & V4L2_TUNER_CAP_BANDS_MASK) {
+                               printf("\tAvailable bands      : %s\n",
+                                       tcap2bands(vt.capability).c_str());
+                               printf("\tCurrent band         : %s\n",
+                                       band2s(vt.band));
+                       }
                        if (vt.capability & V4L2_TUNER_CAP_LOW)
                                printf("\tFrequency range      : %.1f MHz - %.1f MHz\n",
                                     vt.rangelow / 16000.0, vt.rangehigh / 16000.0);
@@ -3962,6 +4013,12 @@ int main(int argc, char **argv)
                        printf("Modulator %d:\n", modulator.index);
                        printf("\tName                 : %s\n", mt.name);
                        printf("\tCapabilities         : %s\n", tcap2s(mt.capability).c_str());
+                       if (mt.capability & V4L2_TUNER_CAP_BANDS_MASK) {
+                               printf("\tAvailable bands      : %s\n",
+                                       tcap2bands(mt.capability).c_str());
+                               printf("\tCurrent band         : %s\n",
+                                       band2s(mt.band));
+                       }
                        if (mt.capability & V4L2_TUNER_CAP_LOW)
                                printf("\tFrequency range      : %.1f MHz - %.1f MHz\n",
                                     mt.rangelow / 16000.0, mt.rangehigh / 16000.0);