From f6c52523764419abc96672df40efb446e03d3c1a Mon Sep 17 00:00:00 2001 From: pascallanger Date: Fri, 26 Aug 2016 18:33:05 +0200 Subject: [PATCH] DEVO PPM fixed id mode --- Multiprotocol/Devo_cyrf6936.ino | 15 ++++++++++++++- Multiprotocol/Multiprotocol.h | 30 ++++++++++++++++++++---------- Multiprotocol/Multiprotocol.ino | 21 ++++++++++++++++----- 3 files changed, 50 insertions(+), 16 deletions(-) diff --git a/Multiprotocol/Devo_cyrf6936.ino b/Multiprotocol/Devo_cyrf6936.ino index 924a779..cf56eed 100644 --- a/Multiprotocol/Devo_cyrf6936.ino +++ b/Multiprotocol/Devo_cyrf6936.ino @@ -78,7 +78,20 @@ static void __attribute__((unused)) DEVO_scramble_pkt() static void __attribute__((unused)) DEVO_add_pkt_suffix() { uint8_t bind_state; - if(prev_option!=option) + #ifdef ENABLE_PPM + if(mode_select && option==0 && IS_BIND_DONE_on) //PPM mode and option not already set and bind is finished + { + BIND_SET_INPUT; + BIND_SET_PULLUP; // set pullup + if(IS_BIND_BUTTON_on) + { + eeprom_write_byte((uint8_t*)(30+mode_select),0x01); // Set fixed id mode for the current model + option=1; + } + BIND_SET_OUTPUT; + } + #endif //ENABLE_PPM + if(prev_option!=option && IS_BIND_DONE_on) { MProtocol_id = RX_num + MProtocol_id_master; bind_counter=DEVO_BIND_COUNT; diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index bf25279..c4a55bd 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -248,17 +248,27 @@ struct PPM_Parameters // LED #ifdef XMEGA - #define LED_ON PORTD.OUTCLR = _BV(1) - #define LED_OFF PORTD.OUTSET = _BV(1) - #define LED_TOGGLE PORTD.OUTTGL = _BV(1) - #define LED_SET_OUTPUT PORTD.DIRSET = _BV(1) - #define IS_LED_on ( (PORTD.OUT & _BV(1)) != 0x00 ) + #define LED_ON PORTD.OUTCLR = _BV(1) + #define LED_OFF PORTD.OUTSET = _BV(1) + #define LED_TOGGLE PORTD.OUTTGL = _BV(1) + #define LED_SET_OUTPUT PORTD.DIRSET = _BV(1) + #define IS_LED_on ( (PORTD.OUT & _BV(1)) != 0x00 ) #else - #define LED_ON PORTB |= _BV(5) - #define LED_OFF PORTB &= ~_BV(5) - #define LED_TOGGLE PORTB ^= _BV(5) - #define LED_SET_OUTPUT DDRB |= _BV(5) - #define IS_LED_on ( (PORTB & _BV(5)) != 0x00 ) + #define LED_ON PORTB |= _BV(5) + #define LED_OFF PORTB &= ~_BV(5) + #define LED_TOGGLE PORTB ^= _BV(5) + #define LED_SET_OUTPUT DDRB |= _BV(5) + #define IS_LED_on ( (PORTB & _BV(5)) != 0x00 ) +#endif + +//BIND +#ifdef XMEGA + #define IS_BIND_BUTTON_on ( (PORTD.IN & _BV(2)) == 0x00 ) +#else + #define BIND_SET_INPUT DDRB &= ~_BV(5) + #define BIND_SET_PULLUP PORTB |= _BV(5) + #define IS_BIND_BUTTON_on ( (PINB & _BV(5)) == 0x00 ) + #define BIND_SET_OUTPUT DDRB |= _BV(5) #endif // TX diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index 4124685..0ded1cb 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -196,11 +196,7 @@ void setup() delayMilliseconds(100); // Read status of bind button -#ifdef XMEGA - if( (PORTD.IN & _BV(2)) == 0x00 ) -#else - if( (PINB & _BV(5)) == 0x00 ) -#endif + if( IS_BIND_BUTTON_on ) BIND_BUTTON_FLAG_on; // If bind button pressed save the status for protocol id reset under hubsan // Read status of mode select binary switch @@ -483,6 +479,21 @@ static void protocol_init() #endif #if defined(DEVO_CYRF6936_INO) case MODE_DEVO: + #ifdef ENABLE_PPM + if(mode_select) //PPM mode + { + if(IS_BIND_BUTTON_FLAG_on) + { + eeprom_write_byte((uint8_t*)(30+mode_select),0x00); // reset to autobind mode for the current model + option=0; + } + else + { + option=eeprom_read_byte((uint8_t*)(30+mode_select)); // load previous mode: autobind or fixed id + if(option!=1) option=0; // if not fixed id mode then it should be autobind + } + } + #endif //ENABLE_PPM CTRL2_on; //antenna RF4 next_callback = DevoInit(); remote_callback = devo_callback;