Exemple #1
0
extern int raise_event(control_t* ctrl, int event, unsigned int params) {
	if(ctrl->event_handler) 
		if(bit_chk(ctrl->events, event))
			return ctrl->event_handler(ctrl, event, params);
			
	return -1;
}
Exemple #2
0
void shiftOut(int dataPin, int clockPin, BITORDER_T bitOrder, byte value) {
	CPin dat(unoPIN[dataPin]);
	CPin clk(unoPIN[clockPin]);
	dat.output(NOT_OPEN);
	clk.output(NOT_OPEN);
	for (int i = 0; i < 8; i++)  {
		if (bitOrder == LSBFIRST)
			dat = (bit_chk(value,i)? HIGH:LOW);
		else
			dat = (bit_chk(value,(7-i))? HIGH:LOW);

		clk = HIGH;
		delayMicroseconds(2);	// 2us
		clk = LOW;
	}
}
Exemple #3
0
void SWPwm::run() {
	SWPWM_T *ch;
	LIST_POS pos;
	while(1) {
		// wait timer interrupt
		m_timer.wait();

		pos = m_lstCH.getHeadPos();							// get first channel
		while(pos) {
			ch = (SWPWM_T *)m_lstCH.getAt(pos);				// get channel from list
			if ( ch ) {
				ch->flag++;									// inc pwm count
				if (  ch->dutyCycle>0 ) {
					if ( bit_chk(ch->flag, CH_STATE) ) {
						if ( CH_COUNT>=ch->dutyCycle ) {		// count to dutyCycle?
							ch->pin = LOW;						// set output low
							bit_clr(ch->flag, CH_STATE);		// change state
						}
					} else if ( CH_COUNT>=m_accuracy ) {		// count to end ?
						ch->pin = HIGH;							// set output high
						ch->flag = bit(CH_STATE);				// change state & RESET count
					}
				} else {
					ch->pin = LOW;								// always LOW when dutycycle=0
				}
			}
			pos = m_lstCH.getNext(pos);						// next channel
		}
		m_cycle++;
	}
}
Exemple #4
0
bool CAdcKey::isPressed(ADKEY_T key, bool clearFlag) {
	bool res = bit_chk(m_flag, key);
	if (res && clearFlag) {
		m_mutex.lock();
		bit_clr(m_flag, key);
		m_mutex.unlock();
	}
	return res;
}
Exemple #5
0
int CButtons::isKeyDown() {
	int pins=0;
	for (int i=0; i<m_pins.count(); i++) {
		if ( bit_chk(m_down, i)==false ) {	// LOW is down
			pins |= bit(i);
		}
	}
	return pins;
}
Exemple #6
0
void CButtons::run() {
	CTimeout tm;
	uint32_t newval;
	while(1) {
		newval = m_pins;
		if ( newval != m_flag ) {
			if ( tm.isExpired(10) ) {						// wait for bounce time
				m_down = newval;
				for (int i=0; i<m_pins.count(); i++) {
					if ( bit_chk((m_flag ^ newval), i)  ) {	// is different? Key Even caused...
						if ( bit_chk(newval, i) ) { 		// HIGH is key up
							onKeyUp(i);
						} else {							// LOW is key down
							onKeyDown(i);
						}
					}
				}
				m_flag = newval;
			}
		} else {
			tm.reset();
		}
	}
}
Exemple #7
0
void CButton::run() {
	CTimeout bounce;
	while(1) {
		if ( bit_chk(m_flag, KEY_FLAG_DOWN) ) {
			if ( m_pin==HIGH ){
				if ( bounce.isExpired(10)  ) {
					bit_clr(m_flag, KEY_FLAG_DOWN);
					onKeyUp();		// call virtual function "onKeyUp()"
				}
			} else {
				bounce.reset();
			}
		} else {
			if ( m_pin==LOW ){
				if ( bounce.isExpired(5)  ) {
					bit_set(m_flag, KEY_FLAG_DOWN);
					onKeyDown();	// call virtual function "onKeyDown()"
				}
			} else {
				bounce.reset();
			}
		}
	}
}