diff --git a/Multiprotocol/Bayang_nrf24l01.ino b/Multiprotocol/Bayang_nrf24l01.ino index 87053b5..b485a66 100644 --- a/Multiprotocol/Bayang_nrf24l01.ino +++ b/Multiprotocol/Bayang_nrf24l01.ino @@ -265,11 +265,7 @@ uint16_t BAYANG_callback() #ifdef ENABLE_BAYANG_TELEMETRY if(sub_protocol == BAYANG_TELEM) { - Bayang_process(); - // Return 0 here so that Bayang_process is called as often as possible - // to check for the incomming telemetry data. When telemetry is enabled - // the packet period is handled in the Bayang_process function. - return 0; + return Bayang_process(); } else #endif @@ -317,6 +313,9 @@ uint16_t initBAYANG(void) #ifdef ENABLE_BAYANG_TELEMETRY extern float telemetry_voltage; +extern uint16_t telemetry_rx_recv_pps; +extern uint16_t telemetry_tx_recv_pps; +extern uint16_t telemetry_tx_sent_pps; extern uint8_t telemetry_rx_rssi; extern uint8_t telemetry_tx_rssi; extern uint8_t telemetry_datamode; @@ -326,13 +325,21 @@ uint16_t initBAYANG(void) extern uint16_t telemetry_flighttime; extern uint8_t telemetry_flightmode; - uint8_t telemetry_tx_rssi_count; - uint8_t telemetry_tx_rssi_next; - - + uint16_t telemetry_tx_sent_pkt_count; + uint32_t telemetry_tx_sent_pps_time; + uint16_t telemetry_tx_recv_pkt_count; + uint32_t telemetry_tx_recv_pps_time; + + + + + + + + static uint32_t bayang_tx_time = 0; uint8_t BAYANG_recv_packet() { uint8_t received = 0; - if (NRF24L01_ReadReg(NRF24L01_07_STATUS) & _BV(NRF24L01_07_RX_DR)) { + if (NRF24L01_Strobe(NRF24L01_FF_NOP) & _BV(NRF24L01_07_RX_DR)) { int sum = 0; uint16_t roll, pitch, yaw, throttle; @@ -357,7 +364,13 @@ uint16_t initBAYANG(void) v.bytes[1] = packet[2]; telemetry_voltage = v.v / 100.f; - telemetry_rx_rssi = packet[3]; + telemetry_rx_recv_pps = packet[3]*2; + telemetry_rx_rssi = (uint8_t)(telemetry_rx_recv_pps*100/telemetry_tx_sent_pps); + if (telemetry_rx_rssi > 100) + telemetry_rx_rssi = 100; + telemetry_tx_rssi = (uint8_t)(telemetry_tx_recv_pps*100/telemetry_rx_recv_pps); + if (telemetry_tx_rssi > 100) + telemetry_tx_rssi = 100; v.bytes[0] = packet[4]; @@ -401,60 +414,83 @@ uint16_t initBAYANG(void) BayangState Bayang_state = BAYANG_STATE_IDLE; uint32_t Bayang_next_send = 0; - void Bayang_process() { + uint16_t Bayang_process() { uint32_t time_micros = micros(); + uint16_t callback_period = 30; // asap if (BAYANG_STATE_TRANSMITTING == Bayang_state) { - if (NRF24L01_ReadReg(NRF24L01_07_STATUS) & _BV(NRF24L01_07_TX_DS)) { + if (NRF24L01_Strobe(NRF24L01_FF_NOP) & _BV(NRF24L01_07_TX_DS) || time_micros - bayang_tx_time > 1100) { // send finished, switch to rx to receive telemetry XN297_Configure(_BV(NRF24L01_00_EN_CRC) | _BV(NRF24L01_00_CRCO) | _BV(NRF24L01_00_PWR_UP) | _BV(NRF24L01_00_PRIM_RX)); NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70); - NRF24L01_FlushTx(); NRF24L01_FlushRx(); - telemetry_tx_rssi_count++; + Bayang_state = BAYANG_STATE_RECEIEVING; - Bayang_state = BAYANG_STATE_RECEIEVING; + callback_period = Bayang_next_send - time_micros - 550; // wait a while for quad to receive then send a packet } } else if (BAYANG_STATE_RECEIEVING == Bayang_state) { + uint8_t change_state = 1; // 250us is about the time it takes to read a packet over spi - if (time_micros > (Bayang_next_send-250)) { - // didnt receive telemetry in time - Bayang_state = BAYANG_STATE_IDLE; - + if (time_micros > (Bayang_next_send-250)) + { // if it's been a while since receiving telemetry data, // stop sending the telemetry data to the transmitter - if (millis() - bayang_telemetry_last_rx > 1000) + if (time_micros - bayang_telemetry_last_rx > 1000000) telemetry_lost = 1; } - else if (BAYANG_recv_packet()) { - telemetry_tx_rssi_next++; + else if (BAYANG_recv_packet()) + { + telemetry_tx_recv_pkt_count++; // received telemetry packet telemetry_lost = 0; - bayang_telemetry_last_rx = millis(); + bayang_telemetry_last_rx = time_micros; } else { - return; + change_state = 0; } - if (100 == telemetry_tx_rssi_count) + if (telemetry_tx_recv_pps_time < time_micros) { - telemetry_tx_rssi = telemetry_tx_rssi_next; - telemetry_tx_rssi_next = 0; - telemetry_tx_rssi_count = 0; + telemetry_tx_recv_pps = telemetry_tx_recv_pps + telemetry_tx_recv_pkt_count - telemetry_tx_recv_pps/10; + telemetry_tx_recv_pkt_count = 0; + telemetry_tx_recv_pps_time += 100000; } + if (change_state) + { Bayang_state = BAYANG_STATE_IDLE; - XN297_Configure(_BV(NRF24L01_00_EN_CRC) | _BV(NRF24L01_00_CRCO) | _BV(NRF24L01_00_PWR_UP)); - NRF24L01_FlushRx(); + XN297_Configure(_BV(NRF24L01_00_EN_CRC) | _BV(NRF24L01_00_CRCO) | _BV(NRF24L01_00_PWR_UP)); + NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70); + NRF24L01_FlushRx(); + } } - else if (time_micros > Bayang_next_send) { + else if (time_micros > Bayang_next_send) + { + bayang_tx_time = time_micros; + BAYANG_send_packet(0); Bayang_state = BAYANG_STATE_TRANSMITTING; Bayang_next_send = time_micros + BAYANG_PACKET_PERIOD_TELEM; + callback_period = 600; // takes about 1ms to send(spi transfer + tx send) + + telemetry_tx_sent_pkt_count++; + if (telemetry_tx_sent_pps_time < time_micros) + { + telemetry_tx_sent_pps = telemetry_tx_sent_pps + telemetry_tx_sent_pkt_count - telemetry_tx_sent_pps/10; + telemetry_tx_sent_pkt_count = 0; + telemetry_tx_sent_pps_time += 100000; + } + + } + else + { + callback_period = Bayang_next_send - time_micros; + } + return callback_period; } #endif //ENABLE_BAYANG_TELEMETRY #endif diff --git a/Multiprotocol/FlySky_a7105.ino b/Multiprotocol/FlySky_a7105.ino index 4c76806..29c01aa 100644 --- a/Multiprotocol/FlySky_a7105.ino +++ b/Multiprotocol/FlySky_a7105.ino @@ -196,7 +196,9 @@ uint16_t initFlySky() A7105_Init(); - if ((rx_tx_addr[3]&0xF0) > 0x90) // limit offset to 9 as higher values don't work with some RX (ie V912) + // limit offset to 9 as higher values don't work with some RX (ie V912) + // limit offset to 9 as CX20 repeats the same channels after that + if ((rx_tx_addr[3]&0xF0) > 0x90) rx_tx_addr[3]=rx_tx_addr[3]-0x70; // Build frequency hop table @@ -213,11 +215,18 @@ uint16_t initFlySky() if(i&0x01) temp+=0x50; if(sub_protocol==CX20) - {//Might need more dumps to be 100% sure but this is how it looks like to work + { if(temp==0x0A) temp+=0x37; if(temp==0xA0) - temp-=0x73; + { + if (chanoffset<4) + temp=0x37; + else if (chanoffset<9) + temp=0x2D; + else + temp=0x29; + } } hopping_frequency[((chanrow&1)?15-i:i)]=temp-chanoffset; } diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index 0823634..e8e4692 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -420,7 +420,10 @@ void loop() { TX_MAIN_PAUSE_on; tx_pause(); - next_callback=remote_callback(); + if(IS_INPUT_SIGNAL_on) + next_callback=remote_callback(); + else + next_callback=2000; // No PPM/serial signal check again in 2ms... TX_MAIN_PAUSE_off; tx_resume(); while(next_callback>4000) @@ -536,8 +539,8 @@ static void update_channels_aux(void) static void update_led_status(void) { if(IS_INPUT_SIGNAL_on) - if(millis()-last_signal>50) - INPUT_SIGNAL_off; //no valid signal (PPM or Serial) received for 50ms + if(millis()-last_signal>70) + INPUT_SIGNAL_off; //no valid signal (PPM or Serial) received for 70ms if(blink> 1; // divided by 2 + frame[5] = telemetry_rx_recv_pps >> 1; // divided by 2 break; case 13: // xjt t2 frame[2] = 0x05; frame[3] = 0x00; - frame[4] = 0; + frame[4] = telemetry_tx_recv_pps >> 1; // divided by 2 + frame[5] = 0; break; default: if(sport) @@ -963,7 +965,7 @@ ISR(TIMER0_COMPB_vect) else { // prepare next byte and allow for 2 stop bits - struct t_serial_bash *ptr = &SerialControl ; + volatile struct t_serial_bash *ptr = &SerialControl ; if ( ptr->head != ptr->tail ) { GPIOR0 = ptr->data[ptr->tail] ; @@ -1014,7 +1016,7 @@ ISR(TIMER0_OVF_vect) if ( --GPIOR1 == 0 ) { // prepare next byte - struct t_serial_bash *ptr = &SerialControl ; + volatile struct t_serial_bash *ptr = &SerialControl ; if ( ptr->head != ptr->tail ) { GPIOR0 = ptr->data[ptr->tail] ; diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index 0ecc831..bc16d7d 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -151,6 +151,7 @@ //In this section you can configure the NUNCHUCK. //If you do not plan to use the NUNCHUCK mode comment this line using "//" to save Flash space, you don't need to configure anything below in this case #define ENABLE_NUNCHUCK +// pont diviseur VCC --------------- 240K ------------- analogRead(0) -------------- 75K ----------- GND #define VBAT_PIN 3 // for Tx adapters with battery #define VBAT_VAL 340 // for Tx adapters with battery (attention pont divisieur pour avoir 1,1V max ,~=3,404V) #define VBAT_LIM 330 // for Tx adapters with battery (attention pont divisieur pour avoir 1,1V max , ~=3,302V) diff --git a/Multiprotocol/sync.ffs_db b/Multiprotocol/sync.ffs_db index bfdd61b..30f54e3 100644 Binary files a/Multiprotocol/sync.ffs_db and b/Multiprotocol/sync.ffs_db differ