mirror of
https://github.com/pascallanger/DIY-Multiprotocol-TX-Module.git
synced 2025-07-12 17:57:53 +00:00
En attente de test
This commit is contained in:
parent
aa6058b0dd
commit
a95221200f
@ -216,7 +216,7 @@ static void __attribute__((unused)) BAYANG_send_packet(uint8_t bind)
|
|||||||
packet[11] = val & 0xFF;
|
packet[11] = val & 0xFF;
|
||||||
}
|
}
|
||||||
packet[12] = rx_tx_addr[2]; // txid[2]
|
packet[12] = rx_tx_addr[2]; // txid[2]
|
||||||
packet[13] = 0x0A;
|
packet[13] = sub_protocol==H8S3D?0x34:0x0A;
|
||||||
packet[14] = 0;
|
packet[14] = 0;
|
||||||
for (uint8_t i=0; i < BAYANG_PACKET_SIZE-1; i++)
|
for (uint8_t i=0; i < BAYANG_PACKET_SIZE-1; i++)
|
||||||
packet[14] += packet[i];
|
packet[14] += packet[i];
|
||||||
|
@ -144,8 +144,11 @@ static void __attribute__((unused)) flysky_build_packet(uint8_t init)
|
|||||||
packet[4] = rx_tx_addr[0];
|
packet[4] = rx_tx_addr[0];
|
||||||
for(i = 0; i < 8; i++)
|
for(i = 0; i < 8; i++)
|
||||||
{
|
{
|
||||||
packet[5 + i*2]=Servo_data[CH_AETR[i]]&0xFF; //low byte of servo timing(1000-2000us)
|
uint16_t temp=Servo_data[CH_AETR[i]];
|
||||||
packet[6 + i*2]=(Servo_data[CH_AETR[i]]>>8)&0xFF; //high byte of servo timing(1000-2000us)
|
if(sub_protocol == CX20 && CH_AETR[i] == ELEVATOR)
|
||||||
|
temp=servo_mid-temp; //reverse channel
|
||||||
|
packet[5 + i*2]=temp&0xFF; //low byte of servo timing(1000-2000us)
|
||||||
|
packet[6 + i*2]=(temp>>8)&0xFF; //high byte of servo timing(1000-2000us)
|
||||||
}
|
}
|
||||||
flysky_apply_extension_flags();
|
flysky_apply_extension_flags();
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,22 @@ uint8_t tpsc=0, tpsz=0;
|
|||||||
uint8_t data[6]; //nunchuck
|
uint8_t data[6]; //nunchuck
|
||||||
boolean c=false, z=false, cl=false, zl=false, op=false;
|
boolean c=false, z=false, cl=false, zl=false, op=false;
|
||||||
|
|
||||||
|
uint8_t batteryTX = 255;
|
||||||
|
|
||||||
|
|
||||||
void nunchuck_init() {
|
void nunchuck_init() {
|
||||||
|
analogReference(INTERNAL);
|
||||||
|
pinMode(BUZZER_PIN, OUTPUT); digitalWrite(BUZZER_PIN, BUZZER_INIT);
|
||||||
|
|
||||||
|
|
||||||
|
/** Interrupt routines **/
|
||||||
|
TCCR2A = 0b00000010; // COM 2A1, 2A0, 2B1, 2B0, - , - , WGM21, WGM20
|
||||||
|
TCCR2B = 0b00000110; // Clock / 256 soit 16 micro-s et WGM22 = 0 // FOC2A, FOC2B, - , - , WGM22, CS22, CS21, CS20
|
||||||
|
TIMSK2 = 0b00000010; // Interruption locale autorisée par OCIE2A // - , - , - , - , - , OCIE2B, OCIE2A, TOIE2
|
||||||
|
OCR2A = 250; // Interruption du compte à ...
|
||||||
|
sei(); // autorisation générale des interruptions
|
||||||
|
|
||||||
|
|
||||||
strip.begin();
|
strip.begin();
|
||||||
strip.setPixelColor(0, color[0], color[0+1], color[0+2]);
|
strip.setPixelColor(0, color[0], color[0+1], color[0+2]);
|
||||||
strip.setBrightness(200);
|
strip.setBrightness(200);
|
||||||
@ -82,13 +97,19 @@ void nunchuck_update() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
#define DIVISOR_PERCENTS (32)
|
#define DIVISOR_PERCENTS (32)
|
||||||
#define PERCENT_TO_BYTE(P) ((int8_t)((((int)P) * DIVISOR_PERCENTS) / 100))
|
#define PERCENT_TO_BYTE(P) ((int8_t)((((int)P) * DIVISOR_PERCENTS) / 100))
|
||||||
#define BYTE_TO_PERCENT(P) ((int8_t)((((int)P) * 100) / DIVISOR_PERCENTS))
|
#define BYTE_TO_PERCENT(P) ((int8_t)((((int)P) * 100) / DIVISOR_PERCENTS))
|
||||||
int16_t expo(int8_t a, int32_t x) {
|
int16_t expo(int8_t a, int32_t x) {
|
||||||
return (((BYTE_TO_PERCENT(a) * x * x) / 100) * x) / (((int32_t)MAX_LEVEL) * MAX_LEVEL)
|
return (((BYTE_TO_PERCENT(a) * x * x) / 100) * x) / (((int32_t)servo_max_125) * servo_max_125)
|
||||||
+ (100 - BYTE_TO_PERCENT(a)) * x / 100;
|
+ (100 - BYTE_TO_PERCENT(a)) * x / 100;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
/** Interrupt routines 4ms **/
|
||||||
|
ISR (TIMER2_OVF_vect) {
|
||||||
|
batteryTX = map(analogRead(VBAT_PIN), 0,1023, 0,430);
|
||||||
|
if(batteryTX < VBAT_LIM) { digitalWrite(BUZZER_PIN, !BUZZER_INIT); }
|
||||||
|
else if(batteryTX < VBAT_VAL) { digitalWrite(BUZZER_PIN, !digitalRead(BUZZER_PIN)); }
|
||||||
|
nunchuck_update();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
@ -11,7 +11,7 @@
|
|||||||
#include <avr/interrupt.h>
|
#include <avr/interrupt.h>
|
||||||
|
|
||||||
static void protocol_init(void) ;
|
static void protocol_init(void) ;
|
||||||
static void update_aux_flags(void) ;
|
static void update_channels_aux(void) ;
|
||||||
static uint32_t random_id(uint16_t adress, uint8_t create_new) ;
|
static uint32_t random_id(uint16_t adress, uint8_t create_new) ;
|
||||||
static void update_serial_data(void) ;
|
static void update_serial_data(void) ;
|
||||||
static void Mprotocol_serial_init(void) ;
|
static void Mprotocol_serial_init(void) ;
|
||||||
|
@ -66,6 +66,7 @@ uint8_t packet[40];
|
|||||||
uint16_t Servo_data[NUM_CHN];
|
uint16_t Servo_data[NUM_CHN];
|
||||||
uint8_t Servo_AUX;
|
uint8_t Servo_AUX;
|
||||||
uint16_t servo_max_100,servo_min_100,servo_max_125,servo_min_125;
|
uint16_t servo_max_100,servo_min_100,servo_max_125,servo_min_125;
|
||||||
|
uint16_t servo_mid;
|
||||||
|
|
||||||
// Protocol variables
|
// Protocol variables
|
||||||
uint8_t cyrfmfg_id[6];//for dsm2 and devo
|
uint8_t cyrfmfg_id[6];//for dsm2 and devo
|
||||||
@ -248,11 +249,6 @@ void setup()
|
|||||||
// Timer1 config
|
// Timer1 config
|
||||||
TCCR1A = 0;
|
TCCR1A = 0;
|
||||||
TCCR1B = (1 << CS11); //prescaler8, set timer1 to increment every 0.5us(16Mhz) and start timer
|
TCCR1B = (1 << CS11); //prescaler8, set timer1 to increment every 0.5us(16Mhz) and start timer
|
||||||
#ifdef ENABLE_NUNCHUCK
|
|
||||||
TCCR2A = 0; //default
|
|
||||||
TCCR2B = 0b00000010; // clk/8
|
|
||||||
TIMSK2 = 0b00000001; // TOIE2
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Random
|
// Random
|
||||||
random_init();
|
random_init();
|
||||||
@ -283,7 +279,7 @@ void setup()
|
|||||||
for(uint8_t i=0;i<NUM_CHN;i++)
|
for(uint8_t i=0;i<NUM_CHN;i++)
|
||||||
Servo_data[i]=1500;
|
Servo_data[i]=1500;
|
||||||
Servo_data[THROTTLE]=servo_min_100;
|
Servo_data[THROTTLE]=servo_min_100;
|
||||||
#if defined (ENABLE_PPM) || defined(ENABLE_NUNCHUCK)
|
#ifdef ENABLE_PPM
|
||||||
memcpy((void *)PPM_data,Servo_data, sizeof(Servo_data));
|
memcpy((void *)PPM_data,Servo_data, sizeof(Servo_data));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -377,12 +373,12 @@ void setup()
|
|||||||
servo_max_125=SERIAL_MAX_125; servo_min_125=SERIAL_MIN_125;
|
servo_max_125=SERIAL_MAX_125; servo_min_125=SERIAL_MIN_125;
|
||||||
Mprotocol_serial_init(); // Configure serial and enable RX interrupt
|
Mprotocol_serial_init(); // Configure serial and enable RX interrupt
|
||||||
#endif //ENABLE_SERIAL
|
#endif //ENABLE_SERIAL
|
||||||
|
}
|
||||||
|
servo_mid=servo_min_100+servo_max_100; //In fact 2* mid_value
|
||||||
|
|
||||||
#ifdef ENABLE_NUNCHUCK
|
#ifdef ENABLE_NUNCHUCK
|
||||||
analogReference(INTERNAL);
|
|
||||||
nunchuck_init();
|
nunchuck_init();
|
||||||
#endif //ENABLE_NUNCHUCK
|
#endif //ENABLE_NUNCHUCK
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Main
|
// Main
|
||||||
@ -470,7 +466,7 @@ void Update_All()
|
|||||||
if(mode_select==MODE_SERIAL && IS_RX_FLAG_on) // Serial mode and something has been received
|
if(mode_select==MODE_SERIAL && IS_RX_FLAG_on) // Serial mode and something has been received
|
||||||
{
|
{
|
||||||
update_serial_data(); // Update protocol and data
|
update_serial_data(); // Update protocol and data
|
||||||
update_aux_flags();
|
|
||||||
}
|
}
|
||||||
#endif //ENABLE_SERIAL
|
#endif //ENABLE_SERIAL
|
||||||
#ifdef ENABLE_PPM
|
#ifdef ENABLE_PPM
|
||||||
@ -486,12 +482,12 @@ void Update_All()
|
|||||||
else if(temp_ppm>PPM_MAX_125) temp_ppm=PPM_MAX_125;
|
else if(temp_ppm>PPM_MAX_125) temp_ppm=PPM_MAX_125;
|
||||||
Servo_data[i]= temp_ppm ;
|
Servo_data[i]= temp_ppm ;
|
||||||
}
|
}
|
||||||
update_aux_flags();
|
|
||||||
PPM_FLAG_off; // wait for next frame before update
|
PPM_FLAG_off; // wait for next frame before update
|
||||||
INPUT_SIGNAL_on; //valid signal received
|
INPUT_SIGNAL_on; //valid signal received
|
||||||
last_signal=millis();
|
last_signal=millis();
|
||||||
}
|
}
|
||||||
#endif //ENABLE_PPM
|
#endif //ENABLE_PPM
|
||||||
|
update_channels_aux();
|
||||||
#if defined(TELEMETRY)
|
#if defined(TELEMETRY)
|
||||||
if((protocol==MODE_FRSKYD) || (protocol==MODE_HUBSAN) || (protocol==MODE_AFHDS2A) || (protocol==MODE_FRSKYX) || (protocol==MODE_DSM)
|
if((protocol==MODE_FRSKYD) || (protocol==MODE_HUBSAN) || (protocol==MODE_AFHDS2A) || (protocol==MODE_FRSKYX) || (protocol==MODE_DSM)
|
||||||
#ifdef ENABLE_BAYANG_TELEMETRY
|
#ifdef ENABLE_BAYANG_TELEMETRY
|
||||||
@ -503,9 +499,23 @@ void Update_All()
|
|||||||
update_led_status();
|
update_led_status();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update Servo_AUX flags based on servo AUX positions
|
// Update channels direction and Servo_AUX flags based on servo AUX positions
|
||||||
static void update_aux_flags(void)
|
static void update_channels_aux(void)
|
||||||
{
|
{
|
||||||
|
//Reverse channels direction
|
||||||
|
#ifdef REVERSE_AILERON
|
||||||
|
Servo_data[AILERON]=servo_mid-Servo_data[AILERON];
|
||||||
|
#endif
|
||||||
|
#ifdef REVERSE_ELEVATOR
|
||||||
|
Servo_data[ELEVATOR]=servo_mid-Servo_data[ELEVATOR];
|
||||||
|
#endif
|
||||||
|
#ifdef REVERSE_THROTTLE
|
||||||
|
Servo_data[THROTTLE]=servo_mid-Servo_data[THROTTLE];
|
||||||
|
#endif
|
||||||
|
#ifdef REVERSE_RUDDER
|
||||||
|
Servo_data[RUDDER]=servo_mid-Servo_data[RUDDER];
|
||||||
|
#endif
|
||||||
|
//Calc AUX flags
|
||||||
Servo_AUX=0;
|
Servo_AUX=0;
|
||||||
for(uint8_t i=0;i<8;i++)
|
for(uint8_t i=0;i<8;i++)
|
||||||
if(Servo_data[AUX1+i]>PPM_SWITCH)
|
if(Servo_data[AUX1+i]>PPM_SWITCH)
|
||||||
@ -1164,20 +1174,6 @@ static uint32_t random_id(uint16_t adress, uint8_t create_new)
|
|||||||
/**************************/
|
/**************************/
|
||||||
/**************************/
|
/**************************/
|
||||||
|
|
||||||
//NUNCHUCK
|
|
||||||
#ifdef ENABLE_NUNCHUCK
|
|
||||||
ISR (TIMER2_OVF_vect) {
|
|
||||||
static uint16_t Prev_TCNT2=0;
|
|
||||||
// le flag OVF est mis à zéro par la fonction ISR
|
|
||||||
TCNT2 = 62;
|
|
||||||
// 256-200 --> 200X50ns = 100 us
|
|
||||||
if (Prev_TCNT2++ > 10000) {
|
|
||||||
Prev_TCNT2 = 0;
|
|
||||||
nunchuck_update();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//PPM
|
//PPM
|
||||||
#ifdef ENABLE_PPM
|
#ifdef ENABLE_PPM
|
||||||
#ifdef ORANGE_TX
|
#ifdef ORANGE_TX
|
||||||
|
@ -34,6 +34,11 @@
|
|||||||
//Default is AETR.
|
//Default is AETR.
|
||||||
#define EATR
|
#define EATR
|
||||||
|
|
||||||
|
//Uncomment to reverse the direction of the specified channel for all protocols
|
||||||
|
//#define REVERSE_AILERON
|
||||||
|
//#define REVERSE_ELEVATOR
|
||||||
|
//#define REVERSE_THROTTLE
|
||||||
|
//#define REVERSE_RUDDER
|
||||||
|
|
||||||
//Modify the channel for a software reset modul: AUX...(channel number - 4)
|
//Modify the channel for a software reset modul: AUX...(channel number - 4)
|
||||||
//Default is AUX10 (channel 14).
|
//Default is AUX10 (channel 14).
|
||||||
@ -95,7 +100,7 @@
|
|||||||
|
|
||||||
#define BAYANG_NRF24L01_INO
|
#define BAYANG_NRF24L01_INO
|
||||||
#define CG023_NRF24L01_INO
|
#define CG023_NRF24L01_INO
|
||||||
#define CX10_NRF24L01_INO
|
#define CX10_NRF24L01_INO // Include Q2X2 protocol
|
||||||
#define ESKY_NRF24L01_INO
|
#define ESKY_NRF24L01_INO
|
||||||
// #define HISKY_NRF24L01_INO
|
// #define HISKY_NRF24L01_INO
|
||||||
#define KN_NRF24L01_INO
|
#define KN_NRF24L01_INO
|
||||||
@ -145,7 +150,12 @@
|
|||||||
/******************************/
|
/******************************/
|
||||||
//In this section you can configure the NUNCHUCK.
|
//In this section you can configure the NUNCHUCK.
|
||||||
//If you do not plan to use the NUNCHUCK mode comment this line using "//" to save Flash space, you don't need to configure anything below in this case
|
//If you do not plan to use the NUNCHUCK mode comment this line using "//" to save Flash space, you don't need to configure anything below in this case
|
||||||
//#define ENABLE_NUNCHUCK
|
#define ENABLE_NUNCHUCK
|
||||||
|
#define VBAT_PIN 3 // for Tx adapters with battery
|
||||||
|
#define VBAT_VAL 340 // for Tx adapters with battery (attention pont divisieur pour avoir 1,1V max ,~=3,404V)
|
||||||
|
#define VBAT_LIM 330 // for Tx adapters with battery (attention pont divisieur pour avoir 1,1V max , ~=3,302V)
|
||||||
|
#define BUZZER_PIN 14 //A0
|
||||||
|
#define BUZZER_INIT HIGH
|
||||||
const uint8_t color[] = {
|
const uint8_t color[] = {
|
||||||
0, 255, 0, 0, 255, 100, // VERT
|
0, 255, 0, 0, 255, 100, // VERT
|
||||||
255, 255, 0, 127, 255, 0, // rouge
|
255, 255, 0, 127, 255, 0, // rouge
|
||||||
@ -204,7 +214,7 @@ const PPM_Parameters PPM_prot[15]= {
|
|||||||
/* 11 */ {MODE_SLT , 0 , 0 , P_HIGH , NO_AUTOBIND , 0 },
|
/* 11 */ {MODE_SLT , 0 , 0 , P_HIGH , NO_AUTOBIND , 0 },
|
||||||
/* 12 */ {MODE_CX10 , CX10_BLUE , 0 , P_HIGH , NO_AUTOBIND , 0 },
|
/* 12 */ {MODE_CX10 , CX10_BLUE , 0 , P_HIGH , NO_AUTOBIND , 0 },
|
||||||
/* 13 */ {MODE_CG023 , CG023 , 0 , P_HIGH , NO_AUTOBIND , 0 },
|
/* 13 */ {MODE_CG023 , CG023 , 0 , P_HIGH , NO_AUTOBIND , 0 },
|
||||||
/* 14 */ {MODE_BAYANG, 0 , 0 , P_HIGH , NO_AUTOBIND , 0 },
|
/* 14 */ {MODE_BAYANG, BAYANG , 0 , P_HIGH , NO_AUTOBIND , 0 },
|
||||||
/* 15 */ {MODE_SYMAX , SYMAX5C , 0 , P_HIGH , NO_AUTOBIND , 0 }
|
/* 15 */ {MODE_SYMAX , SYMAX5C , 0 , P_HIGH , NO_AUTOBIND , 0 }
|
||||||
};
|
};
|
||||||
/* Available protocols and associated sub protocols to pick and choose from
|
/* Available protocols and associated sub protocols to pick and choose from
|
||||||
@ -263,7 +273,9 @@ const PPM_Parameters PPM_prot[15]= {
|
|||||||
YD829
|
YD829
|
||||||
H8_3D
|
H8_3D
|
||||||
MODE_BAYANG
|
MODE_BAYANG
|
||||||
NONE
|
BAYANG
|
||||||
|
BAYANG TELEMETRY
|
||||||
|
H8S3D
|
||||||
MODE_FRSKYX
|
MODE_FRSKYX
|
||||||
CH_16
|
CH_16
|
||||||
CH_8
|
CH_8
|
||||||
|
@ -138,6 +138,12 @@ enum CG023
|
|||||||
YD829 = 1,
|
YD829 = 1,
|
||||||
H8_3D = 2
|
H8_3D = 2
|
||||||
};
|
};
|
||||||
|
enum BAYANG
|
||||||
|
{
|
||||||
|
BAYANG = 0,
|
||||||
|
BAYANG_TELEM = 1,
|
||||||
|
H8S3D = 2
|
||||||
|
};
|
||||||
enum MT99XX
|
enum MT99XX
|
||||||
{
|
{
|
||||||
MT99 = 0,
|
MT99 = 0,
|
||||||
@ -167,11 +173,6 @@ enum HONTAI
|
|||||||
FORMAT_FQ777 = 3
|
FORMAT_FQ777 = 3
|
||||||
};
|
};
|
||||||
|
|
||||||
enum BAYANG
|
|
||||||
{
|
|
||||||
BAYANG = 0,
|
|
||||||
BAYANG_TELEM = 1
|
|
||||||
};
|
|
||||||
enum HUBSAN
|
enum HUBSAN
|
||||||
{
|
{
|
||||||
H107 = 0,
|
H107 = 0,
|
||||||
@ -517,6 +518,10 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p --
|
|||||||
CG023 0
|
CG023 0
|
||||||
YD829 1
|
YD829 1
|
||||||
H8_3D 2
|
H8_3D 2
|
||||||
|
sub_protocol==BAYANG
|
||||||
|
BAYANG 0
|
||||||
|
BAYANG TELEM 1
|
||||||
|
H8S3D 2
|
||||||
sub_protocol==MT99XX
|
sub_protocol==MT99XX
|
||||||
MT99 0
|
MT99 0
|
||||||
H7 1
|
H7 1
|
||||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user