示例#1
0
static int second_driver_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
{
//    unsigned int *ptr = (unsigned int *)arg;
//    unsigned int led_num = *ptr;

    unsigned int led_num = (unsigned int)arg;

    printk("arg: %d \n", led_num);
    switch(cmd)
    {
    case LED_ON:

        if(led_num == 3)
            ALL_LED_ON();
        else
            LED_ON_NUM(led_num);

        break;

    case LED_OFF:
        if(led_num == 3)
            ALL_LED_OFF();
        else
            LED_OFF_NUM(led_num);
        break;

    default:
        break;
    }


    return 0;
}
示例#2
0
int main()
{
	/* Enabling Global interrupts */
	CyGlobalIntEnable; 
	
	/* Start BLE component with appropriate Event handler function */
	CyBle_Start(ApplicationEventHandler);	
	
	/* Turn OFF All the LEDs */
	ALL_LED_OFF();
	
	/* Loop For Ever */
    for(;;)
    {
		/* Function to handle the state of the Client */
		handle_ble_CAR_Client_State();		
		
		/* This function checks the internal task queue in the BLE Stack, 
		and pending operation of the BLE Stack, if any */
		CyBle_ProcessEvents();
    }
}
示例#3
0
int main()
{
  
    /* Initializing all the Flags and Indexes to 0 */
    ALL_LED_OFF ();
    Count = 0;
    Index = 0;
    AddRequest = 0;
    DelRequest = 0;

    CyGlobalIntEnable;  /* Comment this line to disable global interrupts. */
    
    /* Start BLE component and register Event handler function */	
    CyBle_Start(StackEventHandler);
	

    /* Start UART Component which is used for receiving inputs and Debugging */
    UART_Start();

	printf("BLE WhiteList Example \r\n");
    printf("Press A to add a Device to WhiteList. R to remove the Device from Whitelist \r\n");

    /* Continuous loop scans for inputs from UART Terminal and accordingly 
    handles Addition to and Removal from Whitelist. Also processes
    BLE events */
    
    for(;;)
    {
        //Checks the internal task queue in the BLE Stack
        CyBle_ProcessEvents();
        
        if(UART_SpiUartGetRxBufferSize())
		{
		   	UartRxDataSim = UART_UartGetChar();
            if (UartRxDataSim == 'A' || UartRxDataSim == 'a')  // The user has to Enter D for disconnection 
            {
                printf ("Enter the Address of the Device. Press Z to Go Back \r\n");
                for (;;)
                {
                    if (Count ==12)
                    {
                        //If the user had entered the full address, stop advertisement
                        //for addition process
                        CyBle_GappStopAdvertisement ();
                        /*Once We stop advertisement, the 
                        CYBLE_EVT_GAPP_ADVERTISEMENT_START_STOP event is invoked.
                         After this, the API for adding the device to whitelist is invoked
                        in the StackEventHandler*/
                        RED_LED_ON ();
                        AddRequest = 1;
                        printf ("\r\n");
                        printf ("Address is 0x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x \r\n",
                                whitelistdeviceaddress.bdAddr[5],
                                whitelistdeviceaddress.bdAddr[4],
                                whitelistdeviceaddress.bdAddr[3],
                                whitelistdeviceaddress.bdAddr[2],
                                whitelistdeviceaddress.bdAddr[1],
                                whitelistdeviceaddress.bdAddr[0]);
                        printf ("Attempting to Add to whitelist \r \n");
                        Count = 0; 
                        break;
                    }
                    
                    if(UART_SpiUartGetRxBufferSize())
                    {
                        UartRxDataSim = UART_UartGetChar();
                        if (UartRxDataSim == 'Z' || UartRxDataSim == 'z')  
                        {
                            Count = 0;
                            printf("Press A to add a Device to WhiteList \r\n");
                            break;
                        }
                       
                        else
                        {
                            if ((UartRxDataSim >= '0') && (UartRxDataSim <= '9' ))
                            {
                                AddrNibble = UartRxDataSim - '0';
                                UART_UartPutChar (UartRxDataSim);
                            }
                            else if ((UartRxDataSim >= 'A') && (UartRxDataSim <= 'F' ))
                            {
                                AddrNibble = UartRxDataSim - 'A' + 0xA;
                                UART_UartPutChar (UartRxDataSim);
                            }
                             else if ((UartRxDataSim >= 'a') && (UartRxDataSim <= 'f' ))
                            {
                                AddrNibble = UartRxDataSim - 'a' + 0xA;
                                UART_UartPutChar (UartRxDataSim);
                            }
                            else 
                            {
                                printf ("\nplease Enter a Valid Address. Press A to Enter a New Address. R ro remove the Device\r\n");
                                Count = 0;
                                break;
                            }
                            
                            //Receiving the addresss Nibble by Nibble
                            whitelistdeviceaddress.bdAddr[5 - (Count/2)] =
                            (whitelistdeviceaddress.bdAddr[5 - (Count/2)]<<4)|AddrNibble;
                            Count ++;
                        }
                    }
                }
            }
            
            else if (UartRxDataSim == 'R' || UartRxDataSim == 'r')
            {
                if (Index == 0)
                {
                    printf ("No Devices in WhiteList. press A to Add \r\n");
                   
                }
                else
                {
                    printf (" The List of Devices are given below \4\n");
                    uint8 i = 0;
                    // Retrieving the list of added devices for user to choose
                    for (i = 0; i< Index; i++)
                    {
                        printf ("Device %d 0x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x \r\n",i + 1,
                            whitelistdeviceaddressBackup[i].bdAddr[5],
                            whitelistdeviceaddressBackup[i].bdAddr[4],
                            whitelistdeviceaddressBackup[i].bdAddr[3],
                            whitelistdeviceaddressBackup[i].bdAddr[2],
                            whitelistdeviceaddressBackup[i].bdAddr[1],
                            whitelistdeviceaddressBackup[i].bdAddr[0]);
                    }
                    printf ("Enter the Index of the device to be removed. Press Z to go back \r\n");
                    
                    for (;;)
                    {
                        if(UART_SpiUartGetRxBufferSize())
                        {
                            UartRxDataSim = UART_UartGetChar();
                            if (UartRxDataSim == 'Z' || UartRxDataSim == 'z')  
                            {
                                printf("Press A to add a Device to WhiteList. R to remove \r\n");
                                break;
                            }
                            else if (UartRxDataSim >= '1' || UartRxDataSim <= '0' + Index)
                            {
                                RemoveIndex = UartRxDataSim - '1';
                                if(RemoveIndex < Index)
                                {
                                    CyBle_GappStopAdvertisement ();
                                /*Once We stop advertisement, the 
                                CYBLE_EVT_GAPP_ADVERTISEMENT_START_STOP event is invoked.
                                After this, the API for removing the device from whitelist 
                                is invoked in the StackEventHandler*/
                                    DelRequest = 1;
                                    break;
                                }
                                else
                                {
                                    printf("There is no device with that number.\r\n");
                                }
                            }
                            else 
                            {
                                printf ("Invaid Index. Press A to Add and R to remove a Device");
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
}