From a95221200fca71684f3eab330238d97beff17a93 Mon Sep 17 00:00:00 2001 From: tipouic Date: Sat, 3 Dec 2016 17:03:37 +0100 Subject: [PATCH] En attente de test --- Multiprotocol/Bayang_nrf24l01.ino | 2 +- Multiprotocol/DSM_cyrf6936.ino | 2 +- Multiprotocol/Devo_cyrf6936.ino | 2 +- Multiprotocol/FlySky_a7105.ino | 7 +++- Multiprotocol/I2C_Nunchuck.ino | 27 +++++++++++-- Multiprotocol/MultiOrange.cpp.orangetx | 2 +- Multiprotocol/Multiprotocol.ino | 54 ++++++++++++------------- Multiprotocol/_Config.h | 20 +++++++-- Multiprotocol/multiprotocol.h | 15 ++++--- Multiprotocol/sync.ffs_db | Bin 1113 -> 1118 bytes 10 files changed, 84 insertions(+), 47 deletions(-) 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 d5cceeebc3d6d304fa4edd0d40528001e6e8c7c4..bfdd61ba4a89d36649d9ecf94030e99b01017e20 100644 GIT binary patch delta 1108 zcmV-a1grbm2;K;g8GjI^93JR z8L=0+8_A`h*n4{mv3`e!Co7Qx-d-3)fgN~xRk`Kv0rdBe2mXhmamwZGw-O3?vY?_Q zrq)WC17(Bof>$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