diff --git a/Multiprotocol/Bayang_nrf24l01.ino b/Multiprotocol/Bayang_nrf24l01.ino index 043dd0c..3d5af6a 100644 --- a/Multiprotocol/Bayang_nrf24l01.ino +++ b/Multiprotocol/Bayang_nrf24l01.ino @@ -25,6 +25,7 @@ Multiprotocol is distributed in the hope that it will be useful, #define BAYANG_PACKET_SIZE 15 #define BAYANG_RF_NUM_CHANNELS 4 #define BAYANG_RF_BIND_CHANNEL 0 +#define BAYANG_RF_BIND_CHANNEL_X16_AH 10 #define BAYANG_ADDRESS_LENGTH 5 enum BAYANG_FLAGS { @@ -35,9 +36,12 @@ enum BAYANG_FLAGS { BAYANG_FLAG_VIDEO = 0x10, BAYANG_FLAG_PICTURE = 0x20, // flags going to packet[3] - BAYANG_FLAG_INVERTED = 0x80 // inverted flight on Floureon H101 + BAYANG_FLAG_INVERTED = 0x80, // inverted flight on Floureon H101 + BAYANG_FLAG_TAKE_OFF = 0x20, // take off / landing on X16 AH }; +uint8_t bayang_bind_chan; + static void __attribute__((unused)) BAYANG_send_packet(uint8_t bind) { uint8_t i; @@ -53,15 +57,29 @@ static void __attribute__((unused)) BAYANG_send_packet(uint8_t bind) packet[i+1]=rx_tx_addr[i]; for(i=0;i<4;i++) packet[i+6]=hopping_frequency[i]; - packet[10] = rx_tx_addr[0]; // txid[0] - packet[11] = rx_tx_addr[1]; // txid[1] + switch (sub_protocol) { + case X16_AH: + packet[10] = 0x00; + packet[11] = 0x00; + break; + default: + packet[10] = rx_tx_addr[0]; // txid[0] + packet[11] = rx_tx_addr[1]; // txid[1] + break; + } } else { uint16_t val; - packet[0] = 0xA5; + switch (sub_protocol) { + case X16_AH: + packet[0] = 0xA6; + break; + default: + packet[0] = 0xA5; + break; + } packet[1] = 0xFA; // normal mode is 0xf7, expert 0xfa - //Flags packet[2] packet[2] = 0x00; if(Servo_AUX1) @@ -78,7 +96,8 @@ static void __attribute__((unused)) BAYANG_send_packet(uint8_t bind) packet[3] = 0x00; if(Servo_AUX6) packet[3] = BAYANG_FLAG_INVERTED; - + if(Servo_AUX7) + packet[3] |= BAYANG_FLAG_TAKE_OFF; //Aileron val = convert_channel_10b(AILERON); packet[4] = (val>>8) + ((val>>2) & 0xFC); @@ -96,13 +115,26 @@ static void __attribute__((unused)) BAYANG_send_packet(uint8_t bind) packet[10] = (val>>8) + (val>>2 & 0xFC); packet[11] = val & 0xFF; } - packet[12] = rx_tx_addr[2]; // txid[2] - packet[13] = sub_protocol==H8S3D?0x34:0x0A; + switch (sub_protocol) { + case H8S3D: + packet[12] = rx_tx_addr[2]; // txid[2] + packet[13] = 0x34; + break; + case X16_AH: + packet[12] = 0; + packet[13] = 0; + break; + default: + packet[12] = rx_tx_addr[2]; // txid[2] + packet[13] = 0x0A; + break; + } + packet[14] = 0; for (uint8_t i=0; i < BAYANG_PACKET_SIZE-1; i++) packet[14] += packet[i]; - NRF24L01_WriteReg(NRF24L01_05_RF_CH, bind ? BAYANG_RF_BIND_CHANNEL:hopping_frequency[hopping_frequency_no++]); + NRF24L01_WriteReg(NRF24L01_05_RF_CH, bind ? bayang_bind_chan:hopping_frequency[hopping_frequency_no++]); hopping_frequency_no%=BAYANG_RF_NUM_CHANNELS; // clear packet status bits and TX FIFO @@ -180,6 +212,15 @@ static void __attribute__((unused)) BAYANG_init() NRF24L01_WriteReg(NRF24L01_1C_DYNPD, 0x00); // Disable dynamic payload length on all pipes NRF24L01_WriteReg(NRF24L01_1D_FEATURE, 0x01); NRF24L01_Activate(0x73); + + switch(sub_protocol) { + case X16_AH: + bayang_bind_chan = BAYANG_RF_BIND_CHANNEL_X16_AH; + break; + default: + bayang_bind_chan = BAYANG_RF_BIND_CHANNEL; + break; + } } uint16_t BAYANG_callback() diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index c7173e4..69e998e 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -136,7 +136,8 @@ enum CG023 enum BAYANG { BAYANG = 0, - H8S3D = 1 + H8S3D = 1, + X16_AH = 2, }; enum MT99XX { @@ -537,6 +538,7 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p -- sub_protocol==BAYANG BAYANG 0 H8S3D 1 + X16_AH 2 sub_protocol==MT99XX MT99 0 H7 1 diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index 513ca8b..92a4529 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -305,6 +305,7 @@ const PPM_Parameters PPM_prot[15]= { MODE_BAYANG BAYANG H8S3D + X16_AH MODE_ESKY NONE MODE_MT99XX