Ejemplo n.º 1
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(blink_thread(struct pt *pt))
{
    PT_BEGIN(pt);
    
    while(1)
    {        
        cli();
        
        timer1_counter = 0;
        
        sei();
        
        PT_WAIT_UNTIL(pt,timer1_counter > 5);

        led1_toggle();                
    }
    
    PT_END(pt);
}
Ejemplo n.º 2
0
/**************************************************************************//**
*  \brief Touch task handler
******************************************************************************/
uint8_t Touch_measurement(uint8_t *button_event, uint8_t *button_state)
{
	uint8_t temp_status1;
	uint8_t temp_status2;

	uint8_t button = INVALID_KEY;
	uint8_t event = BUTTON_NO_EVENT;

	/* time_to_measure_touch = 1; //added for timing debug */

	/* After sending the data, do Touch Measurements */
	if ((time_to_measure_touch) || (burst_flag)) {
		time_to_measure_touch = 0u;

		/* Measure touch once */
		status_flag = qt_measure_sensors(current_time_ms_touch);
		burst_flag = status_flag & QTLIB_BURST_AGAIN;

		/* check whether the sensor status is changed from previous
		 * status */
		temp_status1 = memory_map.body.sensor_status[0] ^
				qt_measure_data.qt_touch_status.sensor_states[0];
		temp_status2 = memory_map.body.sensor_status[1] ^
				qt_measure_data.qt_touch_status.sensor_states[1];
		temp_status2 &= 0x03;

		/* If Sensor status is changed, do not sleep, but buzz  */
		if (temp_status1 | temp_status2) {
			event = BUTTON_PRESSED_EVENT;
			if (qt_measure_data.qt_touch_status.sensor_states[0] &
					0x01) {
				button = KEY_SW16;
			} else if (qt_measure_data.qt_touch_status.sensor_states
					[0] & 0x02) {
				button = KEY_SW09;
			} else if (qt_measure_data.qt_touch_status.sensor_states
					[0] & 0x04) {
				button = KEY_SW10;
			} else if (qt_measure_data.qt_touch_status.sensor_states
					[0] & 0x08) {
				button = KEY_SW17;
			} else if (qt_measure_data.qt_touch_status.sensor_states
					[0] & 0x10) {
				button = KEY_SW14;
			} else if (qt_measure_data.qt_touch_status.sensor_states
					[0] & 0x20) {
				button = KEY_SW11;
			} else if (qt_measure_data.qt_touch_status.sensor_states
					[0] & 0x40) {
				button = KEY_SW12;
			} else if (qt_measure_data.qt_touch_status.sensor_states
					[0] & 0x80) {
				button = KEY_SW15;
			} else {
				event = BUTTON_NO_EVENT;
			}

			if (qt_measure_data.qt_touch_status.sensor_states[1] &
					0x02) {
				button = KEY_SW13;
				event = BUTTON_PRESSED_EVENT;
#ifdef QDEBUG
				key_touch++;
#endif
			}

			if (qt_measure_data.qt_touch_status.sensor_states[1] &
					0x01) {
#ifdef QDEBUG
				wheel_pos1[wheel_index1++]
					= qt_measure_data.channel_signals
						[8];
				wheel_pos2[wheel_index2++]
					= qt_measure_data.channel_signals
						[9];
				wheel_pos3[wheel_index3++]
					= qt_measure_data.channel_signals
						[10];
				wheel_pos4[wheel_index4++]
					= qt_measure_data.channel_signals
						[11];
#endif
				if (qt_measure_data.qt_touch_status.
						rotor_slider_values[0] <
						memory_map.body.wheel_position)
				{
					button = KEY_ROT_CW;
					event = BUTTON_RELEASED_EVENT;
#ifdef QDEBUG
					rotor_up++;
#endif
				} else {
					button = KEY_ROT_CCW;
					event = BUTTON_RELEASED_EVENT;
#ifdef QDEBUG
					rotor_down++;
#endif
				}
			}

			/* Store back the current sensor status */
			temp_status1 = 0;
			temp_status2 = 0;
			memory_map.body.sensor_status[0]
				= qt_measure_data.qt_touch_status.
					sensor_states[0];
			memory_map.body.sensor_status[1]
				= qt_measure_data.qt_touch_status.
					sensor_states[1];
			memory_map.body.wheel_position
				= qt_measure_data.qt_touch_status.
					rotor_slider_values[0];

			if (event != BUTTON_NO_EVENT) {
				if (button == KEY_SW15) {
					led1_toggle();
				} else {
					led0_toggle();
				}

				*button_event = event;
				*button_state = button;
				return true;
			}

			/* Time-critical host application code goes here */
		}

		/* Non time-critical application code goes here */
	}

	return false;
}