//BIND_TX bool CX10::bind_XN297(int slot) { byte counter=255; bool bound=false; Craft *c = &craft_[slot]; while(!bound && counter > 240){ uint32_t t = micros(); for (int s = 0; s < nextSlot_; ++s) if (t >= craft_[s].nextPacket + PACKET_INTERVAL * 100) return false; CE_off; delayMicroseconds(5); _spi_write_address(0x20, 0x0e); // Power on, TX mode, 2 byte CRC _spi_write_address(0x25, 0x02); // set RF channel 2 _spi_write_address(0x27, 0x70); // Clear interrupts _spi_write_address(0xe1, 0x00); // Flush TX Write_Packet(slot, 0xaa); // send bind packet delay(2); _spi_write_address(0x27, 0x70); // Clear interrupts _spi_write_address(0x25, 0x02); // Set RF channel _spi_write_address(0x20, 0x0F); // Power on, RX mode, 2 byte CRC CE_on; // RX mode uint32_t timeout = millis()+4; while(millis()<timeout) { if(_spi_read_address(0x07) == 0x40) { // data received CE_off; Read_Packet(); c->aid[0] = packet[5]; c->aid[1] = packet[6]; c->aid[2] = packet[7]; c->aid[3] = packet[8]; if(packet[9]==1) { bound=true; break; } } } CE_off; digitalWrite(ledPin, bitRead(--counter,3)); //check for 0bxxxx1xxx to flash LED } if (bound) { c->nextPacket = micros() + PACKET_INTERVAL * 1000; c->chan = 0; digitalWrite(ledPin, HIGH);//LED on at end of bind // Serial.println("found a craft!"); // printTXID(slot); // Serial.print('+'); // printAID(slot); // Serial.println(""); Serial.print("X"); } else { c->nextPacket = 0; } return bound; }
int _readrx(void) { for (int i=0;i<21;i++) packet[i]=0; channel=tx_channels[chanrow][chancol]-1-chanoffset; A7105_Strobe(A7105_STANDBY); A7105_Strobe(A7105_RST_RDPTR); A7105_WriteRegister(0x0F, channel); A7105_Strobe(A7105_RX); chancol = (chancol + 1) % 16; unsigned long pause; uint8_t x; pause=lib_timers_starttimer(); while(1){ if (lib_timers_gettimermicroseconds(pause) > 2000) { // Red_LED_OFF; chancol = (chancol + 1) % 16; channel=tx_channels[chanrow][chancol]-1-chanoffset; break; } if(A7105_ReadRegister(A7105_00_MODE) & A7105_MODE_TRER_MASK){ continue; } x=A7105_ReadRegister(0x00); if (!(bitRead(x,5)==0)&& !(bitRead(x,6)==0)){ continue; } Read_Packet(); if (convert2id(packet[1],packet[2],packet[3],packet[4])!=usersettings.flysky_id) { // Serial.println("bad id"); continue; } decodepacket(); // reset the failsafe timer global.failsafetimer = lib_timers_starttimer(); return 1; } return 0; }