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 ELEC351_Group_T by
Revision 43:fb9faec1dc72, committed 2018-01-08
- Comitter:
- chills
- Date:
- Mon Jan 08 16:49:44 2018 +0000
- Parent:
- 42:ae1640bca2e1
- Child:
- 44:e0eac2382810
- Commit message:
- 2018_01_08 16:46; SETT checks for decimals
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Jan 08 15:38:53 2018 +0000
+++ b/main.cpp Mon Jan 08 16:49:44 2018 +0000
@@ -96,6 +96,24 @@
}
}
}
+
+bool Decimal_Check(char Input[100])
+{
+ for(int x = 0; x < mailsize; x++)
+ {
+ if(Input[x] == '.'){return true;}
+ }
+ return false;
+}
+
+int Decimal_Position(char Input[100])
+{
+ for(int x = 0; x < mailsize; x++)
+ {
+ if(Input[x] == '.'){return x;}
+ }
+}
+
void Network()
{
while(1)
@@ -525,13 +543,12 @@
stringstream Number(ReadNumber);
Number >> NumberToRead;
-
if(Log_Value == 1){cout<<"Getting Data"<<endl;}
Data_Buffer_Lock.lock();//Lock data buffer due to critical section
int Start_Address = Write_Pointer;
Data_Buffer_Lock.unlock();//unLock data buffer due to critical section
-
+
for(int x = (Start_Address - NumberToRead); x != Start_Address; x = x )
{
if(x < 0){x = x + mailsize;}
@@ -651,13 +668,37 @@
else if(input[0] == 'S' & input[1] == 'E' & input[2] == 'T' & input[3] == 'T' & input[4] == ' ')
{
- int NumberOfChars = 0; int ArrayAddress = 0; string SettNumber; int NumberToSett;
+ int NumberOfChars = 0; int ArrayAddress = 0;
+ string SettNumber; float NumberToSett;
+ int Post_Decimal_Count; int Decimal_Divider = 10;
+ float Sample_Rate_Integer = 0; string Sample_Rate_Integer_String;
+ float Sample_Rate_Decimal = 0; string Sample_Rate_Decimal_String;
while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;}
- for(int x=5; x < NumberOfChars; x++){SettNumber += input[x];}
- stringstream Number(SettNumber);
- Number >> NumberToSett;
+
+ if (Decimal_Check(input) == true)
+ {
+ for(int x = 5; x < Decimal_Position(input); x++){Sample_Rate_Integer_String += input[x];}
+ stringstream Number_1(Sample_Rate_Integer_String);
+ Number_1 >> Sample_Rate_Integer;
+
+ for(int x = Decimal_Position(input) + 1; x < NumberOfChars; x++){Sample_Rate_Decimal_String += input[x];}
+ stringstream Number_2(Sample_Rate_Decimal_String);
+ Number_2 >> Sample_Rate_Decimal;
+
+ for(int tens_power = 1; tens_power != NumberOfChars - Decimal_Position(input) - 1; tens_power++)
+ {
+ Decimal_Divider = Decimal_Divider * 10;
+ }
+ NumberToSett = Sample_Rate_Integer + (Sample_Rate_Decimal / float(Decimal_Divider));
+ }
+ else
+ {
+ for(int x=5; x < NumberOfChars; x++){SettNumber += input[x];}
+ stringstream Number_3(SettNumber);
+ Number_3 >> NumberToSett;
+ }
- if(NumberToSett >= 1){Sample_Rate = NumberToSett;}
+ if(NumberToSett > 0){Sample_Rate = NumberToSett;}
Sampling_Timer.detach();
Console_Output_Timer.detach();
@@ -746,6 +787,7 @@
LCD.Initialise();
LCD.DDRAM_Address(0x00);
+ /*
post(); //Power on Self Test
//Initialise the SD card (this needs to move)
@@ -778,6 +820,7 @@
errorCode(NETWORK_FATAL);
}
//Last message before sampling begins
+ */
LCD.Display_Clear();
LCD.Write_String("READY PLAYER");
LCD.DDRAM_Address(0x40);
@@ -791,7 +834,7 @@
t1.start(Sample);
t2.start(SD_Card);
t3.start(LCD_Output);
- t4.start(Network);
+ //t4.start(Network);
t5.start(Serial_Commands);
//Main thread ID
@@ -804,12 +847,12 @@
id3 = t3.gettid();
id4 = t4.gettid();
id5 = t5.gettid();
-
+
while(true) {
if(onBoardSwitch == 1)
{
- fclose(fp);//Close File
- sd.deinit();//Close down
+ //fclose(fp);//Close File
+ //sd.deinit();//Close down
LCD.Display_Clear();
LCD.DDRAM_Address(0x00);
LCD.Write_String("SD Card");
@@ -818,6 +861,7 @@
LCD.DDRAM_Address(0x00);
cout << "SD Card Unmounted" << endl;
}
+
greenLED = 1;
wait(0.5);
greenLED = 0;
