From 669bde1e452070a69b3932671e87eaaea55cb8fc Mon Sep 17 00:00:00 2001 From: jphelirc Date: Mon, 18 Oct 2010 08:26:08 +0000 Subject: [PATCH] preparing for DIP switch functions git-svn-id: https://arducopter.googlecode.com/svn/trunk@686 f9c3cf11-9bcb-44bc-f272-b75c42450872 --- ArducopterNG/Arducopter.h | 6 ++++++ ArducopterNG/Functions.pde | 22 +++++++++++++++++++++- ArducopterNG/System.pde | 23 +++++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/ArducopterNG/Arducopter.h b/ArducopterNG/Arducopter.h index a419cde504..f62d97f436 100644 --- a/ArducopterNG/Arducopter.h +++ b/ArducopterNG/Arducopter.h @@ -205,6 +205,12 @@ int control_pitch; int control_yaw; //float K_aux; + +boolean SW_DIP1; // closest to SW2 slider switch +boolean SW_DIP2; +boolean SW_DIP3; +boolean SW_DIP4; // closest to header pins + // Attitude PID controls float roll_I=0; float roll_D; diff --git a/ArducopterNG/Functions.pde b/ArducopterNG/Functions.pde index d5ae514ee8..65395b1bc3 100644 --- a/ArducopterNG/Functions.pde +++ b/ArducopterNG/Functions.pde @@ -111,4 +111,24 @@ int channel_filter(int ch, int ch_old) } return((ch + ch_old) >> 1); // Small filtering //return(ch); -} +} + + +// Special APM PinMode settings and others +void APMPinMode(volatile unsigned char &Port, byte Pin, boolean Set) +{ + if (Set) { + Port |= (1 << Pin); + } else { + Port &= ~(1 << Pin); + } +} + +boolean APMPinRead(volatile unsigned char &Port, byte Pin) +{ + if(Port & (1 << Pin)) + return 1; + else + return 0; +} + diff --git a/ArducopterNG/System.pde b/ArducopterNG/System.pde index 72332c4098..5ab767e1e1 100644 --- a/ArducopterNG/System.pde +++ b/ArducopterNG/System.pde @@ -41,6 +41,13 @@ void APM_Init() { pinMode(LED_Green,OUTPUT); //Green LED C (PC0) pinMode(SW1_pin,INPUT); //Switch SW1 (pin PG0) pinMode(RELE_pin,OUTPUT); // Rele output + + APMPinMode(DDRE,7,INPUT); //DIP1 + APMPinMode(DDRE,6,INPUT); //DIP2 + APMPinMode(DDRL,6,INPUT); //DIP3 + APMPinMode(DDRL,7,INPUT); //DIP4 + + digitalWrite(RELE_pin,LOW); APM_RC.Init(); // APM Radio initialization @@ -122,6 +129,22 @@ void APM_Init() { delay(1000); + // Read DIP Switches and other important values. DIP switches needs special functions to + // read due they are not defined as normal pins like other GPIO's are. + SW_DIP1 = APMPinRead(PINE, 7); + SW_DIP2 = APMPinRead(PINE, 6); + SW_DIP3 = APMPinRead(PINL, 6); + SW_DIP4 = APMPinRead(PINL, 7); + + /* Works, tested 18-10-10 JP + if(SW_DIP1) { + SerPrln("+ mode"); + } else { + SerPrln("x mode"); + } + */ + + DataFlash.StartWrite(1); // Start a write session on page 1 //timer = millis(); //tlmTimer = millis();