-
Notifications
You must be signed in to change notification settings - Fork 0
Home
In this SDR++ fork I have added code in core/src/gui/main_window.cpp to enable reading the PI OS filesystem for rotary encoder events.
https://github.com/K7MDL2/SDRPlusPlus
I emulated mouse scroll wheel and slider events with encoder events and removed the requirement to have the mouse in the FFT window area for the control to operate. Currently I have VFO Tune encoder, and 2 encoders assigned Roles for Zoom Slider, Snap Interval, FFT Min and FFT Max sliders. There are also 2 encoder push switches that toggle the encoder role assignments so 4 roles share 2 Aux encoders.
On a RPi use you must add this dtoverlay line so the OS handles the encoder and switch events for you and presents the events in a file.
dtoverlay=rotary-encoder,pin_a=18,pin_b=17,relative_axis=1,steps-per-period=1
dtoverlay=gpio-key,gpio=25,label="rotary-switch-25",keycode=185
for RPi5
/boot/firmware/config.txt
for RPi4
/boot/config.txt
I have steps-per-period=1 which suits my particular encoder, adjust to suit yours. Also set the pins to match yours. When you reboot, you will have new event files created in /dev/input folders.
Here is an example of a rotary encoder and a GPIO switch defined in the code to match those config.txt entries.
const char* ENC_VFO = "/dev/input/by-path/platform-rotary@12-event"; // for PinA=GPIO18
const char* ENC_AUX1_SW = "/dev/input/by-path/platform-button@19-event"; // for PinA=GPIO25 toggle function
The number at the end of the name is the hex value of the Pin_A GPIO number so it is repeatable. Here it is my pin 18 (0x12) for the encoder and pin 25 (0x19) for the switch. Edit it to match your device pin assignments. If the values are backwards, reverse pin A and B assignments and reboot.
You can test the devices are working by using 'evtest' utility to print out the event file codes.
Above is the list of devices sorted by eventXX order. Enter XX to see that file result.
Above you can see I entered 10 for event10 which is mapped to my VFO encoder (rotary@12). For results you get Type=2 for encoder, Code=0 for encoder, and value will be 1 or -1 based on spin direction. There is a dt_overlay for GPIO switches (aka keys) and they are Type 1 with a keycode value you assign noted as ON or OFF.
Some time ago I built a Pi control head for my Hermes Lite 2 (HL2) SDR which has several encoders with push switches. Inside is a small USB Audio dongle feeding a stereo amp and speakers and some other things like a 12V to 5V DC-DC converter and buffers for PTT. The case is a Smarti Pi Pro (deep) with the official Pi 7" touch screen at 800x 480. I was originally a RPi4B that was upgraded to a RPi5. The newer Touch 2 screen is 1280 x 720. The microphone in the picture is for when I run PiHPSDR or SparkSDr as a transceiver.
In SDR++ I added support for 3 encoders and 2 switches to be able to toggle the encoder function assignment. The main encoder is for VFO tuning and the 2 extra encoders (in SDR++ so far) are hard coded for their functions until some future generic configuration mechanism is built.
I typically use one encoder to adjust the min and max FFT levels, using the push switch to toggle the encoder assignment between them. Another encoder handles Zoom and maybe step rate. One of the knobs on my control head is an analog volume pot for the stereo amp module so I do not use digital volume, I leave it set near full.
Configuration details are here:
https://github.com/K7MDL2/SDRPlusPlus/wiki/Configuring-Encoders-and-Switches
The changes to the code involve these functions so far: int MainWindow::open_GPIO_device(int device) // opens the file path indicated by the device index number passed (1-3). int MainWindow::read_encoder(int device) // Reads the open event file for the device index passed in. If the files is not open (file handle is -1) then the file is opened. int MainWindow::read_switch(int device) // reads the switch event file for the named device, opening the device if needed.
All that is required in the main program is to call read_encoder(_VFO_ENC) to open and read the VFO encoder device. It returns the count(s) with + or - to indicate direction. Then use that counts value to adjust the VFO, or slider position in other cases like Min and Max FFT and Zoom. Same thing for a switch.
On a Pi5 you can build from source builds pretty fast, especially when only changing 1 file.
Mike K7MDL