Skip to content

Commit

Permalink
JJRC345: last commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Pascal Langer committed May 22, 2020
1 parent b31bbfa commit cffe667
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions Multiprotocol/JJRC345_nrf24l01.ino
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include "iface_nrf24l01.h"

#define JJRC345_FORCE_ID
//#define JJRC345_FORCE_ID

#define JJRC345_PACKET_PERIOD 7450 // Timeout for callback in uSec
#define JJRC345_INITIAL_WAIT 500
Expand All @@ -37,15 +37,15 @@ enum JJRC345_FLAGS {
static uint8_t __attribute__((unused)) JJRC345_convert_channel(uint8_t 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)
{
val=0x80-val; // 80..01
if(val>0x70)
val=0x70; // 70..01
if(val>0x7E)
val=0x7E; // 7E..01
}
else if(val>0xF0)
val=0xF0; // 81..F0
else if(val>0xFE)
val=0xFE; // 81..FE
return val;
}

Expand All @@ -55,7 +55,6 @@ static void __attribute__((unused)) JJRC345_send_packet()
packet[2] = 0x00;
if (IS_BIND_IN_PROGRESS)
{ //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[4] = hopping_frequency[0];
packet[5] = hopping_frequency[1];
Expand All @@ -66,7 +65,6 @@ static void __attribute__((unused)) JJRC345_send_packet()
else
{ //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]);
debug("CH:%d,", hopping_frequency[hopping_frequency_no]);
hopping_frequency_no++;
hopping_frequency_no %= JJRC345_NUM_CHANNELS;
packet[1] = hopping_frequency[hopping_frequency_no]; // next packet will be sent on this channel
Expand All @@ -78,19 +76,20 @@ static void __attribute__((unused)) JJRC345_send_packet()

if(CH5_SW) //Flip
{
if(packet[6]>90)
if(packet[6]>0x90)
packet[6]=0xFF;
else if(packet[6]<80 && packet[6]>10)
else if(packet[6]<0x80 && packet[6]>0x10)
packet[6]=0x7F;
else if(packet[7]>90)
else if(packet[7]>0x90)
packet[7]=0xFF;
else if(packet[7]<80 && packet[7]>10)
else if(packet[7]<0x80 && packet[7]>0x10)
packet[7]=0x7F;
}

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
| GET_FLAG(CH6_SW,JJRC345_FLAG_HEADLESS) // Headless mode: 00 normal, 40 headless
Expand All @@ -101,19 +100,15 @@ static void __attribute__((unused)) JJRC345_send_packet()
packet[11] = hopping_frequency[0]; // First hopping frequency

// Checksum
packet[13] = 0x02-packet[3];
uint16_t sum=2;
for (uint8_t i = 0; i < 13; i++)
{
debug(" %02X", packet[i]);
packet[13] += packet[i];
}
debug("%02X ", packet[13]);
sum += packet[i];
packet[13]=sum;
packet[3]=((sum>>8)<<2)+2;

// TX ID
packet[14] = rx_tx_addr[2];
debug(" %02X", packet[14]);
packet[15] = rx_tx_addr[3];
debugln(" %02X", packet[15]);

// Power on, TX mode
XN297_Configure(_BV(NRF24L01_00_EN_CRC) | _BV(NRF24L01_00_CRCO) | _BV(NRF24L01_00_PWR_UP));
Expand Down

0 comments on commit cffe667

Please sign in to comment.