/*
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 XK TX X4 and model A160S.
#if defined(XK2_CCNRF_INO)
#include "iface_xn297.h"
#define FORCE_XK2_ID
#define XK2_RF_BIND_CHANNEL 71
#define XK2_PAYLOAD_SIZE 9
#define XK2_PACKET_PERIOD 4911
#define XK2_RF_NUM_CHANNELS 4
enum {
XK2_BIND1,
XK2_BIND2,
XK2_DATA_PREP,
XK2_DATA
};
static void __attribute__((unused)) XK2_send_packet()
{
static uint8_t trim_ch=0;
if(IS_BIND_IN_PROGRESS)
{
packet[0] = 0x9D;
//TXID
memcpy(&packet[1], rx_tx_addr, 3);
//RXID
//memcpy(&packet[4], rx_id , 3);
//Unknown
packet[7] = 0x00;
//Checksum seed
packet[8] = 0xC0; //Constant?
}
else
{
XN297_Hopping(hopping_frequency_no);
hopping_frequency_no++;
hopping_frequency_no &= 0x03;
//Channels
packet[0] = convert_channel_16b_limit(AILERON ,0x00,0x64); //Aileron
packet[1] = convert_channel_16b_limit(ELEVATOR,0x00,0x64); //Elevator
packet[2] = convert_channel_16b_limit(THROTTLE,0x00,0x64); //Throttle
packet[3] = convert_channel_16b_limit(RUDDER ,0x00,0x64); //Rudder
//Center the trims
trim_ch++;
if(trim_ch > 2) trim_ch = 0;
packet[4] = 0x20 + 0x40 * trim_ch; //Trims are A=01..20..3F/E=41..60..7F/R=81..A0..BF, E0 appears when telemetry is received, C1 when p[6] changes from 00->08, C0 when p[6] changes from 08->00
if(trim_ch == 2) //Drive rudder trim since otherwise there is no control...
{
packet[4] = 0x80 + (convert_channel_8b(RUDDER)>>2);
if(packet[4] <= 0x81) packet[4] = 0x81;
}
//Flags
packet[5] = GET_FLAG(CH5_SW, 0x01) //Rate
| GET_FLAG(CH6_SW, 0x08) //Mode
| GET_FLAG(CH7_SW, 0x20); //Hover
//Telemetry not received=00, Telemetry received=01 but sometimes switch to 1 even if telemetry is not there...
packet[6] = 0x00;
//Unknown
packet[7] = 0x5A; //Constant?
//Checksum seed
packet[8] = 0x7F; //Constant?
}
//Checksum
for(uint8_t i=0; i