Plymouth ELEC351 Group T
/
ELEC351_Group_T
FINAL PROJECT isn't it
Fork of ELEC351 by
main.cpp@46:bd9e7e40b3f9, 2018-01-08 (annotated)
- Committer:
- chills
- Date:
- Mon Jan 08 19:03:49 2018 +0000
- Revision:
- 46:bd9e7e40b3f9
- Parent:
- 45:875f7e18a386
- Child:
- 47:6d128e500875
2018_01_08 19:00; LCD Fix
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
thomasmorris | 6:97f586597310 | 1 | /* |
thomasmorris | 6:97f586597310 | 2 | ELEC 351 Group T |
thomasmorris | 6:97f586597310 | 3 | Team Members : Christopher Hills, Thomas Morris |
thomasmorris | 42:ae1640bca2e1 | 4 | Current Verision 19 |
thomasmorris | 42:ae1640bca2e1 | 5 | Overiew: Working Tasks 1,2,3,5,6,7,8,9,10,11,12,13,14,15 |
thomasmorris | 8:0e4481b64353 | 6 | |
thomasmorris | 12:536eca338ae8 | 7 | Last Revision: Added Mail Box to serial |
thomasmorris | 8:0e4481b64353 | 8 | Todo: |
thomasmorris | 42:ae1640bca2e1 | 9 | Add functionality to SD card import chris's work on delete serial commnads |
thomasmorris | 42:ae1640bca2e1 | 10 | Commnet code |
thomasmorris | 42:ae1640bca2e1 | 11 | Check for race conditions |
thomasmorris | 42:ae1640bca2e1 | 12 | Move code around |
thomasmorris | 42:ae1640bca2e1 | 13 | Other fixes |
thomasmorris | 6:97f586597310 | 14 | */ |
thomasmorris | 6:97f586597310 | 15 | |
thomasmorris | 25:36699ed589ab | 16 | #include "SETUP.hpp" |
thomasmorris | 35:26b0a9b55d82 | 17 | #include "NETWORK.hpp" |
thomasmorris | 38:8d86e0d8a816 | 18 | |
thomasmorris | 38:8d86e0d8a816 | 19 | #define Do_Read_Data 1 |
thomasmorris | 38:8d86e0d8a816 | 20 | #define Dont_Read_Data 0 |
thomasmorris | 38:8d86e0d8a816 | 21 | #define Do_Delete_Data 1 |
thomasmorris | 38:8d86e0d8a816 | 22 | #define Dont_Delete_Data 0 |
chills | 24:7d2da96e05ad | 23 | |
chills | 33:3b5096f0126a | 24 | Mutex Time_Lock_Main; |
thomasmorris | 38:8d86e0d8a816 | 25 | Mutex Data_Buffer_Lock; |
thomasmorris | 38:8d86e0d8a816 | 26 | |
thomasmorris | 41:859b5e1e3d9a | 27 | int Write_Data(DATA Data_Store, int Write_Pointer)//Writes data passed in to the array at address Write Pointer |
thomasmorris | 38:8d86e0d8a816 | 28 | { |
thomasmorris | 41:859b5e1e3d9a | 29 | Data_Buffer_Lock.lock();//Appling lock for critial section |
thomasmorris | 38:8d86e0d8a816 | 30 | Data_Buffer[Write_Pointer] = Data_Store; |
thomasmorris | 41:859b5e1e3d9a | 31 | if(Write_Pointer < mailsize - 1)//Checks if write pointer will be greater than mail size |
thomasmorris | 38:8d86e0d8a816 | 32 | { |
thomasmorris | 41:859b5e1e3d9a | 33 | Write_Pointer = Write_Pointer + 1;//Increment write pointer |
thomasmorris | 38:8d86e0d8a816 | 34 | } |
thomasmorris | 38:8d86e0d8a816 | 35 | else |
thomasmorris | 38:8d86e0d8a816 | 36 | { |
thomasmorris | 41:859b5e1e3d9a | 37 | Write_Pointer = 0;//Else set it to 0 thus a FIFO system |
thomasmorris | 38:8d86e0d8a816 | 38 | } |
thomasmorris | 41:859b5e1e3d9a | 39 | Data_Buffer_Lock.unlock();//Releasing lock for critial section |
thomasmorris | 41:859b5e1e3d9a | 40 | return Write_Pointer;//New address of Write pointer |
thomasmorris | 38:8d86e0d8a816 | 41 | |
thomasmorris | 38:8d86e0d8a816 | 42 | } |
thomasmorris | 38:8d86e0d8a816 | 43 | DATA Read_Data(int Read_Pointer) |
thomasmorris | 38:8d86e0d8a816 | 44 | { |
thomasmorris | 41:859b5e1e3d9a | 45 | Data_Buffer_Lock.lock();//Appling lock for critial section |
thomasmorris | 38:8d86e0d8a816 | 46 | DATA Temp_Data = Data_Buffer[Read_Pointer]; |
thomasmorris | 41:859b5e1e3d9a | 47 | Data_Buffer_Lock.unlock();//Releasing lock for critial section |
thomasmorris | 38:8d86e0d8a816 | 48 | |
thomasmorris | 38:8d86e0d8a816 | 49 | return Temp_Data; |
thomasmorris | 38:8d86e0d8a816 | 50 | } |
thomasmorris | 38:8d86e0d8a816 | 51 | void Delete_Data(int Delete_Pointer) |
thomasmorris | 38:8d86e0d8a816 | 52 | { |
thomasmorris | 41:859b5e1e3d9a | 53 | Data_Buffer_Lock.lock();//Appling lock for critial section |
thomasmorris | 38:8d86e0d8a816 | 54 | Data_Buffer[Delete_Pointer].set_all_zero(); |
thomasmorris | 41:859b5e1e3d9a | 55 | Data_Buffer_Lock.unlock();//Releasing lock for critial section |
thomasmorris | 41:859b5e1e3d9a | 56 | } |
thomasmorris | 41:859b5e1e3d9a | 57 | |
thomasmorris | 41:859b5e1e3d9a | 58 | void SD_Card()//Writes data to the SD card |
thomasmorris | 41:859b5e1e3d9a | 59 | { |
thomasmorris | 41:859b5e1e3d9a | 60 | while(1) |
thomasmorris | 41:859b5e1e3d9a | 61 | { |
thomasmorris | 42:ae1640bca2e1 | 62 | Thread::wait(Sample_Rate*1000); //Waits until a new is taken before checking again |
thomasmorris | 42:ae1640bca2e1 | 63 | if(Write_Pointer == mailsize - 1) |
thomasmorris | 42:ae1640bca2e1 | 64 | { |
chills | 46:bd9e7e40b3f9 | 65 | if(Log_Value==1){pc.printf("In SD_Card Thread\n");} |
thomasmorris | 41:859b5e1e3d9a | 66 | |
thomasmorris | 42:ae1640bca2e1 | 67 | //Open to WRITE |
thomasmorris | 42:ae1640bca2e1 | 68 | FILE* fp = fopen("/sd/test.csv","a"); |
chills | 46:bd9e7e40b3f9 | 69 | if(Log_Value==1){pc.printf("File Opened\n");} |
thomasmorris | 42:ae1640bca2e1 | 70 | |
thomasmorris | 42:ae1640bca2e1 | 71 | for(int SD_Card_Data_Pointer = 0; SD_Card_Data_Pointer != mailsize; SD_Card_Data_Pointer++) |
thomasmorris | 42:ae1640bca2e1 | 72 | { |
thomasmorris | 42:ae1640bca2e1 | 73 | time_t Time = Data_Buffer[SD_Card_Data_Pointer].get_time(); |
thomasmorris | 42:ae1640bca2e1 | 74 | tm* Time_Pointer = localtime(&Time); |
thomasmorris | 42:ae1640bca2e1 | 75 | int temp_day = Time_Pointer->tm_mday; |
thomasmorris | 42:ae1640bca2e1 | 76 | int temp_month = (Time_Pointer->tm_mon+1);//Set to current month |
thomasmorris | 42:ae1640bca2e1 | 77 | int temp_year = (Time_Pointer->tm_year+1900);//Set to current year |
thomasmorris | 42:ae1640bca2e1 | 78 | |
thomasmorris | 42:ae1640bca2e1 | 79 | int temp_hours = Time_Pointer->tm_hour; |
thomasmorris | 42:ae1640bca2e1 | 80 | int temp_minute = Time_Pointer->tm_min; |
thomasmorris | 45:875f7e18a386 | 81 | int temp_seconds = Time_Pointer->tm_sec; |
thomasmorris | 42:ae1640bca2e1 | 82 | |
thomasmorris | 42:ae1640bca2e1 | 83 | float temp_temperature = Data_Buffer[SD_Card_Data_Pointer].get_temperature(); |
thomasmorris | 42:ae1640bca2e1 | 84 | float temp_pressure = Data_Buffer[SD_Card_Data_Pointer].get_pressure(); |
thomasmorris | 42:ae1640bca2e1 | 85 | float temp_light = Data_Buffer[SD_Card_Data_Pointer].get_light(); |
thomasmorris | 42:ae1640bca2e1 | 86 | |
thomasmorris | 45:875f7e18a386 | 87 | fprintf(fp, "Date: %02d/%02d/%d,",temp_day,temp_month,temp_year);//Date |
thomasmorris | 45:875f7e18a386 | 88 | fprintf(fp, "Time: %02d:%02d:%02d,",temp_hours,temp_minute, temp_seconds);//Time |
thomasmorris | 42:ae1640bca2e1 | 89 | fprintf(fp, "Temperature: %1.1f,",temp_temperature);//Temperature |
thomasmorris | 42:ae1640bca2e1 | 90 | fprintf(fp, "Pressure: %1.1f,",temp_pressure);//Pressure |
thomasmorris | 42:ae1640bca2e1 | 91 | fprintf(fp, "Light: %5.3f,",temp_light);//Light |
chills | 46:bd9e7e40b3f9 | 92 | fprintf(fp, "End of Data \n");//End of data |
thomasmorris | 42:ae1640bca2e1 | 93 | } |
chills | 46:bd9e7e40b3f9 | 94 | if(Log_Value==1){pc.printf("Dumped data to SD Card\n");} |
thomasmorris | 42:ae1640bca2e1 | 95 | //Close File |
thomasmorris | 42:ae1640bca2e1 | 96 | fclose(fp); |
thomasmorris | 42:ae1640bca2e1 | 97 | } |
thomasmorris | 41:859b5e1e3d9a | 98 | } |
thomasmorris | 38:8d86e0d8a816 | 99 | } |
thomasmorris | 45:875f7e18a386 | 100 | |
thomasmorris | 45:875f7e18a386 | 101 | bool Decimal_Check(char Input[100]) |
thomasmorris | 45:875f7e18a386 | 102 | { |
thomasmorris | 45:875f7e18a386 | 103 | for(int x = 0; x < mailsize; x++) |
thomasmorris | 45:875f7e18a386 | 104 | { |
thomasmorris | 45:875f7e18a386 | 105 | if(Input[x] == '.'){return true;} |
thomasmorris | 45:875f7e18a386 | 106 | } |
thomasmorris | 45:875f7e18a386 | 107 | return false; |
thomasmorris | 45:875f7e18a386 | 108 | } |
thomasmorris | 45:875f7e18a386 | 109 | |
thomasmorris | 45:875f7e18a386 | 110 | int Decimal_Position(char Input[100]) |
thomasmorris | 45:875f7e18a386 | 111 | { |
thomasmorris | 45:875f7e18a386 | 112 | for(int x = 0; x < mailsize; x++) |
thomasmorris | 45:875f7e18a386 | 113 | { |
thomasmorris | 45:875f7e18a386 | 114 | if(Input[x] == '.'){return x;} |
thomasmorris | 45:875f7e18a386 | 115 | } |
thomasmorris | 45:875f7e18a386 | 116 | return 0; |
thomasmorris | 45:875f7e18a386 | 117 | } |
thomasmorris | 35:26b0a9b55d82 | 118 | void Network() |
thomasmorris | 8:0e4481b64353 | 119 | { |
thomasmorris | 35:26b0a9b55d82 | 120 | while(1) |
thomasmorris | 35:26b0a9b55d82 | 121 | { |
thomasmorris | 41:859b5e1e3d9a | 122 | Thread::wait(NetworkWait);//Waits Network Wait amount of time |
chills | 46:bd9e7e40b3f9 | 123 | if(Log_Value==1){pc.printf("In Network Thread\n");} |
thomasmorris | 36:a0098306fc58 | 124 | |
thomasmorris | 45:875f7e18a386 | 125 | time_t Time = Data_Buffer[(Write_Pointer - 1)].get_time(); |
thomasmorris | 36:a0098306fc58 | 126 | tm* Time_Pointer = localtime(&Time); |
thomasmorris | 36:a0098306fc58 | 127 | int temp_day = Time_Pointer->tm_mday; |
thomasmorris | 41:859b5e1e3d9a | 128 | int temp_month = (Time_Pointer->tm_mon+1);//Set to current month |
thomasmorris | 41:859b5e1e3d9a | 129 | int temp_year = (Time_Pointer->tm_year+1900);//Set to current year |
thomasmorris | 36:a0098306fc58 | 130 | |
thomasmorris | 36:a0098306fc58 | 131 | int temp_hours = Time_Pointer->tm_hour; |
thomasmorris | 36:a0098306fc58 | 132 | int temp_minute = Time_Pointer->tm_min; |
thomasmorris | 45:875f7e18a386 | 133 | int temp_seconds = Time_Pointer->tm_sec; |
thomasmorris | 36:a0098306fc58 | 134 | |
thomasmorris | 45:875f7e18a386 | 135 | float temp_temperature = Data_Buffer[(Write_Pointer - 1)].get_temperature(); |
thomasmorris | 45:875f7e18a386 | 136 | float temp_pressure = Data_Buffer[(Write_Pointer - 1)].get_pressure(); |
thomasmorris | 45:875f7e18a386 | 137 | float temp_light = Data_Buffer[(Write_Pointer - 1)].get_light(); |
thomasmorris | 36:a0098306fc58 | 138 | |
thomasmorris | 36:a0098306fc58 | 139 | |
thomasmorris | 45:875f7e18a386 | 140 | Networking(temp_day,temp_month,temp_year,temp_hours,temp_minute,temp_seconds,temp_temperature,temp_pressure,temp_light);//Pass in networking data and time values |
thomasmorris | 35:26b0a9b55d82 | 141 | } |
chills | 13:db857b3744c6 | 142 | } |
thomasmorris | 31:4a88bf97b53e | 143 | void LCD_Write_Year() |
thomasmorris | 12:536eca338ae8 | 144 | { |
thomasmorris | 41:859b5e1e3d9a | 145 | Time_Lock_Main.lock();//Appling lock for critial section |
chills | 46:bd9e7e40b3f9 | 146 | if(Log_Value == 1){pc.printf("In LCD_Write_Year Time lock taken\n");} |
chills | 33:3b5096f0126a | 147 | time_t Time = time(NULL); |
chills | 33:3b5096f0126a | 148 | tm* Time_Pointer = localtime(&Time); |
chills | 33:3b5096f0126a | 149 | int Years = 1900 + Time_Pointer->tm_year; |
thomasmorris | 41:859b5e1e3d9a | 150 | Time_Lock_Main.unlock();//Releasing lock for critial section |
chills | 46:bd9e7e40b3f9 | 151 | if(Log_Value == 1){pc.printf("In LCD_Write_Year Time lock released\n");} |
thomasmorris | 31:4a88bf97b53e | 152 | stringstream ss; |
thomasmorris | 31:4a88bf97b53e | 153 | ss << Years; |
thomasmorris | 31:4a88bf97b53e | 154 | string Year_String = ss.str(); |
thomasmorris | 31:4a88bf97b53e | 155 | LCD.DDRAM_Address(0x00); |
thomasmorris | 31:4a88bf97b53e | 156 | LCD.Write_String("Set Year"); |
thomasmorris | 31:4a88bf97b53e | 157 | LCD.DDRAM_Address(0x40); |
thomasmorris | 31:4a88bf97b53e | 158 | LCD.Write_String(Year_String); |
thomasmorris | 30:4cde05cc7c4f | 159 | } |
thomasmorris | 31:4a88bf97b53e | 160 | void LCD_Write_Month() |
thomasmorris | 31:4a88bf97b53e | 161 | { |
thomasmorris | 41:859b5e1e3d9a | 162 | Time_Lock_Main.lock();//Appling lock for critial section |
chills | 46:bd9e7e40b3f9 | 163 | if(Log_Value == 1){pc.printf("In LCD_Write_Month Time lock taken\n");} |
chills | 33:3b5096f0126a | 164 | time_t Time = time(NULL); |
chills | 33:3b5096f0126a | 165 | tm* Time_Pointer = localtime(&Time); |
chills | 33:3b5096f0126a | 166 | int Months = 1 + Time_Pointer->tm_mon; |
thomasmorris | 41:859b5e1e3d9a | 167 | Time_Lock_Main.unlock();//Releasing lock for critial section |
chills | 46:bd9e7e40b3f9 | 168 | if(Log_Value == 1){pc.printf("In LCD_Write_Month Time lock released\n");} |
thomasmorris | 31:4a88bf97b53e | 169 | stringstream ss; |
thomasmorris | 31:4a88bf97b53e | 170 | ss << Months; |
thomasmorris | 31:4a88bf97b53e | 171 | string Month_String = ss.str(); |
thomasmorris | 31:4a88bf97b53e | 172 | LCD.DDRAM_Address(0x00); |
thomasmorris | 31:4a88bf97b53e | 173 | LCD.Write_String("Set Month"); |
thomasmorris | 31:4a88bf97b53e | 174 | LCD.DDRAM_Address(0x40); |
thomasmorris | 31:4a88bf97b53e | 175 | LCD.Write_String(Month_String); |
thomasmorris | 31:4a88bf97b53e | 176 | } |
thomasmorris | 31:4a88bf97b53e | 177 | void LCD_Write_Day() |
thomasmorris | 31:4a88bf97b53e | 178 | { |
thomasmorris | 41:859b5e1e3d9a | 179 | Time_Lock_Main.lock();//Appling lock for critial section |
chills | 46:bd9e7e40b3f9 | 180 | if(Log_Value == 1){pc.printf("In LCD_Write_Day Time lock taken\n");} |
chills | 33:3b5096f0126a | 181 | time_t Time = time(NULL); |
chills | 33:3b5096f0126a | 182 | tm* Time_Pointer = localtime(&Time); |
chills | 33:3b5096f0126a | 183 | int Days = Time_Pointer->tm_mday; |
thomasmorris | 41:859b5e1e3d9a | 184 | Time_Lock_Main.unlock();//Releasing lock for critial section |
chills | 46:bd9e7e40b3f9 | 185 | if(Log_Value == 1){pc.printf("In LCD_Write_Day Time lock released\n");} |
thomasmorris | 31:4a88bf97b53e | 186 | stringstream ss; |
thomasmorris | 31:4a88bf97b53e | 187 | ss << Days; |
thomasmorris | 31:4a88bf97b53e | 188 | string Day_String = ss.str(); |
thomasmorris | 31:4a88bf97b53e | 189 | LCD.DDRAM_Address(0x00); |
thomasmorris | 31:4a88bf97b53e | 190 | LCD.Write_String("Set Day"); |
thomasmorris | 31:4a88bf97b53e | 191 | LCD.DDRAM_Address(0x40); |
thomasmorris | 31:4a88bf97b53e | 192 | LCD.Write_String(Day_String); |
thomasmorris | 31:4a88bf97b53e | 193 | } |
thomasmorris | 31:4a88bf97b53e | 194 | void LCD_Write_Hour() |
thomasmorris | 30:4cde05cc7c4f | 195 | { |
thomasmorris | 41:859b5e1e3d9a | 196 | Time_Lock_Main.lock();//Appling lock for critial section |
chills | 46:bd9e7e40b3f9 | 197 | if(Log_Value == 1){pc.printf("In LCD_Write_Hour Time lock taken\n");} |
chills | 33:3b5096f0126a | 198 | time_t Time = time(NULL); |
chills | 33:3b5096f0126a | 199 | tm* Time_Pointer = localtime(&Time); |
chills | 33:3b5096f0126a | 200 | int Hours = Time_Pointer->tm_hour; |
thomasmorris | 41:859b5e1e3d9a | 201 | Time_Lock_Main.unlock();//Releasing lock for critial section |
chills | 46:bd9e7e40b3f9 | 202 | if(Log_Value == 1){pc.printf("In LCD_Write_Hour Time lock released\n");} |
thomasmorris | 31:4a88bf97b53e | 203 | stringstream ss; |
thomasmorris | 31:4a88bf97b53e | 204 | ss << Hours; |
thomasmorris | 31:4a88bf97b53e | 205 | string Hour_String = ss.str(); |
thomasmorris | 31:4a88bf97b53e | 206 | LCD.DDRAM_Address(0x00); |
thomasmorris | 31:4a88bf97b53e | 207 | LCD.Write_String("Set Hour"); |
thomasmorris | 31:4a88bf97b53e | 208 | LCD.DDRAM_Address(0x40); |
thomasmorris | 31:4a88bf97b53e | 209 | LCD.Write_String(Hour_String); |
thomasmorris | 31:4a88bf97b53e | 210 | } |
thomasmorris | 31:4a88bf97b53e | 211 | void LCD_Write_Minute() |
thomasmorris | 31:4a88bf97b53e | 212 | { |
thomasmorris | 41:859b5e1e3d9a | 213 | Time_Lock_Main.lock();//Appling lock for critial section |
chills | 46:bd9e7e40b3f9 | 214 | if(Log_Value == 1){pc.printf("In LCD_Write_Minute Time lock taken\n");} |
chills | 33:3b5096f0126a | 215 | time_t Time = time(NULL); |
chills | 33:3b5096f0126a | 216 | tm* Time_Pointer = localtime(&Time); |
chills | 33:3b5096f0126a | 217 | int Minutes = Time_Pointer->tm_min; |
thomasmorris | 41:859b5e1e3d9a | 218 | Time_Lock_Main.unlock();//Releasing lock for critial section |
chills | 46:bd9e7e40b3f9 | 219 | if(Log_Value == 1){pc.printf("In LCD_Write_Minute Time lock released\n");} |
thomasmorris | 31:4a88bf97b53e | 220 | stringstream ss; |
thomasmorris | 31:4a88bf97b53e | 221 | ss << Minutes; |
thomasmorris | 31:4a88bf97b53e | 222 | string Minute_String = ss.str(); |
thomasmorris | 31:4a88bf97b53e | 223 | LCD.DDRAM_Address(0x00); |
thomasmorris | 31:4a88bf97b53e | 224 | LCD.Write_String("Set Minute"); |
thomasmorris | 31:4a88bf97b53e | 225 | LCD.DDRAM_Address(0x40); |
thomasmorris | 31:4a88bf97b53e | 226 | LCD.Write_String(Minute_String); |
thomasmorris | 31:4a88bf97b53e | 227 | } |
thomasmorris | 31:4a88bf97b53e | 228 | void LCD_Write_Seconds() |
thomasmorris | 31:4a88bf97b53e | 229 | { |
thomasmorris | 41:859b5e1e3d9a | 230 | Time_Lock_Main.lock();//Appling lock for critial section |
chills | 46:bd9e7e40b3f9 | 231 | if(Log_Value == 1){pc.printf("In LCD_Write_Seconds Time lock taken\n");} |
chills | 33:3b5096f0126a | 232 | time_t Time = time(NULL); |
chills | 33:3b5096f0126a | 233 | tm* Time_Pointer = localtime(&Time); |
chills | 33:3b5096f0126a | 234 | int Seconds = Time_Pointer->tm_sec; |
thomasmorris | 41:859b5e1e3d9a | 235 | Time_Lock_Main.unlock();//Releasing lock for critial section |
chills | 46:bd9e7e40b3f9 | 236 | if(Log_Value == 1){pc.printf("In LCD_Write_Seconds Time lock released\n");} |
thomasmorris | 31:4a88bf97b53e | 237 | stringstream ss; |
thomasmorris | 31:4a88bf97b53e | 238 | ss << Seconds; |
thomasmorris | 31:4a88bf97b53e | 239 | string Second_String = ss.str(); |
thomasmorris | 31:4a88bf97b53e | 240 | LCD.DDRAM_Address(0x00); |
thomasmorris | 31:4a88bf97b53e | 241 | LCD.Write_String("Set Second"); |
thomasmorris | 31:4a88bf97b53e | 242 | LCD.DDRAM_Address(0x40); |
thomasmorris | 31:4a88bf97b53e | 243 | LCD.Write_String(Second_String); |
thomasmorris | 7:dfe19413fdc2 | 244 | } |
thomasmorris | 30:4cde05cc7c4f | 245 | |
thomasmorris | 30:4cde05cc7c4f | 246 | void LCD_Output() |
chills | 34:c0b8705f183d | 247 | { |
thomasmorris | 30:4cde05cc7c4f | 248 | while(1) |
thomasmorris | 29:64b1f95a807c | 249 | { |
thomasmorris | 41:859b5e1e3d9a | 250 | Thread::wait(10);//Small wait |
thomasmorris | 30:4cde05cc7c4f | 251 | if(mode == 0)//Default mode |
thomasmorris | 30:4cde05cc7c4f | 252 | { |
chills | 46:bd9e7e40b3f9 | 253 | if(Log_Value == 1){pc.printf("In mode 0 \n");} |
chills | 33:3b5096f0126a | 254 | |
thomasmorris | 41:859b5e1e3d9a | 255 | Thread::wait(Default_Mode_Toggle_Time);//Wait for this amount of time |
chills | 46:bd9e7e40b3f9 | 256 | if(Log_Value == 1){pc.printf("Writing Data to LCD\n");} |
chills | 46:bd9e7e40b3f9 | 257 | sprintf (LCD_buffer, "%1.1f %1.0f %1.2f",Data_Active.get_temperature(),Data_Active.get_pressure(),Data_Active.get_light());//Used for converting to a sting |
chills | 33:3b5096f0126a | 258 | |
thomasmorris | 30:4cde05cc7c4f | 259 | LCD.DDRAM_Address(0x00); |
chills | 46:bd9e7e40b3f9 | 260 | LCD.Write_String("Temp Pres Lite"); |
thomasmorris | 30:4cde05cc7c4f | 261 | LCD.DDRAM_Address(0x40); |
thomasmorris | 41:859b5e1e3d9a | 262 | LCD.Write_String(LCD_buffer);//Print out current data values to the LCD |
thomasmorris | 25:36699ed589ab | 263 | |
thomasmorris | 41:859b5e1e3d9a | 264 | Thread::wait(Default_Mode_Toggle_Time); //Wait for this amount of time |
chills | 46:bd9e7e40b3f9 | 265 | if(Log_Value == 1){pc.printf("Writing Time and Date to LCD\n");} |
thomasmorris | 41:859b5e1e3d9a | 266 | Time_Lock_Main.lock();//lock Time_lock for critial section |
chills | 34:c0b8705f183d | 267 | time_t Time = Data_Active.get_time(); |
chills | 34:c0b8705f183d | 268 | tm* Time_Pointer = localtime(&Time); |
thomasmorris | 30:4cde05cc7c4f | 269 | LCD.Display_Clear(); |
chills | 46:bd9e7e40b3f9 | 270 | sprintf (LCD_buffer, "%02d:%02d %02d,%d",Time_Pointer->tm_hour,Time_Pointer->tm_min,(Time_Pointer->tm_mon+1),(Time_Pointer->tm_year+1900));//Used for converting to a sting |
thomasmorris | 41:859b5e1e3d9a | 271 | Time_Lock_Main.unlock();//unlock Time_lock for critial section |
chills | 33:3b5096f0126a | 272 | |
thomasmorris | 30:4cde05cc7c4f | 273 | LCD.DDRAM_Address(0x00); |
thomasmorris | 30:4cde05cc7c4f | 274 | LCD.Write_String("Current Time:"); |
thomasmorris | 30:4cde05cc7c4f | 275 | LCD.DDRAM_Address(0x40); |
thomasmorris | 41:859b5e1e3d9a | 276 | LCD.Write_String(LCD_buffer);//Print the current time to the LCD |
thomasmorris | 31:4a88bf97b53e | 277 | |
chills | 46:bd9e7e40b3f9 | 278 | if(Log_Value == 1){pc.printf("Checking Switches for next mode\n");} |
thomasmorris | 31:4a88bf97b53e | 279 | if(SW1.read() & SW2.read() == 1) |
thomasmorris | 31:4a88bf97b53e | 280 | { |
thomasmorris | 31:4a88bf97b53e | 281 | mode = 1; |
thomasmorris | 31:4a88bf97b53e | 282 | } |
thomasmorris | 30:4cde05cc7c4f | 283 | } |
thomasmorris | 30:4cde05cc7c4f | 284 | else if(mode == 1)//Choose either date setting or time setting |
thomasmorris | 30:4cde05cc7c4f | 285 | { |
chills | 46:bd9e7e40b3f9 | 286 | if(Log_Value == 1){pc.printf("In Mode 1\n");} |
thomasmorris | 30:4cde05cc7c4f | 287 | LCD.Display_Clear(); |
thomasmorris | 31:4a88bf97b53e | 288 | while(1) |
thomasmorris | 31:4a88bf97b53e | 289 | { |
thomasmorris | 31:4a88bf97b53e | 290 | LCD.DDRAM_Address(0x00); |
thomasmorris | 31:4a88bf97b53e | 291 | LCD.Write_String("Date Time"); |
thomasmorris | 31:4a88bf97b53e | 292 | LCD.DDRAM_Address(0x40); |
thomasmorris | 31:4a88bf97b53e | 293 | LCD.Write_String("< >"); |
thomasmorris | 31:4a88bf97b53e | 294 | Thread::wait(1000); |
chills | 46:bd9e7e40b3f9 | 295 | if(Log_Value == 1){pc.printf("Checking SW1 to go to Date setting\n");} |
thomasmorris | 37:7c4d7f206039 | 296 | if(SW1.read() == 1 & SW2.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 297 | { |
thomasmorris | 37:7c4d7f206039 | 298 | mode = 2;//Date Setting |
thomasmorris | 31:4a88bf97b53e | 299 | break; |
thomasmorris | 31:4a88bf97b53e | 300 | } |
chills | 46:bd9e7e40b3f9 | 301 | if(Log_Value == 1){pc.printf("Checking SW2 to go to Time setting\n");} |
thomasmorris | 37:7c4d7f206039 | 302 | if(SW2.read() == 1 & SW1.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 303 | { |
thomasmorris | 37:7c4d7f206039 | 304 | mode = 5;//Time Setting |
thomasmorris | 31:4a88bf97b53e | 305 | break; |
thomasmorris | 31:4a88bf97b53e | 306 | } |
thomasmorris | 31:4a88bf97b53e | 307 | } |
thomasmorris | 30:4cde05cc7c4f | 308 | } |
thomasmorris | 30:4cde05cc7c4f | 309 | else if(mode == 2)//Set the Year |
thomasmorris | 30:4cde05cc7c4f | 310 | { |
chills | 46:bd9e7e40b3f9 | 311 | if(Log_Value == 1){pc.printf("In Mode 2\n");} |
thomasmorris | 31:4a88bf97b53e | 312 | LCD.Display_Clear(); |
thomasmorris | 31:4a88bf97b53e | 313 | while(1) |
thomasmorris | 31:4a88bf97b53e | 314 | { |
thomasmorris | 32:8f2795716e97 | 315 | LCD_Write_Year(); |
thomasmorris | 31:4a88bf97b53e | 316 | Thread::wait(1000); |
chills | 46:bd9e7e40b3f9 | 317 | if(Log_Value == 1){pc.printf("Checking SW1 and SW2 to go to Month setting\n");} |
chills | 33:3b5096f0126a | 318 | if(SW1.read() & SW2.read() == 1) |
chills | 33:3b5096f0126a | 319 | { |
chills | 33:3b5096f0126a | 320 | mode = 3; |
chills | 33:3b5096f0126a | 321 | break; |
chills | 33:3b5096f0126a | 322 | } |
chills | 46:bd9e7e40b3f9 | 323 | if(Log_Value == 1){pc.printf("Checking SW1 to add Year\n");} |
thomasmorris | 31:4a88bf97b53e | 324 | if(SW1.read() == 1 & SW2.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 325 | { |
thomasmorris | 31:4a88bf97b53e | 326 | Add_Year(); |
thomasmorris | 31:4a88bf97b53e | 327 | } |
chills | 46:bd9e7e40b3f9 | 328 | if(Log_Value == 1){pc.printf("Checking SW2 to subtract Year\n");} |
thomasmorris | 31:4a88bf97b53e | 329 | else if(SW2.read() == 1 & SW1.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 330 | { |
thomasmorris | 31:4a88bf97b53e | 331 | Subtract_Year(); |
thomasmorris | 31:4a88bf97b53e | 332 | } |
thomasmorris | 31:4a88bf97b53e | 333 | LCD_Write_Year(); |
thomasmorris | 31:4a88bf97b53e | 334 | } |
thomasmorris | 30:4cde05cc7c4f | 335 | } |
thomasmorris | 30:4cde05cc7c4f | 336 | else if(mode == 3)//Set the Month |
thomasmorris | 30:4cde05cc7c4f | 337 | { |
chills | 46:bd9e7e40b3f9 | 338 | if(Log_Value == 1){pc.printf("In Mode 3\n");} |
thomasmorris | 31:4a88bf97b53e | 339 | LCD.Display_Clear(); |
thomasmorris | 31:4a88bf97b53e | 340 | while(1) |
thomasmorris | 32:8f2795716e97 | 341 | { |
thomasmorris | 32:8f2795716e97 | 342 | LCD_Write_Month(); |
thomasmorris | 31:4a88bf97b53e | 343 | Thread::wait(1000); |
chills | 46:bd9e7e40b3f9 | 344 | if(Log_Value == 1){pc.printf("Checking SW1 and SW2 to go to Day setting\n");} |
chills | 33:3b5096f0126a | 345 | if(SW1.read() & SW2.read() == 1) |
chills | 33:3b5096f0126a | 346 | { |
chills | 33:3b5096f0126a | 347 | mode = 4; |
chills | 33:3b5096f0126a | 348 | break; |
thomasmorris | 37:7c4d7f206039 | 349 | } |
chills | 46:bd9e7e40b3f9 | 350 | if(Log_Value == 1){pc.printf("Checking SW1 to add Month\n");} |
thomasmorris | 31:4a88bf97b53e | 351 | if(SW1.read() == 1 & SW2.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 352 | { |
thomasmorris | 31:4a88bf97b53e | 353 | Add_Month(); |
thomasmorris | 31:4a88bf97b53e | 354 | } |
chills | 46:bd9e7e40b3f9 | 355 | if(Log_Value == 1){pc.printf("Checking SW2 to subtract Month\n");} |
thomasmorris | 31:4a88bf97b53e | 356 | else if(SW2.read() == 1 & SW1.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 357 | { |
thomasmorris | 31:4a88bf97b53e | 358 | Subtract_Month(); |
thomasmorris | 32:8f2795716e97 | 359 | } |
chills | 33:3b5096f0126a | 360 | |
thomasmorris | 31:4a88bf97b53e | 361 | } |
thomasmorris | 30:4cde05cc7c4f | 362 | } |
thomasmorris | 30:4cde05cc7c4f | 363 | else if(mode == 4)//Set the Day |
thomasmorris | 30:4cde05cc7c4f | 364 | { |
chills | 46:bd9e7e40b3f9 | 365 | if(Log_Value == 1){pc.printf("In Mode 4\n");} |
thomasmorris | 31:4a88bf97b53e | 366 | LCD.Display_Clear(); |
thomasmorris | 31:4a88bf97b53e | 367 | while(1) |
thomasmorris | 32:8f2795716e97 | 368 | { |
thomasmorris | 32:8f2795716e97 | 369 | LCD_Write_Day(); |
thomasmorris | 31:4a88bf97b53e | 370 | Thread::wait(1000); |
chills | 46:bd9e7e40b3f9 | 371 | if(Log_Value == 1){pc.printf("Checking SW1 and SW2 to go Default setting\n");} |
chills | 33:3b5096f0126a | 372 | if(SW1.read() & SW2.read() == 1) |
chills | 33:3b5096f0126a | 373 | { |
chills | 33:3b5096f0126a | 374 | mode = 0; |
chills | 33:3b5096f0126a | 375 | break; |
chills | 33:3b5096f0126a | 376 | } |
chills | 46:bd9e7e40b3f9 | 377 | if(Log_Value == 1){pc.printf("Checking SW1 to add Day\n");} |
thomasmorris | 31:4a88bf97b53e | 378 | if(SW1.read() == 1 & SW2.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 379 | { |
thomasmorris | 31:4a88bf97b53e | 380 | Add_Day(); |
thomasmorris | 31:4a88bf97b53e | 381 | } |
chills | 46:bd9e7e40b3f9 | 382 | if(Log_Value == 1){pc.printf("Checking SW2 to subtract Day\n");} |
thomasmorris | 31:4a88bf97b53e | 383 | else if(SW2.read() == 1 & SW1.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 384 | { |
thomasmorris | 31:4a88bf97b53e | 385 | Subtract_Day(); |
thomasmorris | 32:8f2795716e97 | 386 | } |
thomasmorris | 31:4a88bf97b53e | 387 | } |
thomasmorris | 30:4cde05cc7c4f | 388 | } |
thomasmorris | 30:4cde05cc7c4f | 389 | else if(mode == 5)//Set the Hour |
thomasmorris | 30:4cde05cc7c4f | 390 | { |
chills | 46:bd9e7e40b3f9 | 391 | if(Log_Value == 1){pc.printf("In Mode 5\n");} |
thomasmorris | 31:4a88bf97b53e | 392 | LCD.Display_Clear(); |
thomasmorris | 31:4a88bf97b53e | 393 | while(1) |
thomasmorris | 31:4a88bf97b53e | 394 | { |
thomasmorris | 32:8f2795716e97 | 395 | LCD_Write_Hour(); |
thomasmorris | 32:8f2795716e97 | 396 | Thread::wait(1000); |
chills | 46:bd9e7e40b3f9 | 397 | if(Log_Value == 1){pc.printf("Checking SW1 and SW2 to go Minute setting\n");} |
chills | 33:3b5096f0126a | 398 | if(SW1.read() & SW2.read() == 1) |
chills | 33:3b5096f0126a | 399 | { |
chills | 33:3b5096f0126a | 400 | mode = 6; |
chills | 33:3b5096f0126a | 401 | break; |
thomasmorris | 37:7c4d7f206039 | 402 | } |
chills | 46:bd9e7e40b3f9 | 403 | if(Log_Value == 1){pc.printf("Checking SW1 to add Hour\n");} |
thomasmorris | 31:4a88bf97b53e | 404 | if(SW1.read() == 1 & SW2.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 405 | { |
thomasmorris | 31:4a88bf97b53e | 406 | Add_Hour(); |
thomasmorris | 31:4a88bf97b53e | 407 | } |
chills | 46:bd9e7e40b3f9 | 408 | if(Log_Value == 1){pc.printf("Checking SW2 to subtract Hour\n");} |
thomasmorris | 31:4a88bf97b53e | 409 | else if(SW2.read() == 1 & SW1.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 410 | { |
thomasmorris | 31:4a88bf97b53e | 411 | Subtract_Hour(); |
thomasmorris | 31:4a88bf97b53e | 412 | } |
thomasmorris | 31:4a88bf97b53e | 413 | } |
thomasmorris | 30:4cde05cc7c4f | 414 | } |
thomasmorris | 30:4cde05cc7c4f | 415 | else if(mode == 6)//Set the Minute |
thomasmorris | 30:4cde05cc7c4f | 416 | { |
chills | 46:bd9e7e40b3f9 | 417 | if(Log_Value == 1){pc.printf("In Mode 6\n");} |
thomasmorris | 31:4a88bf97b53e | 418 | LCD.Display_Clear(); |
thomasmorris | 31:4a88bf97b53e | 419 | while(1) |
thomasmorris | 31:4a88bf97b53e | 420 | { |
thomasmorris | 32:8f2795716e97 | 421 | LCD_Write_Minute(); |
thomasmorris | 32:8f2795716e97 | 422 | Thread::wait(1000); |
chills | 46:bd9e7e40b3f9 | 423 | if(Log_Value == 1){pc.printf("Checking SW1 and SW2 to go Seconds setting\n");} |
chills | 33:3b5096f0126a | 424 | if(SW1.read() & SW2.read() == 1) |
chills | 33:3b5096f0126a | 425 | { |
chills | 33:3b5096f0126a | 426 | mode = 7; |
chills | 33:3b5096f0126a | 427 | break; |
chills | 33:3b5096f0126a | 428 | } |
chills | 46:bd9e7e40b3f9 | 429 | if(Log_Value == 1){pc.printf("Checking SW1 to add Minute\n");} |
thomasmorris | 31:4a88bf97b53e | 430 | if(SW1.read() == 1 & SW2.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 431 | { |
thomasmorris | 31:4a88bf97b53e | 432 | Add_Minute(); |
thomasmorris | 31:4a88bf97b53e | 433 | } |
chills | 46:bd9e7e40b3f9 | 434 | if(Log_Value == 1){pc.printf("Checking SW2 to subtract Minute\n");} |
thomasmorris | 31:4a88bf97b53e | 435 | else if(SW2.read() == 1 & SW1.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 436 | { |
thomasmorris | 31:4a88bf97b53e | 437 | Subtract_Minute(); |
thomasmorris | 32:8f2795716e97 | 438 | } |
thomasmorris | 31:4a88bf97b53e | 439 | } |
thomasmorris | 30:4cde05cc7c4f | 440 | } |
thomasmorris | 30:4cde05cc7c4f | 441 | else if(mode == 7)//Set the Seconds |
thomasmorris | 30:4cde05cc7c4f | 442 | { |
chills | 46:bd9e7e40b3f9 | 443 | if(Log_Value == 1){pc.printf("In Mode 7\n");} |
thomasmorris | 31:4a88bf97b53e | 444 | LCD.Display_Clear(); |
thomasmorris | 31:4a88bf97b53e | 445 | while(1) |
thomasmorris | 31:4a88bf97b53e | 446 | { |
thomasmorris | 32:8f2795716e97 | 447 | LCD_Write_Seconds(); |
thomasmorris | 32:8f2795716e97 | 448 | Thread::wait(1000); |
chills | 46:bd9e7e40b3f9 | 449 | if(Log_Value == 1){pc.printf("Checking SW1 and SW2 to go Default setting\n");} |
chills | 33:3b5096f0126a | 450 | if(SW1.read() & SW2.read() == 1) |
chills | 33:3b5096f0126a | 451 | { |
chills | 33:3b5096f0126a | 452 | mode = 0; |
chills | 33:3b5096f0126a | 453 | break; |
thomasmorris | 37:7c4d7f206039 | 454 | } |
chills | 46:bd9e7e40b3f9 | 455 | if(Log_Value == 1){pc.printf("Checking SW1 to add Second\n");} |
thomasmorris | 31:4a88bf97b53e | 456 | if(SW1.read() == 1 & SW2.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 457 | { |
thomasmorris | 31:4a88bf97b53e | 458 | Add_Second(); |
thomasmorris | 31:4a88bf97b53e | 459 | } |
chills | 46:bd9e7e40b3f9 | 460 | if(Log_Value == 1){pc.printf("Checking SW1 to subtract Second\n");} |
thomasmorris | 31:4a88bf97b53e | 461 | else if(SW2.read() == 1 & SW1.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 462 | { |
thomasmorris | 31:4a88bf97b53e | 463 | Subtract_Second(); |
thomasmorris | 32:8f2795716e97 | 464 | } |
thomasmorris | 31:4a88bf97b53e | 465 | } |
thomasmorris | 30:4cde05cc7c4f | 466 | } |
thomasmorris | 30:4cde05cc7c4f | 467 | else |
thomasmorris | 30:4cde05cc7c4f | 468 | { |
chills | 46:bd9e7e40b3f9 | 469 | if(Log_Value == 1){pc.printf("Mode Error occured mode now set to 0\n");} |
thomasmorris | 35:26b0a9b55d82 | 470 | mode = 0; |
thomasmorris | 7:dfe19413fdc2 | 471 | } |
thomasmorris | 7:dfe19413fdc2 | 472 | } |
thomasmorris | 7:dfe19413fdc2 | 473 | } |
thomasmorris | 29:64b1f95a807c | 474 | void Serial_Commands()//Used for getting input from the user to determine the opperations to perform |
thomasmorris | 22:eb4cc12087b2 | 475 | { |
thomasmorris | 38:8d86e0d8a816 | 476 | char input[100]; |
thomasmorris | 25:36699ed589ab | 477 | while(1) { |
thomasmorris | 38:8d86e0d8a816 | 478 | |
chills | 46:bd9e7e40b3f9 | 479 | if(Log_Value == 1){pc.printf("In Serial_Commands\n");} |
thomasmorris | 38:8d86e0d8a816 | 480 | for (int x = 0; x < 100; x++){input[x] = ' ';}; |
thomasmorris | 38:8d86e0d8a816 | 481 | |
chills | 46:bd9e7e40b3f9 | 482 | pc.printf("Please type in a command\n");//Log this |
chills | 34:c0b8705f183d | 483 | |
thomasmorris | 38:8d86e0d8a816 | 484 | cin.getline(input,sizeof(input),'\r'); |
thomasmorris | 38:8d86e0d8a816 | 485 | |
thomasmorris | 45:875f7e18a386 | 486 | //READ ALL |
thomasmorris | 39:5c499989d2b9 | 487 | if(input[0] == 'R' & input[1] == 'E' & input[2] == 'A' & input[3] == 'D' & input[4] == ' ' & input[5] == 'A' & input[6] == 'L' & input[7] == 'L') |
thomasmorris | 22:eb4cc12087b2 | 488 | { |
chills | 46:bd9e7e40b3f9 | 489 | if(Log_Value == 1){pc.printf("READ ALL Confirmed\n");} |
thomasmorris | 39:5c499989d2b9 | 490 | |
thomasmorris | 41:859b5e1e3d9a | 491 | Data_Buffer_Lock.lock();//Lock data buffer due to critical section |
thomasmorris | 39:5c499989d2b9 | 492 | int Start_Address_Read_All = Write_Pointer; |
thomasmorris | 41:859b5e1e3d9a | 493 | Data_Buffer_Lock.unlock();//unLock data buffer due to critical section |
thomasmorris | 39:5c499989d2b9 | 494 | |
thomasmorris | 39:5c499989d2b9 | 495 | for(int x_Read_All = (Start_Address_Read_All - mailsize); x_Read_All != Start_Address_Read_All; x_Read_All = x_Read_All ) |
thomasmorris | 39:5c499989d2b9 | 496 | { |
thomasmorris | 39:5c499989d2b9 | 497 | if(x_Read_All < 0){x_Read_All = x_Read_All + mailsize;} |
thomasmorris | 39:5c499989d2b9 | 498 | else {x_Read_All = x_Read_All;} |
thomasmorris | 39:5c499989d2b9 | 499 | |
thomasmorris | 39:5c499989d2b9 | 500 | DATA Serial_Read_Data = Read_Data(x_Read_All); |
thomasmorris | 39:5c499989d2b9 | 501 | |
thomasmorris | 39:5c499989d2b9 | 502 | time_t Time = Serial_Read_Data.get_time(); |
thomasmorris | 39:5c499989d2b9 | 503 | tm* Time_Pointer = localtime(&Time); |
thomasmorris | 39:5c499989d2b9 | 504 | |
thomasmorris | 45:875f7e18a386 | 505 | pc.printf("Date = %02d %02d %d ,\t", Time_Pointer->tm_mday, (Time_Pointer->tm_mon+1),(Time_Pointer->tm_year+1900)); |
thomasmorris | 45:875f7e18a386 | 506 | pc.printf("Time = %02d:%02d:%02d ,\t", Time_Pointer->tm_hour, Time_Pointer->tm_min, Time_Pointer->tm_sec); //Print the string formatted time |
thomasmorris | 45:875f7e18a386 | 507 | pc.printf("Temperature = %f ,\t", Serial_Read_Data.get_temperature()); //Print Temperature |
thomasmorris | 45:875f7e18a386 | 508 | pc.printf("Pressure = %f ,\t", Serial_Read_Data.get_pressure()); //Print Pressure |
chills | 46:bd9e7e40b3f9 | 509 | pc.printf("Light = %f ,\n", Serial_Read_Data.get_light()); //Print Light |
thomasmorris | 39:5c499989d2b9 | 510 | |
thomasmorris | 39:5c499989d2b9 | 511 | if(x_Read_All == mailsize - 1){x_Read_All = 0;} |
thomasmorris | 39:5c499989d2b9 | 512 | else {x_Read_All = x_Read_All + 1;} |
thomasmorris | 39:5c499989d2b9 | 513 | } |
thomasmorris | 38:8d86e0d8a816 | 514 | } |
thomasmorris | 38:8d86e0d8a816 | 515 | |
thomasmorris | 42:ae1640bca2e1 | 516 | //DELETE ALL FIX THIS - Might need to disable sampling during the delete |
thomasmorris | 45:875f7e18a386 | 517 | else if(input[0] == 'D' & input[1] == 'E' & input[2] == 'L' & input[3] == 'E' & input[4] == 'T' & input[5] == 'E' & input[6] == ' ' & input[7] == 'A' & input[8] == 'L' & input[9] == 'L') |
chills | 26:78f5e454e59f | 518 | { |
chills | 46:bd9e7e40b3f9 | 519 | if(Log_Value == 1){pc.printf("DELETE ALL Confirmed\n");} |
thomasmorris | 42:ae1640bca2e1 | 520 | |
thomasmorris | 42:ae1640bca2e1 | 521 | Data_Buffer_Lock.lock(); |
thomasmorris | 42:ae1640bca2e1 | 522 | int Start_Address = Write_Pointer; |
thomasmorris | 42:ae1640bca2e1 | 523 | Data_Buffer_Lock.unlock(); |
thomasmorris | 42:ae1640bca2e1 | 524 | |
thomasmorris | 42:ae1640bca2e1 | 525 | for(int x_Delete_All = (Start_Address - mailsize); x_Delete_All != Start_Address; x_Delete_All = x_Delete_All) |
thomasmorris | 42:ae1640bca2e1 | 526 | { |
thomasmorris | 42:ae1640bca2e1 | 527 | if(x_Delete_All < 0){x_Delete_All = x_Delete_All + mailsize;} |
thomasmorris | 42:ae1640bca2e1 | 528 | else {x_Delete_All = x_Delete_All;} |
thomasmorris | 42:ae1640bca2e1 | 529 | |
thomasmorris | 42:ae1640bca2e1 | 530 | Delete_Data(x_Delete_All); |
thomasmorris | 42:ae1640bca2e1 | 531 | |
thomasmorris | 42:ae1640bca2e1 | 532 | if(x_Delete_All == mailsize - 1){x_Delete_All = 0;} |
thomasmorris | 42:ae1640bca2e1 | 533 | else {x_Delete_All = x_Delete_All + 1;} |
thomasmorris | 42:ae1640bca2e1 | 534 | |
thomasmorris | 42:ae1640bca2e1 | 535 | } |
chills | 46:bd9e7e40b3f9 | 536 | pc.printf("DELETED %d RECORDS\n",mailsize); |
thomasmorris | 38:8d86e0d8a816 | 537 | } |
thomasmorris | 38:8d86e0d8a816 | 538 | |
thomasmorris | 41:859b5e1e3d9a | 539 | //READ |
thomasmorris | 38:8d86e0d8a816 | 540 | else if(input[0] == 'R' & input[1] == 'E' & input[2] == 'A' & input[3] == 'D' & input[4] == ' ') |
thomasmorris | 38:8d86e0d8a816 | 541 | { |
thomasmorris | 38:8d86e0d8a816 | 542 | int NumberOfChars = 0; int ArrayAddress = 0; string ReadNumber; int NumberToRead; |
thomasmorris | 38:8d86e0d8a816 | 543 | while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;} |
thomasmorris | 38:8d86e0d8a816 | 544 | for(int x=5; x < NumberOfChars; x++){ReadNumber += input[x];} |
thomasmorris | 38:8d86e0d8a816 | 545 | stringstream Number(ReadNumber); |
thomasmorris | 38:8d86e0d8a816 | 546 | Number >> NumberToRead; |
thomasmorris | 38:8d86e0d8a816 | 547 | |
thomasmorris | 45:875f7e18a386 | 548 | if(NumberToRead > mailsize) |
thomasmorris | 45:875f7e18a386 | 549 | { |
thomasmorris | 45:875f7e18a386 | 550 | NumberToRead = mailsize; |
thomasmorris | 45:875f7e18a386 | 551 | } |
thomasmorris | 39:5c499989d2b9 | 552 | |
chills | 46:bd9e7e40b3f9 | 553 | if(Log_Value == 1){pc.printf("Getting Data\n");} |
thomasmorris | 39:5c499989d2b9 | 554 | |
thomasmorris | 41:859b5e1e3d9a | 555 | Data_Buffer_Lock.lock();//Lock data buffer due to critical section |
thomasmorris | 39:5c499989d2b9 | 556 | int Start_Address = Write_Pointer; |
thomasmorris | 41:859b5e1e3d9a | 557 | Data_Buffer_Lock.unlock();//unLock data buffer due to critical section |
thomasmorris | 39:5c499989d2b9 | 558 | |
thomasmorris | 39:5c499989d2b9 | 559 | for(int x = (Start_Address - NumberToRead); x != Start_Address; x = x ) |
thomasmorris | 39:5c499989d2b9 | 560 | { |
thomasmorris | 39:5c499989d2b9 | 561 | if(x < 0){x = x + mailsize;} |
thomasmorris | 39:5c499989d2b9 | 562 | else {x = x;} |
thomasmorris | 39:5c499989d2b9 | 563 | |
thomasmorris | 39:5c499989d2b9 | 564 | DATA Serial_Read_Data = Read_Data(x); |
thomasmorris | 39:5c499989d2b9 | 565 | |
thomasmorris | 39:5c499989d2b9 | 566 | time_t Time = Serial_Read_Data.get_time(); |
thomasmorris | 39:5c499989d2b9 | 567 | tm* Time_Pointer = localtime(&Time); |
thomasmorris | 45:875f7e18a386 | 568 | |
thomasmorris | 45:875f7e18a386 | 569 | pc.printf("Date = %02d %02d %d ,\t", Time_Pointer->tm_mday, (Time_Pointer->tm_mon+1),(Time_Pointer->tm_year+1900)); |
thomasmorris | 45:875f7e18a386 | 570 | pc.printf("Time = %02d:%02d:%02d ,\t", Time_Pointer->tm_hour, Time_Pointer->tm_min, Time_Pointer->tm_sec); //Print the string formatted time |
thomasmorris | 45:875f7e18a386 | 571 | pc.printf("Temperature = %f ,\t", Serial_Read_Data.get_temperature()); //Print Temperature |
thomasmorris | 45:875f7e18a386 | 572 | pc.printf("Pressure = %f ,\t", Serial_Read_Data.get_pressure()); //Print Pressure |
chills | 46:bd9e7e40b3f9 | 573 | pc.printf("Light = %f ,\n", Serial_Read_Data.get_light()); //Print Light |
thomasmorris | 39:5c499989d2b9 | 574 | |
thomasmorris | 39:5c499989d2b9 | 575 | if(x == mailsize - 1){x = 0;} |
thomasmorris | 39:5c499989d2b9 | 576 | else {x = x + 1;} |
thomasmorris | 39:5c499989d2b9 | 577 | } |
chills | 46:bd9e7e40b3f9 | 578 | if(Log_Value == 1){pc.printf("Read %d samples\n",NumberToRead);} |
thomasmorris | 38:8d86e0d8a816 | 579 | |
thomasmorris | 25:36699ed589ab | 580 | } |
thomasmorris | 38:8d86e0d8a816 | 581 | |
thomasmorris | 42:ae1640bca2e1 | 582 | //DELETE look into this mgiht need to turn off sampling |
thomasmorris | 38:8d86e0d8a816 | 583 | else if(input[0] == 'D' & input[1] == 'E' & input[2] == 'L' & input[3] == 'E' & input[4] == 'T' & input[5] == 'E' & input[6] == ' ') |
thomasmorris | 22:eb4cc12087b2 | 584 | { |
thomasmorris | 38:8d86e0d8a816 | 585 | int NumberOfChars = 0; int ArrayAddress = 0; string DeleteNumber; int NumberToDelete; |
thomasmorris | 38:8d86e0d8a816 | 586 | while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;} |
thomasmorris | 38:8d86e0d8a816 | 587 | for(int x=7; x < NumberOfChars; x++){DeleteNumber += input[x];} |
thomasmorris | 38:8d86e0d8a816 | 588 | stringstream Number(DeleteNumber); |
thomasmorris | 38:8d86e0d8a816 | 589 | Number >> NumberToDelete; |
thomasmorris | 38:8d86e0d8a816 | 590 | |
thomasmorris | 45:875f7e18a386 | 591 | if(NumberToDelete > mailsize) |
thomasmorris | 45:875f7e18a386 | 592 | { |
thomasmorris | 45:875f7e18a386 | 593 | NumberToDelete = mailsize; |
thomasmorris | 45:875f7e18a386 | 594 | } |
chills | 46:bd9e7e40b3f9 | 595 | if(Log_Value == 1){pc.printf("Deleted %d samples\n",NumberToDelete);} |
thomasmorris | 38:8d86e0d8a816 | 596 | |
thomasmorris | 42:ae1640bca2e1 | 597 | Data_Buffer_Lock.lock(); |
thomasmorris | 42:ae1640bca2e1 | 598 | int Start_Address = Write_Pointer; |
thomasmorris | 42:ae1640bca2e1 | 599 | Data_Buffer_Lock.unlock(); |
thomasmorris | 42:ae1640bca2e1 | 600 | |
thomasmorris | 42:ae1640bca2e1 | 601 | for(int x_Delete = (Start_Address - NumberToDelete); x_Delete != Start_Address; x_Delete = x_Delete ) |
thomasmorris | 42:ae1640bca2e1 | 602 | { |
thomasmorris | 42:ae1640bca2e1 | 603 | if(x_Delete < 0){x_Delete = x_Delete + mailsize;} |
thomasmorris | 42:ae1640bca2e1 | 604 | else {x_Delete = x_Delete;} |
thomasmorris | 42:ae1640bca2e1 | 605 | |
thomasmorris | 42:ae1640bca2e1 | 606 | Delete_Data(x_Delete); |
thomasmorris | 42:ae1640bca2e1 | 607 | |
thomasmorris | 42:ae1640bca2e1 | 608 | if(x_Delete == mailsize - 1){x_Delete = 0;} |
thomasmorris | 42:ae1640bca2e1 | 609 | else {x_Delete = x_Delete + 1;} |
thomasmorris | 42:ae1640bca2e1 | 610 | |
thomasmorris | 42:ae1640bca2e1 | 611 | } |
chills | 46:bd9e7e40b3f9 | 612 | pc.printf("DELETED %d RECORDS\n",NumberToDelete); |
chills | 46:bd9e7e40b3f9 | 613 | if(Log_Value == 1){pc.printf("Deleted %d samples\n",NumberToDelete);} |
chills | 34:c0b8705f183d | 614 | } |
thomasmorris | 38:8d86e0d8a816 | 615 | |
thomasmorris | 38:8d86e0d8a816 | 616 | //STATE |
thomasmorris | 38:8d86e0d8a816 | 617 | else if(input[0] == 'S' & input[1] == 'T' & input[2] == 'A' & input[3] == 'T' & input[4] == 'E' & input[5] == ' ') |
chills | 34:c0b8705f183d | 618 | { |
thomasmorris | 38:8d86e0d8a816 | 619 | int NumberOfChars = 0; int ArrayAddress = 0; string StateNumber; int NumberToState; |
thomasmorris | 38:8d86e0d8a816 | 620 | while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;} |
thomasmorris | 38:8d86e0d8a816 | 621 | for(int x=6; x < NumberOfChars; x++){StateNumber += input[x];} |
thomasmorris | 38:8d86e0d8a816 | 622 | stringstream Number(StateNumber); |
thomasmorris | 38:8d86e0d8a816 | 623 | Number >> NumberToState; |
thomasmorris | 38:8d86e0d8a816 | 624 | |
chills | 46:bd9e7e40b3f9 | 625 | if(NumberToState==0) {Sampling_Timer.detach(); Console_Output_Timer.detach(); pc.printf("SAMPLING 0\n");}//Stop Sampling |
chills | 46:bd9e7e40b3f9 | 626 | else if(NumberToState==1) {Sampling_Timer.attach(&Sampling_ISR,Sample_Rate); pc.printf("SAMPLING 1\n");}//Start Sampling |
chills | 46:bd9e7e40b3f9 | 627 | else {pc.printf("Invalid State\n");} |
thomasmorris | 45:875f7e18a386 | 628 | |
chills | 26:78f5e454e59f | 629 | } |
thomasmorris | 38:8d86e0d8a816 | 630 | |
thomasmorris | 38:8d86e0d8a816 | 631 | //SETDATE |
thomasmorris | 38:8d86e0d8a816 | 632 | else if(input[0] == 'S' & input[1] == 'E' & input[2] == 'T' & input[3] == 'D' & input[4] == 'A' & input[5] == 'T' & input[6] == 'E' & input[7] == ' ' & input[10] == ' ' & input[13] == ' ') |
thomasmorris | 38:8d86e0d8a816 | 633 | { |
thomasmorris | 41:859b5e1e3d9a | 634 | //int NumberOfChars = 0; int ArrayAddress = 0; |
thomasmorris | 38:8d86e0d8a816 | 635 | string DayNumber, MonthNumber, YearNumber; |
thomasmorris | 38:8d86e0d8a816 | 636 | int NumberToDay, NumberToMonth, NumberToYear; |
thomasmorris | 38:8d86e0d8a816 | 637 | |
thomasmorris | 38:8d86e0d8a816 | 638 | for(int x=8; x < 10; x++){DayNumber += input[x];} |
thomasmorris | 38:8d86e0d8a816 | 639 | stringstream Number_1(DayNumber); |
thomasmorris | 38:8d86e0d8a816 | 640 | Number_1 >> NumberToDay; |
thomasmorris | 38:8d86e0d8a816 | 641 | |
thomasmorris | 38:8d86e0d8a816 | 642 | for(int x=11; x < 13; x++){MonthNumber += input[x];} |
thomasmorris | 38:8d86e0d8a816 | 643 | stringstream Number_2(MonthNumber); |
thomasmorris | 38:8d86e0d8a816 | 644 | Number_2 >> NumberToMonth; |
thomasmorris | 38:8d86e0d8a816 | 645 | |
thomasmorris | 38:8d86e0d8a816 | 646 | for(int x=14; x < 18; x++){YearNumber += input[x];} |
thomasmorris | 38:8d86e0d8a816 | 647 | stringstream Number_3(YearNumber); |
thomasmorris | 38:8d86e0d8a816 | 648 | Number_3 >> NumberToYear; |
thomasmorris | 38:8d86e0d8a816 | 649 | |
thomasmorris | 38:8d86e0d8a816 | 650 | set_new_date(NumberToDay,NumberToMonth,NumberToYear); |
chills | 46:bd9e7e40b3f9 | 651 | pc.printf("DATE UPDATED TO %02d %02d %d\n",NumberToDay,NumberToMonth,NumberToYear); |
thomasmorris | 38:8d86e0d8a816 | 652 | } |
thomasmorris | 38:8d86e0d8a816 | 653 | |
thomasmorris | 38:8d86e0d8a816 | 654 | //SETTIME |
thomasmorris | 38:8d86e0d8a816 | 655 | else if(input[0] == 'S' & input[1] == 'E' & input[2] == 'T' & input[3] == 'T' & input[4] == 'I' & input[5] == 'M' & input[6] == 'E' & input[7] == ' ' & input[10] == ' ' & input[13] == ' ') |
thomasmorris | 22:eb4cc12087b2 | 656 | { |
thomasmorris | 41:859b5e1e3d9a | 657 | //int NumberOfChars = 0; int ArrayAddress = 0; |
thomasmorris | 38:8d86e0d8a816 | 658 | string HourNumber, MinuteNumber, SecondNumber; |
thomasmorris | 38:8d86e0d8a816 | 659 | int NumberToHour, NumberToMinute, NumberToSecond; |
thomasmorris | 38:8d86e0d8a816 | 660 | |
thomasmorris | 38:8d86e0d8a816 | 661 | for(int x=8; x < 10; x++){HourNumber += input[x];} |
thomasmorris | 38:8d86e0d8a816 | 662 | stringstream Number_1(HourNumber); |
thomasmorris | 38:8d86e0d8a816 | 663 | Number_1 >> NumberToHour; |
thomasmorris | 38:8d86e0d8a816 | 664 | |
thomasmorris | 38:8d86e0d8a816 | 665 | for(int x=11; x < 13; x++){MinuteNumber += input[x];} |
thomasmorris | 38:8d86e0d8a816 | 666 | stringstream Number_2(MinuteNumber); |
thomasmorris | 38:8d86e0d8a816 | 667 | Number_2 >> NumberToMinute; |
thomasmorris | 38:8d86e0d8a816 | 668 | |
thomasmorris | 38:8d86e0d8a816 | 669 | for(int x=14; x < 16; x++){SecondNumber += input[x];} |
thomasmorris | 38:8d86e0d8a816 | 670 | stringstream Number_3(SecondNumber); |
thomasmorris | 38:8d86e0d8a816 | 671 | Number_3 >> NumberToSecond; |
thomasmorris | 38:8d86e0d8a816 | 672 | |
thomasmorris | 45:875f7e18a386 | 673 | set_new_time(NumberToHour,NumberToMinute,NumberToSecond); |
chills | 46:bd9e7e40b3f9 | 674 | pc.printf("TIME UPDATED TO %02d %02d %02d\n",NumberToHour,NumberToMinute,NumberToSecond); |
thomasmorris | 38:8d86e0d8a816 | 675 | } |
thomasmorris | 38:8d86e0d8a816 | 676 | |
thomasmorris | 38:8d86e0d8a816 | 677 | //SETT |
thomasmorris | 38:8d86e0d8a816 | 678 | else if(input[0] == 'S' & input[1] == 'E' & input[2] == 'T' & input[3] == 'T' & input[4] == ' ') |
thomasmorris | 38:8d86e0d8a816 | 679 | { |
thomasmorris | 38:8d86e0d8a816 | 680 | |
thomasmorris | 45:875f7e18a386 | 681 | int NumberOfChars = 0; int ArrayAddress = 0; |
thomasmorris | 45:875f7e18a386 | 682 | string SettNumber; double NumberToSett; |
thomasmorris | 45:875f7e18a386 | 683 | int Decimal_Divider = 10; |
thomasmorris | 45:875f7e18a386 | 684 | float Sample_Rate_Integer = 0; string Sample_Rate_Integer_String; |
thomasmorris | 45:875f7e18a386 | 685 | float Sample_Rate_Decimal = 0; string Sample_Rate_Decimal_String; |
thomasmorris | 38:8d86e0d8a816 | 686 | while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;} |
thomasmorris | 45:875f7e18a386 | 687 | |
thomasmorris | 45:875f7e18a386 | 688 | if (Decimal_Check(input) == true) |
thomasmorris | 45:875f7e18a386 | 689 | { |
thomasmorris | 45:875f7e18a386 | 690 | for(int x = 5; x < Decimal_Position(input); x++){Sample_Rate_Integer_String += input[x];} |
thomasmorris | 45:875f7e18a386 | 691 | stringstream Number_1(Sample_Rate_Integer_String); |
thomasmorris | 45:875f7e18a386 | 692 | Number_1 >> Sample_Rate_Integer; |
thomasmorris | 45:875f7e18a386 | 693 | |
thomasmorris | 45:875f7e18a386 | 694 | for(int x = Decimal_Position(input) + 1; x < NumberOfChars; x++){Sample_Rate_Decimal_String += input[x];} |
thomasmorris | 45:875f7e18a386 | 695 | stringstream Number_2(Sample_Rate_Decimal_String); |
thomasmorris | 45:875f7e18a386 | 696 | Number_2 >> Sample_Rate_Decimal; |
thomasmorris | 45:875f7e18a386 | 697 | |
thomasmorris | 45:875f7e18a386 | 698 | for(int tens_power = 1; tens_power != NumberOfChars - Decimal_Position(input) - 1; tens_power++) |
thomasmorris | 45:875f7e18a386 | 699 | { |
thomasmorris | 45:875f7e18a386 | 700 | Decimal_Divider = Decimal_Divider * 10; |
thomasmorris | 45:875f7e18a386 | 701 | } |
thomasmorris | 45:875f7e18a386 | 702 | NumberToSett = Sample_Rate_Integer + (Sample_Rate_Decimal / float(Decimal_Divider)); |
thomasmorris | 45:875f7e18a386 | 703 | } |
thomasmorris | 45:875f7e18a386 | 704 | else |
thomasmorris | 45:875f7e18a386 | 705 | { |
thomasmorris | 45:875f7e18a386 | 706 | for(int x=5; x < NumberOfChars; x++){SettNumber += input[x];} |
thomasmorris | 45:875f7e18a386 | 707 | stringstream Number_3(SettNumber); |
thomasmorris | 45:875f7e18a386 | 708 | Number_3 >> NumberToSett; |
thomasmorris | 45:875f7e18a386 | 709 | } |
thomasmorris | 38:8d86e0d8a816 | 710 | |
thomasmorris | 45:875f7e18a386 | 711 | if(NumberToSett >= 0.1 & NumberToSett <= 60) |
thomasmorris | 45:875f7e18a386 | 712 | { |
thomasmorris | 45:875f7e18a386 | 713 | Sample_Rate = NumberToSett; |
chills | 46:bd9e7e40b3f9 | 714 | pc.printf("T UPDATED TO %1.1f \n",NumberToSett); |
thomasmorris | 45:875f7e18a386 | 715 | } |
thomasmorris | 45:875f7e18a386 | 716 | else |
thomasmorris | 45:875f7e18a386 | 717 | { |
thomasmorris | 45:875f7e18a386 | 718 | Sample_Rate = Sample_Rate;//No change |
chills | 46:bd9e7e40b3f9 | 719 | pc.printf("OUT OF RANGE\n"); |
thomasmorris | 45:875f7e18a386 | 720 | } |
chills | 26:78f5e454e59f | 721 | |
chills | 26:78f5e454e59f | 722 | Sampling_Timer.detach(); |
chills | 26:78f5e454e59f | 723 | Console_Output_Timer.detach(); |
chills | 26:78f5e454e59f | 724 | Sampling_Timer.attach(&Sampling_ISR,Sample_Rate); |
thomasmorris | 38:8d86e0d8a816 | 725 | } |
thomasmorris | 38:8d86e0d8a816 | 726 | //LOGGING |
thomasmorris | 38:8d86e0d8a816 | 727 | else if(input[0] == 'L' & input[1] == 'O' & input[2] == 'G' & input[3] == 'G' & input[4] == 'I' & input[5] == 'N' & input[6] == 'G' & input[7] == ' ') |
thomasmorris | 38:8d86e0d8a816 | 728 | { |
thomasmorris | 38:8d86e0d8a816 | 729 | int NumberOfChars = 0; int ArrayAddress = 0; string LoggingNumber; int NumberToLogging; |
thomasmorris | 38:8d86e0d8a816 | 730 | while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;} |
thomasmorris | 38:8d86e0d8a816 | 731 | for(int x=8; x < NumberOfChars; x++){LoggingNumber += input[x];} |
thomasmorris | 38:8d86e0d8a816 | 732 | stringstream Number(LoggingNumber); |
thomasmorris | 38:8d86e0d8a816 | 733 | Number >> NumberToLogging; |
thomasmorris | 45:875f7e18a386 | 734 | if(NumberToLogging != 1) |
thomasmorris | 45:875f7e18a386 | 735 | { |
thomasmorris | 45:875f7e18a386 | 736 | NumberToLogging = 0; |
thomasmorris | 45:875f7e18a386 | 737 | } |
thomasmorris | 38:8d86e0d8a816 | 738 | Log_Value = NumberToLogging; |
chills | 46:bd9e7e40b3f9 | 739 | pc.printf("LOGGING %d\n",NumberToLogging); |
thomasmorris | 25:36699ed589ab | 740 | } |
thomasmorris | 38:8d86e0d8a816 | 741 | |
thomasmorris | 38:8d86e0d8a816 | 742 | //HELP |
thomasmorris | 38:8d86e0d8a816 | 743 | else if(input[0] == 'H' & input[1] == 'E' & input[2] == 'L' & input[3] == 'P')// Use this to display all of the availble commands |
thomasmorris | 25:36699ed589ab | 744 | { |
thomasmorris | 41:859b5e1e3d9a | 745 | HELP();//Run HELP Command |
thomasmorris | 22:eb4cc12087b2 | 746 | } |
thomasmorris | 25:36699ed589ab | 747 | else |
thomasmorris | 22:eb4cc12087b2 | 748 | { |
chills | 46:bd9e7e40b3f9 | 749 | pc.printf("Please enter an acceptable command\n"); |
thomasmorris | 22:eb4cc12087b2 | 750 | } |
thomasmorris | 22:eb4cc12087b2 | 751 | } |
thomasmorris | 22:eb4cc12087b2 | 752 | } |
thomasmorris | 5:2594b953f111 | 753 | |
thomasmorris | 41:859b5e1e3d9a | 754 | void Sampling_ISR(){t1.signal_set(SamplingTime);} |
chills | 26:78f5e454e59f | 755 | |
chills | 26:78f5e454e59f | 756 | |
thomasmorris | 5:2594b953f111 | 757 | void Sample()//Samples the hardware and prints the result to the LCD |
thomasmorris | 5:2594b953f111 | 758 | { |
thomasmorris | 30:4cde05cc7c4f | 759 | while(1) |
thomasmorris | 30:4cde05cc7c4f | 760 | { |
chills | 10:46946784326d | 761 | Thread::signal_wait(SamplingTime); //Set the time between samples |
chills | 46:bd9e7e40b3f9 | 762 | if(Log_Value == 1){pc.printf("Sample Time\n");} |
chills | 34:c0b8705f183d | 763 | Data_Active.set_temperature(sensor.getTemperature()); //Read Temperature |
chills | 34:c0b8705f183d | 764 | Data_Active.set_pressure(sensor.getPressure()); //Read Pressure |
chills | 34:c0b8705f183d | 765 | Data_Active.set_light(adcIn.read()); //Read Light |
chills | 33:3b5096f0126a | 766 | |
chills | 33:3b5096f0126a | 767 | Time_Lock_Main.lock(); |
chills | 34:c0b8705f183d | 768 | time_t buffer_time = time(NULL); |
chills | 33:3b5096f0126a | 769 | Time_Lock_Main.unlock(); |
thomasmorris | 25:36699ed589ab | 770 | |
chills | 34:c0b8705f183d | 771 | Data_Active.set_time(buffer_time); |
thomasmorris | 25:36699ed589ab | 772 | |
thomasmorris | 45:875f7e18a386 | 773 | Red_led.flash(0.02);//ahh he saved everyone of us |
thomasmorris | 39:5c499989d2b9 | 774 | Write_Pointer = Write_Data(Data_Active,Write_Pointer); |
thomasmorris | 5:2594b953f111 | 775 | t1.signal_set(NotSamplingTime); |
chills | 46:bd9e7e40b3f9 | 776 | if(Log_Value == 1){pc.printf("New Sample avaliable\n");} |
thomasmorris | 41:859b5e1e3d9a | 777 | t2.signal_set(SD_Data_Ready); |
thomasmorris | 5:2594b953f111 | 778 | } |
thomasmorris | 25:36699ed589ab | 779 | } |
thomasmorris | 25:36699ed589ab | 780 | int main() |
thomasmorris | 25:36699ed589ab | 781 | { |
thomasmorris | 37:7c4d7f206039 | 782 | set_time(1515352584); //Set RTC time to December 10 2017 |
thomasmorris | 30:4cde05cc7c4f | 783 | |
chills | 10:46946784326d | 784 | pc.baud(9600); //Sets the Serial Comms Baud Rate |
thomasmorris | 25:36699ed589ab | 785 | |
chills | 20:cbb71f84cff9 | 786 | LCD.Initialise(); |
thomasmorris | 28:09b5c46c8afd | 787 | LCD.DDRAM_Address(0x00); |
thomasmorris | 29:64b1f95a807c | 788 | |
thomasmorris | 25:36699ed589ab | 789 | post(); //Power on Self Test |
thomasmorris | 25:36699ed589ab | 790 | |
noutram | 3:a88838ff33e7 | 791 | //Initialise the SD card (this needs to move) |
noutram | 1:e1cf7663f5ff | 792 | if ( sd.init() != 0) { |
thomasmorris | 45:875f7e18a386 | 793 | printf("SD Init failed \n"); |
thomasmorris | 28:09b5c46c8afd | 794 | LCD.Display_Clear(); |
thomasmorris | 28:09b5c46c8afd | 795 | LCD.Write_String("CANNOT INIT SD"); //Change me |
noutram | 1:e1cf7663f5ff | 796 | errorCode(FATAL); |
thomasmorris | 25:36699ed589ab | 797 | } |
noutram | 1:e1cf7663f5ff | 798 | //Create a filing system for SD Card |
thomasmorris | 25:36699ed589ab | 799 | FATFileSystem fs("sd", &sd); |
noutram | 0:36e89e3ed7c4 | 800 | |
noutram | 1:e1cf7663f5ff | 801 | //Open to WRITE |
thomasmorris | 41:859b5e1e3d9a | 802 | FILE* fp = fopen("/sd/test.csv","a");//test.csv is created in the SD Card |
noutram | 1:e1cf7663f5ff | 803 | if (fp == NULL) { |
noutram | 1:e1cf7663f5ff | 804 | error("Could not open file for write\n"); |
thomasmorris | 28:09b5c46c8afd | 805 | LCD.Display_Clear(); |
thomasmorris | 37:7c4d7f206039 | 806 | LCD.Write_String("CANNOT OPEN FILE"); |
noutram | 1:e1cf7663f5ff | 807 | errorCode(FATAL); |
noutram | 1:e1cf7663f5ff | 808 | } |
thomasmorris | 41:859b5e1e3d9a | 809 | //Close File |
thomasmorris | 41:859b5e1e3d9a | 810 | fclose(fp); |
thomasmorris | 37:7c4d7f206039 | 811 | int network_temp; |
thomasmorris | 37:7c4d7f206039 | 812 | network_temp = Network_Init(); |
thomasmorris | 37:7c4d7f206039 | 813 | if(network_temp == 1)//Sets up the network and checks if the network cable is not pluged in |
thomasmorris | 37:7c4d7f206039 | 814 | { |
thomasmorris | 37:7c4d7f206039 | 815 | error("Could not access network"); |
thomasmorris | 37:7c4d7f206039 | 816 | LCD.Display_Clear(); |
thomasmorris | 37:7c4d7f206039 | 817 | LCD.Write_String("Could not access network"); |
thomasmorris | 41:859b5e1e3d9a | 818 | errorCode(NETWORK_FATAL); |
thomasmorris | 37:7c4d7f206039 | 819 | } |
noutram | 3:a88838ff33e7 | 820 | //Last message before sampling begins |
thomasmorris | 28:09b5c46c8afd | 821 | LCD.Display_Clear(); |
thomasmorris | 35:26b0a9b55d82 | 822 | LCD.Write_String("READY PLAYER"); |
thomasmorris | 31:4a88bf97b53e | 823 | LCD.DDRAM_Address(0x40); |
thomasmorris | 35:26b0a9b55d82 | 824 | LCD.Write_String(" One "); |
thomasmorris | 31:4a88bf97b53e | 825 | LCD.DDRAM_Address(0x00); |
thomasmorris | 25:36699ed589ab | 826 | |
thomasmorris | 25:36699ed589ab | 827 | Sample_Rate = TimerInterval; |
chills | 24:7d2da96e05ad | 828 | //Run interrupt |
chills | 26:78f5e454e59f | 829 | Sampling_Timer.attach(&Sampling_ISR,Sample_Rate); |
chills | 24:7d2da96e05ad | 830 | |
thomasmorris | 5:2594b953f111 | 831 | t1.start(Sample); |
thomasmorris | 41:859b5e1e3d9a | 832 | t2.start(SD_Card); |
thomasmorris | 30:4cde05cc7c4f | 833 | t3.start(LCD_Output); |
thomasmorris | 35:26b0a9b55d82 | 834 | t4.start(Network); |
thomasmorris | 23:3c85d7f657a2 | 835 | t5.start(Serial_Commands); |
thomasmorris | 25:36699ed589ab | 836 | |
thomasmorris | 5:2594b953f111 | 837 | //Main thread ID |
thomasmorris | 25:36699ed589ab | 838 | |
thomasmorris | 5:2594b953f111 | 839 | idMain = osThreadGetId(); //CMSIS RTOS call |
thomasmorris | 25:36699ed589ab | 840 | |
thomasmorris | 5:2594b953f111 | 841 | //Thread ID |
thomasmorris | 5:2594b953f111 | 842 | id1 = t1.gettid(); |
thomasmorris | 5:2594b953f111 | 843 | id2 = t2.gettid(); |
thomasmorris | 21:3c078c799caa | 844 | id3 = t3.gettid(); |
thomasmorris | 21:3c078c799caa | 845 | id4 = t4.gettid(); |
chills | 24:7d2da96e05ad | 846 | id5 = t5.gettid(); |
thomasmorris | 25:36699ed589ab | 847 | |
noutram | 1:e1cf7663f5ff | 848 | while(true) { |
thomasmorris | 41:859b5e1e3d9a | 849 | if(onBoardSwitch == 1) |
thomasmorris | 41:859b5e1e3d9a | 850 | { |
thomasmorris | 41:859b5e1e3d9a | 851 | fclose(fp);//Close File |
thomasmorris | 41:859b5e1e3d9a | 852 | sd.deinit();//Close down |
thomasmorris | 41:859b5e1e3d9a | 853 | LCD.Display_Clear(); |
thomasmorris | 41:859b5e1e3d9a | 854 | LCD.DDRAM_Address(0x00); |
thomasmorris | 41:859b5e1e3d9a | 855 | LCD.Write_String("SD Card"); |
thomasmorris | 41:859b5e1e3d9a | 856 | LCD.DDRAM_Address(0x40); |
thomasmorris | 41:859b5e1e3d9a | 857 | LCD.Write_String("Unmounted"); |
thomasmorris | 41:859b5e1e3d9a | 858 | LCD.DDRAM_Address(0x00); |
chills | 46:bd9e7e40b3f9 | 859 | pc.printf("SD Card Unmounted\n"); |
thomasmorris | 45:875f7e18a386 | 860 | Green_led.switchOn(); |
thomasmorris | 41:859b5e1e3d9a | 861 | } |
noutram | 0:36e89e3ed7c4 | 862 | } |
thomasmorris | 45:875f7e18a386 | 863 | } |