示例#1
0
/*******************************************************************************
* Function Name: InitializeSystem
********************************************************************************
* Summary:
* Start the components and initialize system.
*
* Parameters:
*  void
*
* Return:
*  void
*
*******************************************************************************/
void InitializeSystem(void)
{
	/* Enable global interrupt mask */
	CyGlobalIntEnable; 
		
	/* Start BLE component and register the CustomEventHandler function. This 
	 * function exposes the events from BLE component for application use */
    CyBle_Start(CustomEventHandler);	
    
	/* Start both the PrISM components for LED control*/
    PRS_1_Start();
    PRS_2_Start();
	
	/* The RGB LED on BLE Pioneer kit are active low. Drive HIGH on 
	 * pin for OFF and drive LOW on pin for ON*/
	PRS_1_WritePulse0(RGB_LED_OFF);
	PRS_1_WritePulse1(RGB_LED_OFF);
	PRS_2_WritePulse0(RGB_LED_OFF);
	
	/* Set Drive mode of output pins from HiZ to Strong */
	RED_SetDriveMode(RED_DM_STRONG);
	GREEN_SetDriveMode(GREEN_DM_STRONG);
	BLUE_SetDriveMode(BLUE_DM_STRONG);
	
	/* Initialize CapSense component and initialize baselines*/
	CapSense_Start();
	CapSense_InitializeAllBaselines();
}
示例#2
0
文件: main.c 项目: spiricom/Birl
int main()
{
    /* Place your initialization/startup code here (e.g. MyInst_Start()) */
    EZI2C_Init();
    EZI2C_Start();
    CapSense_Start();
    CyGlobalIntEnable;
    CapSense_InitializeAllBaselines();
    EZI2C_EzI2CSetBuffer1(BUFFER_SIZE, BUFFER_SIZE, ezi2cBuffer);
    /* CyGlobalIntEnable; */ /* Uncomment this line to enable global interrupts. */
    for(;;)
    {
           /* Update all baselines */
            CapSense_UpdateEnabledBaselines();
        
   		    /* Start scanning all enabled sensors */
    	    CapSense_ScanEnabledWidgets();   
    
            /* Wait for scanning to complete */
		
            while(CapSense_IsBusy() != 0)
            {
                ; //wait for the scan to finish
            }
            
            touched = CapSense_GetTouchCentroidPos(CapSense_TOUCHPAD0__TP, pos);
            
            
            ezi2cBuffer[0] = (uint8) pos[0];
            ezi2cBuffer[1] = (uint8) pos[1];
            ezi2cBuffer[2] = touched;
            
            //ezi2cBuffer[0] = i;
            //ezi2cBuffer[1] = i+1;
            //i++;
            XY_DATAREADY_Write(1);
            
            while (!(EZI2C_EzI2CGetActivity() & EZI2C_EZI2C_STATUS_READ1))
            {
                ; //wait for the data to be read from the master
            }
            
            XY_DATAREADY_Write(0);
            
    }
}
示例#3
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();
        }
    }
}
示例#4
0
int main()
{
    uint8 interruptState;

    CyGlobalIntEnable; /* Enable global interrupts */
    
    EZI2C_Start(); /* Start EZI2C component */
    
    /*
    * Set up communication and initialize data buffer to CapSense data structure
    * to use Tuner application
    */
    EZI2C_EzI2CSetBuffer1(sizeof(CapSense_dsRam), sizeof(CapSense_dsRam),
                            (uint8 *)&CapSense_dsRam);

    CapSense_Start(); /* Initialize component */

    BleHandler_Init();
    Tuner_Init(BleHandler_RefreshBuffer, BleHandler_SendBuffer);

    CapSense_ScanAllWidgets(); /* Scan all widgets */

    for(;;)
    {
        /* Do this only when a scan is done */
        interruptState = CyEnterCriticalSection();
        if(CapSense_NOT_BUSY == CapSense_IsBusy())
        {
            CyExitCriticalSection(interruptState);
            CapSense_ProcessAllWidgets(); /* Process all widgets */
            Tuner_RunTuner();

            if (CapSense_IsAnyWidgetActive()) /* Scan result verification */
            {
                /* add custom tasks to execute when touch detected */
            }
            CapSense_ScanAllWidgets(); /* Start next scan */
        }
        CySysPmSleep(); /* Sleep until scan is finished */
        CyExitCriticalSection(interruptState);
    }
}
/*******************************************************************************
* Function Name: int  main( void )
********************************************************************************/
int main(void)
{
    uint32  i;
    
    CyGlobalIntEnable; /* Enable global interrupts. */

    EZI2C_Start();
    #ifdef ENABLE_TUNER
    EZI2C_EzI2CSetBuffer1(sizeof(CapSense_dsRam), sizeof(CapSense_dsRam),(uint8 *)&CapSense_dsRam);        
    #else
    EZI2C_EzI2CSetBuffer1(sizeof(I2Cbuf), RW, (void *) &I2Cbuf);     
    #endif   
    
    SmartIO_Start();    
    VDAC_Start();
    PVref_ALS_Start();
    Opamp_ALS1_Start();
    Opamp_ALS2_Start();
    PVref_Therm_Start();
    Opamp_Therm_Start();    
    ADC_Start();
    ADC_IRQ_Enable();
    
    CapSense_Start();   
    /* Over-ride IDAC values for buttons but keep auto for Prox and Humidity */
    CapSense_BUTTON0_IDAC_MOD0_VALUE =          7u;
    CapSense_BUTTON0_SNS0_IDAC_COMP0_VALUE =    6u;
    CapSense_BUTTON1_IDAC_MOD0_VALUE =          7u;
    CapSense_BUTTON1_SNS0_IDAC_COMP0_VALUE =    7u;
    CapSense_BUTTON2_IDAC_MOD0_VALUE =          9u;
    CapSense_BUTTON2_SNS0_IDAC_COMP0_VALUE =    7u;
    CapSense_BUTTON3_IDAC_MOD0_VALUE =          9u;
    CapSense_BUTTON3_SNS0_IDAC_COMP0_VALUE =    8u;
    /* Setup first widget and run the scan */    
    CapSense_SetupWidget(CapSense_BUTTON0_WDGT_ID);
    CapSense_Scan();      
    
    /* Start SysTick Timer to give a 1ms interrupt */
    CySysTickStart();
    /* Find unused callback slot and assign the callback. */
    for (i = 0u; i < CY_SYS_SYST_NUM_OF_CALLBACKS; ++i)
    {
        if (CySysTickGetCallback(i) == NULL)
        {
            /* Set callback */
            CySysTickSetCallback(i, SysTickISRCallback);
            break;
        }
    }
    
    /* Initialize I2C and local data registers to 0's */
    I2Cbuf.dacVal = 0.0;
    I2Cbuf.ledVal = 0x00;
    I2Cbuf.ledControl = 0x00;
    I2Cbuf.buttonVal = 0x00;
    I2Cbuf.temperature = 0.0;
    I2Cbuf.humidity = 0.0;
    I2Cbuf.illuminance = 0.0;
    I2Cbuf.potVal = 0.0;
    
    LocData.dacVal = 0.0;
    LocData.ledVal = 0x00;
    LocData.ledControl = 0x00;
    LocData.buttonVal = 0x00;
    LocData.temperature = 0.0;
    LocData.humidity = 0.0;
    LocData.illuminance = 0.0;
    LocData.potVal = 0.0;
    
    for(;;)
    {
        processButtons();  /* Mechanical buttons and bootloader entry */
        processCapSense(); /* CapSense Scanning */
        processDAC();      /* VDAC output voltage setting */
        processADC();      /* Process ADC results after each scan completes */
        processI2C();      /* Copy date between I2C registers and local operating registers */
    }
} /* End of main */
示例#6
0
文件: main.c 项目: greglandry/PSoC
int main()
{
    
    CyDelay(200);

    uint16 Counts=0;            // ADC value (0 to 4095) right shifted by 6 which gives
                                // us 0 to 63 to be used to simulate actual temperature
    uint16 TempSet = 2400;      // Temperature set default value (left justified) 24 deg
    uint16 DisplayTemp = 0;     // The combined sum of desired temp and actual temp
    
    uint16 bleTemp = 0;         // Temperature sent to BLE module
    uint16 bleTempSet = 0;      // Temperature set value sent to BLE module
    
    uint8 button0 = 0;      // Declare CapSense button name button0
    uint8 button1 = 0;      // Declare CapSense button name button1
    uint8 firstpress0 = 0;  // Detects a transition of button1 from 0 to 1
    uint8 firstpress1 = 0;  // Detects a transition of button1 from 0 to 1
    
    int buttonPrevious = 1;

    CyGlobalIntEnable;
    
    ADC_Start();        // Starts the ADC component
    ADC_StartConvert(); // The ADC conversion process begins
    LCD_Start();        // Start the LCD component 
    
    CapSense_Start();
    CapSense_ScanAllWidgets();
    
    LCD_WritePixel(LCD_COLON, TRUE);
       
    ResetTimer_Start();
    sendBootload_StartEx(StartBootload_ISR);
    
    BLEIOT_Start();
    
    /* Initialize temperuature values out of range so that main loop update is triggered */
    BLEIOT_updateTemperature(10000);
    BLEIOT_updatePot(100);    
       
    for(;;)
    {
        
        /* Turn BLE on/off with button press */
        if(buttonPrevious && (Button_Read() == 0))
        {          
            if(BLEIOT_remote.bleState == BLEIOT_BLEOFF)
            {
                BLEIOT_updateBleState(BLEIOT_BLEON);  
            }
            else
            {
                BLEIOT_updateBleState(BLEIOT_BLEOFF);
            }
            
        }
        buttonPrevious = Button_Read();
           
        /* Local Thermostat Operation */
        /* ADC */
        // Read the ADC, shift right by 6 (i.e. divide by 64)
        // and store result in Counts
        Counts = ADC_GetResult16(POT_CHAN);
        Counts = Counts >> 6;

        /* CapSense */
        if (!CapSense_IsBusy())
        {
            // Check Button states and store
            CapSense_ProcessAllWidgets();
            if(CapSense_IsWidgetActive(CapSense_BUTTON0_WDGT_ID))
            {
                button0 = 1;
            }
            else
            {
                button0 = 0;
            }
            if(CapSense_IsWidgetActive(CapSense_BUTTON1_WDGT_ID))
            {
                button1 = 1;
            }
            else
            {
                button1 = 0;
            }
            
            // Light LEDs Based on Capsense buttons
            LED_CS0_Write(~button0);
            LED_CS1_Write(~button1);
            
            // Check for button touchdown transitions
            if (button0 == 1)
            {
                if(firstpress0 == 0) // Touchdown event
                {
                    firstpress0 = 1; // Remember button0 was pressed
                    TempSet = TempSet + 100; // Increment Temp by 1 deg
                }
            }
            else
            {
                firstpress0 = 0; // Button released
            }
            if (button1 == 1)
            {
                if(firstpress1 == 0) // Touchdown event
                {
                    firstpress1 = 1; // Remember button0 was pressed                   
                    TempSet = TempSet - 100; // Decrement Temp by 1 deg
                }
            }
            else
            {
                firstpress1 = 0; // Button released
            }
                 
            CapSense_ScanAllWidgets();  // Start Next Scan
        }
     
        /* Warning LEDs and Buzzer */
        if((Counts * 100) < TempSet)    // Temperature Cold
        {
            LED_Blue_Write(LED_ON);     // Blue On
            LED_Green_Write(LED_OFF);   // Green Off
            LED_Red_Write(LED_OFF);     // Red Off
            PWM_Stop(); // Buzzer Off
        }
        else if ((Counts * 100) <= (TempSet + 500))  // Temperature OK
        {
            LED_Blue_Write(LED_OFF);    // Blue Off
            LED_Green_Write(LED_ON);    // Green On
            LED_Red_Write(LED_OFF);     // Red Off
            PWM_Stop();// Buzzer Off
        }
        else // Tempearture too high
        {
            LED_Blue_Write(LED_OFF);    // Blue Off
            LED_Green_Write(LED_OFF);   // Green Off
            LED_Red_Write(LED_ON);      // Red On
            PWM_Start(); // Buzzer On
        }
    
        /* LCD Display */
        DisplayTemp = TempSet + Counts;
        LCD_Write7SegNumber_0(DisplayTemp, POS, MODE);        
    
        
        /* BLE operation - do only if BLE is not off */    
        if(BLEIOT_remote.bleState != BLEIOT_BLEOFF)
        {
            /* Send new temperature data to the BLE module */
            if(bleTemp != Counts)
            {
                bleTemp = Counts;
                BLEIOT_updatePot(bleTemp);
            }
            if(bleTempSet != TempSet)
            {
                bleTempSet = TempSet;
                /* Scale set temperature down to whole number of  degrees */
                BLEIOT_updateTemperature(TempSet / 100); 
            }     
                       
            /* Get new data from the BLE module */
            /* LED0 is used for temperature changes */
            if(BLEIOT_getDirtyFlags() & BLEIOT_FLAG_LED0)
            {
                /* Update local variable copy and clear dirty flag */
                BLEIOT_updateLed0(BLEIOT_remote.led0); 
                if(BLEIOT_local.led0 == UP)
                {
                    TempSet = TempSet + 100; // Increment Temp by 1 deg
                }
                else if (BLEIOT_local.led0 == DOWN)
                {
                    TempSet = TempSet - 100; // Decrement Temp by 1 deg
                }
            }
        } /* End of !BLEOFF state operations */
    } /* End of superloop */
} /* End of main */
示例#7
0
文件: main.c 项目: wuweijia1994/PSOC
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);
		}
    }
}