toggle.comp

来自「CNC 的开放码,EMC2 V2.2.8版」· COMP 代码 · 共 42 行

COMP
42
字号
component toggle "'push-on, push-off' from momentary pushbuttons";pin in bit in "button input";pin io bit out "on/off output";param rw u32 debounce = 2 "debounce delay in periods";option data toggle_data;function _ nofp;license "GPL";;;typedef struct {    int debounce_cntr;    int debounced;} toggle_data;FUNCTION(_) {    if (( debounce < 1 ) || ( debounce > 10000 )) {	/* set a sane value, we don't want 2 million second delays */	debounce = 2;    }    if ( in ) {	/* pressed */	data.debounce_cntr++;	if ( data.debounce_cntr >= debounce ) {	    data.debounce_cntr = debounce;	    if ( data.debounced == 0 ) {		/* toggle output */		out = !out;	    }	    data.debounced = 1;	}    } else {	/* not pressed */	data.debounce_cntr--;	if ( data.debounce_cntr <= 0 ) {	    data.debounce_cntr = 0;	    data.debounced = 0;	}    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?