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
putty.h
- Committer:
- joseph_adamu
- Date:
- 2018-01-10
- Revision:
- 1:dc648c5624b9
- Parent:
- 0:4e623dbef4b8
File content as of revision 1:dc648c5624b9:
#include "mbed.h"
#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 = 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 = counter_store;
}
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", temperature_data [datan], pressure_data[datan], LDR_data[datan]); // printing all the BMP280 sensor data to putty
if (datan == 0)
{
datan = 121;
}
datan--;
counterd++;
}
counterd = 0;
}
/*---------------------------------------------------------*/
/* fuction to get a certain number of data to putty*/
/*---------------------------------------------------------*/
void readn()
{
counterd = 0;
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", 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", temperature_data [datan], pressure_data[datan], LDR_data[datan]); // printing the sensor data to putty
if (datan == 0)
{
datan = 121;
}
datan--;
counterd++;
}
}
}
/*---------------------------------------------------------*/
/* fuction to delete all the data from the putty */
/*---------------------------------------------------------*/
void deleteall()
{
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)
{
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 = counter_store;
counterd = 0;
n = atoi(input_user2);
if (n > counter_store && full == 0)
{
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 < counter_store)
{
pc.printf("deleted %i datas \n\r", n);
counter_store = counter_store-n;
while (counterd < n)
{
LDR_data[datan] = 0;
temperature_data [datan] = 0;
pressure_data[datan] = 0;
counterd ++;
datan--;
}
}
else if(full == 1 && n < 120)
{
pc.printf("deleted %i datas \n\r", n);
counter_store = counter_store-n;
while (counterd < 120)
{
LDR_data[datan] = 0;
temperature_data [datan] = 0;
pressure_data[datan] = 0;
counterd ++;
datan--;
}
}
}
//**********clearing function ********
void clear()
{
int counter = 0;
while (counter < 40)
{
input_user[counter] = 0;
counter ++;
}
}
//**********clearing function ********
void clear2()
{
int counter = 0;
while (counter < 40)
{
input_user2[counter] = 0;
counter ++;
}
}
//********************* function fro reading all data and a certain number of data************************
void read_or_read_all()
{
counterd = 0;
datan = counter_store-1;
if (input_user[0] == 'R'&& input_user[1] == 'E'&& input_user[2] == 'A'&& input_user[3] == 'D')
{
if (input_user2[0] == 'A'&& input_user2[1]== 'L'&& input_user2[2]== 'L')
{
readall();
}
else
{
readn();
}
}
}
//*** 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 (input_user2[0] == 'A'&& input_user2[1]== 'L'&& input_user2[2]== 'L')
{
pc.printf("deleteall selected\n\r");
deleteall();
}
else
{
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();
}
// ****************** 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();
}
}
