/*
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 .
Thanks to Goebish ,Ported from his deviation firmware
*/
#if defined(V761_NRF24L01_INO)
#include "iface_xn297.h"
//#define V761_FORCE_ID
#define V761_PACKET_PERIOD 7060 // Timeout for callback in uSec
#define V761_INITIAL_WAIT 500
#define V761_PACKET_SIZE 8
#define V761_BIND_COUNT 200
#define V761_BIND_FREQ 0x28
#define V761_RF_NUM_CHANNELS 3
enum
{
V761_BIND1 = 0,
V761_BIND2,
V761_DATA
};
static void __attribute__((unused)) V761_set_checksum()
{
uint8_t checksum = packet[0];
for(uint8_t i=1; i= V761_RF_NUM_CHANNELS)
{
hopping_frequency_no = 0;
packet_count++;
if(packet_count >= 4)
packet_count = 0;
}
packet[0] = convert_channel_8b(THROTTLE); // Throttle
packet[2] = convert_channel_8b(ELEVATOR)>>1; // Elevator
if(sub_protocol==V761_3CH)
{
packet[1] = convert_channel_8b(RUDDER)>>1; // Rudder
packet[3] = convert_channel_8b(AILERON)>>1; // Aileron
}
else
{
packet[1] = convert_channel_8b(AILERON)>>1; // Aileron
packet[3] = convert_channel_8b(RUDDER)>>1; // Rudder
}
packet[5] = packet_count<<6; // 0X, 4X, 8X, CX
packet[4] = 0x20; // Trims 00..20..40, 0X->20 4X->TrAil 8X->TrEle CX->TrRud
if(CH5_SW) // Mode Expert Gyro off
flags = 0x0c;
else
if(Channel_data[CH5] < CHANNEL_MIN_COMMAND)
flags = 0x08; // Beginer mode (Gyro on, yaw and pitch rate limited)
else
flags = 0x0a; // Mid Mode ( Gyro on no rate limits)
if(!prev_ch6 && CH6_SW) // -100% -> 100% launch gyro calib
calib=!calib;
prev_ch6 = CH6_SW;
if(calib)
flags |= 0x01; // Gyro calibration
packet[5] |= flags;
packet[6] = GET_FLAG(CH7_SW, 0x20) // Flip
|GET_FLAG(CH8_SW, 0x08) // RTH activation
|GET_FLAG(CH9_SW, 0x10); // RTH on/off
if(sub_protocol==V761_3CH)
packet[6] |= 0x80; // Unknown, set on original V761-1 dump but not on eachine dumps, keeping for compatibility
}
V761_set_checksum();
#if 0
debug("H:%02X P:",hopping_frequency_no);
for(uint8_t i=0;i= 20)
{
packet_count = 0;
phase = V761_BIND2;
}
return 15730;
case V761_BIND2:
if(bind_counter)
bind_counter--;
packet_count ++;
XN297_Hopping(0);
XN297_SetTXAddr(rx_tx_addr, 4);
V761_send_packet();
if(bind_counter == 0)
{
packet_count = 0;
BIND_DONE;
phase = V761_DATA;
}
else if(packet_count >= 20)
{
packet_count = 0;
phase = V761_BIND1;
}
return 15730;
case V761_DATA:
#ifdef MULTI_SYNC
telemetry_set_input_sync(V761_PACKET_PERIOD);
#endif
V761_send_packet();
break;
}
return V761_PACKET_PERIOD;
}
void V761_init(void)
{
V761_initialize_txid();
if(IS_BIND_IN_PROGRESS)
{
bind_counter = V761_BIND_COUNT;
phase = V761_BIND1;
}
else
{
XN297_SetTXAddr(rx_tx_addr, 4);
phase = V761_DATA;
}
V761_RF_init();
hopping_frequency_no = 0;
packet_count = 0;
}
#endif