mirror of
https://github.com/pascallanger/DIY-Multiprotocol-TX-Module.git
synced 2025-02-04 16:38:12 +00:00
Bugs protocol fix?
This commit is contained in:
parent
2589c67f6c
commit
e51f91f041
@ -26,8 +26,6 @@
|
||||
#define BUGSMINI_NUM_RF_CHANNELS 15
|
||||
#define BUGSMINI_ADDRESS_SIZE 5
|
||||
|
||||
static uint8_t BUGSMINI_armed, BUGSMINI_arm_flags;
|
||||
static uint8_t BUGSMINI_arm_channel_previous;
|
||||
static uint8_t BUGSMINI_txid[3];
|
||||
static uint8_t BUGSMINI_txhash;
|
||||
|
||||
@ -79,18 +77,18 @@ static void __attribute__((unused)) BUGSMINI_check_arming()
|
||||
{
|
||||
uint8_t arm_channel = BUGSMINI_CH_SW_ARM;
|
||||
|
||||
if (arm_channel != BUGSMINI_arm_channel_previous)
|
||||
if (arm_channel != arm_channel_previous)
|
||||
{
|
||||
BUGSMINI_arm_channel_previous = arm_channel;
|
||||
arm_channel_previous = arm_channel;
|
||||
if (arm_channel)
|
||||
{
|
||||
BUGSMINI_armed = 1;
|
||||
BUGSMINI_arm_flags ^= BUGSMINI_FLAG_ARM;
|
||||
armed = 1;
|
||||
arm_flags ^= BUGSMINI_FLAG_ARM;
|
||||
}
|
||||
else
|
||||
{
|
||||
BUGSMINI_armed = 0;
|
||||
BUGSMINI_arm_flags ^= BUGSMINI_FLAG_DISARM;
|
||||
armed = 0;
|
||||
arm_flags ^= BUGSMINI_FLAG_DISARM;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -101,7 +99,7 @@ static void __attribute__((unused)) BUGSMINI_send_packet(uint8_t bind)
|
||||
|
||||
uint16_t aileron = convert_channel_16b_limit(AILERON,500,0);
|
||||
uint16_t elevator = convert_channel_16b_limit(ELEVATOR,0,500);
|
||||
uint16_t throttle = BUGSMINI_armed ? convert_channel_16b_limit(THROTTLE,0,500) : 0;
|
||||
uint16_t throttle = armed ? convert_channel_16b_limit(THROTTLE,0,500) : 0;
|
||||
uint16_t rudder = convert_channel_16b_limit(RUDDER,500,0);
|
||||
|
||||
packet[1] = BUGSMINI_txid[0];
|
||||
@ -136,9 +134,9 @@ static void __attribute__((unused)) BUGSMINI_send_packet(uint8_t bind)
|
||||
| BUGSMINI_FLAG_MODE
|
||||
| GET_FLAG(BUGSMINI_CH_SW_PICTURE, BUGSMINI_FLAG_PICTURE)
|
||||
| GET_FLAG(BUGSMINI_CH_SW_VIDEO, BUGSMINI_FLAG_VIDEO);
|
||||
if(BUGSMINI_armed)
|
||||
if(armed)
|
||||
packet[12] |= GET_FLAG(BUGSMINI_CH_SW_FLIP, BUGSMINI_FLAG_FLIP);
|
||||
packet[13] = BUGSMINI_arm_flags
|
||||
packet[13] = arm_flags
|
||||
| GET_FLAG(BUGSMINI_CH_SW_LED, BUGSMINI_FLAG_LED)
|
||||
| GET_FLAG(BUGSMINI_CH_SW_ANGLE, BUGSMINI_FLAG_ANGLE);
|
||||
|
||||
@ -355,9 +353,12 @@ uint16_t initBUGSMINI()
|
||||
XN297_SetRXAddr(rx_tx_addr, 5);
|
||||
phase = BUGSMINI_DATA1;
|
||||
}
|
||||
BUGSMINI_armed = 0;
|
||||
BUGSMINI_arm_flags = BUGSMINI_FLAG_DISARM; // initial value from captures
|
||||
BUGSMINI_arm_channel_previous = BUGSMINI_CH_SW_ARM;
|
||||
armed = 0;
|
||||
arm_flags = BUGSMINI_FLAG_DISARM; // initial value from captures
|
||||
arm_channel_previous = BUGSMINI_CH_SW_ARM;
|
||||
#ifdef BUGS_HUB_TELEMETRY
|
||||
init_frskyd_link_telemetry();
|
||||
#endif
|
||||
return BUGSMINI_INITIAL_WAIT;
|
||||
}
|
||||
|
||||
|
@ -175,9 +175,6 @@ static uint32_t __attribute__((unused)) BUGS_rxid_to_radioid(uint16_t rxid)
|
||||
#define BUGS_PACKET_SIZE 22
|
||||
#define BUGS_NUM_RFCHAN 16
|
||||
|
||||
static uint8_t BUGS_armed, BUGS_arm_flags;
|
||||
static uint8_t BUGS_arm_channel_previous;
|
||||
|
||||
enum {
|
||||
BUGS_BIND_1,
|
||||
BUGS_BIND_2,
|
||||
@ -191,25 +188,25 @@ static void __attribute__((unused)) BUGS_check_arming()
|
||||
{
|
||||
uint8_t arm_channel = BUGS_CH_SW_ARM;
|
||||
|
||||
if (arm_channel != BUGS_arm_channel_previous)
|
||||
if (arm_channel != arm_channel_previous)
|
||||
{
|
||||
BUGS_arm_channel_previous = arm_channel;
|
||||
arm_channel_previous = arm_channel;
|
||||
if (arm_channel)
|
||||
{
|
||||
BUGS_armed = 1;
|
||||
BUGS_arm_flags ^= BUGS_FLAG_ARM;
|
||||
armed = 1;
|
||||
arm_flags ^= BUGS_FLAG_ARM;
|
||||
}
|
||||
else
|
||||
{
|
||||
BUGS_armed = 0;
|
||||
BUGS_arm_flags ^= BUGS_FLAG_DISARM;
|
||||
armed = 0;
|
||||
arm_flags ^= BUGS_FLAG_DISARM;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void __attribute__((unused)) BUGS_build_packet(uint8_t bind)
|
||||
{
|
||||
uint8_t force_values = bind | !BUGS_armed;
|
||||
uint8_t force_values = bind | !armed;
|
||||
uint8_t change_channel = ((packet_count & 0x1) << 6);
|
||||
uint16_t aileron = convert_channel_16b_limit(AILERON,800,0);
|
||||
uint16_t elevator = convert_channel_16b_limit(ELEVATOR,800,0);
|
||||
@ -225,7 +222,7 @@ static void __attribute__((unused)) BUGS_build_packet(uint8_t bind)
|
||||
if(bind)
|
||||
{
|
||||
packet[4] = change_channel | 0x80;
|
||||
packet[5] = 0x02 | BUGS_arm_flags
|
||||
packet[5] = 0x02 | arm_flags
|
||||
| GET_FLAG(BUGS_CH_SW_ANGLE, BUGS_FLAG_ANGLE);
|
||||
}
|
||||
else
|
||||
@ -234,7 +231,7 @@ static void __attribute__((unused)) BUGS_build_packet(uint8_t bind)
|
||||
| GET_FLAG(BUGS_CH_SW_FLIP, BUGS_FLAG_FLIP)
|
||||
| GET_FLAG(BUGS_CH_SW_PICTURE, BUGS_FLAG_PICTURE)
|
||||
| GET_FLAG(BUGS_CH_SW_VIDEO, BUGS_FLAG_VIDEO);
|
||||
packet[5] = 0x02 | BUGS_arm_flags
|
||||
packet[5] = 0x02 | arm_flags
|
||||
| GET_FLAG(BUGS_CH_SW_ANGLE, BUGS_FLAG_ANGLE)
|
||||
| GET_FLAG(BUGS_CH_SW_LED, BUGS_FLAG_LED);
|
||||
}
|
||||
@ -309,19 +306,20 @@ static void __attribute__((unused)) BUGS_increment_counts()
|
||||
}
|
||||
}
|
||||
|
||||
#define BUGS_DELAY_POST_TX 1100
|
||||
#define BUGS_DELAY_WAIT_TX 500
|
||||
#define BUGS_DELAY_WAIT_RX 2000
|
||||
#define BUGS_DELAY_POST_RX 2000
|
||||
#define BUGS_PACKET_PERIOD 6100
|
||||
#define BUGS_DELAY_TX 2000
|
||||
#define BUGS_DELAY_POST_RX 1500
|
||||
#define BUGS_DELAY_BIND_RST 200
|
||||
|
||||
// FIFO config is one less than desired value
|
||||
#define BUGS_FIFO_SIZE_RX 15
|
||||
#define BUGS_FIFO_SIZE_TX 21
|
||||
uint16_t ReadBUGS(void)
|
||||
{
|
||||
uint8_t mode, timeout, base_adr;
|
||||
uint8_t mode, base_adr;
|
||||
uint16_t rxid;
|
||||
uint32_t radio_id;
|
||||
uint16_t start;
|
||||
|
||||
// keep frequency tuning updated
|
||||
#ifndef FORCE_FLYSKY_TUNING
|
||||
@ -336,19 +334,15 @@ uint16_t ReadBUGS(void)
|
||||
A7105_WriteReg(A7105_03_FIFOI, BUGS_FIFO_SIZE_TX);
|
||||
A7105_WriteData(BUGS_PACKET_SIZE, hopping_frequency[hopping_frequency_no]);
|
||||
phase = BUGS_BIND_2;
|
||||
packet_period = BUGS_DELAY_POST_TX;
|
||||
packet_period = BUGS_DELAY_TX;
|
||||
break;
|
||||
|
||||
case BUGS_BIND_2:
|
||||
// wait here a bit for tx complete because
|
||||
// need to start rx immediately to catch return packet
|
||||
timeout = 20;
|
||||
while (A7105_ReadReg(A7105_00_MODE) & 0x01)
|
||||
if (timeout-- == 0)
|
||||
{
|
||||
packet_period = BUGS_DELAY_WAIT_TX; // don't proceed until transmission complete
|
||||
//Wait for TX completion
|
||||
start=micros();
|
||||
while ((uint16_t)micros()-start < 500) // Wait max 500µs, using serial+telemetry exit in about 60µs
|
||||
if(!(A7105_ReadReg(A7105_00_MODE) & 0x01))
|
||||
break;
|
||||
}
|
||||
A7105_SetTxRxMode(RX_EN);
|
||||
A7105_WriteReg(A7105_0F_PLL_I, hopping_frequency[hopping_frequency_no] - 2);
|
||||
A7105_WriteReg(A7105_03_FIFOI, BUGS_FIFO_SIZE_RX);
|
||||
@ -356,7 +350,7 @@ uint16_t ReadBUGS(void)
|
||||
|
||||
BUGS_increment_counts();
|
||||
phase = BUGS_BIND_3;
|
||||
packet_period = BUGS_DELAY_WAIT_RX;
|
||||
packet_period = BUGS_PACKET_PERIOD-BUGS_DELAY_TX-BUGS_DELAY_POST_RX;
|
||||
break;
|
||||
|
||||
case BUGS_BIND_3:
|
||||
@ -397,19 +391,15 @@ uint16_t ReadBUGS(void)
|
||||
A7105_WriteReg(A7105_03_FIFOI, BUGS_FIFO_SIZE_TX);
|
||||
A7105_WriteData(BUGS_PACKET_SIZE, hopping_frequency[hopping_frequency_no]);
|
||||
phase = BUGS_DATA_2;
|
||||
packet_period = BUGS_DELAY_POST_TX;
|
||||
packet_period = BUGS_DELAY_TX;
|
||||
break;
|
||||
|
||||
case BUGS_DATA_2:
|
||||
// wait here a bit for tx complete because
|
||||
// need to start rx immediately to catch return packet
|
||||
timeout = 20;
|
||||
while (A7105_ReadReg(A7105_00_MODE) & 0x01)
|
||||
if (timeout-- == 0)
|
||||
{
|
||||
packet_period = BUGS_DELAY_WAIT_TX; // don't proceed until transmission complete
|
||||
//Wait for TX completion
|
||||
start=micros();
|
||||
while ((uint16_t)micros()-start < 500) // Wait max 500µs, using serial+telemetry exit in about 60µs
|
||||
if(!(A7105_ReadReg(A7105_00_MODE) & 0x01))
|
||||
break;
|
||||
}
|
||||
A7105_SetTxRxMode(RX_EN);
|
||||
A7105_WriteReg(A7105_0F_PLL_I, hopping_frequency[hopping_frequency_no] - 2);
|
||||
A7105_WriteReg(A7105_03_FIFOI, BUGS_FIFO_SIZE_RX);
|
||||
@ -417,7 +407,7 @@ uint16_t ReadBUGS(void)
|
||||
|
||||
BUGS_increment_counts();
|
||||
phase = BUGS_DATA_3;
|
||||
packet_period = BUGS_DELAY_WAIT_RX;
|
||||
packet_period = BUGS_PACKET_PERIOD-BUGS_DELAY_TX-BUGS_DELAY_POST_RX;
|
||||
break;
|
||||
|
||||
case BUGS_DATA_3:
|
||||
@ -447,6 +437,13 @@ uint16_t ReadBUGS(void)
|
||||
|
||||
uint16_t initBUGS(void)
|
||||
{
|
||||
uint32_t radio_id=0;
|
||||
uint8_t base_adr=BUGS_EEPROM_OFFSET+RX_num*4;
|
||||
for(uint8_t i=0; i<4; i++)
|
||||
radio_id|=eeprom_read_byte((EE_ADDR)(base_adr+i))<<(i*8);
|
||||
if(radio_id==0xffffffff)
|
||||
BIND_IN_PROGRESS;
|
||||
|
||||
BUGS_set_radio_data();
|
||||
if (IS_BIND_IN_PROGRESS)
|
||||
phase = BUGS_BIND_1;
|
||||
@ -457,9 +454,12 @@ uint16_t initBUGS(void)
|
||||
|
||||
hopping_frequency_no = 0;
|
||||
packet_count = 0;
|
||||
BUGS_armed = 0;
|
||||
BUGS_arm_flags = BUGS_FLAG_DISARM; // initial value from captures
|
||||
BUGS_arm_channel_previous = BUGS_CH_SW_ARM;
|
||||
armed = 0;
|
||||
arm_flags = BUGS_FLAG_DISARM; // initial value from captures
|
||||
arm_channel_previous = BUGS_CH_SW_ARM;
|
||||
#ifdef BUGS_HUB_TELEMETRY
|
||||
init_frskyd_link_telemetry();
|
||||
#endif
|
||||
|
||||
return 10000;
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
#define VERSION_MAJOR 1
|
||||
#define VERSION_MINOR 2
|
||||
#define VERSION_REVISION 1
|
||||
#define VERSION_PATCH_LEVEL 6
|
||||
#define VERSION_PATCH_LEVEL 7
|
||||
|
||||
//******************
|
||||
// Protocols
|
||||
@ -71,6 +71,7 @@ enum PROTOCOLS
|
||||
PROTO_BUGSMINI = 42, // =>NRF24L01
|
||||
PROTO_TRAXXAS = 43, // =>CYRF6936
|
||||
PROTO_NCC1701 = 44, // =>NRF24L01
|
||||
PROTO_E01X = 45, // =>NRF24L01
|
||||
PROTO_TEST = 63, // =>NRF24L01
|
||||
};
|
||||
|
||||
@ -247,6 +248,11 @@ enum HITEC
|
||||
OPT_HUB = 1,
|
||||
MINIMA = 2,
|
||||
};
|
||||
enum E01X
|
||||
{
|
||||
E012 = 0,
|
||||
E015 = 1,
|
||||
};
|
||||
|
||||
#define NONE 0
|
||||
#define P_HIGH 1
|
||||
@ -365,7 +371,7 @@ enum MultiPacketTypes
|
||||
uint16_t debug_time=0;
|
||||
#define debug(msg, ...) {char buf[64]; sprintf(buf, msg, ##__VA_ARGS__); Serial.write(buf);}
|
||||
#define debugln(msg, ...) {char buf[64]; sprintf(buf, msg "\r\n", ##__VA_ARGS__); Serial.write(buf);}
|
||||
#define debug_time(msg) { uint16_t debug_time_TCNT1=TCNT1; debug_time=debug_time_TCNT1-debug_time; debugln(msg "%u", debug_time); debug_time=debug_time_TCNT1; }
|
||||
#define debug_time(msg) { uint16_t debug_time_TCNT1=TCNT1; debug_time=debug_time_TCNT1-debug_time; debugln(msg "%u", debug_time>>1); debug_time=debug_time_TCNT1; }
|
||||
#else
|
||||
#define debug(...) { }
|
||||
#define debugln(...) { }
|
||||
@ -585,6 +591,7 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p --
|
||||
BUGSMINI 42
|
||||
TRAXXAS 43
|
||||
NCC1701 44
|
||||
E01X 45
|
||||
BindBit=> 0x80 1=Bind/0=No
|
||||
AutoBindBit=> 0x40 1=Yes /0=No
|
||||
RangeCheck=> 0x20 1=Yes /0=No
|
||||
@ -712,6 +719,9 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p --
|
||||
Q100 2
|
||||
Q200 3
|
||||
MR100 4
|
||||
sub_protocol==E01X
|
||||
E012 0
|
||||
E015 1
|
||||
|
||||
Power value => 0x80 0=High/1=Low
|
||||
Stream[3] = option_protocol;
|
||||
|
Loading…
x
Reference in New Issue
Block a user