示例#1
0
int main(void)
{

	/* USER CODE BEGIN 1 */

	/* USER CODE END 1 */

	/* MCU Configuration----------------------------------------------------------*/

	/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
	HAL_Init();

	/* Configure the system clock */
	SystemClock_Config();

	/* Initialize all configured peripherals */
	MX_GPIO_Init();
	MX_USART1_UART_Init();
	MX_SPI1_Init();
	MX_TIM1_Init();
	MX_TIM3_Init();

	HAL_TIM_Base_Start(&htim1);

	static char buf[50];


	NRF24L01_Reset();
	NRF24L01_Initialize();
	HAL_Delay(150);


	CX10_init();
	HAL_Delay(50);
	CX10_bind();

	while (1) {
		process_CX10();
		HAL_Delay(6);
	}

}
示例#2
0
void loop()
{
    uint32_t timeout;
    // reset / rebind
    //Serial.println("begin loop");
    if(reset || ppm[AUX8] > PPM_MAX_COMMAND) {
        reset = false;
        Serial.println("selecting protocol");
        selectProtocol();        
        Serial.println("selected protocol.");
        NRF24L01_Reset();
        Serial.println("nrf24l01 reset.");
        NRF24L01_Initialize();
        Serial.println("nrf24l01 init.");
        init_protocol();
        Serial.println("init protocol.");
    }
    // process protocol
    //Serial.println("processing protocol.");
    switch(current_protocol) {
        case PROTO_CG023:
        case PROTO_YD829:
            timeout = process_CG023();
            break;
        case PROTO_V2X2: 
            timeout = process_V2x2();
            break;
        case PROTO_CX10_GREEN:
        case PROTO_CX10_BLUE:
            timeout = process_CX10(); // returns micros()+6000 for time to next packet. 
            break;
        case PROTO_H7:
            timeout = process_H7();
            break;
        case PROTO_BAYANG:
            timeout = process_Bayang();
            break;
        case PROTO_SYMAX5C1:
            timeout = process_SymaX(); 
            break;
        case PROTO_H8_3D:
            timeout = process_H8_3D();
            break;
    }
    // updates ppm values out of ISR
    //update_ppm();
    overrun_cnt=0;

    if (stringComplete) {
        //Serial.println(inputString);
        // process string
        p = strtok_r(record,",",&i);
        while (p !=0){
          Serial.print(p);
          Serial.print("c");
          p = strtok_r(NULL,",",&i);
        }
        Serial.println("X");
        //ppm[0]=
        
        
        
        // clear the string:
        inputString = "";
        stringComplete = false;
    }
    while (Serial.available()) {
      // get the new byte:
      char inChar = (char)Serial.read();
      // if the incoming character is a newline, set a flag
      // so the main loop can do something about it:
      if (inChar == '\n') {
        stringComplete = true;
      }
      else {      
        // add it to the inputString:
        inputString += inChar;
      }
      
    }
    // wait before sending next packet
    while(micros() < timeout) // timeout for CX-10 blue = 6000microseconds. 
    {
      overrun_cnt+=1;
    };
    if ((overrun_cnt<1000)||(stringComplete)) {
      Serial.println(overrun_cnt);
    }
}