diff --git a/Multiprotocol/Bayang_nrf24l01.ino b/Multiprotocol/Bayang_nrf24l01.ino index 8e761bf..226a06c 100644 --- a/Multiprotocol/Bayang_nrf24l01.ino +++ b/Multiprotocol/Bayang_nrf24l01.ino @@ -285,7 +285,7 @@ uint16_t BAYANG_callback() switch(phase) { case BAYANG_BIND: - if (bind_counter-- == 0) + if (--bind_counter == 0) { XN297_SetTXAddr(rx_tx_addr, BAYANG_ADDRESS_LENGTH); #ifdef BAYANG_HUB_TELEMETRY @@ -326,7 +326,6 @@ uint16_t BAYANG_callback() while ((uint16_t)((uint16_t)micros()-(uint16_t)start) < 1000) // Wait max 1ms if((NRF24L01_ReadReg(NRF24L01_07_STATUS) & _BV(NRF24L01_07_TX_DS))) break; - debugln("time: %d",(uint16_t)((uint16_t)micros()-(uint16_t)start)); NRF24L01_WriteReg(NRF24L01_00_CONFIG, 0x03); phase++; // READ return BAYANG_PACKET_TELEM_PERIOD - BAYANG_CHECK_DELAY - BAYANG_READ_DELAY; diff --git a/Multiprotocol/Multi.txt b/Multiprotocol/Multi.txt index 5bb313d..176f24a 100644 --- a/Multiprotocol/Multi.txt +++ b/Multiprotocol/Multi.txt @@ -43,7 +43,7 @@ 43,Traxxas,RX6519 44,NCC1701 45,E01X,E012,E015,E016H -46,V911S +46,V911S,Std 47,GD00X,GD_V1,GD_V2 48,V761 49,KF606 @@ -59,4 +59,5 @@ 59,Bayang_RX 60,Pelikan 61,Tiger +62,XK,X450,X420 63,XN_DUMP,250K,1M,2M,AUTO diff --git a/Multiprotocol/Multi_Names.ino b/Multiprotocol/Multi_Names.ino index eb4eda8..120d4be 100644 --- a/Multiprotocol/Multi_Names.ino +++ b/Multiprotocol/Multi_Names.ino @@ -75,6 +75,7 @@ const char STR_FX816[] ="FX816"; const char STR_BAYANG_RX[] ="BayanRX"; const char STR_PELIKAN[] ="Pelikan"; const char STR_TIGER[] ="Tiger"; +const char STR_XK[] ="XK"; const char STR_XN297DUMP[] ="XN297DP"; const char STR_SUBTYPE_FLYSKY[] = "\x04""Std\0""V9x9""V6x6""V912""CX20"; @@ -115,6 +116,7 @@ const char STR_SUBTYPE_FX816[] = "\x03""P38"; const char STR_SUBTYPE_XN297DUMP[] = "\x07""250Kbps""1Mbps\0 ""2Mbps\0 ""Auto\0 "; const char STR_SUBTYPE_ESKY150[] = "\x03""4CH""7CH"; const char STR_SUBTYPE_V911S[] = "\x04""Std\0""E119"; +const char STR_SUBTYPE_XK[] = "\x04""X450""X420"; enum { @@ -313,6 +315,9 @@ const mm_protocol_definition multi_protocols[] = { #if defined(TIGER_NRF24L01_INO) {PROTO_TIGER, STR_TIGER , 0, NO_SUBTYPE, OPTION_NONE }, #endif +#if defined(XK_NRF24L01_INO) + {PROTO_XK, STR_XK , 2, STR_SUBTYPE_XK, OPTION_RFTUNE }, +#endif #if defined(XN297DUMP_NRF24L01_INO) {PROTO_XN297DUMP, STR_XN297DUMP, 4, STR_SUBTYPE_XN297DUMP, OPTION_RFCHAN }, #endif diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index 73de653..46b4044 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 0 -#define VERSION_PATCH_LEVEL 56 +#define VERSION_PATCH_LEVEL 57 //****************** // Protocols @@ -88,6 +88,7 @@ enum PROTOCOLS PROTO_BAYANG_RX = 59, // =>NRF24L01 PROTO_PELIKAN = 60, // =>A7105 PROTO_TIGER = 61, // =>NRF24L01 + PROTO_XK = 62, // =>NRF24L01 PROTO_XN297DUMP = 63, // =>NRF24L01 }; @@ -305,6 +306,11 @@ enum V911S V911S_STD = 0, V911S_E119 = 1, }; +enum XK +{ + X450 = 0, + X420 = 1, +}; enum XN297DUMP { XN297DUMP_250K = 0, @@ -703,6 +709,8 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p -- BAYANG_RX 59 PELIKAN 60 TIGER 61 + XK 62 + XN297DUMP 63 BindBit=> 0x80 1=Bind/0=No AutoBindBit=> 0x40 1=Yes /0=No RangeCheck=> 0x20 1=Yes /0=No @@ -850,6 +858,12 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p -- sub_protocol==V911S V911S_STD 0 V911S_E119 1 + sub_protocol==XK + X450 0 + X420 1 + sub_protocol==V911S + V911S_STD 0 + V911S_E119 1 Power value => 0x80 0=High/1=Low Stream[3] = option_protocol; diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index 1a5b461..771c8df 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -1478,6 +1478,12 @@ static void protocol_init() remote_callback = TIGER_callback; break; #endif + #if defined(XK_NRF24L01_INO) + case PROTO_XK: + next_callback=initXK(); + remote_callback = XK_callback; + break; + #endif #if defined(XN297DUMP_NRF24L01_INO) case PROTO_XN297DUMP: next_callback=initXN297Dump(); diff --git a/Multiprotocol/Validate.h b/Multiprotocol/Validate.h index 50906f1..8159fef 100644 --- a/Multiprotocol/Validate.h +++ b/Multiprotocol/Validate.h @@ -248,6 +248,7 @@ #undef ZSX_NRF24L01_INO #undef BAYANG_RX_NRF24L01_INO #undef TIGER_NRF24L01_INO + #undef XK_NRF24L01_INO #endif //Make sure telemetry is selected correctly diff --git a/Multiprotocol/XK_nrf24l01.ino b/Multiprotocol/XK_nrf24l01.ino new file mode 100644 index 0000000..ad808de --- /dev/null +++ b/Multiprotocol/XK_nrf24l01.ino @@ -0,0 +1,179 @@ +/* + This project is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + +Multiprotocol is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Multiprotocol. If not, see . + */ +// Compatible with X450 and X420 plane. + +#if defined(XK_NRF24L01_INO) + +#include "iface_xn297l.h" + +#define FORCE_XK_ORIGINAL_ID + +#define XK_INITIAL_WAIT 500 +#define XK_PACKET_PERIOD 4000 +#define XK_RF_BIND_NUM_CHANNELS 8 +#define XK_RF_NUM_CHANNELS 4 +#define XK_PAYLOAD_SIZE 16 +#define XK_BIND_COUNT 750 //3sec + +static uint16_t __attribute__((unused)) XK_convert_channel(uint8_t num) +{ + uint16_t val=convert_channel_10b(num); + // 1FF..01=left, 00=center, 200..3FF=right + if(val==0x200) + val=0; // 0 + else + if(val>0x200) + val--; // 200..3FE + else + { + val=0x200-val; // 200..01 + if(val==0x200) + val--; // 1FF..01 + } + return val; +} + +static void __attribute__((unused)) XK_send_packet() +{ + memset(packet,0x00,16); + + memcpy(&packet[7],rx_tx_addr,3); + packet[12]=0x40; + packet[13]=0x40; + if(IS_BIND_IN_PROGRESS) + packet[14] = 0xC0; + else + { + uint16_t val=convert_channel_10b(THROTTLE); + packet[0] = val>>2; // 0..255 + packet[12] |= val & 2; + val=XK_convert_channel(RUDDER); + packet[1] = val>>2; + packet[12] |= (val & 2)<<2; + val=XK_convert_channel(ELEVATOR); + packet[2] = val>>2; + packet[13] |= val & 2; + val=XK_convert_channel(AILERON); + packet[3] = val>>2; + packet[13] |= (val & 2)<<2; + + memset(&packet[4],0x40,3); // Trims + + if(Channel_data[CH5] > CHANNEL_MAX_COMMAND) + packet[10] = 0x10; // V-Mode + else + if(Channel_data[CH5] > CHANNEL_MIN_COMMAND) + packet[10] = 0x04; // 6G-Mode + //0x00 default M-Mode + packet[10] |= GET_FLAG(CH7_SW,0x80); // Emergency stop momentary switch + + packet[11] = GET_FLAG(CH8_SW,0x03) // 3D/6G momentary switch + |GET_FLAG(CH6_SW,0x40); // Take off momentary switch + packet[14] = GET_FLAG(CH9_SW,0x01); // Photo momentary switch + } + + crc=packet[0]; + for(uint8_t i=1; i>1)]); + XN297L_Hopping((IS_BIND_IN_PROGRESS?0:XK_RF_BIND_NUM_CHANNELS)+(hopping_frequency_no>>1)); + hopping_frequency_no++; + if(hopping_frequency_no >= (IS_BIND_IN_PROGRESS?XK_RF_BIND_NUM_CHANNELS*2:XK_RF_NUM_CHANNELS*2)) + hopping_frequency_no=0; + + XN297L_WritePayload(packet, XK_PAYLOAD_SIZE); + //for(uint8_t i=0; i