Exemple #1
0
int main()
{
    CyGlobalIntEnable;
    CapSense_Start();
    CapSense_InitializeEnabledBaselines();
    CapSense_ScanEnabledWidgets();

    for(;;)
    {
        if(!CapSense_IsBusy())
        {
            LED0_Write(!CapSense_CheckIsWidgetActive(CapSense_BUTTON0__BTN));
            LED1_Write(!CapSense_CheckIsWidgetActive(CapSense_BUTTON1__BTN));
            CapSense_UpdateEnabledBaselines();
            CapSense_ScanEnabledWidgets();
        }
    }
}
Exemple #2
0
/*******************************************************************************
* Function Name: GestureDetection
****************************************************************************//**
* @par Summary
*    This function detects forward and backward gestures using
*	 two proximity sensors
*
* @return
*    None
*
* @param[in]
*	 Proximity sensor information, gesture structure instance reference 
*
* @param[out] 
*	 None    
*
* @pre
*    None
*
* @post
*    None
*
* @par Theory of Operation
*    Logic to say left to right gesture is completed is given below
*	 1) Both the proximity sensors are OFF
*	 2) Left proximity sensor turned ON
*	 3) Both Left and Right proximity sensors ON
* 	 4) Only right proximity sensor ON
*	 5) Both the proximity sensors are OFF
* 	 To determine invalid gestures following additional checks are implemented
*    1) Configurable debounce for each state
*
* @par Notes
*    None
*
**//***************************************************************************/
void GestureDetection(SENSOR_NAMES Sensor1, SENSOR_NAMES Sensor2, gesture* axisPtr)
{    
	ZONE_NAMES currentZone = INVALID_ZONE;
	/*This function has different cases based on the proximity sensor status
	*	and each state follow similar steps which are given below*/
	/*Steps for any case
	*	1) Reset debounce counters on first entry to this state
	*	2) Update the current zone 
	*	3) Based on current and previous zone decide if it is forward or backward gesture
	*	4) Apply debounce before taking final decision on gesture tracking
	*	5) Update the previous zone */

	/* Sensor1 ON, Sensor2 OFF , Zone 1 */	
    if(CapSense_CheckIsWidgetActive(Sensor1) && (CapSense_CheckIsWidgetActive(Sensor2)==0))
    {		
		currentZone = ZONE_ONE;
		/*Check forward and backward gesture in this zone*/
		GestureForwardDetection(axisPtr,currentZone);
		GestureBackwardDetection(axisPtr,currentZone);	
    }
	/* Sensor1 OFF, Sensor2 ON , Zone 3 */
    else if((CapSense_CheckIsWidgetActive(Sensor1) == 0) && CapSense_CheckIsWidgetActive(Sensor2))
    {
		currentZone = ZONE_THREE;
		/*Check forward and backward gesture in this zone*/
		GestureForwardDetection(axisPtr,currentZone);
		GestureBackwardDetection(axisPtr,currentZone);	
    }
    /* Sensor1 ON, Sensor2 ON , Zone 2 */
    else if(CapSense_CheckIsWidgetActive(Sensor1) && CapSense_CheckIsWidgetActive(Sensor2))
    {
		currentZone = ZONE_TWO;
		/*Check forward and backward gesture in this zone*/
		GestureForwardDetection(axisPtr,currentZone);
		GestureBackwardDetection(axisPtr,currentZone);				
    }     
    else 
    {
		/*Both proximity sensors are OFF*/
		if (axisPtr->forwardGestureTracking)
		{
			if (axisPtr->previousZone == ZONE_THREE)
			{
				/*If previous zone is ZONE_THREE (Only sensor2 is ON) then forward gesture is complete*/
				axisPtr->forwardGestureComplete = true;
				/*Decide the LED direction based on X-Axis or Y-Axis*/
				if (Sensor1 == LEFT_SENSOR)
				{
					/*Based on sensors being used to detect X-Axis or Y-Axis is determined*/
					LEDDriveSequence = LEFT_TO_RIGHT;
				}
				else
				{
					LEDDriveSequence = BOTTOM_TO_TOP;
				}
				/*Reset the LED on time counter to start the time*/
				LEDCounter = RESET_COUNTER;
			}
		}			

		if (axisPtr->backwardGestureTracking)
		{
			if (axisPtr->previousZone == ZONE_ONE)
			{
				/*If previous zone is ZONE_ONE (Only sensor1 is ON) then backward gesture is complete*/
				axisPtr->backwardGestureComplete = true;
				/*Decide the LED direction based on X-Axis or Y-Axis*/
				if (Sensor1 == LEFT_SENSOR)
				{
					/*Based on sensors being used to detect X-Axis or Y-Axis is determined*/
					LEDDriveSequence = RIGHT_TO_LEFT;
				}
				else
				{
					LEDDriveSequence = TOP_TO_BOTTOM;
				}
				LEDCounter = RESET_COUNTER;
			}			
		}			
		/*Reset the gesture to start tracking the next gestures*/
		GestureVariableInit(axisPtr);
	}
	/*Drive LEDs*/
	DriveLEDs(currentZone);
}
Exemple #3
0
void main()
{
	CYGlobalIntEnable; /* Enable global interrupts */
	
	ADC_DelSig_1_Start();/* Configure and power up ADC */
	LCD_Char_1_Start(); /* Initialize and clear the LCD */
	
	/* Move the cursor to Row 0 Column 0 */
	LCD_Char_1_Position(ROW_0,COLUMN_0); 
	/* Print Label for the pot voltage raw count */
	LCD_Char_1_PrintString("TEMP NOW:    C");
	
	LCD_Char_1_Position(ROW_1,COLUMN_0);
	LCD_Char_1_PrintString("TEMP SET:    C");
	
	ADC_DelSig_1_StartConvert(); /* Force ADC to initiate a conversion */
	
	/* Start capsense and initialize baselines and enable scan */
	CapSense_Start();
	CapSense_InitializeAllBaselines();
	CapSense_ScanEnabledWidgets();

    /* CyGlobalIntEnable; */ /* Uncomment this line to enable global interrupts. */
	//Start the pwm;
	PWM_1_Start();
    for(;;)
    {
		/* If scanning is completed update the baseline count and check if sensor is active */
		while(CapSense_IsBusy());
		
		/* Update baseline for all the sensors */
		CapSense_UpdateEnabledBaselines();
		CapSense_ScanEnabledWidgets();
		
		/* Test if button widget is active */
		stateB_1 = CapSense_CheckIsWidgetActive(CapSense_BUTTON0__BTN);
		stateB_2 = CapSense_CheckIsWidgetActive(CapSense_BUTTON1__BTN);
	
        /* Wait for end of conversion */
		ADC_DelSig_1_IsEndConversion(ADC_DelSig_1_WAIT_FOR_RESULT);
		/* Get converted result */
		voltageRawCount = ADC_DelSig_1_GetResult16();
		//Change voltageRawCount to Temperature;
		temp = voltageRawCount / 3.870 * 0.1017 + 0.5;
		cold = (9999 - (temp > temp_set ? temp - temp_set : 0) * 50);
		if(cold < 1000)
			cold = 1000;
		if(cold > 9999)
			cold = 9999;
		//Change the pwm;
		PWM_1_WriteCompare(cold);
		/* Set range limit */
		if (temp > 0x7FFF)
		{
			temp = 0;
		}
		else
		{
		/* Continue on */
		}
		if(show < 10)
		{
			show++;
		}
		else
		{
			show = 0;
			UpdateDisplay(temp, 0); /* Print result on LCD */
			UpdateButtonState(stateB_1, stateB_2);
		}
    }
}