finished

Dependencies:   C12832 mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
cathal66
Date:
Fri May 08 10:21:45 2015 +0000
Parent:
0:b0b296a7503f
Commit message:
finished

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r b0b296a7503f -r d7e31ae56923 main.cpp
--- a/main.cpp	Sun Apr 26 12:00:40 2015 +0000
+++ b/main.cpp	Fri May 08 10:21:45 2015 +0000
@@ -78,7 +78,7 @@
     if(can1.write(CANMessage(79, &counter, 1)))     //send heartbeat message
         {
         counter++;                                  //increament counter
-        pc.printf("Heartbeat Message sent: %d\n", counter);
+        pc.printf("Heartbeat Message sent: %d\n\r", counter);
         Heartbeat_timer_Mutex.lock();
         heatbeat_timeout = 1;                       //set that the timer has run out and message sent
         Heartbeat_timer_Mutex.unlock();
@@ -98,7 +98,7 @@
             {
             message_t *message = (message_t*)evt.value.p;  
             can1.write(CANMessage(message->can_id, message->msg_data_mem, 8));  //send the store in the queue 
-            printf("cad: %d cmd: %4d %4d %4d %4d %4d %4d %4d %4d\n\r",message->can_id, message->msg_data_mem[0],message->msg_data_mem[1],message->msg_data_mem[2],message->msg_data_mem[3],message->msg_data_mem[4],message->msg_data_mem[5],message->msg_data_mem[6],message->msg_data_mem[7]);
+            pc.printf("cad: %d cmd: %4d %4d %4d %4d %4d %4d %4d %4d \n \r",message->can_id, message->msg_data_mem[0],message->msg_data_mem[1],message->msg_data_mem[2],message->msg_data_mem[3],message->msg_data_mem[4],message->msg_data_mem[5],message->msg_data_mem[6],message->msg_data_mem[7]);
         
             mpool.free(message);                //dump the message in the mpool
             }
@@ -114,7 +114,7 @@
     char fire=0;
     char up=0;
     char right=0;
-     
+    int  high_to_low= 1;
      while(1)
      {
          //pc.printf("Debug 1: \n\r");   
@@ -127,23 +127,18 @@
         fire = button_fire;             //read the button_fire into down in the thread.
         up = button_up;                 //read the button_up into down in the thread.
         right = button_right;           //read the button_right into down in the thread.
-        button_down = 0;                //after reading the variable, init the variable to zero
-        button_left = 0;                //after reading the variable, init the variable to zero
-        button_fire = 0;                //after reading the variable, init the variable to zero
-        button_up = 0;                  //after reading the variable, init the variable to zero
-        button_right = 0;               //after reading the variable, init the variable to zero
         Button_Press_Mutex.unlock();    //Mutex unlock the gobal variables to leave other thread use them
             //__enable_irq();           // Enable Interrupts
         
         //pc.printf("Debug 2: \n\r");   //for debugging
-        
+        //pc.printf("data: %4d %4d %4d %4d %4d HtL: %4d \n\r",down , left , fire , up , right, high_to_low);
         
         //Cheack to see if any of the variables equals to '1' if any of the variables 
         //equals to '1' then send all of the value of the button on the canbus with 
         //the addrress 70 to match the design layout. the 'if' statment 'or' each of 
         //the variable together and then compares  them to '1'. if the statement is 
         //true, then send the  CANbus message.
-        if (down || left || fire || up || right == 1)
+        if ((down || left || fire || up || right == 1) && (high_to_low == 1))
             {
             message_t *message = mpool.alloc(); //alocate memory in the mpool for message
             message-> can_id = 70;              //set the address of the CANbus message
@@ -158,13 +153,26 @@
             queue.put(message);                 //add the message to the queue to send on CANbus
             
             //led3 = !led3;                     //debugging
-            down = 0;                           //init the variable to '0'
-            left = 0;                           //init the variable to '0'     
-            fire = 0;                           //init the variable to '0'
-            up = 0;                             //init the variable to '0'
-            right = 0;                          //init the variable to '0'
+            high_to_low = 0;
             } 
-        Thread::wait(500);                      //debounce delay for thread 
+        if ((!down && !left && !fire && !up && !right == 1) && (high_to_low == 0))
+            {
+            message_t *message = mpool.alloc(); //alocate memory in the mpool for message
+            message-> can_id = 70;              //set the address of the CANbus message
+            message-> msg_data_mem[0] = fire;   //store the value of fire in msg.data[0]
+            message-> msg_data_mem[1] = left;   //store the value of left in msg.data[1]
+            message-> msg_data_mem[2] = right;  //store the value of right in msg.data[2]
+            message-> msg_data_mem[3] = up;     //store the value of up in msg.data[3]
+            message-> msg_data_mem[4] = down;   //store the value of down in msg.data[4]
+            message-> msg_data_mem[5] = 0;      //store the value of 0 in msg.data[5]
+            message-> msg_data_mem[6] = 0;      //store the value of 0 in msg.data[6]
+            message-> msg_data_mem[7] = 0;      //store the value of 0 in msg.data[7]           
+            queue.put(message);                 //add the message to the queue to send on CANbus
+            
+            //led3 = !led3;                     //debugging
+            high_to_low = 1;
+            } 
+        Thread::wait(10);                      //debounce delay for thread 
         }
 }
 
@@ -212,25 +220,45 @@
 ////////////////////////////////////////////////////////////////////////////////////////
 ////////////////////////////////interrupts//////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////////////////////////
-void Button_down_Intrp() {
+void Button_down_Intrp_rise() {
 button_down = 1;            //set the varible to 1 when button press
 } 
 
-void Button_left_Intrp() {
+void Button_left_Intrp_rise() {
 button_left = 1;            //set the varible to 1 when button press
 } 
 
-void Button_fire_Intrp() {
+void Button_fire_Intrp_rise() {
 button_fire = 1;            //set the varible to 1 when button press 
 }
  
-void Button_up_Intrp() {
+void Button_up_Intrp_rise() {
 button_up = 1;              //set the varible to 1 when button press
 }
  
-void Button_right_Intrp() {
+void Button_right_Intrp_rise() {
 button_right = 1;           //set the varible to 1 when button press 
 } 
+/////
+void Button_down_Intrp_fall() {
+button_down = 0;            //set the varible to 0 when button press
+} 
+
+void Button_left_Intrp_fall() {
+button_left = 0;            //set the varible to 0 when button press
+} 
+
+void Button_fire_Intrp_fall() {
+button_fire = 0;            //set the varible to 0 when button press 
+}
+ 
+void Button_up_Intrp_fall() {
+button_up = 0;              //set the varible to 0 when button press
+}
+ 
+void Button_right_Intrp_fall() {
+button_right = 0;           //set the varible to 0 when button press 
+} 
 
 
 ////////////////////////////////////////////////////////////////////////////////////////
@@ -249,12 +277,17 @@
     RtosTimer timer(timeout_heartbeat_event, osTimerPeriodic, (void *)0);
     
     //Setup Interrupts
-    down_intrp.rise(&Button_down_Intrp);    //joystick down
-    left_intrp.rise(&Button_left_Intrp);    //joystick left
-    fire_intrp.rise(&Button_fire_Intrp);    //joystick fire
-    up_intrp.rise(&Button_up_Intrp);        //joystick up
-    right_intrp.rise(&Button_right_Intrp);  //joystick right
-
+    down_intrp.rise(&Button_down_Intrp_rise);    //joystick down
+    left_intrp.rise(&Button_left_Intrp_rise);    //joystick left
+    fire_intrp.rise(&Button_fire_Intrp_rise);    //joystick fire
+    up_intrp.rise(&Button_up_Intrp_rise);        //joystick up
+    right_intrp.rise(&Button_right_Intrp_rise);  //joystick right
+    down_intrp.fall(&Button_down_Intrp_fall);    //joystick down
+    left_intrp.fall(&Button_left_Intrp_fall);    //joystick left
+    fire_intrp.fall(&Button_fire_Intrp_fall);    //joystick fire
+    up_intrp.fall(&Button_up_Intrp_fall);        //joystick up
+    right_intrp.fall(&Button_right_Intrp_fall);  //joystick right
+    
     timer.start(2000);                      //start the timer
     
     while(1)