Dan Cohen / Mbed 2 deprecated car_stereo

Dependencies:   Adafruit_GFX PinDetect_KL25Z PreampTDA7419 mbed

Revision:
4:46da1eff72bf
Parent:
3:8d3cc3488cd8
Child:
5:28533591b528
diff -r 8d3cc3488cd8 -r 46da1eff72bf main.cpp
--- a/main.cpp	Mon Oct 20 05:55:05 2014 +0000
+++ b/main.cpp	Sun Oct 26 22:53:27 2014 +0000
@@ -25,6 +25,9 @@
 Adafruit_SSD1306 display (gSpi, PTD0, PTD5, PTA13);  // SPI obect, DC, RST, CS
 PreampTDA7419    Preamp  (PTE0, PTE1);
 
+/////////////////////////////////////////////
+// Helper functions for the serial display // 
+/////////////////////////////////////////////
 void testfillrect(void) {
   uint8_t color = 1;
   for (int16_t i=0; i<display.height()/2; i+=3) {
@@ -48,9 +51,16 @@
   display.display();    
 }
 
-/////////////////////////////////////////////
-// Helper functions for the serial display // 
-/////////////////////////////////////////////
+void displayWrite(char firstLine[], char secondLine[])
+{
+  display.clearDisplay();
+  display.setCursor(0,0);
+  display.setTextSize(2);
+  display.printf("%s\r\n", firstLine);
+  display.printf("%s\r\n", secondLine);  
+  display.display();    
+}
+
 void processButtonPress (int button) {
 
   if (button == 0) {
@@ -99,131 +109,106 @@
     }
     displayWrite("Treble", Preamp.readTreble());
   break;
-  case (3):  // manage the middle value
-    displayWrite("Middle", 42);
-  break;
-  }
-}
-/*
-  case (3):  // manage the middle value
+  case (3):  // manage the treble value
     if (button == 2) {
-      if (middle > -5) {
-        middle--;
-      }
+      Preamp.decreaseMiddle();
     }
     if (button == 3) {
-      if (middle < 5) {
-        middle++;
-      }
+      Preamp.increaseMiddle();
     }
-    displayWrite("Middle",  middle );
-    break;
-  case (4):  // manage the bass value
+    displayWrite("Middle", Preamp.readMiddle());
+  break;
+  case (4):  // manage the treble value
     if (button == 2) {
-      if (bass > -5) {
-        bass--;
-      }
+      Preamp.decreaseBass();
     }
     if (button == 3) {
-      if (bass < 5) {
-        bass++;
-      }
+      Preamp.increaseBass();
     }
-    displayWrite("Bass",  bass );
+    displayWrite("Bass", Preamp.readBass());
   break;
 
   // Manage the attenuators
   case (5):  // manage the atten_lf value
     if (button == 2) {
-      if (atten_lf > 0) {
-        atten_lf--;
-      }
+        displayWrite("LF",   Preamp.decreaseSpeaker(1) );
+    } 
+    else if (button == 3) {
+        displayWrite("LF",   Preamp.increaseSpeaker(1) );
+    } 
+    else {
+        displayWrite("LF",   Preamp.readSpeaker(1) );
     }
-    if (button == 3) {
-      if (atten_lf < 11) {
-        atten_lf++;
-      }
-    }
-    displayWrite("LF",  atten_lf );
   break;
   case (6):  // manage the atten_rf value
     if (button == 2) {
-      if (atten_rf > 0) {
-        atten_rf--;
-      }
+        displayWrite("RF",   Preamp.decreaseSpeaker(2) );
+    } 
+    else if (button == 3) {
+        displayWrite("RF",   Preamp.increaseSpeaker(2) );
     }
-    if (button == 3) {
-      if (atten_rf < 11) {
-        atten_rf++;
-      }
-    }
-    displayWrite("RF",  atten_rf );
+    else {
+        displayWrite("RF",   Preamp.readSpeaker(2) );
+    }   
   break;
   case (7):  // manage the atten_lr value
     if (button == 2) {
-      if (atten_lr > 0) {
-        atten_lr--;
-      }
+        displayWrite("LR",   Preamp.decreaseSpeaker(3) );
     }
-    if (button == 3) {
-      if (atten_lr < 11) {
-        atten_lr++;
-      }
-    }
-    displayWrite("LR",  atten_lr );
+    else if (button == 3) {
+        displayWrite("LR",   Preamp.increaseSpeaker(3) );
+    } 
+    else {
+        displayWrite("LR",   Preamp.readSpeaker(3) );
+    }           
   break;
   case (8):  // manage the atten_rr value
     if (button == 2) {
-      if (atten_rr > 0) {
-        atten_rr--;
-      }
+        displayWrite("RR",   Preamp.decreaseSpeaker(4) );
+    } 
+    else if (button == 3) {
+        displayWrite("RR",   Preamp.increaseSpeaker(4) );
     }
-    if (button == 3) {
-      if (atten_rr < 11) {
-        atten_rr++;
-      }
-    }
-    displayWrite("RR",  atten_rr );
+    else {
+        displayWrite("RR",   Preamp.readSpeaker(4) );
+    }     
   break;
-  case (9):  // manage the atten_mix value
+  case (9):  // manage the atten_sub value
     if (button == 2) {
-      if (atten_mix > 0) {
-        atten_mix--;
-      }
+        displayWrite("SUB",  Preamp.decreaseSpeaker(5) );
     }
-    if (button == 3) {
-      if (atten_mix < 11) {
-        atten_mix++;
-      }
+    else if (button == 3) {
+        displayWrite("SUB",  Preamp.increaseSpeaker(5) );
     }
-    displayWrite("Mix",  atten_mix );
+    else {
+        displayWrite("SUB",   Preamp.readSpeaker(5) );
+    }      
   break;
-  case (10):  // manage the atten_sub value
+  case (10):  // manage the atten_mix value
     if (button == 2) {
-      if (atten_sub > 0) {
-        atten_sub--;
-      }
+        displayWrite("Mix Level",  Preamp.decreaseSpeaker(6) );
     }
-    if (button == 3) {
-      if (atten_sub < 11) {
-        atten_sub++;
-      }
+    else if (button == 3) {
+        displayWrite("Mix Level",  Preamp.increaseSpeaker(6) );
     }
-    displayWrite("SUB",  atten_sub );
+    else {
+        displayWrite("Mix Level",   Preamp.readSpeaker(6) );
+    }         
   break;
   case (11):  // manage the atten_sub value
-    if (button == 2) {
-      mix = 0;
+    if ( (button == 2) || (button == 3) ) {
+      Preamp.toggleMix();
+    } 
+    if (Preamp.readMix()) {
+      displayWrite("Mix",  "Enabled");
     }
-    if (button == 3) {
-      mix = 1;
+    else {
+      displayWrite("Mix", "Disabled");
     }
-    displayWrite("Mix",  mix );
-  break;
-
+  break;  
+  
   }
 }
-*/
 
 void UpPressed( void )
 {
@@ -260,7 +245,7 @@
     display.clearDisplay();
     // draw multiple rectangles
     testfillrect();
-    wait(0.5);
+    wait(0.3);
     display.display();
     display.clearDisplay();
     display.display();