diff --git a/Multiprotocol/Common.ino b/Multiprotocol/Common.ino index 4622b6b..37415f1 100644 --- a/Multiprotocol/Common.ino +++ b/Multiprotocol/Common.ino @@ -146,6 +146,24 @@ uint16_t convert_channel_frsky(uint8_t num) return ((val*15)>>4)+1290; } +uint16_t limit_uint_16_t(uint16_t val, uint16_t min, uint16_t max) +{ + if(val > max) + return max; + else + if (val < min) + return min; + return val; +} + +uint16_t apply_direct_input_dead_band_center(uint16_t val, uint16_t center, uint16_t dead_band){ + uint16_t off_center = abs(center - val); + if(off_center < dead_band){ + return center; + } + return val; +} + /******************************/ /** FrSky D and X routines **/ /******************************/ diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index 349793e..a76f010 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -261,14 +261,26 @@ void setup() #else TX_INV_off; RX_INV_off; - #endif + #endif #endif pinMode(BIND_pin,INPUT_PULLUP); pinMode(PPM_pin,INPUT); - pinMode(S1_pin,INPUT_PULLUP);//dial switch - pinMode(S2_pin,INPUT_PULLUP); - pinMode(S3_pin,INPUT_PULLUP); - pinMode(S4_pin,INPUT_PULLUP); + #ifdef ENABLE_DIRECT_INPUT + pinMode(S1_pin, INPUT_ANALOG); //joystick pins + pinMode(S2_pin, INPUT_ANALOG); + pinMode(S3_pin, INPUT_ANALOG); + pinMode(S4_pin, INPUT_ANALOG); + pinMode(AUX1_pin, INPUT_PULLUP); + pinMode(AUX2_pin, INPUT_PULLUP); + pinMode(AUX3_pin, INPUT_PULLUP); + pinMode(AUX4_pin, INPUT_PULLUP); + #else + pinMode(S1_pin, INPUT_PULLUP); //dial switch + pinMode(S2_pin, INPUT_PULLUP); + pinMode(S3_pin, INPUT_PULLUP); + pinMode(S4_pin ,INPUT_PULLUP); + #endif + //Random pins pinMode(PB0, INPUT_ANALOG); // set up pin for analog input pinMode(PB1, INPUT_ANALOG); // set up pin for analog input @@ -339,7 +351,7 @@ void setup() //Wait for every component to start delayMilliseconds(100); - + // Read status of bind button if( IS_BIND_BUTTON_on ) { @@ -357,7 +369,7 @@ void setup() mode_select= 0x0F -(uint8_t)(((GPIOA->regs->IDR)>>4)&0x0F); #else mode_select = - ((PROTO_DIAL1_ipr & _BV(PROTO_DIAL1_pin)) ? 0 : 1) + + ((PROTO_DIAL1_ipr & _BV(PROTO_DIAL1_pin)) ? 0 : 1) + ((PROTO_DIAL2_ipr & _BV(PROTO_DIAL2_pin)) ? 0 : 2) + ((PROTO_DIAL3_ipr & _BV(PROTO_DIAL3_pin)) ? 0 : 4) + ((PROTO_DIAL4_ipr & _BV(PROTO_DIAL4_pin)) ? 0 : 8); @@ -385,7 +397,7 @@ void setup() #ifndef ORANGE_TX //Init the seed with a random value created from watchdog timer for all protocols requiring random values #ifdef STM32_BOARD - randomSeed((uint32_t)analogRead(PB0) << 10 | analogRead(PB1)); + randomSeed((uint32_t)analogRead(PB0) << 10 | analogRead(PB1)); #else randomSeed(random_value()); #endif @@ -395,7 +407,7 @@ void setup() MProtocol_id_master=random_id(10,false); debugln("Module Id: %lx", MProtocol_id_master); - + #ifdef ENABLE_PPM //Protocol and interrupts initialization if(mode_select != MODE_SERIAL) @@ -478,6 +490,13 @@ void setup() #endif //ENABLE_SERIAL } LED2_on; + #ifdef ENABLE_DIRECT_INPUT + for(uint8_t i=0;i<3;i++) + cur_protocol[i]= DIRECT_INPUT_PROTOCOL_SELECT; + protocol = DIRECT_INPUT_PROTOCOL_SELECT; + CHANGE_PROTOCOL_FLAG_on; + #endif //ENABLE_DIRECT_INPUT + debugln("Init complete"); } @@ -602,6 +621,12 @@ uint8_t Update_All() last_signal=millis(); } #endif //ENABLE_PPM + #ifdef ENABLE_DIRECT_INPUT + update_direct_input_data(); + update_channels_aux(); + INPUT_SIGNAL_on; //valid signal received + last_signal=millis(); + #endif //ENABLE_DIRECT_INPUT update_led_status(); #if defined(TELEMETRY) #if ( !( defined(MULTI_TELEMETRY) || defined(MULTI_STATUS) ) ) @@ -661,6 +686,66 @@ static void update_channels_aux(void) Channel_AUX|=1<16 #error MIN_PPM_CHANNELS must be below or equal to 16. The default for this value is 4. #endif diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index 2d54dc5..c730f06 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -271,6 +271,39 @@ //If you do not plan to use the PPM mode comment this line using "//" to save Flash space, you don't need to configure anything below in this case #define ENABLE_PPM + +/**********************************/ +/*** DIRECT INPUT MODE SETTINGS ***/ +/**********************************/ +//In this section you can configure the direct input mode. +//The direct mode enables controls(analog joystics, buttons) wired directly to the board +//Current mappings are: AILERON-PA4, ELEVATOR-PA5, THROTTLE-PA6, RUDDER-PA7, AUX1-PB10, AUX2-PB11, AUX3-PA2, AUX4-PA3 + +//If plan to use direct input mode please uncomment lines below and comment out SERIAL and PPM MODE +//#define ENABLE_DIRECT_INPUT +// +//#define DIRECT_INPUT_PROTOCOL_SELECT PROTO_SYMAX +// +//#define DEAD_CENTER 25 //change in raw input value before being reporter as movement +// +////Enable serial debug and update calibration values below based on the output +// +//#define THROTTLE_MIN 500 +//#define THROTTLE_MAX 3550 +// +//#define AILERON_MIN 500 +//#define AILERON_CENTER 1525 +//#define AILERON_MAX 3550 +// +//#define ELEVATOR_MIN 500 +//#define ELEVATOR_CENTER 1525 +//#define ELEVATOR_MAX 3550 +// +//#define RUDDER_MIN 500 +//#define RUDDER_CENTER 1525 +//#define RUDDER_MAX 3550 + + /** TX END POINTS **/ //It is important for the module to know the endpoints of your radio. //Below are some standard transmitters already preconfigured.