Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of CW_copy by
Diff: putty.h
- Revision:
- 1:dc648c5624b9
- Parent:
- 0:4e623dbef4b8
--- a/putty.h Wed Jan 03 17:32:16 2018 +0000
+++ b/putty.h Wed Jan 10 09:50:29 2018 +0000
@@ -1,29 +1,38 @@
#include "mbed.h"
-#include "data.h"
-Serial pc(USBTX, USBRX);
-char user_command[40] = {0};
-char user_command2[40] = {0};
-char read[5] = "READ";
-int n, datan = 0, datac = 0, counterd = 0;
+#include "sensor_data.h"
+Serial pc(USBTX, USBRX);
+DigitalOut RedLed(PE_15);
+DigitalOut YellowLed(PB_10);
+
+char input_user[40] = {0}; // user input array can store up to 40 elements of type char
+char input_user2[40] = {0}; // user input array 2 can store up to 40 elements of type char
+int n, datan = 0, datac = 0, counterd = 0; //integer for datan datac
+int set_dates =0, clocks= 0;
+int output;
+int stoppingit;
+int getting_data;
+void date_input();
-
+/*-----------------------------------------------------------*/
+/*function to that enables to read all sensors data putty */
+/*---------------------------------------------------------*/
void readall()
{
- datan = counterw;
- pc.printf("readall selected\n\r");
+ datan = counter_store; // getting the 120 past record
+ pc.printf("readall selected\n\r"); // printing readall to the putty
if (full == 1)
{
datac = 120;
}
else
{
- datac = counterw;
+ datac = counter_store;
}
- pc.printf("printting %i datas\n\r", datac);
+ pc.printf("printting %i datas\n\r", datac); // printing the
while (counterd < datac)
{
- pc.printf("light: %2.4f, temp: %3.4f, press: %3.4f\n\r", data_temp [datan], data_press[datan], data_light[datan]);
+ pc.printf("light: %2.4f, temp: %3.4f, press: %3.4f\n\r", temperature_data [datan], pressure_data[datan], LDR_data[datan]); // printing all the BMP280 sensor data to putty
if (datan == 0)
{
datan = 121;
@@ -34,21 +43,25 @@
counterd = 0;
}
+/*---------------------------------------------------------*/
+/* fuction to get a certain number of data to putty*/
+/*---------------------------------------------------------*/
+
void readn()
{
counterd = 0;
- n = atoi(user_command2);
- pc.printf("read %i datas\n\r",n);
- if (n > counterw)
+ n = atoi(input_user2); // converting string data type to integer
+ pc.printf("read %i datas\n\r",n); // printing the number of data to putty
+ if (n > counter_store)
{
- pc.printf("we only have %i datas \n\r", counterw);
+ pc.printf("we only have %i datas \n\r", counter_store);// printing the number of data entered to the putty
}
else
{
while (counterd < n)
{
- pc.printf("light: %2.4f, temp: %3.4f, press: %3.4f\n\r", data_temp [datan], data_press[datan], data_light[datan]);
+ pc.printf("light: %2.4f, temp: %3.4f, press: %3.4f\n\r", temperature_data [datan], pressure_data[datan], LDR_data[datan]); // printing the sensor data to putty
if (datan == 0)
{
datan = 121;
@@ -59,100 +72,102 @@
}
}
+/*---------------------------------------------------------*/
+/* fuction to delete all the data from the putty */
+/*---------------------------------------------------------*/
+
void deleteall()
{
- pc.printf("deleted %i datas \n\r", counterw);
- counterw = 0;
+ pc.printf("deleted %i datas \n\r", counter_store); //print that the sensor data has been deleted
+ counter_store = 0;
int counter = 0;
while (counter < 121)
{
- data_light[counter] = 0;
- data_temp [counter] = 0;
- data_press[counter] = 0;
+ LDR_data[counter] = 0;
+ temperature_data [counter] = 0;
+ pressure_data[counter] = 0;
counter ++;
full = 0;
}
}
+
+/*------------------------------------------------------------------*/
+/* fuction to delete the number of data you specify from the putty */
+/*--------------------------------------------------------------------*/
+
void deleten()
{
- datan = counterw;
+ datan = counter_store;
counterd = 0;
- n = atoi(user_command2);
- if (n > counterw && full == 0)
+ n = atoi(input_user2);
+ if (n > counter_store && full == 0)
{
- pc.printf("we only have %i datas \n\r", counterw);
+ pc.printf("we only have %i datas \n\r", counter_store);
}
else if(full == 1 && n> 120)
{
pc.printf("we only have 120 datas \n\r");
}
- else if(full == 0 && n < counterw)
+ else if(full == 0 && n < counter_store)
{
pc.printf("deleted %i datas \n\r", n);
- counterw = counterw-n;
+ counter_store = counter_store-n;
while (counterd < n)
{
- data_light[datan] = 0;
- data_temp [datan] = 0;
- data_press[datan] = 0;
+ LDR_data[datan] = 0;
+ temperature_data [datan] = 0;
+ pressure_data[datan] = 0;
counterd ++;
datan--;
}
}
else if(full == 1 && n < 120)
{
- pc.printf("deleted 120 datas \n\r");
- counterw = counterw-n;
+ pc.printf("deleted %i datas \n\r", n);
+ counter_store = counter_store-n;
while (counterd < 120)
{
- data_light[datan] = 0;
- data_temp [datan] = 0;
- data_press[datan] = 0;
+ LDR_data[datan] = 0;
+ temperature_data [datan] = 0;
+ pressure_data[datan] = 0;
counterd ++;
datan--;
}
}
}
-//void fill(char c[20], char c2[20])
-//{
-// int counterino = 0;
-// while (counterino <21)
-// {
-// user_command[counterino] = c[counterino];
-// user_command2[counterino] = c2[counterino];
-// counterino++;
-// }
-
-//}
+//**********clearing function ********
+
void clear()
{
int counter = 0;
while (counter < 40)
{
- user_command[counter] = 0;
+ input_user[counter] = 0;
counter ++;
}
}
-
-
+
+//**********clearing function ********
+
void clear2()
{
int counter = 0;
while (counter < 40)
{
- user_command2[counter] = 0;
+ input_user2[counter] = 0;
counter ++;
}
}
-void selection()
+//********************* function fro reading all data and a certain number of data************************
+void read_or_read_all()
{
- counterd = 0;
- datan = counterw-1;
- if (user_command[0] == 'R'&& user_command[1] == 'E'&& user_command[2] == 'A'&& user_command[3] == 'D')
+ counterd = 0;
+ datan = counter_store-1;
+ if (input_user[0] == 'R'&& input_user[1] == 'E'&& input_user[2] == 'A'&& input_user[3] == 'D')
{
- if (user_command2[0] == 'A'&& user_command2[1]== 'L'&& user_command2[2]== 'L')
+ if (input_user2[0] == 'A'&& input_user2[1]== 'L'&& input_user2[2]== 'L')
{
readall();
}
@@ -160,12 +175,18 @@
else
{
readn();
+
}
- }
+ }
- else if (user_command[0] == 'D'&& user_command[1] == 'E'&& user_command[2] == 'L'&& user_command[3] == 'E' && user_command[4] == 'T' && user_command[5] == 'E')
+ }
+//*** function to delete all sensor data or a certain number of data
+
+void delete_deleteall()
+{
+if (input_user[0] == 'D'&& input_user[1] == 'E'&& input_user[2] == 'L'&& input_user[3] == 'E' && input_user[4] == 'T' && input_user[5] == 'E')
{
- if (user_command2[0] == 'A'&& user_command2[1]== 'L'&& user_command2[2]== 'L')
+ if (input_user2[0] == 'A'&& input_user2[1]== 'L'&& input_user2[2]== 'L')
{
pc.printf("deleteall selected\n\r");
deleteall();
@@ -173,26 +194,164 @@
else
{
- n = atoi(user_command2);
+ n = atoi(input_user2);
pc.printf("delete %i\n\r",n);
deleten();
}
}
+
+
+
+
+ }
+//******* function hold reading all date, a certain data, and date input ***********************************
+void choice()
+{
+ read_or_read_all();
+ delete_deleteall();
+ date_input();
}
-//int main()
-//{
-// pc.printf("putty ready\n\r");
-// while(1)
-// {
-// clear();
-// clear2();
-// while (user_command[0] == 0)
-// {
-// pc.scanf("%s",user_command);
-// pc.scanf("%s",user_command2);
-// pc.printf("you typed: %s %s\n\r",user_command,user_command2);
-// }
-//
-// selection();
-// }
-//}
\ No newline at end of file
+
+// ****************** setting the time and this awaits a user input of TIME to display the time **************************
+void setting_time()
+{
+ if (input_user[0] == 'T'&& input_user[1] == 'I'&& input_user[2] == 'M'&& input_user[3] == 'E')
+{
+
+ clocks = atoi (input_user2);
+
+ s=clocks%10;
+ clocks /= 10;
+ ss = clocks%10;
+ clocks /= 10;
+ mi=clocks%10;
+ clocks /= 10;
+ mmi =clocks%10;
+ clocks /= 10;
+ h=clocks%10;
+ clocks /= 10;
+ hh =clocks%10;
+ clocks /= 10;
+
+ pc.printf("TIME UPDATED TO %i%i:%i%i:%i%i%i%i\n\r",hh,h,mmi,mi,ss,s);
+}
+
+
+ }
+
+ //******receive input from user DATE and then the user sets the date ************
+
+void setting_dates()
+{
+ if (input_user[0] == 'D'&& input_user[1] == 'A'&& input_user[2] == 'T'&& input_user[3] == 'E')
+{
+set_dates = atoi (input_user2);
+d= set_dates%10;
+set_dates /= 10;
+dd = set_dates%10;
+set_dates /= 10;
+m=set_dates%10;
+set_dates /= 10;
+ mm =set_dates%10;
+set_dates /= 10;
+y =set_dates%10;
+set_dates /= 10;
+yy =set_dates%10;
+set_dates /= 10;
+yyy =set_dates%10;
+ set_dates /= 10;
+yyyy =set_dates&10;
+ set_dates /= 10;
+
+pc.printf("DATE UPDATED TO %i%i/%i%i/%i%i%i%i\n\r",yyyy,yyy,yy,y,mm,m,dd,d);
+}
+ }
+
+void setting_sett()
+{
+
+
+ //******receive input from user SETT to set the sampling rate
+
+if (input_user[0] == 'S'&& input_user[1] == 'E'&& input_user[2] == 'T'&& input_user[3] == 'T')
+{
+output = atoi (input_user2);
+
+ if (output <= 60 && output >= 0.1)
+{
+ pc.printf("Good job time period set\n\r",output);
+ stoppingit = 1;
+
+ }
+ else
+ {
+ pc.printf("The Range is out\n\r");
+
+ }
+}
+ }
+
+//*************************** function to which the debug off/ ON***************************************
+void switch_off_on()
+{
+if (input_user[0] == 'D'&& input_user[1] == 'E'&& input_user[2] == 'C'&& input_user[3] == 'I' && input_user[4] == 'S' && input_user[5] == 'I' && input_user[6] == 'O'&& input_user[7] == 'N')
+{
+ if (input_user[0] == 'N'&& input_user[1] == 'O')
+ {
+ getting_data = 1;
+ pc.printf("Data gotten\n\r");
+ }
+
+
+ else if (input_user[0] == 'O'&& input_user[1] == 'F'&& input_user[2] == 'F')
+
+ {
+ getting_data = 0;
+ pc.printf("Data Switched off\n\r");
+ }
+
+ }
+
+
+ }
+//* function holds setting the time , date switch debugger off/on and seeting the sampleing rate
+
+void date_input ()
+{
+ setting_time();
+setting_dates();
+switch_off_on();
+setting_sett();
+ }
+
+
+void disp_putty ()
+{
+ while(1) {
+
+ int count = 0;
+ int wcount = 0;
+ while (input_user[wcount]!= ' ')
+ {
+ input_user[count] = pc.getc();
+ pc.putc(input_user[count]);
+ count++;
+ wcount = count -1;
+ }
+ int count2 = 0;
+ int wcount2 = 0;
+ while(input_user2[wcount2]!= '\r')
+ {
+ input_user2[count2] = pc.getc();
+ pc.putc(input_user2[count2]);
+ count2++;
+ wcount2 = count2 -1;
+ }
+
+
+ pc.printf("you typed: %s %s\n\r",input_user,input_user2);
+ choice();
+ clear();
+ clear2();
+ }
+}
\ No newline at end of file
