Tweaked the GPIO keyer code, made a more flexible keyer startup: can use 2-5 input parameters (e.g. "gpio:a,b", "gpio:a,b,c", etc.).

This commit is contained in:
Rob French 2020-03-10 00:06:13 -05:00
parent 9a343877e5
commit fba22c95f7

View File

@ -112,6 +112,7 @@ Boston, MA 02110-1301, USA.
#define NSEC_PER_SEC (1000000000) #define NSEC_PER_SEC (1000000000)
#define CW_HANGTIME_DEFAULT (250) #define CW_HANGTIME_DEFAULT (250)
#define NUM_PARMS (5)
/*********************************************************************** /***********************************************************************
* Types * Types
@ -604,23 +605,50 @@ static void* keyer_thread(void *arg) {
int open_key_gpiokeyer(const char * name) int open_key_gpiokeyer(const char * name)
{ {
int i; int i;
int parms[NUM_PARMS];
/* KC4UPR: Read the GPIO keyer name, and parse out the pins for /* KC4UPR: Read the GPIO keyer name, and parse out the pins for
* left paddle, right paddle, keyer out, and T/R switch. The last * left paddle, right paddle, keyer out, and T/R switch. The last
* two can be zero if that functionality is not desired, but they * two can be zero if that functionality is not desired, but they
* must be present in the name string. * must be present in the name string.
*/ */
switch(sscanf(name, "gpio:%d,%d,%d,%d,%d", &left_paddle_gpio, &right_paddle_gpio, &keyer_out_gpio, &tr_switch_gpio, &cw_hangtime_msec)) { switch(sscanf(name, "gpio:%d,%d,%d,%d,%d", &parm[0], &parm[1], &parm[2], &parm[3], &parm[4])) {
case 5: case 5: // v0.2
if (cw_hangtime_msec > 1000) cw_hangtime_msec = 1000; left_paddle_gpio = parm[0];
if (cw_hangtime_msec < 0) cw_hangtime_msec = 0; right_paddle_gpio = parm[1];
keyer_out_gpio = parm[2];
tr_switch_gpio = parm[3];
quisk_set_gpio_keyer_hangtime(parm[4]);
break; break;
case 4: case 4: // v0.1
/* KC4UPR: matched the first 4 inputs - original v0.1 interface. /* KC4UPR: matched the first 4 inputs - original v0.1 interface.
* Need to fill-in-blanks for later version(s).
*/ */
cw_hangtime_msec = CW_HANGTIME_DEFAULT; left_paddle_gpio = parm[0];
right_paddle_gpio = parm[1];
keyer_out_gpio = parm[2];
tr_switch_gpio = parm[3];
quisk_set_gpio_keyer_hangtime(CW_HANGTIME_DEFAULT);
break;
case 3: // v0.2
/* KC4UPR: three inputs--no discrete outputs, but hangtime set.
*/
left_paddle_gpio = parm[0];
right_paddle_gpio = parm[1];
keyer_out_gpio = 0;
tr_switch_gpio = 0;
quisk_set_gpio_keyer_hangtime(parm[2]);
break;
case 2: // v0.2
/* KC4UPR: only two inputs--the discrete outputs won't be used.
*/
left_paddle_gpio = parm[0];
right_paddle_gpio = parm[1];
keyer_out_gpio = 0;
tr_switch_gpio = 0;
quisk_set_gpio_keyer_hangtime(CW_HANGTIME_DEFAULT);
break; break;
default: default: