JJRC345: last commit

This commit is contained in:
Pascal Langer 2020-05-22 21:03:01 +02:00
parent b31bbfa04f
commit cffe66747a

View File

@ -18,7 +18,7 @@
#include "iface_nrf24l01.h" #include "iface_nrf24l01.h"
#define JJRC345_FORCE_ID //#define JJRC345_FORCE_ID
#define JJRC345_PACKET_PERIOD 7450 // Timeout for callback in uSec #define JJRC345_PACKET_PERIOD 7450 // Timeout for callback in uSec
#define JJRC345_INITIAL_WAIT 500 #define JJRC345_INITIAL_WAIT 500
@ -37,15 +37,15 @@ enum JJRC345_FLAGS {
static uint8_t __attribute__((unused)) JJRC345_convert_channel(uint8_t num) static uint8_t __attribute__((unused)) JJRC345_convert_channel(uint8_t num)
{ {
uint8_t val=convert_channel_8b(num); uint8_t val=convert_channel_8b(num);
// 70..60..41..01, 80 center, 81..C1..E0..F0 // 7E..60..41..01, 80 center, 81..C1..E0..FE
if(val<0x80) if(val<0x80)
{ {
val=0x80-val; // 80..01 val=0x80-val; // 80..01
if(val>0x70) if(val>0x7E)
val=0x70; // 70..01 val=0x7E; // 7E..01
} }
else if(val>0xF0) else if(val>0xFE)
val=0xF0; // 81..F0 val=0xFE; // 81..FE
return val; return val;
} }
@ -55,7 +55,6 @@ static void __attribute__((unused)) JJRC345_send_packet()
packet[2] = 0x00; packet[2] = 0x00;
if (IS_BIND_IN_PROGRESS) if (IS_BIND_IN_PROGRESS)
{ //00 05 00 0A 46 4A 41 47 00 00 40 46 A5 4A F1 18 { //00 05 00 0A 46 4A 41 47 00 00 40 46 A5 4A F1 18
debug("CH:%d,",JJRC345_RF_BIND_CHANNEL);
packet[1] = JJRC345_RF_BIND_CHANNEL; packet[1] = JJRC345_RF_BIND_CHANNEL;
packet[4] = hopping_frequency[0]; packet[4] = hopping_frequency[0];
packet[5] = hopping_frequency[1]; packet[5] = hopping_frequency[1];
@ -66,7 +65,6 @@ static void __attribute__((unused)) JJRC345_send_packet()
else else
{ //00 41 00 0A 00 80 80 80 00 00 40 46 00 49 F1 18 { //00 41 00 0A 00 80 80 80 00 00 40 46 00 49 F1 18
NRF24L01_WriteReg(NRF24L01_05_RF_CH, hopping_frequency[hopping_frequency_no]); NRF24L01_WriteReg(NRF24L01_05_RF_CH, hopping_frequency[hopping_frequency_no]);
debug("CH:%d,", hopping_frequency[hopping_frequency_no]);
hopping_frequency_no++; hopping_frequency_no++;
hopping_frequency_no %= JJRC345_NUM_CHANNELS; hopping_frequency_no %= JJRC345_NUM_CHANNELS;
packet[1] = hopping_frequency[hopping_frequency_no]; // next packet will be sent on this channel packet[1] = hopping_frequency[hopping_frequency_no]; // next packet will be sent on this channel
@ -78,19 +76,20 @@ static void __attribute__((unused)) JJRC345_send_packet()
if(CH5_SW) //Flip if(CH5_SW) //Flip
{ {
if(packet[6]>90) if(packet[6]>0x90)
packet[6]=0xFF; packet[6]=0xFF;
else if(packet[6]<80 && packet[6]>10) else if(packet[6]<0x80 && packet[6]>0x10)
packet[6]=0x7F; packet[6]=0x7F;
else if(packet[7]>90) else if(packet[7]>0x90)
packet[7]=0xFF; packet[7]=0xFF;
else if(packet[7]<80 && packet[7]>10) else if(packet[7]<0x80 && packet[7]>0x10)
packet[7]=0x7F; packet[7]=0x7F;
} }
packet[12] = 0x02; // Rate: 00-01-02 packet[12] = 0x02; // Rate: 00-01-02
} }
packet[3] = (packet[4] >= 0xB7) ? 0x0e : 0x0a; // Some flag or check... 0A when Thr <= B6, 0E when Thr >= B7, sometimes 06 when moving Ele/Ail
packet[3] = 0x00; // Checksum upper bits
packet[8] = 0x00 // Rudder trim, 00 when not used, 01..1F when trimmed left, 20..3F packet[8] = 0x00 // Rudder trim, 00 when not used, 01..1F when trimmed left, 20..3F
| GET_FLAG(CH6_SW,JJRC345_FLAG_HEADLESS) // Headless mode: 00 normal, 40 headless | GET_FLAG(CH6_SW,JJRC345_FLAG_HEADLESS) // Headless mode: 00 normal, 40 headless
@ -101,19 +100,15 @@ static void __attribute__((unused)) JJRC345_send_packet()
packet[11] = hopping_frequency[0]; // First hopping frequency packet[11] = hopping_frequency[0]; // First hopping frequency
// Checksum // Checksum
packet[13] = 0x02-packet[3]; uint16_t sum=2;
for (uint8_t i = 0; i < 13; i++) for (uint8_t i = 0; i < 13; i++)
{ sum += packet[i];
debug(" %02X", packet[i]); packet[13]=sum;
packet[13] += packet[i]; packet[3]=((sum>>8)<<2)+2;
}
debug("%02X ", packet[13]);
// TX ID // TX ID
packet[14] = rx_tx_addr[2]; packet[14] = rx_tx_addr[2];
debug(" %02X", packet[14]);
packet[15] = rx_tx_addr[3]; packet[15] = rx_tx_addr[3];
debugln(" %02X", packet[15]);
// Power on, TX mode // Power on, TX mode
XN297_Configure(_BV(NRF24L01_00_EN_CRC) | _BV(NRF24L01_00_CRCO) | _BV(NRF24L01_00_PWR_UP)); XN297_Configure(_BV(NRF24L01_00_EN_CRC) | _BV(NRF24L01_00_CRCO) | _BV(NRF24L01_00_PWR_UP));