lucas kovaci
/
SOFT253_Assignment_Group_K
SOFT253 ASSIGNMENT
Fork of SOFT253_Assignment_V4 by
Diff: main.cpp
- Revision:
- 47:5f364311bc45
- Parent:
- 46:ca411482a095
- Child:
- 48:f7487eb2c82a
diff -r ca411482a095 -r 5f364311bc45 main.cpp --- a/main.cpp Mon May 15 01:59:16 2017 +0000 +++ b/main.cpp Mon May 15 03:57:27 2017 +0000 @@ -3,6 +3,9 @@ #include "rtos.h" #include "hts221.h" #include "LPS25H.h" +#include "time.h" +#include "stdio.h" +#include "stdlib.h" Serial pc(USBTX, USBRX); @@ -23,10 +26,22 @@ char input2[20]; char inputSet1[20]; char inputSet2[20]; +char inputDel1[20]; +char inputDel2[20]; +char inputState1[20]; +char inputState2[20]; +char inputStateOFF1[20]; +char inputStateOFF2[20]; char stringToCompare1[20]; char stringToCompare2[20]; char stringToCompareSet1[20]; char stringToCompareSet2[20]; +char stringToCompareDel1[20]; +char stringToCompareDel2[20]; +char stringToCompareState1[20]; +char stringToCompareState2[20]; +char stringToCompareStateOFF1[20]; +char stringToCompareStateOFF2[20]; float tempArray[N]; float humArray[N]; float pressArray[N]; @@ -38,10 +53,12 @@ int res2; int resSet1; int resSet2; +int resState1; +int resState2; LPS25H barometer(i2c2, LPS25H_V_CHIP_ADDR); HTS221 humidity(I2C_SDA, I2C_SCL); - +time_t timeNow; void adcISR(); void thread1 (void const *args ); @@ -49,8 +66,7 @@ Thread* t1; Thread* t2; -Thread* t3; -Thread* t4; + @@ -140,7 +156,8 @@ { for (unsigned int n=0; n<val; n++) { - pc.printf("the element of %d is %4.2f\n\r",n,tempArray[n]); + pc.printf("the element of %d is %4.2f ,%3.1f, %6.1f \n\r",n,tempArray[n],humArray[n],pressArray[n]); + //printf("the temperature is: %4.2fC\n\r The humidity is: %3.1f\n\r", tempCelsius, humi); } } } @@ -154,7 +171,7 @@ { for (unsigned int n=0; n<N; n++) { - pc.printf("the element of %d is %4.2f\n\r",n,tempArray[n]); + pc.printf("the element of %d is %4.2f ,%3.1f, %6.1f \n\r",n,tempArray[n],humArray[n],pressArray[n]); } } @@ -167,7 +184,9 @@ if(res==0 && res2==0) { //Delete every element. - memset(tempArray, 0, sizeof tempArray); + memset(tempArray, 0, sizeof tempArray); + memset(humArray, 0, sizeof humArray); + memset(pressArray, 0, sizeof pressArray); pc.printf("%d Elements deleted\n",N); counters=0; } @@ -176,13 +195,13 @@ } //1 - strcpy (inputSet1,cmd); - strcpy (inputSet2,cmd2); - strcpy (stringToCompareSet1,"DELETE"); //STRING TO COMPARE 1 - strcpy (stringToCompareSet2,inputSet2); - resSet1 = strncmp(input1,stringToCompareSet1,20); - resSet2 = strncmp(input2,stringToCompareSet2,20); - int valDel = atoi(inputSet2); + strcpy (inputDel1,cmd); + strcpy (inputDel2,cmd2); + strcpy (stringToCompareDel1,"DELETE"); //STRING TO COMPARE 1 + strcpy (stringToCompareDel2,inputDel2); + resSet1 = strncmp(input1,stringToCompareDel1,20); + resSet2 = strncmp(input2,stringToCompareDel2,20); + int valDel = atoi(inputDel2); int startDel=(counters - valDel); if (valDel <=10 && valDel >=1) { @@ -191,11 +210,66 @@ for (unsigned int n=startDel; n<counters; n++) { tempArray[n]=0.00; + humArray[n]=0.00; + pressArray[n]=0.00; } pc.printf("Deleted %d records\n",valDel); counters = counters - valDel; } - } + } + strcpy (inputSet1,cmd); //INPUT 1 + strcpy (inputSet2,cmd2); + strcpy (stringToCompareSet1,"SETT"); //STRING TO COMPARE 1 + strcpy (stringToCompareSet2,inputSet2); //STRING TO COMPARE 2 + resSet1 = strncmp(inputSet1,stringToCompareSet1,20); + resSet2 = strncmp(inputSet2,stringToCompareSet2,20); + int inputSpeed = atoi(inputSet2); + if (inputSpeed <=60 && inputSpeed >=0.1) + { + if (resSet1==0 && resSet2==0) + { + sampleSpeed = inputSpeed; + t.attach(&adcISR, sampleSpeed); + pc.printf("T UPDATED TO %d\n",sampleSpeed); + + + } + } + strcpy (inputState1,cmd); //INPUT 1 + strcpy (inputState2,cmd2); + strcpy (stringToCompareState1,"STATE"); //STRING TO COMPARE 1 + strcpy (stringToCompareState2,"ON"); //STRING TO COMPARE 2 + resSet1 = strncmp(inputState1,stringToCompareState1,20); + resSet2 = strncmp(inputState2,stringToCompareState2,20); + + if (resSet1==0 && resSet2==0) + { + + //t.detach(); + // LPC_TIM3->TC = 0; + t.attach(&adcISR, sampleSpeed); + pc.printf("Sampling: ON\n"); + + } + strcpy (inputStateOFF1,cmd); //INPUT 1 + strcpy (inputStateOFF2,cmd2); + strcpy (stringToCompareStateOFF1,"STATE"); //STRING TO COMPARE 1 + strcpy (stringToCompareStateOFF2,"OFF"); //STRING TO COMPARE 2 + resState1 = strncmp(inputStateOFF1,stringToCompareStateOFF1,20); + resState2 = strncmp(inputStateOFF2,stringToCompareStateOFF2,20); + + if (resState1==0 && resState2==0) + { + + t.detach(); + // LPC_TIM3->TC = 0; + // t.attach(&adcISR, 2.0); + pc.printf("Sampling: OFF\n"); + + } + + + }//while } @@ -203,42 +277,7 @@ char answer; - void threadSetTComun (void const *args) -{ - - pc.baud(115200); - - //while(cmd==NULL){cmd=getchar();} - while(1) - { - scanf("%s%s",cmdSet,cmdSet2); - //READ ALL------------------------------------------ - //INPUT 2 - - strcpy (inputSet1,cmdSet); //INPUT 1 - pc.printf("you entered: %s\n\r",inputSet1); - strcpy (inputSet2,cmdSet2); - strcpy (stringToCompareSet1,"SETT"); //STRING TO COMPARE 1 - strcpy (stringToCompareSet2,inputSet2); //STRING TO COMPARE 2 - resSet1 = strncmp(inputSet1,stringToCompareSet1,20); - resSet2 = strncmp(inputSet2,stringToCompareSet2,20); - int inputSpeed = atoi(inputSet2); - - - if (inputSpeed <=60 && inputSpeed >=0.1) - { - if (resSet1==0 && resSet2==0) - { - pc.printf("CURRENT SPEED %d \n",inputSpeed); - sampleSpeed = inputSpeed; - pc.printf("T UPDATED TO %d %d\n",sampleSpeed,inputSpeed); - - - } - } - } - - } + int main(void) @@ -248,15 +287,10 @@ t1 = new Thread(thread1); t2 = new Thread(threadComun); - // t3 = new Thread( threadDeleteComun); - //t4 = new Thread( threadSetTComun); - - // Thread (thread1); - //threadcomun(); - - //Thread thread(threadcomun); + t.attach(&adcISR,sampleSpeed); // timer of measurements - + time(&timeNow); + pc.printf(" current time is : %s\n",ctime(&timeNow)); while(1) { humidity.init();