Skip to content

Commit a8897df

Browse files
committed
New protocol: Mould King
1 parent 7157d3d commit a8897df

9 files changed

+194
-4
lines changed

Lua_scripts/MultiChan.txt

+3
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,6 @@
192192
83,0,E129,E129,1,TakLan,EmStop,TrimA,TrimE,TrimR
193193
84,0,JOYSWAY,Std,0
194194
85,0,E016H,Std,1,Stop,Flip,n-a,HLess,RTH
195+
87,0,IKEA
196+
89,0,LOSI
197+
90,0,MouldKg,Std,E,F

Lua_scripts/MultiChannelsUpdater.lua

+7-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ local function Multi_Init()
280280
end
281281

282282
--Exceptions on first 4 channels...
283-
if ( protocol == 73 or (protocol == 74 and sub_protocol == 0) or (protocol == 60 and sub_protocol == 2) ) then -- Kyosho or RadioLink Surface or Pelikan/SCX24
283+
if ( protocol == 73 or (protocol == 74 and sub_protocol == 0) or (protocol == 60 and sub_protocol == 2) or protocol == 89) then -- Kyosho or RadioLink Surface or Pelikan/SCX24 or Losi
284284
channel_names[1] = "ST"
285285
channel_names[2] = "THR"
286286
channel_names[3] = "CH3"
@@ -296,6 +296,12 @@ local function Multi_Init()
296296
channel_names[3] = "AUX1"
297297
channel_names[4] = "AUX2"
298298
end
299+
if ( protocol == 90 ) then -- Mould King
300+
channel_names[1] = "A"
301+
channel_names[2] = "B"
302+
channel_names[3] = "C"
303+
channel_names[4] = "D"
304+
end
299305

300306
--Check MultiChan.txt
301307
local f = io.open("/SCRIPTS/TOOLS/MultiChan.txt", "r")

Multiprotocol/MouldKg_nrf24l01.ino

+162
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/*
2+
This project is free software: you can redistribute it and/or modify
3+
it under the terms of the GNU General Public License as published by
4+
the Free Software Foundation, either version 3 of the License, or
5+
(at your option) any later version.
6+
7+
Multiprotocol is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
GNU General Public License for more details.
11+
12+
You should have received a copy of the GNU General Public License
13+
along with Multiprotocol. If not, see <http://www.gnu.org/licenses/>.
14+
*/
15+
#if defined(MOULDKG_NRF24L01_INO)
16+
17+
#include "iface_xn297.h"
18+
19+
//#define FORCE_MOULDKG_ORIGINAL_ID
20+
21+
#define MOULDKG_PACKET_PERIOD 5000
22+
#define MOULDKG_BIND_PACKET_PERIOD 12000
23+
#define MOULDKG_TX_BIND_CHANNEL 11
24+
#define MOULDKG_RX_BIND_CHANNEL 76
25+
#define MOULDKG_PAYLOAD_SIZE 5
26+
#define MOULDKG_BIND_PAYLOAD_SIZE 7
27+
#define MOULDKG_BIND_COUNT 300
28+
#define MOULDKG_RF_NUM_CHANNELS 4
29+
30+
enum {
31+
MOULDKG_BINDTX=0,
32+
MOULDKG_BINDRX,
33+
MOULDKG_DATA,
34+
};
35+
36+
static void __attribute__((unused)) MOULDKG_send_packet()
37+
{
38+
memcpy(&packet[1],rx_tx_addr,3);
39+
if(IS_BIND_IN_PROGRESS)
40+
{
41+
packet[0] = 0xC0;
42+
memset(&packet[4], 0x00, 3);
43+
}
44+
else
45+
{
46+
XN297_RFChannel(hopping_frequency[(packet_count>>1)&0x03]);
47+
48+
uint8_t val=0;
49+
if(packet_count&1)
50+
{
51+
packet[0] = 0x31;
52+
//Button B
53+
if(Channel_data[CH2]>CHANNEL_MAX_COMMAND) val |= 0x40;
54+
else if(Channel_data[CH2]<CHANNEL_MIN_COMMAND) val |= 0x80;
55+
//Button C
56+
if(Channel_data[CH3]>CHANNEL_MAX_COMMAND) val |= 0x10;
57+
else if(Channel_data[CH3]<CHANNEL_MIN_COMMAND) val |= 0x20;
58+
}
59+
else
60+
{
61+
packet[0] = 0x30;
62+
val = 0x60
63+
| GET_FLAG(CH5_SW, 0x80) // Button E
64+
| GET_FLAG(CH6_SW, 0x10); // Button F
65+
}
66+
//Button A
67+
if(Channel_data[CH1]>CHANNEL_MAX_COMMAND) val |= 0x01;
68+
else if(Channel_data[CH1]<CHANNEL_MIN_COMMAND) val |= 0x02;
69+
//Button D
70+
if(Channel_data[CH4]>CHANNEL_MAX_COMMAND) val |= 0x04;
71+
else if(Channel_data[CH4]<CHANNEL_MIN_COMMAND) val |= 0x08;
72+
packet[4]= val;
73+
74+
packet_count++;
75+
}
76+
77+
// Send
78+
XN297_SetPower();
79+
XN297_SetTxRxMode(TX_EN);
80+
XN297_WritePayload(packet, IS_BIND_IN_PROGRESS?MOULDKG_BIND_PAYLOAD_SIZE:MOULDKG_PAYLOAD_SIZE);
81+
#if 0
82+
uint8_t len = IS_BIND_IN_PROGRESS?MOULDKG_BIND_PAYLOAD_SIZE:MOULDKG_PAYLOAD_SIZE;
83+
for(uint8_t i=0; i < len; i++)
84+
debug("%02X ", packet[i]);
85+
debugln();
86+
#endif
87+
}
88+
89+
static void __attribute__((unused)) MOULDKG_initialize_txid()
90+
{
91+
rx_tx_addr[0]=rx_tx_addr[3]; // Use RX_num;
92+
#ifdef FORCE_MOULDKG_ORIGINAL_ID
93+
rx_tx_addr[0]=0x57;
94+
rx_tx_addr[1]=0x1B;
95+
rx_tx_addr[2]=0xF8;
96+
#endif
97+
//Are the frequencies constant??? If not where are they coming from???
98+
memcpy(hopping_frequency,(uint8_t*)"\x0F\x1C\x39\x3C", MOULDKG_RF_NUM_CHANNELS); // 15,28,57,60
99+
}
100+
101+
static void __attribute__((unused)) MOULDKG_RF_init()
102+
{
103+
XN297_Configure(XN297_CRCEN, XN297_SCRAMBLED, XN297_1M);
104+
XN297_SetTXAddr((uint8_t*)"KDH", 3);
105+
XN297_SetRXAddr((uint8_t*)"KDH", MOULDKG_BIND_PAYLOAD_SIZE);
106+
}
107+
108+
uint16_t MOULDKG_callback()
109+
{
110+
switch(phase)
111+
{
112+
case MOULDKG_BINDTX:
113+
if(XN297_IsRX())
114+
{
115+
//Example: TX: C=11 S=Y A= 4B 44 48 P(7)= C0 37 02 4F 00 00 00
116+
// RX: C=76 S=Y A= 4B 44 48 P(7)= 5A 37 02 4F 03 0D 8E
117+
XN297_ReadPayload(packet_in, MOULDKG_BIND_PAYLOAD_SIZE);
118+
for(uint8_t i=0; i < MOULDKG_BIND_PAYLOAD_SIZE; i++)
119+
debug("%02X ", packet_in[i]);
120+
debugln();
121+
//Not sure if I should test packet_in[0]
122+
if(memcmp(&packet_in[1],&packet[1],3)==0)
123+
{//TX ID match, use RX ID to transmit normal packets
124+
XN297_SetTXAddr(&packet_in[4], 3);
125+
XN297_SetTxRxMode(TXRX_OFF);
126+
BIND_DONE;
127+
}
128+
}
129+
XN297_RFChannel(MOULDKG_TX_BIND_CHANNEL); // Set TX bind channel
130+
XN297_SetTxRxMode(TXRX_OFF);
131+
MOULDKG_send_packet();
132+
phase++;
133+
return 500;
134+
case MOULDKG_BINDRX:
135+
//Wait for the packet transmission to finish
136+
while(XN297_IsPacketSent()==false);
137+
//Switch to RX
138+
XN297_SetTxRxMode(TXRX_OFF);
139+
XN297_RFChannel(MOULDKG_RX_BIND_CHANNEL); // Set RX bind channel
140+
XN297_SetTxRxMode(RX_EN);
141+
phase = MOULDKG_BINDTX;
142+
return MOULDKG_BIND_PACKET_PERIOD-500;
143+
case MOULDKG_DATA:
144+
#ifdef MULTI_SYNC
145+
telemetry_set_input_sync(MOULDKG_PACKET_PERIOD);
146+
#endif
147+
MOULDKG_send_packet();
148+
break;
149+
}
150+
return MOULDKG_PACKET_PERIOD;
151+
}
152+
153+
void MOULDKG_init()
154+
{
155+
BIND_IN_PROGRESS; // autobind protocol
156+
MOULDKG_initialize_txid();
157+
MOULDKG_RF_init();
158+
bind_counter = MOULDKG_BIND_COUNT;
159+
packet_count = 0;
160+
}
161+
162+
#endif

Multiprotocol/Multi.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,5 @@
8484
84,JOYSWAY
8585
85,E016H
8686
87,IKEA
87-
89,LOSI
87+
89,Losi
88+
90,MouldKg

Multiprotocol/Multi_Protos.ino

+4
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ const char STR_E016H[] ="E016H";
101101
const char STR_IKEAANSLUTA[]="Ansluta";
102102
const char STR_CONFIG[] ="Config";
103103
const char STR_LOSI[] ="Losi";
104+
const char STR_MOULDKG[] ="MouldKg";
104105

105106
const char STR_SUBTYPE_FLYSKY[] = "\x04""Std\0""V9x9""V6x6""V912""CX20";
106107
const char STR_SUBTYPE_HUBSAN[] = "\x04""H107""H301""H501";
@@ -365,6 +366,9 @@ const mm_protocol_definition multi_protocols[] = {
365366
#if defined(MLINK_CYRF6936_INO)
366367
{PROTO_MLINK, STR_MLINK, NO_SUBTYPE, 0, OPTION_NONE, 1, 0, SW_CYRF, MLINK_init, MLINK_callback },
367368
#endif
369+
#if defined(MOULDKG_NRF24L01_INO)
370+
{PROTO_MOULDKG, STR_MOULDKG, NO_SUBTYPE, 0, OPTION_NONE, 0, 0, SW_NRF, MOULDKG_init, MOULDKG_callback },
371+
#endif
368372
#if defined(MT99XX_CCNRF_INO)
369373
{PROTO_MT99XX, STR_MT99XX, STR_SUBTYPE_MT99, 7, OPTION_NONE, 0, 0, SW_NRF, MT99XX_init, MT99XX_callback },
370374
#endif

Multiprotocol/Multiprotocol.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#define VERSION_MAJOR 1
2020
#define VERSION_MINOR 3
2121
#define VERSION_REVISION 2
22-
#define VERSION_PATCH_LEVEL 80
22+
#define VERSION_PATCH_LEVEL 81
2323

2424
#define MODE_SERIAL 0
2525

@@ -117,6 +117,7 @@ enum PROTOCOLS
117117
PROTO_IKEAANSLUTA = 87, // =>CC2500
118118
PROTO_WILLIFM = 88, // 27/35ab/40/41/72 MHz module external project
119119
PROTO_LOSI = 89, // =>CYRF6936
120+
PROTO_MOULDKG = 90, // =>NRF24L01
120121

121122
PROTO_NANORF = 126, // =>NRF24L01
122123
PROTO_TEST = 127, // =>CC2500

Multiprotocol/Validate.h

+2
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@
277277
#undef FRSKY_RX_CC2500_INO
278278
#undef HITEC_CC2500_INO
279279
#undef HOTT_CC2500_INO
280+
#undef IKEAANSLUTA_CC2500_INO
280281
#undef REDPINE_CC2500_INO
281282
#undef RLINK_CC2500_INO
282283
#undef SCANNER_CC2500_INO
@@ -307,6 +308,7 @@
307308
#undef JJRC345_NRF24L01_INO
308309
#undef KN_NRF24L01_INO
309310
#undef LOLI_NRF24L01_INO
311+
#undef MOULDKG_NRF24L01_INO
310312
#undef NCC1701_NRF24L01_INO
311313
#undef POTENSIC_NRF24L01_INO
312314
#undef PROPEL_NRF24L01_INO

Multiprotocol/_Config.h

+3
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@
235235
#define JJRC345_NRF24L01_INO
236236
#define KN_NRF24L01_INO
237237
#define LOLI_NRF24L01_INO
238+
#define MOULDKG_NRF24L01_INO
238239
#define NCC1701_NRF24L01_INO
239240
#define POTENSIC_NRF24L01_INO
240241
#define PROPEL_NRF24L01_INO
@@ -726,6 +727,8 @@ const PPM_Parameters PPM_prot[14*NBR_BANKS]= {
726727
PHOENIX
727728
PROTO_MLINK
728729
NONE
730+
PROTO_MOULDKG
731+
NONE
729732
PROTO_MT99XX
730733
MT99
731734
H7

Protocols_Details.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,10 @@ CFlie|38|CFlie||||||||NRF24L01|
114114
[KN](Protocols_Details.md#KN---9)|9|WLTOYS|FEILUN|||||||NRF24L01|
115115
[Kyosho](Protocols_Details.md#Kyosho---73)|73|FHSS|Hype|||||||A7105|
116116
[LOLI](Protocols_Details.md#LOLI---82)|82|||||||||NRF24L01|
117-
[Losi](Protocols_Details.md#LOLI---89)|89|||||||||CYRF6936|
117+
[Losi](Protocols_Details.md#Losi---89)|89|||||||||CYRF6936|
118118
[MJXq](Protocols_Details.md#MJXQ---18)|18|WLH08|X600|X800|H26D|E010*|H26WH|PHOENIX*||NRF24L01|XN297
119119
[MLINK](Protocols_Details.md#MLINK---78)|78|||||||||CYRF6936|
120+
[MouldKg]Protocols_Details.md#MouldKg---90)|90|||||||||NRF24L01|XN297
120121
[MT99xx](Protocols_Details.md#MT99XX---17)|17|MT|H7|YZ|LS|FY805|A180|DRAGON||NRF24L01|XN297
121122
[NCC1701](Protocols_Details.md#NCC1701---44)|44|||||||||NRF24L01|
122123
[OMP](Protocols_Details.md#OMP---77)|77|||||||||CC2500&NRF24L01|XN297L
@@ -1702,6 +1703,13 @@ CH14| CH6 | -100% | 0% | | - | -
17021703
CH15| CH7 | -100% | 0% | - | - | +100%
17031704
CH16| CH8 | -100% | 0% | - | - | -
17041705

1706+
## MouldKg - *90*
1707+
Mould King 2.4GHz TX
1708+
1709+
CH1|CH2|CH3|CH4|CH5|CH6
1710+
---|---|---|---|---|---
1711+
A|B|C|D|E|F
1712+
17051713
## NCC1701 - *44*
17061714
Model: Air Hogs Star Trek USS Enterprise NCC-1701-A
17071715

0 commit comments

Comments
 (0)