コード例 #1
0
int16_t USBUART_CustomGetCount()
{
  if (USBUART_DataIsReady() == 0)
  {
    return 0;
  }
  else
  {
    return USBUART_GetCount();
  }
}
コード例 #2
0
ファイル: main.c プロジェクト: markbradley27/psoc_2_pi
int main()
{
    //StripLights_Start();
    //StripLights_Dim(2); 
    
    CyGlobalIntEnable;  /* enable global interrupts. */
    //SetNeoPixel(2,2,255);
    #if defined(LINX_H)
        LINX_Initialize();
        
        uint8 LINX_Command[LINX_COMMAND_BUFFER_SIZE];
        uint8 LINX_Response[LINX_RESPONSE_BUFFER_SIZE];
    #elif defined(PYTHON_H)
        Python_Initialize();
    #else
        #error "No device chosen! include LINX.h for use of the RPiSoC with LabVIEW, or Python.h for use with a Python device."
    #endif
    
    for(;;)
    {
        #if defined(LINX_H)
            if(USBUART_DataIsReady()) {
                if (LINX_GetCommand(LINX_Command)) {
                    LINX_ProcessCommand(LINX_Command, LINX_Response);
                    LINX_SendResponse(LINX_Response);
                }
                else {
                    #ifdef DEBUG_LINX
                        DEBUG_UART_PutString("Get command FAILED\r\n");
                    #endif
                }
                
            }
        #elif defined(PYTHON_H)
            
            Python_getData(&vessel);
            Python_parser(&vessel);
            
            uint32 result;
            if (readData(vessel, &result)) {
                Python_sendData(result);
            }
        #endif
        
    }
}
コード例 #3
0
ファイル: uart.c プロジェクト: nadavofir/IGVC2013
//"gets" function through USBUART instead of stdio
//echos the input
//terminates on CR or LF
//returns size of string
uint16 UARTgets(uint8 * str, int bufferSize){
	uint16 i = 0;
	uint16 size;
	do{
		while(USBUART_DataIsReady() == 0);
		size = USBUART_GetCount();
		if(size+i > bufferSize){
			str[i]=0;
			UARTprintf("gets: Buffer not big enough. Size: %d Input: %s\r\n", size, str);
			return i;
		}
		USBUART_GetData(&(str[i]),size);
		i+=size;
		if(size == 1)UARTputc(str[i-1]); //echo if single char
	}while((str[i-1] != '\n') && (str[i-1] != '\r'));
	str[--i] = 0; //null terminate, remove the CR/LF
	//UARTprintf("gets: LF or CR found at end of message. Size: %d Input: %s\r\n", size, str);
	//while(USBUART_CDCIsReady()==0);
	//USBUART_PutCRLF(); //print CRLF
	return i;
}
コード例 #4
0
ファイル: uart.c プロジェクト: nadavofir/IGVC2013
void UARTgetMessage(uint8 * str){
	while(USBUART_DataIsReady() == 0);
	USBUART_GetAll(str);
	//UARTprintf("%c",6);//return ACK
}
コード例 #5
0
ファイル: uart.c プロジェクト: nadavofir/IGVC2013
uint8 UARTgetchar(void){
	while(USBUART_DataIsReady() == 0);
	return USBUART_GetChar();
}
コード例 #6
0
ファイル: main.c プロジェクト: yukisega/yukisegaRep
int main()
{
    CyGlobalIntEnable; /* Enable global interrupts. */
    //PWM_1_Start();
    PWM_1_Start();
    USBUART_Start(0,USBUART_5V_OPERATION);
    while(!USBUART_bGetConfiguration()){}
    USBUART_CDC_Init();
    
    int count = 0;
    uint8 buff[64];
    buff[0] = 0;
    
    int up_b = 0;
    int left_b = 0;
    int down_b = 0;
    int right_b = 0;
    int PWM_count = 0;
    int judge_count = 0;
    
    while(1)//main loop
    {   
        if(0 != USBUART_GetConfiguration())
        {
            
            if(0 != USBUART_DataIsReady())
            {
                count = USBUART_GetAll(buff);
                if( count != 0){
                    
                    while(0 == USBUART_CDCIsReady()){}
                    
                    PWM_1_Start();
                    PWM_2_Start();
                    PWM_3_Start();
                    PWM_4_Start();
              
                    USBUART_PutData(buff,count);
                    CyDelay(500);
                    USBUART_PutCRLF(); 
                    
                    switch(buff[0]){
                        case 48:
                            up_b = 1;
                            break;
                        case 49:
                            up_b = 0;
                            break;
                        case 50:
                            left_b = 1;
                            break;
                        case 51:
                            left_b = 0;
                            break;
                        case 52:
                            right_b = 1;
                            break;
                        case 53:
                            right_b = 0;
                            break;
                        case 54:
                            down_b = 1;
                            break;
                        case 55:
                            down_b = 0;
                            break;
                        
                        default:
                        break;
                        
                    }   
            judge_count = up_b + left_b + down_b +right_b;
               
                    
                    if(judge_count == 0){
                        PWM_count = 0;
                    }
            if(judge_count == 1){//押されているボタンの数が1つの場合
                if(PWM_count <=100){
                    PWM_count++;
                    int i = 0;
                    for(i=0;i<=100;i++){}
                }else{}
                    
                    if(up_b == 1){//上ボタン
                    
                    PWM_1_WriteCompare(PWM_count);
                    PWM_1_direction_Write(1);
                    PWM_2_WriteCompare(PWM_count);
                    PWM_2_direction_Write(1);
                    PWM_3_WriteCompare(PWM_count);
                    PWM_3_direction_Write(1);
                    PWM_4_WriteCompare(PWM_count);
                    PWM_4_direction_Write(1);
                    }
                    if(left_b == 1)

                    PWM_1_WriteCompare(PWM_count);
                    PWM_1_direction_Write(0);
                    PWM_2_WriteCompare(PWM_count);
                    PWM_2_direction_Write(1);
                    PWM_3_WriteCompare(PWM_count);
                    PWM_3_direction_Write(1);
                    PWM_4_WriteCompare(PWM_count);
                    PWM_4_direction_Write(0);

                    }
                    if(right_b == 1)

                    PWM_1_WriteCompare(PWM_count);
                    PWM_1_direction_Write(1);
                    PWM_2_WriteCompare(PWM_count);
                    PWM_2_direction_Write(0);
                    PWM_3_WriteCompare(PWM_count);
                    PWM_3_direction_Write(0);
                    PWM_4_WriteCompare(PWM_count);
                    PWM_4_direction_Write(1);

                    }
                    if(down_b == 1)
                    PWM_1_WriteCompare(PWM_count);
                    PWM_1_direction_Write(0);
                    PWM_2_WriteCompare(PWM_count);
                    PWM_2_direction_Write(0);
                    PWM_3_WriteCompare(PWM_count);
                    PWM_3_direction_Write(0);
                    PWM_4_WriteCompare(PWM_count);
                    PWM_4_direction_Write(0);

                    }
        }else if(judge_count == 2){//2個の場合
            if(PWM_count <=100){
                    PWM_count++;
                    int i = 0;
                    for(i=0;i<=100;i++){}
                }else{}
                
                if(up_b == 1&& left_b == 1){
                    PWM_1_WriteCompare(0);
                    PWM_1_direction_Write(0);
                    PWM_2_WriteCompare(PWM_count);
                    PWM_2_direction_Write(1);
                    PWM_3_WriteCompare(PWM_count);
                    PWM_3_direction_Write(1);
                    PWM_4_WriteCompare(0);
                    PWM_4_direction_Write(0);
                }else if(up_b == 1&& right_b == 1){
                    PWM_1_WriteCompare(PWM_count);
                    PWM_1_direction_Write(1);
                    PWM_2_WriteCompare(0);
                    PWM_2_direction_Write(0);
                    PWM_3_WriteCompare(0);
                    PWM_3_direction_Write(0);
                    PWM_4_WriteCompare(PWM_count);
                    PWM_4_direction_Write(1);
                }else if(down_b == 1&& right_b==1){
                    PWM_1_WriteCompare(0);
                    PWM_1_direction_Write(0);
                    PWM_2_WriteCompare(PWM_count);
                    PWM_2_direction_Write(0);
                    PWM_3_WriteCompare(PWM_count);
                    PWM_3_direction_Write(0);
                    PWM_4_WriteCompare(0);
                    PWM_4_direction_Write(0);
                }else if(down_b == 1&& left_b == 1){
                    PWM_1_WriteCompare(PWM_count);
                    PWM_1_direction_Write(0);
                    PWM_2_WriteCompare(0);
                    PWM_2_direction_Write(0);
                    PWM_3_WriteCompare(0);
                    PWM_3_direction_Write(0);
                    PWM_4_WriteCompare(PWM_count);
                    PWM_4_direction_Write(0);
                }
        }else{}
            
                    //if(USBUART_IsLineChanged() == USBUART_LINE_CODING_CHANGED || USBUART_IsLineChanged() == USBUART_LINE_CONTROL_CHANGED)
                    //{
                    USBUART_PutCRLF(); 
                        //CyDelay(100);
                    //}
                    if(64 == count){
                        while(0 == USBUART_CDCIsReady()){}
                        //sent zero packet
                        USBUART_PutData(NULL,0);
                    }
                    //LED_Write(0);
                 
            }
           
}
コード例 #7
0
ファイル: main.c プロジェクト: bill-he/jackbill350
int main()
{
    char freq0Disp[16], freq1Disp[16];
    char usbRx[USBUART_BUFFER_SIZE], usbTx[USBUART_BUFFER_SIZE];
    
    
    /* Initializes the LCD. */
    LCD_Start();
    LCD_Position(1u,0u);
    LCD_Position(0u,0u);
    LCD_PrintString("F1=");
    
    WaveDAC_0_Clock_Start();
    WaveDAC_1_Clock_Start();
    
    // Needed for WaveDACs to operate concurrently
    // I think this might be a bug with PSoC
    WaveDAC_0_Start();
    WaveDAC_1_Start(); 
    WaveDAC_0_Stop();
    WaveDAC_1_Stop();

    USBUART_Start(USBFS_DEVICE, USBUART_5V_OPERATION);
    USBUART_CDC_Init();
    
    CyGlobalIntEnable;

    while (1) {
        if (USBUART_IsConfigurationChanged()) {
            if (USBUART_GetConfiguration()) {
                USBUART_CDC_Init();
            }
        }
        
        if (USBUART_GetConfiguration()) {
            if (USBUART_DataIsReady()) {
                int numArgs;
                int desiredFreq, newFreq, fnGenerator;
                char mode[USBUART_BUFFER_SIZE] = {0};
                
                Serial_GetString(usbRx);
                trimString(usbRx);
                numArgs = sscanf(usbRx, "%d %s %d", &fnGenerator, mode, &desiredFreq);
                if (numArgs == 3) {
                    if (!strcmp(mode, "square")) { 
                        newFreq = changeFrequency(desiredFreq, SQUARE, fnGenerator);
                        sprintf(usbTx, "fn = %d, mode = %s, newFreq = %d\r\n", fnGenerator, mode, newFreq);
                    } else if (!strcmp(mode, "sine")) { 
                        newFreq = changeFrequency(desiredFreq, SINE, fnGenerator);
                        sprintf(usbTx, "fn = %d, mode = %s, newFreq = %d\r\n", fnGenerator, mode, newFreq);
                    } else if (!strcmp(mode, "triangle")) { 
                        newFreq = changeFrequency(desiredFreq, TRIANGLE, fnGenerator);
                        sprintf(usbTx, "fn = %d, mode = %s, newFreq = %d\r\n", fnGenerator, mode, newFreq);
                    } else if (!strcmp(mode, "sawtooth")) { 
                        newFreq = changeFrequency(desiredFreq, SAWTOOTH, fnGenerator);
                        sprintf(usbTx, "fn = %d, mode = %s, newFreq = %d\r\n", fnGenerator, mode, newFreq);
                    } else if (!strcmp(mode, "dc")) { 
                        newFreq = changeFrequency(desiredFreq, DC, fnGenerator);
                        sprintf(usbTx, "fn = %d, mode = %s, newFreq = %d\r\n", fnGenerator, mode, newFreq);
                    } else {
                        sprintf(usbTx, "Invalid mode: %s\r\n", mode);
                    }
                    
                    
                } else if (numArgs == 2) {
                    if (!strcmp(mode, "off")) {
                        if (fnGenerator == 0) {
                            stopWaveDac(WAVEDAC_LOW_0);
                        } else if (fnGenerator == 1) {
                            stopWaveDac(WAVEDAC_LOW_1);   
                        }
                        sprintf(usbTx, "Stopped WaveDAC %d\r\n", fnGenerator);
                    } else {
                        sprintf(usbTx, "Invalid mode: %s\r\n", mode);
                    }
                } else {
                    sprintf(usbTx, "Invalid command: %s\r\n", usbRx);
                }
                
                Serial_PutString(usbTx);
            }
        }
    }
}