Combines locate fix, show/hide cursor + Justin Jordans additions

Fork of Terminal by Justin Jordan

Revision:
6:419eea2fe960
Parent:
4:4510b10fb5d9
Child:
7:aa29b7e10cd8
diff -r 5d3dc5f8f7b4 -r 419eea2fe960 Terminal.cpp
--- a/Terminal.cpp	Fri Jun 03 19:05:10 2016 +0000
+++ b/Terminal.cpp	Sat Jul 30 20:14:05 2016 +0000
@@ -22,8 +22,6 @@
 
 #include "Terminal.h"
 
-#include "mbed.h"
-
 Terminal::Terminal(PinName tx, PinName rx) : Serial(tx, rx){}
 
 void Terminal::cls() {
@@ -138,3 +136,46 @@
     
     return c[0];
 }
+
+
+float Terminal::get_float(const char *msg, const float min_val, const float max_val)
+{
+    char str[32];
+    uint8_t idx;
+    
+    float user_input;
+    
+    do
+    {
+        printf(msg);
+        
+        //get user input
+        idx = 0;
+        do
+        {
+            if(readable())
+            {
+                str[idx++] = getc();
+            }
+        }
+        while((str[idx-1] != 0x0A)  && (idx < 32));
+        
+        //Remove trailing newline and CR, if there.
+        if((strlen(str) > 0 ) && (str[strlen(str) - 1] == 0x0A) && (str[strlen(str) - 2] == 0x0D))
+        {
+            str[strlen(str) - 1] = '\0';
+            str[strlen(str) - 1] = '\0';
+        }
+        
+        user_input = atof(str);
+        
+        if((user_input <= min_val) || (user_input >= max_val))
+        {
+            printf("\nYou entered = %f\n", user_input);
+            printf("\nOut of range\n");
+        }
+    }
+    while((user_input <= min_val) || (user_input >= max_val));
+    
+    return(user_input);
+}