RTOS homework 4

Dependencies:   C12832_lcd mbed

Revision:
8:95f4f470ae28
Parent:
7:562f136c7681
Child:
9:ea97a69b9b93
--- a/main.cpp	Sun Aug 18 16:04:27 2013 +0000
+++ b/main.cpp	Sun Aug 18 16:42:56 2013 +0000
@@ -58,11 +58,11 @@
     InterruptIn   iJoyStickRight (p16);         // joystick right rising edge.
     InterruptIn   iJoyStickCenter(p14);         // 1 if joystick middle pressed.
     
-    DigitalIn    dJoyStickUp    (p15);
-    DigitalIn    dJoyStickDown  (p12);
-    DigitalIn    dJoyStickLeft  (p13);
-    DigitalIn    dJoyStickRight (p16);
-    DigitalIn    dJoyStickCenter(p14);
+    DigitalIn     dJoyStickUp    (p15);         // joystick up sample.
+    DigitalIn     dJoyStickDown  (p12);         // joystick down sample.
+    DigitalIn     dJoyStickLeft  (p13);         // joystick left sample.
+    DigitalIn     dJoyStickRight (p16);         // joystick right sample.
+    DigitalIn     dJoyStickCenter(p14);         // joystick center sample.
 
     DigitalOut  led3(LED1);                     // leftmost LED.
     
@@ -115,75 +115,22 @@
       lUpDownHowMany = 0;
     }
 /*----------------------------------------------//----------------------------*/
-    void ISR_left(void)                         // increase beat rate.
+    void ISR_left(void)                         // increase BPM.
     {
-      int  dPressedSeconds;                     // how many seconds joystick pressed.   
-      int  dMultiCount;                         // slow count rate.
-      char cDiscontinuity;                      // 1 = break phase & change BPM now.
-      
-      cDiscontinuity = 0;                       // don't break phase.
-      
-                                                // calculate slow rate period.
-      dMultiCount = (int) ((float) (1.0 / ((float) UDSAMPLERATE)));
-            
-          while (dJoyStickLeft)                 // while joystick still pressed.
-      {
-                                                // rate-range calculations.
-        dPressedSeconds = (int) (((float) lUpDownHowMany) * UDSAMPLERATE);
-        if (dPressedSeconds < 5) {if (!(lUpDownHowMany % dMultiCount)) dMetroBPM ++;}
-        else
-        if (dPressedSeconds < 10) dMetroBPM++;
-        else dMetroBPM += 5;
-        lUpDownHowMany++;                       // joystick holddown time.
-      }
-      lUpDownHowMany = 0;                  // clear when not up or down.
+      dMetroBPM++;
       
                                                       // saturate metronome BPM.
       if (dMetroBPM > METROMAX) dMetroBPM = METROMAX;
       if (dMetroBPM < METROMIN) dMetroBPM = METROMIN;
-      
-      fMetroDelay = 60.0 / (float) (dMetroBPM); // calculate Ticker delay time.
-      
-      if (cDiscontinuity)                       // implement 60BPS now.
-      {
-        tickerMetronome.detach();               // only one attachment.  
-        tickerMetronome.attach(&interrupt_service_M,fMetroDelay);      
-      }
     }
 /*----------------------------------------------//----------------------------*/
     void ISR_right(void)                        // decrease beat rate.
     {
-      int  dPressedSeconds;                     // how many seconds joystick pressed.   
-      int  dMultiCount;                         // slow count rate.
-      char cDiscontinuity;                      // 1 = break phase & change BPM now.
-      
-      cDiscontinuity = 0;                       // don't break phase.
+      dMetroBPM--;
       
-                                                // calculate slow rate period.
-      dMultiCount = (int) ((float) (1.0 / ((float) UDSAMPLERATE)));
-      while (dJoyStickRight)                    // while joystick still pressed.
-      {
-                                                // rate-range calculations.
-        dPressedSeconds = (int) (((float) lUpDownHowMany) * UDSAMPLERATE);
-        if (dPressedSeconds < 5) {if (!(lUpDownHowMany % dMultiCount)) dMetroBPM --;}
-        else
-        if (dPressedSeconds < 10) dMetroBPM--;
-        else dMetroBPM -= 5;
-        lUpDownHowMany++;                       // joystick holddown time.
-      }
-      lUpDownHowMany = 0;                  // clear when not up or down.
-      
-                                                 // saturate metronome BPM.
+                                                      // saturate metronome BPM.
       if (dMetroBPM > METROMAX) dMetroBPM = METROMAX;
       if (dMetroBPM < METROMIN) dMetroBPM = METROMIN;
-      
-      fMetroDelay = 60.0 / (float) (dMetroBPM); // calculate Ticker delay time.
-      
-      if (cDiscontinuity)                       // implement 60BPS now.
-      {
-        tickerMetronome.detach();               // only one attachment.  
-        tickerMetronome.attach(&interrupt_service_M,fMetroDelay);      
-      }     
     }
 /*----------------------------------------------//----------------------------*/
     void ISR_up(void)
@@ -196,23 +143,7 @@
 /*----------------------------------------------//----------------------------*/
     void ISR_center(void)                       // set BPM = 60.
     {
-          int  dPressedSeconds;                     // how many seconds joystick pressed.   
-      int  dMultiCount;                         // slow count rate.
-      char cDiscontinuity;                      // 1 = break phase & change BPM now.
-      
-          if (dJoyStickCenter)
-      {
-        dMetroBPM      = 60;                    // center-button -> 60BPM.
-        cDiscontinuity = 1;                     // pending phase-break.
-      }
-      
-         fMetroDelay = 60.0 / (float) (dMetroBPM); // calculate Ticker delay time.
-      
-      if (cDiscontinuity)                       // implement 60BPS now.
-      {
-        tickerMetronome.detach();               // only one attachment.  
-        tickerMetronome.attach(&interrupt_service_M,fMetroDelay);      
-      }   
+      dMetroBPM = 60;
       
     }
 /*----------------------------------------------//----------------------------*/
@@ -235,7 +166,7 @@
             
       LCD3;                                     // line 3.
       
-      lcd.printf("  RTOS HW 3 PART 1");
+      lcd.printf("  RTOS HW 4");
     }
 /*----------------------------------------------//----------------------------*/
 //  this metronome tick ISR will self-adjust to the current user-selected