diff options
| author | Rakesh Peter <rakesh.peter@gmail.com> | 2018-12-12 15:41:13 +0530 | 
|---|---|---|
| committer | Brent Stapleton <brent.stapleton@ettus.com> | 2018-12-17 15:19:35 -0800 | 
| commit | 11bbc3c0c2272fdc41765dbb3f3044309564252c (patch) | |
| tree | f17c5db744aa9b21de17380003a900aebfe81ab4 | |
| parent | 027040752f3d0eca91fcc2a0eebee8714c601cf4 (diff) | |
| download | uhd-11bbc3c0c2272fdc41765dbb3f3044309564252c.tar.gz uhd-11bbc3c0c2272fdc41765dbb3f3044309564252c.tar.bz2 uhd-11bbc3c0c2272fdc41765dbb3f3044309564252c.zip | |
examples: Add keyboard controls to rx_ascii_art_dft
- Add keyboard controls for sample rate, gain, analog bandwidth,
frequency, as well as the display's dynamic range, reference level,
and frame rate.
- The current values for these properties, as well as the keys to
control them, are displayed in a small window at the top of the
display. This control window can be toggled by pressing 'c'
| -rw-r--r-- | host/examples/rx_ascii_art_dft.cpp | 119 | 
1 files changed, 116 insertions, 3 deletions
| diff --git a/host/examples/rx_ascii_art_dft.cpp b/host/examples/rx_ascii_art_dft.cpp index e242dbcd6..f37f4694e 100644 --- a/host/examples/rx_ascii_art_dft.cpp +++ b/host/examples/rx_ascii_art_dft.cpp @@ -27,8 +27,9 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){      //variables to be set by po      std::string args, ant, subdev, ref;      size_t num_bins; -    double rate, freq, gain, bw, frame_rate; +    double rate, freq, gain, bw, frame_rate, step;      float ref_lvl, dyn_rng; +    bool show_controls;      //setup the program options      po::options_description desc("Allowed options"); @@ -48,6 +49,8 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){          ("ref-lvl", po::value<float>(&ref_lvl)->default_value(0), "reference level for the display (dB)")          ("dyn-rng", po::value<float>(&dyn_rng)->default_value(60), "dynamic range for the display (dB)")          ("ref", po::value<std::string>(&ref)->default_value("internal"), "reference source (internal, external, mimo)") +        ("step", po::value<double>(&step)->default_value(1e6), "tuning step for rate/bw/freq") +        ("show-controls", po::value<bool>(&show_controls)->default_value(true), "show the keyboard controls")          ("int-n", "tune USRP with integer-N tuning")      ;      po::variables_map vm; @@ -98,6 +101,8 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){          std::cout << boost::format("Setting RX Gain: %f dB...") % gain << std::endl;          usrp->set_rx_gain(gain);          std::cout << boost::format("Actual RX Gain: %f dB...") % usrp->get_rx_gain() << std::endl << std::endl; +    } else { +        gain = usrp->get_rx_gain();      }      //set the analog frontend filter bandwidth @@ -105,6 +110,8 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){          std::cout << boost::format("Setting RX Bandwidth: %f MHz...") % (bw/1e6) << std::endl;          usrp->set_rx_bandwidth(bw);          std::cout << boost::format("Actual RX Bandwidth: %f MHz...") % (usrp->get_rx_bandwidth()/1e6) << std::endl << std::endl; +    } else { +        bw = usrp->get_rx_bandwidth();      }      //set the antenna @@ -169,20 +176,126 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){              ascii_art_dft::log_pwr_dft(&buff.front(), num_rx_samps)          );          std::string frame = ascii_art_dft::dft_to_plot( -            lpdft, COLS, LINES, +            lpdft, COLS, (show_controls ? LINES-6 : LINES),              usrp->get_rx_rate(),              usrp->get_rx_freq(),              dyn_rng, ref_lvl          ); +        std::string border = std::string((COLS), '-'); +          //curses screen handling: clear and print frame          clear(); + +        if (show_controls) { +            printw("%s", border.c_str()); +            printw("[f-F]req: %4.3f MHz   |   [r-R]ate: %2.2f Msps   |" +                   "   [b-B]w: %2.2f MHz   |   [g-G]ain: %2.0f dB\n\n", +                   freq/1e6, rate/1e6, bw/1e6, gain); +            printw("[d-D]yn Range: %2.0f dB    |   Ref [l-L]evel: %2.0f dB   |" +                   "   fp[s-S] : %2.0f   |   [t-T]uning step: %3.3f M\n", +                   dyn_rng, ref_lvl, frame_rate, step/1e6); +            printw("(press c to toggle controls)\n"); +            printw("%s", border.c_str()); +        }          printw("%s", frame.c_str());          //curses key handling: no timeout, any key to exit          timeout(0);          int ch = getch(); -        if (ch != KEY_RESIZE and ch != ERR) break; + +        // Key handling. +        if (ch == 'r') { +            rate -= step; +            usrp->set_rx_rate(rate); +            freq = usrp->get_rx_freq(); +        } + +        else if (ch == 'R') { +            rate += step; +            usrp->set_rx_rate(rate); +            freq = usrp->get_rx_freq(); +        } + +        else if (ch == 'g') { +            gain -= 1; +            usrp->set_rx_gain(gain); +            gain = usrp->get_rx_gain(); +        } + +        else if (ch == 'G') { +            gain += 1; +            usrp->set_rx_gain(gain); +            gain = usrp->get_rx_gain(); +        } + +        else if (ch == 'b') { +            bw -= step; +            usrp->set_rx_bandwidth(bw); +            bw = usrp->get_rx_bandwidth(); +        } + +        else if (ch == 'B') { +            bw += step; +            usrp->set_rx_bandwidth(bw); +            bw = usrp->get_rx_bandwidth(); +        } + +        else if (ch == 'f') { +            freq -= step; +            usrp->set_rx_freq(freq); +            freq = usrp->get_rx_freq(); +        } + +        else if (ch == 'F') { +            freq += step; +            usrp->set_rx_freq(freq); +            freq = usrp->get_rx_freq(); +        } + +        else if (ch == 'l') ref_lvl -= 10; +        else if (ch == 'L') ref_lvl += 10; +        else if (ch == 'd') dyn_rng -= 10; +        else if (ch == 'D') dyn_rng += 10; +        else if (ch == 's') { +            if (frame_rate > 1) { +                frame_rate -= 1; +            } +        } +        else if (ch == 'S') { +            frame_rate += 1; +        } +        else if (ch == 't') { +            if (step > 1) { +                step /= 2; +            } +        } +        else if (ch == 'T') step *= 2; +        else if (ch == 'c' || ch == 'C') { +            show_controls = !show_controls; +        } +         +        // Arrow keypress generates 3 characters: +        // '\033', '[', 'A'/'B'/'C'/'D' for Up / Down / Right / Left +        else if (ch == '\033') { +            getch(); +            switch(getch()) { +                case 'A': +                case 'C': +                    freq += step; +                    usrp->set_rx_freq(freq); +                    freq = usrp->get_rx_freq(); +                    break; + +                case 'B': +                case 'D': +                    freq -= step; +                    usrp->set_rx_freq(freq); +                    freq = usrp->get_rx_freq(); +                    break; +            } +        } +        else if (ch != KEY_RESIZE and ch != ERR) break;      }      //------------------------------------------------------------------ | 
