Skip to content

Commit cffe667

Browse files
author
Pascal Langer
committed
JJRC345: last commit
1 parent b31bbfa commit cffe667

1 file changed

Lines changed: 16 additions & 21 deletions

File tree

Multiprotocol/JJRC345_nrf24l01.ino

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
#include "iface_nrf24l01.h"
2020

21-
#define JJRC345_FORCE_ID
21+
//#define JJRC345_FORCE_ID
2222

2323
#define JJRC345_PACKET_PERIOD 7450 // Timeout for callback in uSec
2424
#define JJRC345_INITIAL_WAIT 500
@@ -37,15 +37,15 @@ enum JJRC345_FLAGS {
3737
static uint8_t __attribute__((unused)) JJRC345_convert_channel(uint8_t num)
3838
{
3939
uint8_t val=convert_channel_8b(num);
40-
// 70..60..41..01, 80 center, 81..C1..E0..F0
40+
// 7E..60..41..01, 80 center, 81..C1..E0..FE
4141
if(val<0x80)
4242
{
4343
val=0x80-val; // 80..01
44-
if(val>0x70)
45-
val=0x70; // 70..01
44+
if(val>0x7E)
45+
val=0x7E; // 7E..01
4646
}
47-
else if(val>0xF0)
48-
val=0xF0; // 81..F0
47+
else if(val>0xFE)
48+
val=0xFE; // 81..FE
4949
return val;
5050
}
5151

@@ -55,7 +55,6 @@ static void __attribute__((unused)) JJRC345_send_packet()
5555
packet[2] = 0x00;
5656
if (IS_BIND_IN_PROGRESS)
5757
{ //00 05 00 0A 46 4A 41 47 00 00 40 46 A5 4A F1 18
58-
debug("CH:%d,",JJRC345_RF_BIND_CHANNEL);
5958
packet[1] = JJRC345_RF_BIND_CHANNEL;
6059
packet[4] = hopping_frequency[0];
6160
packet[5] = hopping_frequency[1];
@@ -66,7 +65,6 @@ static void __attribute__((unused)) JJRC345_send_packet()
6665
else
6766
{ //00 41 00 0A 00 80 80 80 00 00 40 46 00 49 F1 18
6867
NRF24L01_WriteReg(NRF24L01_05_RF_CH, hopping_frequency[hopping_frequency_no]);
69-
debug("CH:%d,", hopping_frequency[hopping_frequency_no]);
7068
hopping_frequency_no++;
7169
hopping_frequency_no %= JJRC345_NUM_CHANNELS;
7270
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()
7876

7977
if(CH5_SW) //Flip
8078
{
81-
if(packet[6]>90)
79+
if(packet[6]>0x90)
8280
packet[6]=0xFF;
83-
else if(packet[6]<80 && packet[6]>10)
81+
else if(packet[6]<0x80 && packet[6]>0x10)
8482
packet[6]=0x7F;
85-
else if(packet[7]>90)
83+
else if(packet[7]>0x90)
8684
packet[7]=0xFF;
87-
else if(packet[7]<80 && packet[7]>10)
85+
else if(packet[7]<0x80 && packet[7]>0x10)
8886
packet[7]=0x7F;
8987
}
9088

9189
packet[12] = 0x02; // Rate: 00-01-02
9290
}
93-
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
91+
92+
packet[3] = 0x00; // Checksum upper bits
9493

9594
packet[8] = 0x00 // Rudder trim, 00 when not used, 01..1F when trimmed left, 20..3F
9695
| GET_FLAG(CH6_SW,JJRC345_FLAG_HEADLESS) // Headless mode: 00 normal, 40 headless
@@ -101,19 +100,15 @@ static void __attribute__((unused)) JJRC345_send_packet()
101100
packet[11] = hopping_frequency[0]; // First hopping frequency
102101

103102
// Checksum
104-
packet[13] = 0x02-packet[3];
103+
uint16_t sum=2;
105104
for (uint8_t i = 0; i < 13; i++)
106-
{
107-
debug(" %02X", packet[i]);
108-
packet[13] += packet[i];
109-
}
110-
debug("%02X ", packet[13]);
105+
sum += packet[i];
106+
packet[13]=sum;
107+
packet[3]=((sum>>8)<<2)+2;
111108

112109
// TX ID
113110
packet[14] = rx_tx_addr[2];
114-
debug(" %02X", packet[14]);
115111
packet[15] = rx_tx_addr[3];
116-
debugln(" %02X", packet[15]);
117112

118113
// Power on, TX mode
119114
XN297_Configure(_BV(NRF24L01_00_EN_CRC) | _BV(NRF24L01_00_CRCO) | _BV(NRF24L01_00_PWR_UP));

0 commit comments

Comments
 (0)