updown.comp

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

COMP
45
字号
component updown "Counts up or down, with optional limits and wraparound behavior";pin in bit countup "Increment count when this pin goes from 0 to 1";pin in bit countdown "Decrement count when this pin goes from 0 to 1";pin out s32 count "The current count";param rw bit clamp "If TRUE, then clamp the output to the min and max parameters.";param rw bit wrap "If TRUE, then wrap around when the count goes above or below the min and max parameters.  Note that wrap implies (and overrides) clamp.";param rw s32 max = 0x7FFFFFFF "If clamp or wrap is set, count will never exceed this number";param rw s32 min "If clamp or wrap is set, count will never be less than this number";variable int oldup;variable int olddown;variable int first = 1;function _ nofp "Process inputs and update count if necessary";license "GPL";;;FUNCTION(_) {	hal_s32_t temp_count = count;	if (first) {		oldup=countup;		olddown=countdown;		first=0;	}	if ((!oldup) && (countup)) { // positive edge, count up		temp_count++;	}	if ((!olddown) && (countdown)) { // positive edge, count down		temp_count--;	}	if (wrap) {		if (temp_count > max)			temp_count = min;		else if (temp_count < min)			temp_count = max;	} else if (clamp) {		if (temp_count > max)			temp_count = max;		else if (temp_count < min)			temp_count = min;	}	count = temp_count;	oldup = countup;	olddown = countdown;}

⌨️ 快捷键说明

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