diff --git a/Multiprotocol/Bayang_nrf24l01.ino b/Multiprotocol/Bayang_nrf24l01.ino index cc1af3d..87053b5 100644 --- a/Multiprotocol/Bayang_nrf24l01.ino +++ b/Multiprotocol/Bayang_nrf24l01.ino @@ -216,7 +216,7 @@ static void __attribute__((unused)) BAYANG_send_packet(uint8_t bind) packet[11] = val & 0xFF; } packet[12] = rx_tx_addr[2]; // txid[2] - packet[13] = 0x0A; + packet[13] = sub_protocol==H8S3D?0x34:0x0A; packet[14] = 0; for (uint8_t i=0; i < BAYANG_PACKET_SIZE-1; i++) packet[14] += packet[i]; diff --git a/Multiprotocol/DSM_cyrf6936.ino b/Multiprotocol/DSM_cyrf6936.ino index acc4331..85cf1ca 100644 --- a/Multiprotocol/DSM_cyrf6936.ino +++ b/Multiprotocol/DSM_cyrf6936.ino @@ -15,7 +15,7 @@ #if defined(DSM_CYRF6936_INO) -#include "iface_cyrf6936.h" +#include "iface_cyrf6936.h" #define DSM_BIND_CHANNEL 0x0d //13 This can be any odd channel diff --git a/Multiprotocol/Devo_cyrf6936.ino b/Multiprotocol/Devo_cyrf6936.ino index 885e6c0..c7d01bd 100644 --- a/Multiprotocol/Devo_cyrf6936.ino +++ b/Multiprotocol/Devo_cyrf6936.ino @@ -15,7 +15,7 @@ #if defined(DEVO_CYRF6936_INO) -#include "iface_cyrf6936.h" +#include "iface_cyrf6936.h" #define DEVO_NUM_CHANNELS 8 diff --git a/Multiprotocol/FlySky_a7105.ino b/Multiprotocol/FlySky_a7105.ino index f1ce4c4..4c76806 100644 --- a/Multiprotocol/FlySky_a7105.ino +++ b/Multiprotocol/FlySky_a7105.ino @@ -144,8 +144,11 @@ static void __attribute__((unused)) flysky_build_packet(uint8_t init) packet[4] = rx_tx_addr[0]; for(i = 0; i < 8; i++) { - packet[5 + i*2]=Servo_data[CH_AETR[i]]&0xFF; //low byte of servo timing(1000-2000us) - packet[6 + i*2]=(Servo_data[CH_AETR[i]]>>8)&0xFF; //high byte of servo timing(1000-2000us) + uint16_t temp=Servo_data[CH_AETR[i]]; + 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(); } diff --git a/Multiprotocol/I2C_Nunchuck.ino b/Multiprotocol/I2C_Nunchuck.ino index 1d86efa..b48d765 100644 --- a/Multiprotocol/I2C_Nunchuck.ino +++ b/Multiprotocol/I2C_Nunchuck.ino @@ -15,7 +15,22 @@ uint8_t tpsc=0, tpsz=0; uint8_t data[6]; //nunchuck boolean c=false, z=false, cl=false, zl=false, op=false; +uint8_t batteryTX = 255; + + 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.setPixelColor(0, color[0], color[0+1], color[0+2]); strip.setBrightness(200); @@ -82,13 +97,19 @@ void nunchuck_update() { } } -/* #define DIVISOR_PERCENTS (32) #define PERCENT_TO_BYTE(P) ((int8_t)((((int)P) * DIVISOR_PERCENTS) / 100)) #define BYTE_TO_PERCENT(P) ((int8_t)((((int)P) * 100) / DIVISOR_PERCENTS)) 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; } -*/ + +/** 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 \ No newline at end of file diff --git a/Multiprotocol/MultiOrange.cpp.orangetx b/Multiprotocol/MultiOrange.cpp.orangetx index 76fdf4d..89df83e 100644 --- a/Multiprotocol/MultiOrange.cpp.orangetx +++ b/Multiprotocol/MultiOrange.cpp.orangetx @@ -11,7 +11,7 @@ #include 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 void update_serial_data(void) ; static void Mprotocol_serial_init(void) ; diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index 58ee07d..0823634 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -66,6 +66,7 @@ uint8_t packet[40]; uint16_t Servo_data[NUM_CHN]; uint8_t Servo_AUX; uint16_t servo_max_100,servo_min_100,servo_max_125,servo_min_125; +uint16_t servo_mid; // Protocol variables uint8_t cyrfmfg_id[6];//for dsm2 and devo @@ -248,11 +249,6 @@ void setup() // Timer1 config TCCR1A = 0; 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_init(); @@ -283,7 +279,7 @@ void setup() for(uint8_t i=0;iPPM_MAX_125) temp_ppm=PPM_MAX_125; Servo_data[i]= temp_ppm ; } - update_aux_flags(); PPM_FLAG_off; // wait for next frame before update INPUT_SIGNAL_on; //valid signal received last_signal=millis(); } #endif //ENABLE_PPM + update_channels_aux(); #if defined(TELEMETRY) if((protocol==MODE_FRSKYD) || (protocol==MODE_HUBSAN) || (protocol==MODE_AFHDS2A) || (protocol==MODE_FRSKYX) || (protocol==MODE_DSM) #ifdef ENABLE_BAYANG_TELEMETRY @@ -503,9 +499,23 @@ void Update_All() update_led_status(); } -// Update Servo_AUX flags based on servo AUX positions -static void update_aux_flags(void) +// Update channels direction and Servo_AUX flags based on servo AUX positions +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; for(uint8_t i=0;i<8;i++) 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 #ifdef ENABLE_PPM #ifdef ORANGE_TX diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index 73a5375..0ecc831 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -34,6 +34,11 @@ //Default is AETR. #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) //Default is AUX10 (channel 14). @@ -95,7 +100,7 @@ #define BAYANG_NRF24L01_INO #define CG023_NRF24L01_INO - #define CX10_NRF24L01_INO + #define CX10_NRF24L01_INO // Include Q2X2 protocol #define ESKY_NRF24L01_INO // #define HISKY_NRF24L01_INO #define KN_NRF24L01_INO @@ -145,7 +150,12 @@ /******************************/ //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 -//#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[] = { 0, 255, 0, 0, 255, 100, // VERT 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 }, /* 12 */ {MODE_CX10 , CX10_BLUE , 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 } }; /* Available protocols and associated sub protocols to pick and choose from @@ -263,7 +273,9 @@ const PPM_Parameters PPM_prot[15]= { YD829 H8_3D MODE_BAYANG - NONE + BAYANG + BAYANG TELEMETRY + H8S3D MODE_FRSKYX CH_16 CH_8 diff --git a/Multiprotocol/multiprotocol.h b/Multiprotocol/multiprotocol.h index bbf4c52..7b920a8 100644 --- a/Multiprotocol/multiprotocol.h +++ b/Multiprotocol/multiprotocol.h @@ -138,6 +138,12 @@ enum CG023 YD829 = 1, H8_3D = 2 }; +enum BAYANG +{ + BAYANG = 0, + BAYANG_TELEM = 1, + H8S3D = 2 +}; enum MT99XX { MT99 = 0, @@ -167,11 +173,6 @@ enum HONTAI FORMAT_FQ777 = 3 }; -enum BAYANG -{ - BAYANG = 0, - BAYANG_TELEM = 1 -}; enum HUBSAN { H107 = 0, @@ -517,6 +518,10 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p -- CG023 0 YD829 1 H8_3D 2 + sub_protocol==BAYANG + BAYANG 0 + BAYANG TELEM 1 + H8S3D 2 sub_protocol==MT99XX MT99 0 H7 1 diff --git a/Multiprotocol/sync.ffs_db b/Multiprotocol/sync.ffs_db index d5cceee..bfdd61b 100644 Binary files a/Multiprotocol/sync.ffs_db and b/Multiprotocol/sync.ffs_db differ