Team Kryptonite EE300 Keypad Subsystem

Dependencies:   keypad mbed

Fork of mbed_can_bus_test1 by Kryptonite

Files at this revision

API Documentation at this revision

Comitter:
Googlesomething
Date:
Fri Dec 01 16:06:09 2017 +0000
Parent:
1:907c82f7f923
Child:
3:e019f1954b2a
Commit message:
Version 1.20

Changed in this revision

keypad.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/keypad.lib	Fri Dec 01 16:06:09 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/yoonghm/code/keypad/#da060f8c03e8
--- a/main.cpp	Fri Dec 01 14:47:22 2017 +0000
+++ b/main.cpp	Fri Dec 01 16:06:09 2017 +0000
@@ -2,51 +2,58 @@
 #include "Keypad.h"
 
 Ticker ticker;
+Serial        PC(USBTX, USBRX);
 DigitalOut led1(LED1);
 DigitalOut led2(LED2);
 CAN can1(p9,p10);
 CAN can2(p30,p29);
+DigitalIn pin21(p21);
+DigitalIn pin22(p22);
+DigitalIn pin23(p23);
+DigitalIn pin24(p24);
+DigitalIn pin25(p25);
+DigitalIn pin26(p26);
+DigitalIn pin27(p27);
+
 
 //Declare KeyPad GPIO pins here
 
 char Keytable[] = { '1', '2', '3', //row0, p1, mbedpin21
                     '4', '5', '6', //row1, p2, mbedpin22
-                    '7', '8', '8', //row2, p3, mbedpin23
+                    '7', '8', '9', //row2, p3, mbedpin23
                     '*', '0', '#', //row3, p4, mbedpin24
                    };
                     //col0, col1, col2
                     //p5, p6, p7
                     //mbedpin25, mbedpin26, mbedpin27
-const byte ROWS = 4;
-const byte COLS = 3;
-char keys[ROWS][COLS] = {
-    {'1','2','3'},
-    {'4','5','6'},
-    {'7','8','9'},
-    {'*','0','#'}
-};
-byte rowPins[ROWS] = {1,2,3,4}; 
-byte colPins[COLS] = {5,6,7};
+
 
-Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS,  COLS);  
+int32_t       Index =-1;
+int           State;
+ 
+uint32_t cbAfterInput(uint32_t _index)
+{
+    Index = _index;
+    return 0;
+} 
 
 //Universal ID: 1337
 //CAN Message Info
 char counter        = 0;    //keypad system CAN test variable
 char start          = '*';  //Start
-char stop           = '#';  //Stop
+char stop           = '#';  //Stop / Reset
 char amp5           = 5;    //Digipot
 char amp4           = 4;    //Digipot
 char amp3           = 3;    //Digipot
 char amp2           = 2;    //Digipot
 char amp1           = 1;    //Digipot
-char sin10Hz        = 'q';  //DAC
-char sin1Hz         = 'w';  //DAC
-char sqr10Hz        = 'o';  //DAC
-char sqr1Hz         = 't';  //DAC
-char saveUSB        = 'u';  //ADC
+char sin10Hz        = 'q';  //DAC -6
+char sin1Hz         = 'w';  //DAC -7
+char sqr10Hz        = 'o';  //DAC -8
+char sqr1Hz         = 't';  //DAC -9
+char saveUSB        = 'u';  //ADC -0
 char saveLocal      = 'l';  //ADC That's an l as in labeorphily
-
+char keypress;
 
 
 //CAN Send (Parameter = message data) 
@@ -63,49 +70,105 @@
 
 
 
-int setupChoice = NULL;
-int main() {  
-    printf("Please select the desired function:\n1: DAC Setup\n2: DigiPot Setup\n3: ADC Setup\n");
-    setupChoice = Keypad[keys]
-    switch(setupChoice) {
-   case 1  ://DAC Setup
-    printf("Please choose waveform:\n1: 1Hz, Square Wave\n2: 1Hz Sine Wave\n3: 10Hz, Square Wave\n4: 10Hz, Sine Wave\n5: Return to previous menu.\n");
-    if (/*Keypad Input*/ == 1)
+
+int main() { 
+
+
+    State = 1;
+
+
+    //             r0   r1   r2   r3   c0   c1   c2   c3
+    Keypad keypad(p21, p22,  p23,  p24, p25, p26,  p27,  NC);
+    keypad.attach(&cbAfterInput);
+    keypad.start();  // energize the columns c0-c3 of the keypad
+ 
+    while (1) {
+        __wfi();
+        if (Index > -1) {
+            PC.printf("Interrupted");
+            PC.printf("Index:%d => Key:%c\r\n", Index, Keytable[Index]);
+            Index = -1;
+            printf("here2");
+        }
+    
+ 
+ printf("Please choose waveform:\n1: 1V \n2: 2V \n3: 3V \n4: 4V \n5: 5V \n6: 10Hz, Sine wave");
+ printf("\n7: 1Hz, Sine Wave\n8: 10Hz, Square Wave \n9: 1Hz, Square wave \n0: Save to USB \n*: Start Waveform Generation \n#: Stop/Reset Waveform\n");
+   
+    while(1)
     {
-    }
-    else if (/*Keypad Input*/ == 2)
-    {
-    }
-    else if (/*Keypad Input*/ == 3)
-    {
-    }
-    else if (/*Keypad Input*/ == 4)
-    {
-    }
-    else if (/*Keypad Input*/ == 5)
-    {
-    }
+        keypress = Keytable[Index];
+    switch(keypress) {
+   case 1  :
+    send(amp1);
+    Index=-1;
+    printf("here1");
+      break; //optional
+      
+   case 2  :
+      send(amp2);
+      Index=-1;
       break; //optional
       
-   case 2  ://DigiPot Setup
-      statement(s);
-      break; //optional
-      
-   case 3  ://ADC Setup
-      statement(s);
-      break; //Optional
-      
-      
-   default : //Optional
-      statement(s);
-        };
-    ticker.attach(&send, 1);
-    CANMessage msg; 
+   case 3  :
+      send(amp3);
+     Index=-1;
+      break; //Optional   
+   
+   case 4 :
+      send(amp4);
+     Index=-1;
+      break;
+   
+    case 5 : 
+      send(amp5);
+      Index=-1;
+      break;
+    
+    case 6 :
+      send(sin10Hz);
+     Index=-1;
+      break;
+    
+    case 7 :
+        send(sin1Hz);
+      Index=-1;
+        break;
+    
+    case 8 :
+        send(sqr10Hz);
+        Index=-1;
+        break;
+    
+    case 9 :
+        send(sqr1Hz);
+       Index=-1;
+        break;
+    
+    case 0 :
+        send(saveUSB);
+      Index=-1;
+        break;
+    
+    case '*' :
+        send(start);
+        Index=-1;
+        break;
+    
+    case '#' :
+        send(stop);
+       Index=-1;
+        break;
+            
+            };
+            }
+    /*CANMessage msg; 
     while(1) {
         if(can2.read(msg)) {
             printf("Message Recieved: %d\n\n", msg.data[0]);
             led2 = !led2;
         }
     wait(0.2);
-    }
+    }*/
 }
+}