Projet s5 - sensors lib
Dependencies: XBeeLib mbed-rtos mbed
ProcessControl.cpp
00001 #include "ProcessControl.h" 00002 00003 static Config config; 00004 static int updated = 0; 00005 00006 static DigitalOut light(p11); // pH - 00007 static DigitalOut pKOH(p12); // pH - 00008 static DigitalOut pH2PO4(p13); // pH + 00009 static DigitalOut HydroBloom(p14); // Nutrients 00010 static DigitalOut solValve(p15); // Nutrients 00011 static DigitalOut drainPump(p16); // Nutrients 00012 static DigitalOut nutPump(p17); // Nutrients 00013 static Serial pc(USBTX,USBRX); 00014 00015 00016 00017 int getConfig(Config *conf) { 00018 if(updated) { 00019 conf = &config; 00020 return 1; 00021 } else { 00022 return 0; 00023 } 00024 } 00025 00026 void initSystem(){ 00027 light = 1; 00028 pKOH=1; 00029 pH2PO4=1; 00030 HydroBloom=1; 00031 solValve=1; 00032 drainPump=1; 00033 nutPump=1; 00034 00035 } 00036 00037 00038 void setConfig(Config conf) { 00039 config = conf; 00040 updated = 1; 00041 } 00042 00043 void drainSystem(){ 00044 pc.printf("Drainage du systeme initie...\n"); 00045 pc.printf("Overture valve et pompe...\n"); 00046 solValve =0; 00047 drainPump=0; 00048 00049 00050 for(int i=120;i>=0;i--){ 00051 wait_ms(1000); 00052 pc.printf("drainage complet dans %i secondes\n",i); 00053 } 00054 solValve =1; 00055 drainPump=1; 00056 pc.printf("Vidange complete\n"); 00057 00058 } 00059 00060 00061 double getTargetTemperature() { 00062 return (config.temperatureMin + config.temperatureMax)/2; 00063 } 00064 00065 void watering(){ 00066 nutPump =0; 00067 wait(60); 00068 nutPump =1; 00069 } 00070 00071 00072 double getTargetPh() { 00073 return (config.phMin + config.phMax)/2; 00074 } 00075 00076 void adjustePh(){ 00077 float ph=getPH(); 00078 while(ph < getTargetPh()*1.1){ 00079 pH2PO4 =0; 00080 wait_ms(1200); 00081 pH2PO4=1; 00082 wait_ms(7000); 00083 ph=getPH(); 00084 } 00085 while(ph > getTargetPh()*1.1){ 00086 pKOH =0; 00087 wait_ms(1200); 00088 pKOH=1; 00089 wait_ms(7000); 00090 ph=getPH(); 00091 } 00092 } 00093 00094 double getTargetEc() { 00095 return config.ec; 00096 } 00097 00098 void adjustEC(){ 00099 float ec = getEC(); 00100 while(ec<1.1*getTargetEc()){ 00101 00102 } 00103 }
Generated on Wed Jul 20 2022 22:26:41 by
1.7.2
