Working read code

Dependencies:   SDFileSystem emic2 mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
nnguyen45
Date:
Mon Dec 04 20:14:24 2017 +0000
Parent:
0:5887cb744114
Commit message:
Updated button array to include almost all letters

Changed in this revision

button.cpp Show annotated file Show diff for this revision Revisions of this file
button.h Show annotated file Show diff for this revision Revisions of this file
buttonArray.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 5887cb744114 -r f3d363ca2343 button.cpp
--- a/button.cpp	Mon Dec 04 19:58:40 2017 +0000
+++ b/button.cpp	Mon Dec 04 20:14:24 2017 +0000
@@ -10,20 +10,15 @@
 // button constructor
 button::button(PwmOut servo, DigitalIn pb, int id)
     : servo(servo), pb(pb), state(0), press(0), id(id) {}
-/*button::button(PwmOut servo, DigitalIn pb, AnalogIn lp)
-    : servo(servo), pb(pb), linpot(lp), press(0), state(0) {}
-*/
-//Serial pc(USBTX, USBRX);
 
 // FUNCTIONS
-
 // get servo pin
 PwmOut button::getServoPin()
 {
     return servo;
 }
 
-// get servo pin
+// set button state
 void button::setState(int mystate)
 {
     state = mystate;
@@ -34,12 +29,6 @@
     press = mypress;
 }
 
-// get servo pin
-/*void button::setMode(int mymode)
-{
-    mode = mymode;
-}*/
-
 // get current state of the button
 int button::getState()
 {
@@ -54,29 +43,23 @@
 
 int button::getPress()
 {
-    //pc.printf("%d", press);
     return press;
 }
 
 // get current state of the button
 int button::getLp()
 {
-    /*    if (linpot < 2)
-            return 1;
-        else*/
     return 0;
 }
 
 // move servo into the slot
 void button::moveServoIn()
 {
-    //myled = 1;
     // rotate 90 degrees one way
     for(int i=4; i<=7; i++) {
         servo = i/100.0;
         wait(0.01);
     }
-    //press = 1;
     switch (id) {
         case 1:
             led2 = 0;
@@ -114,7 +97,6 @@
 // move servo out of the slot
 void button::moveServoOut()
 {
-    //myled = 0;
     for(int i=7; i>4; i--) {
         servo = i/100.0;
         wait(0.01);
@@ -126,7 +108,6 @@
 
 int button::updateState()
 {
-    //myled = 0;
     // state 0 - button is up, pb = 0
     if (pb == 0 && state == 3) {
         // nothing happens here, servo is still
@@ -137,12 +118,6 @@
         moveServoIn();
         state = 1;
         press = 1;
-
-        // Speaker says stuff
-        /*myTTS.volume(18); //max volume
-        myTTS.speakf("S");//Speak command starts with "S"
-        myTTS.speakf("Hey, you pressed a pin!");  // Send the desired string to convert to speech
-        myTTS.speakf("\r"); //marks end of speak command*/
     }
     // state 2 - button is down, pb = 0
     if (pb == 0 && state == 1) {
@@ -156,9 +131,6 @@
         press = 0;
     }
     // state 4 - handle debouncing while button is down
-    /*if (pb1 = 1 && state == 2) {
-        count++;
-    }*/
     return state;
 }
 
diff -r 5887cb744114 -r f3d363ca2343 button.h
--- a/button.h	Mon Dec 04 19:58:40 2017 +0000
+++ b/button.h	Mon Dec 04 20:14:24 2017 +0000
@@ -13,20 +13,14 @@
     int state; // where is the button (0 - 4)
     int press; // is the button up or down
     int id;    // this is the ID, each button should have a unique id
-    // int mode; // is the system in reading or typing mode
-    //AnalogIn linpot;
 
 public:
     // constructors
     button(); // Default
     button(PwmOut servo, DigitalIn pb, int id);
-    //button(PwmOut servo, DigitalIn pb, AnalogIn linpot);
 
-    // button(PwmOut servo, DigitalIn pb, AnalogIn linpot);
     // functions
     PwmOut getServoPin(); // get the servo pin
-    //void setState(int state); // set state
-    //void setMode(int mode); // set mode
     void setState(int);     // set what state the button is in - up or down
     void setPress(int);     // set the button press
     void moveServoIn();   // move servo into the slot
diff -r 5887cb744114 -r f3d363ca2343 buttonArray.cpp
--- a/buttonArray.cpp	Mon Dec 04 19:58:40 2017 +0000
+++ b/buttonArray.cpp	Mon Dec 04 20:14:24 2017 +0000
@@ -1,27 +1,17 @@
 #include "mbed.h"
 #include "buttonArray.h"
 
-// type mode
-
 // buttonArray constructor
 buttonArray::buttonArray(button b1, button b2, button b3, button b4, button b5, button b6)
     : button1(b1), button2(b2), button3(b3), button4(b4), button5(b5), button6(b6) {}
 
-//Serial pc(USBTX, USBRX);
-
 // FUNCTIONS
 
 // map input braille to ascii
 // braille respresentation here - https://en.wikipedia.org/wiki/Braille_ASCII
 char buttonArray::checkVal(char* braille)
 {
-    //pc.printf(" checkVal \n");
-    //char* braille;
     char val = 'K';
-    /*int test = button1.getPress();
-    sprintf(braille, "%d%d%d%d%d%d", test, button2.getPress(),
-            button3.getPress(), button4.getPress(), button5.getPress(), button6.getPress());*/
-    //pc.printf(" %s \n", braille);
     if (strcmp(braille, "000000") == 0) val = 'X';
     if (strcmp(braille, "011111") == 0) val = 'A';
     if (strcmp(braille, "001111") == 0) val = 'B';
@@ -31,27 +21,26 @@
     if (strcmp(braille, "001011") == 0) val = 'F';
     if (strcmp(braille, "001001") == 0) val = 'G';
     if (strcmp(braille, "001101") == 0) val = 'H';
-    if (strcmp(braille, "101101") == 0) val = 'I';
+    if (strcmp(braille, "101011") == 0) val = 'I';
     if (strcmp(braille, "101001") == 0) val = 'J';
+    //if (strcmp(braille, "011111") == 0) val = 'K';
+    if (strcmp(braille, "000111") == 0) val = 'L';
     if (strcmp(braille, "010011") == 0) val = 'M';
+    if (strcmp(braille, "010001") == 0) val = 'N';
     if (strcmp(braille, "010101") == 0) val = 'O';
-    /*if (strcmp(braille, "011111") == 0) val = 'K';
-    if (strcmp(braille, "011111") == 0) val = 'L';
-    if (strcmp(braille, "011111") == 0) val = 'N';
-    if (strcmp(braille, "011111") == 0) val = 'P';
-    if (strcmp(braille, "011111") == 0) val = 'Q';
-    if (strcmp(braille, "011111") == 0) val = 'R';
-    if (strcmp(braille, "011111") == 0) val = 'S';
-    if (strcmp(braille, "011111") == 0) val = 'T';
-    if (strcmp(braille, "011111") == 0) val = 'U';
-    if (strcmp(braille, "011111") == 0) val = 'V';
-    if (strcmp(braille, "011111") == 0) val = 'W';
-    if (strcmp(braille, "011111") == 0) val = 'X';
-    if (strcmp(braille, "011111") == 0) val = 'Y';
-    if (strcmp(braille, "011111") == 0) val = 'Z';*/
+    if (strcmp(braille, "000011") == 0) val = 'P';
+    if (strcmp(braille, "000001") == 0) val = 'Q';
+    if (strcmp(braille, "000101") == 0) val = 'R';
+    if (strcmp(braille, "100011") == 0) val = 'S';
+    if (strcmp(braille, "100001") == 0) val = 'T';
+    if (strcmp(braille, "010110") == 0) val = 'U';
+    if (strcmp(braille, "000110") == 0) val = 'V';
+    if (strcmp(braille, "101000") == 0) val = 'W';
+    //if (strcmp(braille, "010010") == 0) val = 'X';
+    if (strcmp(braille, "010000") == 0) val = 'Y';
+    //if (strcmp(braille, "010100") == 0) val = 'Z';
     // check if reset
     if (strcmp(braille, "111111") == 0) val = 'Z';
-    //pc.printf(" %c \n", val);
     return val;
 }
 
@@ -74,7 +63,6 @@
 int* buttonArray::pinsUp(char val)
 {
     int* pinsup;
-    //pinsup = new int[7];
     char* braille = getBraille(val);
     int j = 1;
     for (int i = 0; i < 6; i++) {
@@ -92,16 +80,13 @@
 // takes in current and actual char as input and returns status of each char
 int* buttonArray::wrongPins(char* inarr, char actual)
 {
-    // TODO check initial value of wrong
     int* wrong;
     wrong = new int[7];
     char* actarr = getBraille(actual);
-    //pc.printf("wrong pins");
     int j = 1;
     for (int i = 0; i < 6; i++) {
         if(inarr[i] != actarr[i]) {
             wrong[j] = i+1;
-            //pc.printf("%d ", wrong[j]);
             j++;
         }
     }
@@ -147,8 +132,7 @@
 
 void buttonArray::setup()
 {
-    // servos begin at 30 degrees
-    // replace with a button setup function
+    // servo setup function; servos begin at 30 degrees
     button1.setup();
     button2.setup();
     button3.setup();