Project Autus - Automated Plant Chamber

Dependencies:   TextLCD mbed

Fork of keypad_test by Plamen Totev

Autus

This is the codebase accompanying the project Autus.

Autus is an automated growth chamber for plants.

Features

Control Humidity inside chamber wrt to external humidity. Control Temperature inside chamber. ( Peltier Heaters/Coolers ) Water and shower plants. Control soil humidity. Monitor water tanks level (Load Cell) /media/uploads/umairaftab/frdm_-_new_page1.png

Code Base Features

Fixed timing and CRC for DHT-11 Sensor. Fixed OneWire bug for ds18b20

Cyclic Executive Scheduler with Priority. Async IPC framework for PC App over bluetooth

Fake RTC systick, I was having some trouble with the on board rtc.

/media/uploads/umairaftab/download.png

Committer:
umairaftab
Date:
Sun Apr 13 00:41:55 2014 +0000
Revision:
26:2f59456a7bad
Parent:
25:a6d1eaf2041c
Child:
27:24478764d4b2
ui_settings menu iter5.2;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
umairaftab 8:2d462919519e 1
umairaftab 8:2d462919519e 2 //QUICK REFS:
umairaftab 8:2d462919519e 3 // TICKER is using timer 1 for buzzer.
umairaftab 8:2d462919519e 4
umairaftab 1:9ef26efedcea 5 #include "mbed.h"
umairaftab 3:087ce66714c0 6
umairaftab 1:9ef26efedcea 7 #include "keypad.h"
umairaftab 1:9ef26efedcea 8 #include "buzz.h"
umairaftab 7:1d691f81d455 9
umairaftab 7:1d691f81d455 10 #include "pindefs.h" //led pin definitions
umairaftab 3:087ce66714c0 11 #include "led_lights.h"
umairaftab 7:1d691f81d455 12
umairaftab 3:087ce66714c0 13 #include "peltier.h"
umairaftab 7:1d691f81d455 14 #include "peltier_pindefs.h"
umairaftab 7:1d691f81d455 15
umairaftab 7:1d691f81d455 16 #include "pumps.h"
umairaftab 7:1d691f81d455 17 #include "pumps_pindefs.h"
umairaftab 7:1d691f81d455 18
umairaftab 7:1d691f81d455 19 #include "airhumidity.h"
umairaftab 7:1d691f81d455 20 #include "soilmoisture.h"
umairaftab 7:1d691f81d455 21 #include "soilmoisture_pindefs.h"
umairaftab 8:2d462919519e 22
umairaftab 7:1d691f81d455 23 #include "ui.h"
umairaftab 7:1d691f81d455 24 #include "ui_pindefs.h"
umairaftab 7:1d691f81d455 25 #include "TextLCD.h"
umairaftab 7:1d691f81d455 26
umairaftab 8:2d462919519e 27 #include "rtcimp.h"
umairaftab 8:2d462919519e 28
umairaftab 14:72176f1e4907 29 #include "weight.h"
umairaftab 14:72176f1e4907 30 #include "weight_pindefs.h"
umairaftab 14:72176f1e4907 31
umairaftab 12:b3137bb72ef7 32 #include <string>
umairaftab 12:b3137bb72ef7 33 using namespace std;
umairaftab 12:b3137bb72ef7 34
umairaftab 8:2d462919519e 35 //SERIAL
umairaftab 8:2d462919519e 36 Serial bluetooth(PTA2, PTA1); // tx, rx
umairaftab 8:2d462919519e 37 Serial printer(PTC4,PTC3); // tx, rx
umairaftab 8:2d462919519e 38 //TICKERS
umairaftab 1:9ef26efedcea 39 Ticker timer1ms;
umairaftab 8:2d462919519e 40 Ticker clock_mine;
umairaftab 11:f9ffd5ab7e94 41 Timer lcd_timeout;
umairaftab 8:2d462919519e 42 //FLAGS
umairaftab 8:2d462919519e 43 bool startup_flag=true;
umairaftab 9:43c339533f7f 44 bool watered_plant1 = false;
umairaftab 9:43c339533f7f 45 int watered_plant1_time = 0;
umairaftab 9:43c339533f7f 46 bool watered_plant2 = false;
umairaftab 9:43c339533f7f 47 int watered_plant2_time = 0;
umairaftab 8:2d462919519e 48
umairaftab 8:2d462919519e 49 //SETPOINTS
umairaftab 8:2d462919519e 50 float setpoint_air_humidity = 30.00 ;
umairaftab 8:2d462919519e 51 float setpoint_soil_humid1 = 0.3 ;
umairaftab 8:2d462919519e 52 float setpoint_soil_humid2 = 0.3 ;
umairaftab 8:2d462919519e 53
umairaftab 12:b3137bb72ef7 54 float setpoint_MAX_air_temp = 45;
umairaftab 12:b3137bb72ef7 55
umairaftab 11:f9ffd5ab7e94 56 int setpoint_red_lights;
umairaftab 11:f9ffd5ab7e94 57 int setpoint_blue_lights;
umairaftab 11:f9ffd5ab7e94 58 int setpoint_green_lights;
umairaftab 12:b3137bb72ef7 59
umairaftab 8:2d462919519e 60 //WINDOWING
umairaftab 9:43c339533f7f 61 float window_f = 5 ;
umairaftab 8:2d462919519e 62 int window_i =2 ;
umairaftab 8:2d462919519e 63
umairaftab 8:2d462919519e 64 //GLOBAL VARS
umairaftab 8:2d462919519e 65 float current_water_level = 0;
umairaftab 12:b3137bb72ef7 66 bool lcd_timeout_flag=false;
umairaftab 12:b3137bb72ef7 67
umairaftab 8:2d462919519e 68 //SAFETY LIMITS
umairaftab 8:2d462919519e 69 const float max_peltier_temp = 68 ; //CELCIUS
umairaftab 12:b3137bb72ef7 70 const int MAX_WATERING_TIME_GAP = 20; //Number of Hours
umairaftab 12:b3137bb72ef7 71 const int CYCLE_AIR_TIME = 2; //Wait between on and off seconds
umairaftab 12:b3137bb72ef7 72 const int LCD_TIMEOUT_VALUE = 30; //Number of seconds
umairaftab 12:b3137bb72ef7 73
umairaftab 12:b3137bb72ef7 74
umairaftab 8:2d462919519e 75 //**************************FUNCTION TO READ SENSORS **********************************************
umairaftab 8:2d462919519e 76 void read_sensors(){
umairaftab 8:2d462919519e 77
umairaftab 8:2d462919519e 78 //Read values for AIR
umairaftab 8:2d462919519e 79
umairaftab 8:2d462919519e 80 //OUTSIDE
umairaftab 8:2d462919519e 81 outside_humidity = get_air_humid_outside();
umairaftab 8:2d462919519e 82 outside_temp = get_air_temp_outside(temp_unit);
umairaftab 8:2d462919519e 83 outside_dewpoint = get_air_dewpoint_outside();
umairaftab 8:2d462919519e 84
umairaftab 8:2d462919519e 85 //INSIDE
umairaftab 8:2d462919519e 86 inside_humidity = get_air_humid_inside();
umairaftab 8:2d462919519e 87 inside_temp = get_air_temp_inside(temp_unit);
umairaftab 8:2d462919519e 88 inside_dewpoint = get_air_dewpoint_inside();
umairaftab 8:2d462919519e 89
umairaftab 8:2d462919519e 90 //Read value for soil
umairaftab 8:2d462919519e 91 read_soil_humidity();
umairaftab 8:2d462919519e 92 calc_soil_humid_values(); //values in soil1_humid and soil2_humid perecentages
umairaftab 11:f9ffd5ab7e94 93 soil1_humidity = soil1_humid ;
umairaftab 11:f9ffd5ab7e94 94 soil2_humidity = soil2_humid ;
umairaftab 14:72176f1e4907 95 //printf("%4.2f \n\r",soil1_humidity);
umairaftab 14:72176f1e4907 96 //READ LOAD SENSOR
umairaftab 14:72176f1e4907 97 read_weight();
umairaftab 14:72176f1e4907 98 calc_weight();
umairaftab 14:72176f1e4907 99 weight_sensor = weight1;
umairaftab 8:2d462919519e 100 }
umairaftab 8:2d462919519e 101
umairaftab 8:2d462919519e 102 //****************************Functions that perform tasks**************************************
umairaftab 9:43c339533f7f 103 //Water Plants
umairaftab 8:2d462919519e 104 void waterplants(){
umairaftab 8:2d462919519e 105
umairaftab 8:2d462919519e 106
umairaftab 9:43c339533f7f 107 if(startup_flag == true){
umairaftab 14:72176f1e4907 108 //call for pump function
umairaftab 14:72176f1e4907 109
umairaftab 9:43c339533f7f 110 watered_plant1 = true;
umairaftab 9:43c339533f7f 111 watered_plant1_time = hour ;
umairaftab 9:43c339533f7f 112 watered_plant2 = true;
umairaftab 9:43c339533f7f 113 watered_plant2_time = hour ;
umairaftab 14:72176f1e4907 114 pumps(true,true,true,false);
umairaftab 14:72176f1e4907 115 wait(5.0);
umairaftab 14:72176f1e4907 116 pumps(false,false,false,false);
umairaftab 9:43c339533f7f 117 }
umairaftab 9:43c339533f7f 118 else{
umairaftab 9:43c339533f7f 119
umairaftab 10:1a0fe96381b0 120 if( (soil1_humid < setpoint_soil_humid1) || (watered_plant1 == false) ){
umairaftab 9:43c339533f7f 121 //enable pump1
umairaftab 9:43c339533f7f 122 watered_plant1 = true;
umairaftab 9:43c339533f7f 123 watered_plant1_time = hour ;
umairaftab 14:72176f1e4907 124 pumps(true,true,true,false);
umairaftab 14:72176f1e4907 125 wait(5.0);
umairaftab 14:72176f1e4907 126 pumps(false,false,false,false);
umairaftab 9:43c339533f7f 127 }
umairaftab 10:1a0fe96381b0 128 if( (soil2_humid < setpoint_soil_humid2) || (watered_plant2 == false) ){
umairaftab 9:43c339533f7f 129 //enable pump2
umairaftab 9:43c339533f7f 130 watered_plant2 = true;
umairaftab 9:43c339533f7f 131 watered_plant2_time = hour ;
umairaftab 14:72176f1e4907 132 pumps(true,true,true,false);
umairaftab 14:72176f1e4907 133 wait(5.0);
umairaftab 14:72176f1e4907 134 pumps(false,false,false,false);
umairaftab 9:43c339533f7f 135 }
umairaftab 9:43c339533f7f 136 }
umairaftab 10:1a0fe96381b0 137 //Make sure it is watered at least every x hours in case soil humid doesnt work
umairaftab 9:43c339533f7f 138 if (watered_plant1 == true){
umairaftab 9:43c339533f7f 139 if(abs(hour-watered_plant1_time)>MAX_WATERING_TIME_GAP){
umairaftab 9:43c339533f7f 140 watered_plant1 = false;
umairaftab 9:43c339533f7f 141 }
umairaftab 9:43c339533f7f 142 }
umairaftab 9:43c339533f7f 143 if (watered_plant2 == true){
umairaftab 9:43c339533f7f 144 if(abs(hour-watered_plant2_time)>MAX_WATERING_TIME_GAP){
umairaftab 9:43c339533f7f 145 watered_plant2 = false;
umairaftab 9:43c339533f7f 146 }
umairaftab 9:43c339533f7f 147 }
umairaftab 9:43c339533f7f 148
umairaftab 9:43c339533f7f 149 }
umairaftab 9:43c339533f7f 150
umairaftab 9:43c339533f7f 151 // Air Humidity Level
umairaftab 9:43c339533f7f 152 void airhumidity(){
umairaftab 9:43c339533f7f 153
umairaftab 11:f9ffd5ab7e94 154 if( !( (setpoint_air_humidity+window_f > inside_humidity) && (setpoint_air_humidity-window_f < inside_humidity) ) ){
umairaftab 9:43c339533f7f 155
umairaftab 9:43c339533f7f 156 //Turn on Air humidity fan
umairaftab 14:72176f1e4907 157 pumps(false,false,false,true);
umairaftab 9:43c339533f7f 158 wait(5);
umairaftab 9:43c339533f7f 159 //Turn off Air humisity fan
umairaftab 14:72176f1e4907 160 pumps(false,false,false,false);
umairaftab 9:43c339533f7f 161 }
umairaftab 9:43c339533f7f 162 }
umairaftab 9:43c339533f7f 163
umairaftab 9:43c339533f7f 164 //CYCLE AIR
umairaftab 9:43c339533f7f 165 void cycleair(){
umairaftab 9:43c339533f7f 166
umairaftab 9:43c339533f7f 167 //Turn on fan
umairaftab 9:43c339533f7f 168 wait(CYCLE_AIR_TIME);
umairaftab 9:43c339533f7f 169 //turn of fan
umairaftab 8:2d462919519e 170
umairaftab 8:2d462919519e 171 }
umairaftab 14:72176f1e4907 172 //**********************************LCD TIMEOUT FUNCTION*********************************
umairaftab 12:b3137bb72ef7 173 void lcd_timeout_check(){
umairaftab 12:b3137bb72ef7 174
umairaftab 12:b3137bb72ef7 175 if(lcd_timeout.read()>LCD_TIMEOUT_VALUE){
umairaftab 12:b3137bb72ef7 176 lcd_timeout_flag = true;
umairaftab 12:b3137bb72ef7 177 }
umairaftab 12:b3137bb72ef7 178
umairaftab 12:b3137bb72ef7 179 }
umairaftab 26:2f59456a7bad 180 void settings_submenu(int counter_menu){
umairaftab 26:2f59456a7bad 181
umairaftab 26:2f59456a7bad 182 char key_value2;
umairaftab 26:2f59456a7bad 183 bool break_flag = false;
umairaftab 26:2f59456a7bad 184 switch(counter_menu){
umairaftab 26:2f59456a7bad 185 case 0:
umairaftab 26:2f59456a7bad 186 lcd.cls();
umairaftab 26:2f59456a7bad 187 lcd.locate(0,0);
umairaftab 26:2f59456a7bad 188 lcd.printf("Not Authorised");
umairaftab 26:2f59456a7bad 189 wait(5);
umairaftab 26:2f59456a7bad 190 break;
umairaftab 26:2f59456a7bad 191 case 1:
umairaftab 26:2f59456a7bad 192 break_flag = false;
umairaftab 26:2f59456a7bad 193 lcd.cls();
umairaftab 26:2f59456a7bad 194 lcd.locate(0,0);
umairaftab 26:2f59456a7bad 195 lcd.printf("Cur Air Humidity Lvl");
umairaftab 26:2f59456a7bad 196 //lcd.locate(0,1);
umairaftab 26:2f59456a7bad 197 //lcd.printf("%3.1f",setpoint_air_humidity);
umairaftab 26:2f59456a7bad 198 while(!break_flag){
umairaftab 26:2f59456a7bad 199 lcd.locate(0,1);
umairaftab 26:2f59456a7bad 200 lcd.printf("%3.1f",setpoint_air_humidity);
umairaftab 26:2f59456a7bad 201 key_value2 = Keypad();
umairaftab 26:2f59456a7bad 202 wait(0.2);
umairaftab 26:2f59456a7bad 203 if(key_value2 == 74){setpoint_air_humidity++;}
umairaftab 26:2f59456a7bad 204 else if(key_value2 == 71){setpoint_air_humidity--;}
umairaftab 26:2f59456a7bad 205 else if(key_value2 == 75){break_flag=true;} //enter
umairaftab 26:2f59456a7bad 206 if (setpoint_air_humidity <0 || setpoint_air_humidity >99) {setpoint_air_humidity=30.00;}
umairaftab 26:2f59456a7bad 207 }
umairaftab 26:2f59456a7bad 208
umairaftab 26:2f59456a7bad 209 lcd.cls();
umairaftab 26:2f59456a7bad 210 lcd.locate(0,0);
umairaftab 26:2f59456a7bad 211 lcd.printf("NEW Air Humid Setpoint");
umairaftab 26:2f59456a7bad 212 lcd.locate(0,1);
umairaftab 26:2f59456a7bad 213 lcd.printf("%3.1f",setpoint_air_humidity);
umairaftab 26:2f59456a7bad 214 wait(5);
umairaftab 26:2f59456a7bad 215
umairaftab 26:2f59456a7bad 216 break;
umairaftab 26:2f59456a7bad 217 case 2:
umairaftab 26:2f59456a7bad 218 break_flag = false;
umairaftab 26:2f59456a7bad 219 lcd.cls();
umairaftab 26:2f59456a7bad 220 lcd.locate(0,0);
umairaftab 26:2f59456a7bad 221 lcd.printf("Soil Humidity Setpoint");
umairaftab 26:2f59456a7bad 222
umairaftab 26:2f59456a7bad 223 while(!break_flag){
umairaftab 26:2f59456a7bad 224 lcd.locate(0,1);
umairaftab 26:2f59456a7bad 225 lcd.printf("S1: %4.2f",setpoint_soil_humid1);
umairaftab 26:2f59456a7bad 226 lcd.printf(" S2: %4.2f",setpoint_soil_humid2);
umairaftab 26:2f59456a7bad 227 key_value2 = Keypad();
umairaftab 26:2f59456a7bad 228 wait(0.2);
umairaftab 26:2f59456a7bad 229 if(key_value2 == 60){ //up
umairaftab 26:2f59456a7bad 230 setpoint_soil_humid1++;
umairaftab 26:2f59456a7bad 231 setpoint_soil_humid2++;
umairaftab 26:2f59456a7bad 232 }
umairaftab 26:2f59456a7bad 233 else if(key_value2 == 62){//down
umairaftab 26:2f59456a7bad 234 setpoint_soil_humid1--;
umairaftab 26:2f59456a7bad 235 setpoint_soil_humid2--;
umairaftab 26:2f59456a7bad 236 }
umairaftab 26:2f59456a7bad 237 else if(key_value2 == 75){break_flag=true;}//enterkey
umairaftab 26:2f59456a7bad 238 //if (setpoint_air_humidity <0 || setpoint_air_humidity >99) {setpoint_air_humidity=30.00;}
umairaftab 26:2f59456a7bad 239 }
umairaftab 26:2f59456a7bad 240
umairaftab 26:2f59456a7bad 241 lcd.cls();
umairaftab 26:2f59456a7bad 242 lcd.locate(0,0);
umairaftab 26:2f59456a7bad 243 lcd.printf("New Soil Setpoints:");
umairaftab 26:2f59456a7bad 244 lcd.locate(0,1);
umairaftab 26:2f59456a7bad 245 lcd.printf("S1: %4.2f",setpoint_soil_humid1);
umairaftab 26:2f59456a7bad 246 lcd.printf(" S2: %4.2f",setpoint_soil_humid2);
umairaftab 26:2f59456a7bad 247 wait(5);
umairaftab 26:2f59456a7bad 248 break;
umairaftab 26:2f59456a7bad 249 case 3:
umairaftab 26:2f59456a7bad 250
umairaftab 26:2f59456a7bad 251 break_flag = false;
umairaftab 26:2f59456a7bad 252 lcd.cls();
umairaftab 26:2f59456a7bad 253 lcd.locate(0,0);
umairaftab 26:2f59456a7bad 254 lcd.printf("Cur Air Tmp Setpoint");
umairaftab 26:2f59456a7bad 255 while(!break_flag){
umairaftab 26:2f59456a7bad 256 lcd.locate(0,1);
umairaftab 26:2f59456a7bad 257 lcd.printf("%3.1f",setpoint_MAX_air_temp);
umairaftab 26:2f59456a7bad 258 key_value2 = Keypad();
umairaftab 26:2f59456a7bad 259 wait(0.2);
umairaftab 26:2f59456a7bad 260 if(key_value2 == 60){setpoint_MAX_air_temp++;}
umairaftab 26:2f59456a7bad 261 else if(key_value2 == 62){setpoint_MAX_air_temp--;}
umairaftab 26:2f59456a7bad 262 else if(key_value2 == 75){break_flag=true;}
umairaftab 26:2f59456a7bad 263 if (setpoint_MAX_air_temp <0 || setpoint_MAX_air_temp >99) {setpoint_MAX_air_temp=45.0;}
umairaftab 26:2f59456a7bad 264 }
umairaftab 26:2f59456a7bad 265
umairaftab 26:2f59456a7bad 266 lcd.cls();
umairaftab 26:2f59456a7bad 267 lcd.locate(0,0);
umairaftab 26:2f59456a7bad 268 lcd.printf("NEW Air Tmp Setpoint");
umairaftab 26:2f59456a7bad 269 lcd.locate(0,1);
umairaftab 26:2f59456a7bad 270 lcd.printf("%3.1f",setpoint_MAX_air_temp);
umairaftab 26:2f59456a7bad 271 wait(5);
umairaftab 26:2f59456a7bad 272 break;
umairaftab 26:2f59456a7bad 273 }//switch end
umairaftab 26:2f59456a7bad 274
umairaftab 26:2f59456a7bad 275 }
umairaftab 14:72176f1e4907 276 //***************************************SETTINGS UI*************************************
umairaftab 12:b3137bb72ef7 277 void ui_settings(){
umairaftab 12:b3137bb72ef7 278
umairaftab 12:b3137bb72ef7 279 lcd.cls();
umairaftab 12:b3137bb72ef7 280 lcd.locate(0,0);
umairaftab 12:b3137bb72ef7 281 lcd.printf("Autus Settings");
umairaftab 12:b3137bb72ef7 282 lcd.locate(0,1);
umairaftab 12:b3137bb72ef7 283 lcd.printf("Performing Checks");
umairaftab 12:b3137bb72ef7 284 char key_value;
umairaftab 12:b3137bb72ef7 285 bool exit_settings=false;
umairaftab 12:b3137bb72ef7 286
umairaftab 12:b3137bb72ef7 287 //disable peltier
umairaftab 14:72176f1e4907 288 peltier(false,false,false,false,0);
umairaftab 12:b3137bb72ef7 289
umairaftab 12:b3137bb72ef7 290 wait(2);
umairaftab 12:b3137bb72ef7 291 string menu[4];
umairaftab 12:b3137bb72ef7 292 menu[0]= "1.LED Brightness";
umairaftab 12:b3137bb72ef7 293 menu[1]= "2.Air Humidty Lvl";
umairaftab 12:b3137bb72ef7 294 menu[2]= "3.Soil Moisture Lvl";
umairaftab 12:b3137bb72ef7 295 menu[3]= "4.Air Temperature";
umairaftab 12:b3137bb72ef7 296
umairaftab 12:b3137bb72ef7 297 lcd.cls();
umairaftab 12:b3137bb72ef7 298 int counter_menu =0 ;
umairaftab 12:b3137bb72ef7 299 while(!exit_settings){
umairaftab 26:2f59456a7bad 300
umairaftab 12:b3137bb72ef7 301 key_value = Keypad();
umairaftab 26:2f59456a7bad 302 printf("Key %d",key_value);
umairaftab 25:a6d1eaf2041c 303 wait(0.5);
umairaftab 25:a6d1eaf2041c 304 if(key_value == 150){
umairaftab 12:b3137bb72ef7 305 lcd.locate(0,0);
umairaftab 12:b3137bb72ef7 306 lcd.printf(">%s",menu[counter_menu].c_str());
umairaftab 12:b3137bb72ef7 307 lcd.locate(0,1);
umairaftab 12:b3137bb72ef7 308 if(counter_menu ==3){
umairaftab 25:a6d1eaf2041c 309 counter_menu = 0;
umairaftab 25:a6d1eaf2041c 310 lcd.printf(" %s",menu[counter_menu].c_str());
umairaftab 12:b3137bb72ef7 311 }
umairaftab 12:b3137bb72ef7 312 else{
umairaftab 25:a6d1eaf2041c 313 lcd.printf(" %s",menu[counter_menu+1].c_str());
umairaftab 12:b3137bb72ef7 314 }
umairaftab 26:2f59456a7bad 315 //wait(0.2);
umairaftab 12:b3137bb72ef7 316 }//No Press If Block
umairaftab 25:a6d1eaf2041c 317 else if(key_value == 62){//Down Key Pressed if block
umairaftab 12:b3137bb72ef7 318 lcd.cls();
umairaftab 12:b3137bb72ef7 319 counter_menu++;
umairaftab 12:b3137bb72ef7 320 }//Down Key Pressed if block end
umairaftab 25:a6d1eaf2041c 321 else if(key_value == 59){ //OK Key Pressed if block
umairaftab 26:2f59456a7bad 322 settings_submenu(counter_menu);
umairaftab 12:b3137bb72ef7 323 } //OK button if block
umairaftab 25:a6d1eaf2041c 324 else if(key_value == 57){ //OK Button
umairaftab 12:b3137bb72ef7 325 exit_settings = true;
umairaftab 12:b3137bb72ef7 326 lcd.cls();
umairaftab 12:b3137bb72ef7 327 lcd.printf("SAVE Config");
umairaftab 12:b3137bb72ef7 328 wait(2);
umairaftab 12:b3137bb72ef7 329 }
umairaftab 12:b3137bb72ef7 330
umairaftab 12:b3137bb72ef7 331 }//While settings loop exit
umairaftab 12:b3137bb72ef7 332 lcd.cls();
umairaftab 12:b3137bb72ef7 333 lcd.printf("Exit Settings");
umairaftab 25:a6d1eaf2041c 334 wait(5);
umairaftab 12:b3137bb72ef7 335 }
umairaftab 26:2f59456a7bad 336
umairaftab 26:2f59456a7bad 337
umairaftab 12:b3137bb72ef7 338 //Function to process keypad inputs
umairaftab 12:b3137bb72ef7 339 void process_user_input(char keypad_value_in, int ui_current_screen_in){
umairaftab 12:b3137bb72ef7 340
umairaftab 18:7ec1691d0d9d 341 if(keypad_value_in == 61){
umairaftab 12:b3137bb72ef7 342 if(lcd_timeout_flag == false){
umairaftab 12:b3137bb72ef7 343 switch (ui_current_screen_in){
umairaftab 12:b3137bb72ef7 344 case 1:
umairaftab 12:b3137bb72ef7 345 ui_screen2();
umairaftab 12:b3137bb72ef7 346 ui_current_screen_in =2;
umairaftab 12:b3137bb72ef7 347 break;
umairaftab 12:b3137bb72ef7 348 case 2:
umairaftab 12:b3137bb72ef7 349 ui_screen3();
umairaftab 12:b3137bb72ef7 350 ui_current_screen_in =3;
umairaftab 12:b3137bb72ef7 351 break;
umairaftab 12:b3137bb72ef7 352 case 3:
umairaftab 12:b3137bb72ef7 353 ui_screen4();
umairaftab 12:b3137bb72ef7 354 ui_current_screen_in =4;
umairaftab 12:b3137bb72ef7 355 break;
umairaftab 12:b3137bb72ef7 356 }//switch block current ui screen
umairaftab 12:b3137bb72ef7 357 lcd_timeout.reset();
umairaftab 12:b3137bb72ef7 358 lcd_timeout.start();
umairaftab 12:b3137bb72ef7 359 wait(2);
umairaftab 12:b3137bb72ef7 360 }// if block lcdflag
umairaftab 12:b3137bb72ef7 361 else{
umairaftab 12:b3137bb72ef7 362 ui_screen1();
umairaftab 12:b3137bb72ef7 363 wait(5);
umairaftab 12:b3137bb72ef7 364 }
umairaftab 12:b3137bb72ef7 365 }// if block 36 end
umairaftab 12:b3137bb72ef7 366
umairaftab 12:b3137bb72ef7 367 // check for setting screen press enter
umairaftab 18:7ec1691d0d9d 368 if(keypad_value_in == 58){
umairaftab 12:b3137bb72ef7 369 //Disable peltier
umairaftab 12:b3137bb72ef7 370 ui_settings();
umairaftab 12:b3137bb72ef7 371 wait(5);
umairaftab 12:b3137bb72ef7 372 }
umairaftab 14:72176f1e4907 373
umairaftab 14:72176f1e4907 374 if(keypad_value_in ==100){
umairaftab 14:72176f1e4907 375 ui_screen1();
umairaftab 17:0ff7385db570 376 wait(0.2);
umairaftab 14:72176f1e4907 377 }
umairaftab 12:b3137bb72ef7 378 }
umairaftab 12:b3137bb72ef7 379
umairaftab 12:b3137bb72ef7 380
umairaftab 12:b3137bb72ef7 381
umairaftab 12:b3137bb72ef7 382
umairaftab 8:2d462919519e 383 //***************************PLACEHOLDER FUNCTION TO DISABLE EVERYTHING **********************
umairaftab 8:2d462919519e 384 void disable_everything(){
umairaftab 8:2d462919519e 385
umairaftab 10:1a0fe96381b0 386 //Disable peltier,vac,fans,pumps,lights.
umairaftab 14:72176f1e4907 387 pumps(false,false,false,false);
umairaftab 14:72176f1e4907 388 peltier(false,false,false,false,0);
umairaftab 8:2d462919519e 389 }
umairaftab 8:2d462919519e 390
umairaftab 8:2d462919519e 391
umairaftab 8:2d462919519e 392 //*********************************************************************************************
umairaftab 8:2d462919519e 393 //* *
umairaftab 8:2d462919519e 394 //* *
umairaftab 8:2d462919519e 395 //* *
umairaftab 8:2d462919519e 396 //* *
umairaftab 8:2d462919519e 397 //* MAIN ROUTINE *
umairaftab 8:2d462919519e 398 //* *
umairaftab 8:2d462919519e 399 //* DO NOT MODIFY WITHOUT TELLING UMAIR *
umairaftab 8:2d462919519e 400 //* *
umairaftab 8:2d462919519e 401 //* *
umairaftab 8:2d462919519e 402 //*********************************************************************************************
umairaftab 1:9ef26efedcea 403
umairaftab 1:9ef26efedcea 404 int main(void)
umairaftab 1:9ef26efedcea 405 {
umairaftab 8:2d462919519e 406
umairaftab 8:2d462919519e 407 //call function that disables everything.
umairaftab 8:2d462919519e 408 disable_everything();
umairaftab 8:2d462919519e 409
umairaftab 8:2d462919519e 410
umairaftab 9:43c339533f7f 411
umairaftab 8:2d462919519e 412 //FOR INTERNAL CLOCK
umairaftab 23:18918f087330 413 //clock_mine.attach(&sec_inc, 1.0);
umairaftab 8:2d462919519e 414 char keypad_value;
umairaftab 11:f9ffd5ab7e94 415 int ui_current_screen = 1;
umairaftab 10:1a0fe96381b0 416 //************************************BOOT SEQUENCE*********************
umairaftab 8:2d462919519e 417 //call LCD boot
umairaftab 8:2d462919519e 418 ui_startup();
umairaftab 9:43c339533f7f 419 wait(2);
umairaftab 8:2d462919519e 420 //SET TIME
umairaftab 8:2d462919519e 421 rtcimp_settime(6,0);
umairaftab 8:2d462919519e 422 //call function that reads values
umairaftab 9:43c339533f7f 423
umairaftab 9:43c339533f7f 424 /* FOR CRTITICALITY
umairaftab 9:43c339533f7f 425 NVIC_DisableIRQ(TIMER3_IRQn);
umairaftab 9:43c339533f7f 426
umairaftab 9:43c339533f7f 427 // critical section
umairaftab 9:43c339533f7f 428
umairaftab 9:43c339533f7f 429 NVIC_EnableIRQ(TIMER3_IRQn);
umairaftab 9:43c339533f7f 430 */
umairaftab 9:43c339533f7f 431 lcd.cls();
umairaftab 9:43c339533f7f 432 lcd.locate(0,0);
umairaftab 9:43c339533f7f 433 lcd.printf("Reading Sensors");
umairaftab 9:43c339533f7f 434
umairaftab 8:2d462919519e 435 read_sensors();
umairaftab 8:2d462919519e 436
umairaftab 9:43c339533f7f 437 wait(2);
umairaftab 9:43c339533f7f 438 lcd.cls();
umairaftab 9:43c339533f7f 439 lcd.locate(0,0);
umairaftab 9:43c339533f7f 440 lcd.printf("Done Reading Sensors");
umairaftab 8:2d462919519e 441 //call function that performs functions.
umairaftab 8:2d462919519e 442
umairaftab 9:43c339533f7f 443 wait(2);
umairaftab 9:43c339533f7f 444 lcd.cls();
umairaftab 9:43c339533f7f 445 lcd.locate(0,0);
umairaftab 9:43c339533f7f 446 lcd.printf("Watering Plants");
umairaftab 9:43c339533f7f 447
umairaftab 24:03e27d9e7aaa 448 //waterplants();
umairaftab 9:43c339533f7f 449
umairaftab 9:43c339533f7f 450 wait(2);
umairaftab 9:43c339533f7f 451 lcd.cls();
umairaftab 9:43c339533f7f 452 lcd.locate(0,0);
umairaftab 9:43c339533f7f 453 lcd.printf("Air Humidity");
umairaftab 9:43c339533f7f 454
umairaftab 24:03e27d9e7aaa 455 //airhumidity();
umairaftab 9:43c339533f7f 456
umairaftab 9:43c339533f7f 457 wait(2);
umairaftab 9:43c339533f7f 458 lcd.cls();
umairaftab 9:43c339533f7f 459 lcd.locate(0,0);
umairaftab 9:43c339533f7f 460 lcd.printf("Cycling Air");
umairaftab 9:43c339533f7f 461
umairaftab 9:43c339533f7f 462 cycleair();
umairaftab 9:43c339533f7f 463
umairaftab 11:f9ffd5ab7e94 464 wait(2);
umairaftab 11:f9ffd5ab7e94 465 lcd.cls();
umairaftab 11:f9ffd5ab7e94 466 lcd.locate(0,0);
umairaftab 11:f9ffd5ab7e94 467 lcd.printf("Testing Lights");
umairaftab 11:f9ffd5ab7e94 468 //led_test();
umairaftab 11:f9ffd5ab7e94 469
umairaftab 11:f9ffd5ab7e94 470
umairaftab 9:43c339533f7f 471 wait(5);
umairaftab 12:b3137bb72ef7 472 ui_current_screen = 1;
umairaftab 9:43c339533f7f 473 ui_screen1();
umairaftab 12:b3137bb72ef7 474 lcd_timeout.reset();
umairaftab 9:43c339533f7f 475 wait(5);
umairaftab 8:2d462919519e 476
umairaftab 14:72176f1e4907 477 startup_flag = false ;
umairaftab 14:72176f1e4907 478 timer1ms.attach(&timer1, 0.001); //interrupt attached function(timer) with interval (1 ms)
umairaftab 25:a6d1eaf2041c 479 led_blue_pulsewidth=50;
umairaftab 25:a6d1eaf2041c 480 led_blue.period_us(1000);
umairaftab 25:a6d1eaf2041c 481
umairaftab 1:9ef26efedcea 482 while(1) {
umairaftab 8:2d462919519e 483
umairaftab 14:72176f1e4907 484
umairaftab 9:43c339533f7f 485 //FOR BUZZER
umairaftab 14:72176f1e4907 486
umairaftab 8:2d462919519e 487 keypad_value = Keypad();
umairaftab 17:0ff7385db570 488 wait(0.1);
umairaftab 25:a6d1eaf2041c 489
umairaftab 19:4313ad838fef 490 //lcd_timeout_check();
umairaftab 19:4313ad838fef 491 //process_user_input(keypad_value,ui_current_screen);
umairaftab 25:a6d1eaf2041c 492
umairaftab 25:a6d1eaf2041c 493 if ( (keypad_value==62) && (ui_current_screen==1) ) {
umairaftab 19:4313ad838fef 494 ui_screen2();
umairaftab 25:a6d1eaf2041c 495 ui_current_screen=2;
umairaftab 22:7a1962d8af68 496 wait(5);
umairaftab 25:a6d1eaf2041c 497 //led_blue_pulsewidth=led_blue_pulsewidth+100;
umairaftab 25:a6d1eaf2041c 498 //led_blue.pulsewidth_us(led_blue_pulsewidth);
umairaftab 25:a6d1eaf2041c 499 //printf("%c\n\r",keypad_value);
umairaftab 19:4313ad838fef 500 }
umairaftab 25:a6d1eaf2041c 501 else if ( (keypad_value==62) && (ui_current_screen==2)) {
umairaftab 19:4313ad838fef 502 ui_screen3();
umairaftab 25:a6d1eaf2041c 503 ui_current_screen=1;
umairaftab 22:7a1962d8af68 504 wait(5);
umairaftab 25:a6d1eaf2041c 505 //printf("%c\n\r",keypad_value);
umairaftab 25:a6d1eaf2041c 506 }
umairaftab 25:a6d1eaf2041c 507 else if ( (keypad_value==62) && (ui_current_screen==3)) {
umairaftab 25:a6d1eaf2041c 508 ui_screen4();
umairaftab 25:a6d1eaf2041c 509 ui_current_screen=1;
umairaftab 25:a6d1eaf2041c 510 wait(5);
umairaftab 25:a6d1eaf2041c 511 //printf("%c\n\r",keypad_value);
umairaftab 25:a6d1eaf2041c 512 }
umairaftab 25:a6d1eaf2041c 513 else if ( (keypad_value==75) ) {
umairaftab 25:a6d1eaf2041c 514 ui_settings();
umairaftab 25:a6d1eaf2041c 515 ui_current_screen=1;
umairaftab 25:a6d1eaf2041c 516 //wait(5);
umairaftab 25:a6d1eaf2041c 517 //printf("%c\n\r",keypad_value);
umairaftab 19:4313ad838fef 518 }
umairaftab 19:4313ad838fef 519 else {
umairaftab 19:4313ad838fef 520 ui_screen1();
umairaftab 25:a6d1eaf2041c 521 wait(0.1);
umairaftab 19:4313ad838fef 522 }
umairaftab 21:592b7112bbba 523 printf("%d\n\r",keypad_value);
umairaftab 12:b3137bb72ef7 524
umairaftab 12:b3137bb72ef7 525 // -> Key pressed
umairaftab 11:f9ffd5ab7e94 526
umairaftab 8:2d462919519e 527 }//WHILE END
umairaftab 8:2d462919519e 528
umairaftab 8:2d462919519e 529
umairaftab 8:2d462919519e 530 }
umairaftab 8:2d462919519e 531
umairaftab 8:2d462919519e 532