diff --git a/Multiprotocol/ESky_nrf24l01.ino b/Multiprotocol/ESky_nrf24l01.ino index 1ed7d3d..9281697 100644 --- a/Multiprotocol/ESky_nrf24l01.ino +++ b/Multiprotocol/ESky_nrf24l01.ino @@ -117,11 +117,10 @@ static void __attribute__((unused)) ESKY_send_packet(uint8_t bind) // For arithmetic simplicity, channels are repeated in rf_channels array if (hopping_frequency_no == 0) { - const uint8_t ch[]={AILERON, ELEVATOR, THROTTLE, RUDDER, AUX1, AUX2}; for (uint8_t i = 0; i < 6; i++) { - packet[i*2] = Servo_data[ch[i]]>>8; //high byte of servo timing(1000-2000us) - packet[i*2+1] = Servo_data[ch[i]]&0xFF; //low byte of servo timing(1000-2000us) + packet[i*2] = Servo_data[CH_AETR[i]]>>8; //high byte of servo timing(1000-2000us) + packet[i*2+1] = Servo_data[CH_AETR[i]]&0xFF; //low byte of servo timing(1000-2000us) } } rf_ch = hopping_frequency[hopping_frequency_no]; diff --git a/Multiprotocol/FlySky_a7105.ino b/Multiprotocol/FlySky_a7105.ino index 4810b5d..92f723d 100644 --- a/Multiprotocol/FlySky_a7105.ino +++ b/Multiprotocol/FlySky_a7105.ino @@ -142,11 +142,10 @@ static void __attribute__((unused)) flysky_build_packet(uint8_t init) packet[2] = rx_tx_addr[2]; packet[3] = rx_tx_addr[1]; packet[4] = rx_tx_addr[0]; - const uint8_t ch[]={AILERON, ELEVATOR, THROTTLE, RUDDER, AUX1, AUX2, AUX3, AUX4}; for(i = 0; i < 8; i++) { - packet[5 + i*2]=Servo_data[ch[i]]&0xFF; //low byte of servo timing(1000-2000us) - packet[6 + i*2]=(Servo_data[ch[i]]>>8)&0xFF; //high byte of servo timing(1000-2000us) + 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) } flysky_apply_extension_flags(); } diff --git a/Multiprotocol/Hisky_nrf24l01.ino b/Multiprotocol/Hisky_nrf24l01.ino index c6edabe..36c35b8 100644 --- a/Multiprotocol/Hisky_nrf24l01.ino +++ b/Multiprotocol/Hisky_nrf24l01.ino @@ -120,9 +120,8 @@ static void __attribute__((unused)) build_ch_data() { uint16_t temp; uint8_t i,j; - const uint8_t ch[]={AILERON, ELEVATOR, THROTTLE, RUDDER, AUX1, AUX2, AUX3, AUX4}; for (i = 0; i< 8; i++) { - j=ch[i]; + j=CH_AETR[i]; temp=map(limit_channel_100(j),PPM_MIN_100,PPM_MAX_100,0,1000); if (j == THROTTLE) // It is clear that hisky's throttle stick is made reversely, so I adjust it here on purpose temp = 1000 -temp; diff --git a/Multiprotocol/J6Pro_cyrf6936.ino b/Multiprotocol/J6Pro_cyrf6936.ino index e434460..f82bb70 100644 --- a/Multiprotocol/J6Pro_cyrf6936.ino +++ b/Multiprotocol/J6Pro_cyrf6936.ino @@ -78,11 +78,10 @@ static void __attribute__((unused)) j6pro_build_data_packet() uint8_t i; uint32_t upperbits = 0; uint16_t value; - const uint8_t ch[]={AILERON, ELEVATOR, THROTTLE, RUDDER, AUX1, AUX2, AUX3, AUX4, AUX5, AUX6, AUX7, AUX8}; packet[0] = 0xaa; //FIXME what is this? for (i = 0; i < 12; i++) { - value = convert_channel_10b(ch[i]); + value = convert_channel_10b(CH_AETR[i]); packet[i+1] = value & 0xff; upperbits |= (value >> 8) << (i * 2); } diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index 2e1cd67..820e11c 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -74,6 +74,11 @@ uint8_t RX_num; uint8_t calData[48][3]; #endif +//Channel mapping for protocols +const uint8_t CH_AETR[]={AILERON, ELEVATOR, THROTTLE, RUDDER, AUX1, AUX2, AUX3, AUX4, AUX5, AUX6, AUX7, AUX8}; +//const uint8_t CH_TAER[]={THROTTLE, AILERON, ELEVATOR, RUDDER, AUX1, AUX2, AUX3, AUX4, AUX5, AUX6, AUX7, AUX8}; +//const uint8_t CH_RETA[]={RUDDER, ELEVATOR, THROTTLE, AILERON, AUX1, AUX2, AUX3, AUX4, AUX5, AUX6, AUX7, AUX8}; + // Mode_select variables uint8_t mode_select; uint8_t protocol_flags=0,protocol_flags2=0; @@ -650,6 +655,17 @@ static void module_reset() } } +int16_t map( int16_t x, int16_t in_min, int16_t in_max, int16_t out_min, int16_t out_max) +{ +// return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; + long y ; + x -= in_min ; + y = out_max - out_min ; + y *= x ; + x = y / (in_max - in_min) ; + return x + out_min ; +} + // Channel value is converted to 8bit values full scale uint8_t convert_channel_8b(uint8_t num) { diff --git a/Multiprotocol/SFHSS_cc2500.ino b/Multiprotocol/SFHSS_cc2500.ino index 4a8b545..29f1880 100644 --- a/Multiprotocol/SFHSS_cc2500.ino +++ b/Multiprotocol/SFHSS_cc2500.ino @@ -135,12 +135,10 @@ static void __attribute__((unused)) SFHSS_build_data_packet() #define spacer1 0x02 //0b10 #define spacer2 (spacer1 << 4) uint8_t ch_offset = state == SFHSS_DATA1 ? 0 : 4; - const uint8_t ch[]={AILERON, ELEVATOR, THROTTLE, RUDDER, AUX1, AUX2, AUX3, AUX4}; - - uint16_t ch1 = SFHSS_convert_channel(ch[ch_offset+0]); - uint16_t ch2 = SFHSS_convert_channel(ch[ch_offset+1]); - uint16_t ch3 = SFHSS_convert_channel(ch[ch_offset+2]); - uint16_t ch4 = SFHSS_convert_channel(ch[ch_offset+3]); + uint16_t ch1 = SFHSS_convert_channel(CH_AETR[ch_offset+0]); + uint16_t ch2 = SFHSS_convert_channel(CH_AETR[ch_offset+1]); + uint16_t ch3 = SFHSS_convert_channel(CH_AETR[ch_offset+2]); + uint16_t ch4 = SFHSS_convert_channel(CH_AETR[ch_offset+3]); packet[0] = 0x81; // can be 80, 81, 81 for Orange, only 81 for XK packet[1] = rx_tx_addr[0]; diff --git a/Multiprotocol/SLT_nrf24l01.ino b/Multiprotocol/SLT_nrf24l01.ino index e97ae54..0622b55 100644 --- a/Multiprotocol/SLT_nrf24l01.ino +++ b/Multiprotocol/SLT_nrf24l01.ino @@ -111,9 +111,8 @@ static void __attribute__((unused)) SLT_build_packet() { // aileron, elevator, throttle, rudder, gear, pitch uint8_t e = 0; // byte where extension 2 bits for every 10-bit channel are packed - const uint8_t ch[]={AILERON, ELEVATOR, THROTTLE, RUDDER}; for (uint8_t i = 0; i < 4; ++i) { - uint16_t v = convert_channel_10b(ch[i]); + uint16_t v = convert_channel_10b(CH_AETR[i]); packet[i] = v; e = (e >> 2) | (uint8_t) ((v >> 2) & 0xC0); }