コード例 #1
0
ファイル: renc.c プロジェクト: elseym/kitpi
void t_encoder_func(void *args) {
	int val_pin_button = 0,
	    val_pin_left = 0,
	    val_pin_right = 0;
	int l, e, s, b = 0;

	encdata *enc = (encdata*)args;

	pinMode(enc->pin_button, INPUT); pullUpDnControl(enc->pin_button, PUD_UP);
	pinMode(enc->pin_left  , INPUT); pullUpDnControl(enc->pin_left  , PUD_UP);
	pinMode(enc->pin_right , INPUT); pullUpDnControl(enc->pin_right , PUD_UP);

	while (1) {
		val_pin_button = digitalRead(enc->pin_button);
		val_pin_left = digitalRead(enc->pin_left);
		val_pin_right = digitalRead(enc->pin_right);

		e = (val_pin_left << 1) | val_pin_right;
		s = (l << 2) | e;
		if (val_pin_button != b) {
			b = val_pin_button;
			pthread_mutex_lock(&m_btn);
			cb_button(enc, val_pin_button);
			pthread_mutex_unlock(&m_btn);
		}
		if (s == 1 || s == 2) {
			pthread_mutex_lock(&m_enc);
			cb_rotate(enc, --s ? s : --s);
			pthread_mutex_unlock(&m_enc);
		}
		delay(2);
		l = e;
		if (shutdown) break;
	}

	return;
}
コード例 #2
0
ファイル: cut.c プロジェクト: AgamAgarwal/minix
/*
 * cut --
 *	Put a range of lines/columns into a TEXT buffer.
 *
 * There are two buffer areas, both found in the global structure.  The first
 * is the linked list of all the buffers the user has named, the second is the
 * unnamed buffer storage.  There is a pointer, too, which is the current
 * default buffer, i.e. it may point to the unnamed buffer or a named buffer
 * depending on into what buffer the last text was cut.  Logically, in both
 * delete and yank operations, if the user names a buffer, the text is cut
 * into it.  If it's a delete of information on more than a single line, the
 * contents of the numbered buffers are rotated up one, the contents of the
 * buffer named '9' are discarded, and the text is cut into the buffer named
 * '1'.  The text is always cut into the unnamed buffer.
 *
 * In all cases, upper-case buffer names are the same as lower-case names,
 * with the exception that they cause the buffer to be appended to instead
 * of replaced.  Note, however, that if text is appended to a buffer, the
 * default buffer only contains the appended text, not the entire contents
 * of the buffer.
 *
 * !!!
 * The contents of the default buffer would disappear after most operations
 * in historic vi.  It's unclear that this is useful, so we don't bother.
 *
 * When users explicitly cut text into the numeric buffers, historic vi became
 * genuinely strange.  I've never been able to figure out what was supposed to
 * happen.  It behaved differently if you deleted text than if you yanked text,
 * and, in the latter case, the text was appended to the buffer instead of
 * replacing the contents.  Hopefully it's not worth getting right, and here
 * we just treat the numeric buffers like any other named buffer.
 *
 * PUBLIC: int cut __P((SCR *, ARG_CHAR_T *, MARK *, MARK *, int));
 */
int
cut(SCR *sp, ARG_CHAR_T *namep, MARK *fm, MARK *tm, int flags)
{
	CB *cbp;
	ARG_CHAR_T name = '\0';
	db_recno_t lno;
	int append, copy_one, copy_def;

	/*
	 * If the user specified a buffer, put it there.  (This may require
	 * a copy into the numeric buffers.  We do the copy so that we don't
	 * have to reference count and so we don't have to deal with things
	 * like appends to buffers that are used multiple times.)
	 *
	 * Otherwise, if it's supposed to be put in a numeric buffer (usually
	 * a delete) put it there.  The rules for putting things in numeric
	 * buffers were historically a little strange.  There were three cases.
	 *
	 *	1: Some motions are always line mode motions, which means
	 *	   that the cut always goes into the numeric buffers.
	 *	2: Some motions aren't line mode motions, e.g. d10w, but
	 *	   can cross line boundaries.  For these commands, if the
	 *	   cut crosses a line boundary, it goes into the numeric
	 *	   buffers.  This includes most of the commands.
	 *	3: Some motions aren't line mode motions, e.g. d`<char>,
	 *	   but always go into the numeric buffers, regardless.  This
	 *	   was the commands: % ` / ? ( ) N n { } -- and nvi adds ^A.
	 *
	 * Otherwise, put it in the unnamed buffer.
	 */
	append = copy_one = copy_def = 0;
	if (namep != NULL) {
		name = *namep;
		if (LF_ISSET(CUT_NUMREQ) || (LF_ISSET(CUT_NUMOPT) &&
		    (LF_ISSET(CUT_LINEMODE) || fm->lno != tm->lno))) {
			copy_one = 1;
			cb_rotate(sp);
		}
		if ((append = ISUPPER(name)) == 1) {
			if (!copy_one)
				copy_def = 1;
			name = TOLOWER(name);
		}
namecb:		CBNAME(sp, cbp, name);
	} else if (LF_ISSET(CUT_NUMREQ) || (LF_ISSET(CUT_NUMOPT) &&
	    (LF_ISSET(CUT_LINEMODE) || fm->lno != tm->lno))) {
		name = '1';
		cb_rotate(sp);
		goto namecb;
	} else
		cbp = &sp->wp->dcb_store;

copyloop:
	/*
	 * If this is a new buffer, create it and add it into the list.
	 * Otherwise, if it's not an append, free its current contents.
	 */
	if (cbp == NULL) {
		CALLOC_RET(sp, cbp, CB *, 1, sizeof(CB));
		cbp->name = name;
		CIRCLEQ_INIT(&cbp->textq);
		LIST_INSERT_HEAD(&sp->wp->cutq, cbp, q);
	} else if (!append) {