diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index ec6bdc8..2e4a37d 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -202,8 +202,7 @@ void setup() // Read status of mode select binary switch // after this mode_select will be one of {0000, 0001, ..., 1111} #ifdef XMEGA - mode_select=0x0F - ( PORTA.IN & 0x0F ) ; //encoder dip switches 1,2,4,8=>B2,B3,B4,C0 - mode_select = MODE_SERIAL ; + mode_select = MODE_SERIAL ; // only serial mode #else mode_select=0x0F - ( ( (PINB>>2)&0x07 ) | ( (PINC<<3)&0x08) );//encoder dip switches 1,2,4,8=>B2,B3,B4,C0 #endif @@ -328,7 +327,7 @@ static void update_led_status(void) { if(blink led on + LED_OFF; //bind completed -> led on else blink+=BLINK_BIND_TIME; //blink fastly during binding LED_TOGGLE; @@ -384,7 +383,7 @@ static void CheckTimer(uint16_t (*cb)(void)) while((TCC1.INTFLAGS & TC1_CCAIF_bm) == 0); // wait 2ms... #else cli(); // Disable global int due to RW of 16 bits registers - OCR1A = OCR1A + 2000*2 ; // set compare A for callback + OCR1A += 2000*2 ; // set compare A for callback TIFR1=(1<>4)& 0x07; //subprotocol no (0-7) bits 4-6 - RX_num=rx_ok_buff[1]& 0x0F; - MProtocol_id=MProtocol_id_master+RX_num;//personalized RX bind + rx num // rx_num bits 0---3 - } - else - if( ((rx_ok_buff[0]&0x80)!=0) && ((cur_protocol[0]&0x80)==0) ) // Bind flag has been set - CHANGE_PROTOCOL_FLAG_on; //restart protocol with bind - cur_protocol[0] = rx_ok_buff[0]; //store current protocol - - // decode channel values - volatile uint8_t *p=rx_ok_buff+2; - uint8_t dec=-3; - for(uint8_t i=0;i=8) - { - dec-=8; - p++; - } - p++; - Servo_data[i]=((((*((uint32_t *)p))>>dec)&0x7FF)*5)/8+860; //value range 860<->2140 -125%<->+125% - } - RX_DONOTUPDTAE_off; + if( ((rx_ok_buff[0]&0x5F) != (cur_protocol[0]&0x5F)) || ( (rx_ok_buff[1]&0x7F) != cur_protocol[1] ) ) + { // New model has been selected + prev_protocol=cur_protocol[0]&0x1F; //store previous protocol so we can reset the module + cur_protocol[1] = rx_ok_buff[1]&0x7F; //store current protocol + CHANGE_PROTOCOL_FLAG_on; //change protocol + sub_protocol=(rx_ok_buff[1]>>4)& 0x07; //subprotocol no (0-7) bits 4-6 + RX_num=rx_ok_buff[1]& 0x0F; + MProtocol_id=MProtocol_id_master+RX_num;//personalized RX bind + rx num // rx_num bits 0---3 } - while(IS_RX_MISSED_BUFF_on); // We've just processed an old frame... + else + if( ((rx_ok_buff[0]&0x80)!=0) && ((cur_protocol[0]&0x80)==0) ) // Bind flag has been set + CHANGE_PROTOCOL_FLAG_on; //restart protocol with bind + cur_protocol[0] = rx_ok_buff[0]; //store current protocol + + // decode channel values + volatile uint8_t *p=rx_ok_buff+2; + uint8_t dec=-3; + for(uint8_t i=0;i=8) + { + dec-=8; + p++; + } + p++; + Servo_data[i]=((((*((uint32_t *)p))>>dec)&0x7FF)*5)/8+860; //value range 860<->2140 -125%<->+125% + } + RX_DONOTUPDTAE_off; + #ifdef XMEGA + cli(); + #else + UCSR0B &= ~(1<