Fixed wait time

Dependencies:   SDFileSystem emic2 mbed-rtos mbed

Fork of BAT_senior_design_Nhi by BAT

Files at this revision

API Documentation at this revision

Comitter:
aismail1997
Date:
Wed Nov 01 15:22:13 2017 +0000
Parent:
20:abbc12fca525
Child:
22:6931917c70cd
Commit message:
Updated button and buttonarray classes

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
buttonArray.h 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
--- a/button.cpp	Fri Oct 27 15:18:28 2017 +0000
+++ b/button.cpp	Wed Nov 01 15:22:13 2017 +0000
@@ -2,10 +2,11 @@
 #include "button.h"
 
 // button constructor
-button::button(PwmOut servo, DigitalIn pb)
-    : servo(servo), pb(pb), press(0), state(0) {}
-//button::button(PwmOut servo, DigitalIn pb, AnalogIn lp)
-//    : servo(servo), pb(pb), linpot(lp), mode(0), state(0) {}
+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) {}
+*/
 
 // FUNCTIONS
 
@@ -21,6 +22,11 @@
     state = mystate;
 }
 
+void button::setPress(int mypress)
+{
+    press = mypress;
+}
+
 // get servo pin
 /*void button::setMode(int mymode)
 {
@@ -33,11 +39,25 @@
     return state;
 }
 
+int button::getID()
+{
+    return id;
+}
+
+
 int button::getPress()
 {
     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()
--- a/button.h	Fri Oct 27 15:18:28 2017 +0000
+++ b/button.h	Wed Nov 01 15:22:13 2017 +0000
@@ -12,25 +12,30 @@
     DigitalIn pb;
     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;
+    //AnalogIn linpot;
 
 public:
     // constructors
     button(); // Default
-    button(PwmOut servo, DigitalIn pb);
+    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);     // determine what state the button is in - up or down
+    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
     void moveServoOut();  // move servo out of the slot
+    int getID();
     int updateState();
     int getState();
     int getPress();
+    int getLp();
 };
 
 #endif
\ No newline at end of file
--- a/buttonArray.cpp	Fri Oct 27 15:18:28 2017 +0000
+++ b/buttonArray.cpp	Wed Nov 01 15:22:13 2017 +0000
@@ -4,16 +4,37 @@
 // 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) {}
-    
+
 // FUNCTIONS
 
 // map input braille to ascii
-int buttonArray::checkVal() {
-    char* val;
-    sprintf(val, "%d%d%d%d%d%d", button1.getPress(), button2.getPress(),
-     button3.getPress(), button4.getPress(), button5.getPress(), button6.getPress());
-    if (val == "000000")
-        return 1;
-    else 
-        return 0;
-}
\ No newline at end of file
+// braille respresentation here - https://en.wikipedia.org/wiki/Braille_ASCII
+char buttonArray::checkVal()
+{
+    char* input;
+    char val = NULL;
+    sprintf(input, "%d%d%d%d%d%d", button1.getPress(), button2.getPress(),
+            button3.getPress(), button4.getPress(), button5.getPress(), button6.getPress());
+    if (strcmp(input, "000000") == 0) val = NULL;
+    if (strcmp(input, "011111") == 0) val = 'A';
+    if (strcmp(input, "001101") == 0) val = 'M';
+    if (strcmp(input, "011001") == 0) val = 'O';
+    // check if reset
+    if (strcmp(input, "111111") == 0) val = ' ';
+    return val;
+}
+
+// return feedback on which pin to correct
+
+
+// release buttons
+void buttonArray::releaseButtons()
+{
+    if (button1.getPress()) {
+        button1.moveServoOut();
+        button1.setState(3);
+        button1.setPress(0);
+    }
+}
+//
+
--- a/buttonArray.h	Fri Oct 27 15:18:28 2017 +0000
+++ b/buttonArray.h	Wed Nov 01 15:22:13 2017 +0000
@@ -20,6 +20,7 @@
     buttonArray(); // Default
     buttonArray(button button1, button button2, button button3, button button4, button button5, button button6);
     // functions
-    int checkVal(); // check buttons ascii representation
+    char checkVal(); // return buttons ascii representation
+    void releaseButtons();// release all buttons;
     
 };
\ No newline at end of file
--- a/main.cpp	Fri Oct 27 15:18:28 2017 +0000
+++ b/main.cpp	Wed Nov 01 15:22:13 2017 +0000
@@ -21,19 +21,20 @@
 
 //DigitalOut led1(LED1);
 //DigitalOut led3(LED3);
-//DigitalOut led4(LED4);
+DigitalOut led4(LED4);
 
 //AnalogIn linpot(p20);
 //Serial pc(USBTX, USBRX);
 //SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card
 //AnalogOut DACout(p26);
 //wave_player waver(&DACout);
-button button1(myservo, pb1);
-button button2(myservo2, pb2);
-button button3(myservo3, pb3);
-button button4(myservo4, pb4);
-button button5(myservo5, pb5);
-button button6(myservo6, pb6);
+//button button1(myservo, pb1, linpot);
+button button1(myservo, pb1, 1);
+button button2(myservo2, pb2, 2);
+button button3(myservo3, pb3, 3);
+button button4(myservo4, pb4, 4);
+button button5(myservo5, pb5, 5);
+button button6(myservo6, pb6, 6);
 
 buttonArray buttonarr(button1, button2, button3, button4, button5, button6);
 
@@ -69,6 +70,7 @@
 {
     while(true) {
         state = button1.updateState();
+        //led4 = button1.getLp();
         Thread::wait(100); // wait till thread is done
     }
 }