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

Revision:
12:b3137bb72ef7
Parent:
11:f9ffd5ab7e94
Child:
13:6bf09cd68013
--- a/main.cpp	Sat Apr 12 06:35:04 2014 +0000
+++ b/main.cpp	Sat Apr 12 11:14:12 2014 +0000
@@ -26,6 +26,9 @@
 
 #include "rtcimp.h"
 
+#include <string>
+using namespace std;
+
 //SERIAL
 Serial bluetooth(PTA2, PTA1);  // tx, rx
 Serial printer(PTC4,PTC3);  // tx, rx
@@ -45,20 +48,27 @@
 float setpoint_soil_humid1 = 0.3 ;
 float setpoint_soil_humid2 = 0.3 ;
 
+float setpoint_MAX_air_temp = 45;
+
 int setpoint_red_lights;
 int setpoint_blue_lights;
 int setpoint_green_lights;
+
 //WINDOWING
 float window_f = 5 ;
 int window_i =2 ;
 
 //GLOBAL VARS
 float current_water_level = 0; 
-bool screen_timeout=false;
+bool lcd_timeout_flag=false;
+
 //SAFETY LIMITS
 const float max_peltier_temp = 68 ; //CELCIUS
-const int MAX_WATERING_TIME_GAP = 20;
-const int CYCLE_AIR_TIME = 2;
+const int MAX_WATERING_TIME_GAP = 20; //Number of Hours
+const int CYCLE_AIR_TIME = 2; //Wait between on and off seconds
+const int LCD_TIMEOUT_VALUE = 30; //Number of seconds
+
+
 //**************************FUNCTION TO READ SENSORS ********************************************** 
 void read_sensors(){
     
@@ -140,6 +150,201 @@
     //turn of fan 
     
 }
+//LCD TIMEOUT FUNCTION
+void lcd_timeout_check(){
+    
+    if(lcd_timeout.read()>LCD_TIMEOUT_VALUE){
+            lcd_timeout_flag = true;
+        }
+    
+}
+//SETTINGS UI 
+void ui_settings(){
+    
+    lcd.cls();
+    lcd.locate(0,0);
+    lcd.printf("Autus Settings");
+    lcd.locate(0,1);
+    lcd.printf("Performing Checks");
+    char key_value;
+    bool exit_settings=false;
+    
+    //disable peltier
+    
+    wait(2);
+    string menu[4];
+    menu[0]= "1.LED Brightness";
+    menu[1]= "2.Air Humidty Lvl";
+    menu[2]= "3.Soil Moisture Lvl";
+    menu[3]= "4.Air Temperature";
+    
+    lcd.cls();
+    int counter_menu =0 ; 
+    while(!exit_settings){
+        key_value = Keypad();
+        if(key_value == 100){
+            lcd.locate(0,0);
+            lcd.printf(">%s",menu[counter_menu].c_str());
+            lcd.locate(0,1);
+            if(counter_menu ==3){
+            counter_menu = 0;
+            lcd.printf(" %s",menu[counter_menu].c_str());
+            }
+            else{
+            lcd.printf(" %s",menu[counter_menu+1].c_str());
+            }
+            wait(0.2); 
+        }//No Press If Block
+        else if(key_value == 44){//Down Key Pressed if block
+            lcd.cls();
+            counter_menu++;
+        }//Down Key Pressed if block end
+        else if(key_value == 41){ //OK Key Pressed if block
+            char key_value2;
+            bool break_flag = false;
+            switch(counter_menu){
+                case 0:
+                    lcd.cls();
+                    lcd.locate(0,0);
+                    lcd.printf("Not Authorised");
+                    wait(5);
+                    break;
+                case 1:
+                    break_flag = false;
+                    lcd.cls();
+                    lcd.locate(0,0);
+                    lcd.printf("Cur Air Humidity Lvl");
+                    //lcd.locate(0,1);
+                    //lcd.printf("%3.1f",setpoint_air_humidity);
+                    while(!break_flag){
+                        lcd.locate(0,1);
+                        lcd.printf("%3.1f",setpoint_air_humidity);
+                        key_value2 = Keypad();
+                        wait(0.2);
+                        if(key_value2 == 50){setpoint_air_humidity++;}
+                        else if(key_value2 == 47){setpoint_air_humidity--;}
+                        else if(key_value2 == 51){break_flag=true;}
+                        if (setpoint_air_humidity <0 || setpoint_air_humidity >99) {setpoint_air_humidity=30.00;}
+                    }
+                    
+                    lcd.cls();
+                    lcd.locate(0,0);
+                    lcd.printf("NEW Air Humid Setpoint");
+                    lcd.locate(0,1);
+                    lcd.printf("%3.1f",setpoint_air_humidity);
+                    wait(5);
+                    
+                    break;
+                case 2:
+                    break_flag = false;
+                    lcd.cls();
+                    lcd.locate(0,0);
+                    lcd.printf("Soil Humidity Setpoint");
+                    
+                    while(!break_flag){
+                        lcd.locate(0,1);
+                        lcd.printf("S1: %4.2f",setpoint_soil_humid1);
+                        lcd.printf(" S2: %4.2f",setpoint_soil_humid2);
+                        key_value2 = Keypad();
+                        wait(0.2);
+                        if(key_value2 == 50){
+                            setpoint_soil_humid1++;
+                            setpoint_soil_humid2++;
+                        }
+                        else if(key_value2 == 47){
+                            setpoint_soil_humid1--;
+                            setpoint_soil_humid2--;
+                        }
+                        else if(key_value2 == 51){break_flag=true;}
+                        //if (setpoint_air_humidity <0 || setpoint_air_humidity >99) {setpoint_air_humidity=30.00;}
+                    }
+                    
+                    lcd.cls();
+                    lcd.locate(0,0);
+                    lcd.printf("New Soil Setpoints:");
+                    lcd.locate(0,1);
+                    lcd.printf("S1: %4.2f",setpoint_soil_humid1);
+                    lcd.printf(" S2: %4.2f",setpoint_soil_humid2);
+                    wait(5);
+                    break;
+                case 3:
+                
+                    break_flag = false;
+                    lcd.cls();
+                    lcd.locate(0,0);
+                    lcd.printf("Cur Air Tmp Setpoint");
+                    while(!break_flag){
+                        lcd.locate(0,1);
+                        lcd.printf("%3.1f",setpoint_MAX_air_temp);
+                        key_value2 = Keypad();
+                        wait(0.2);
+                        if(key_value2 == 50){setpoint_MAX_air_temp++;}
+                        else if(key_value2 == 47){setpoint_MAX_air_temp--;}
+                        else if(key_value2 == 51){break_flag=true;}
+                        if (setpoint_MAX_air_temp <0 || setpoint_MAX_air_temp >99) {setpoint_MAX_air_temp=45.0;}
+                    }
+                    
+                    lcd.cls();
+                    lcd.locate(0,0);
+                    lcd.printf("NEW Air Tmp Setpoint");
+                    lcd.locate(0,1);
+                    lcd.printf("%3.1f",setpoint_MAX_air_temp);
+                    wait(5);
+                    break;
+            }//switch end
+        } //OK button if block
+        else if(key_value == 57){
+            exit_settings = true;
+            lcd.cls();
+            lcd.printf("SAVE Config");
+            wait(2);
+        } 
+
+    }//While settings loop exit 
+    lcd.cls();
+    lcd.printf("Exit Settings");
+    wait(2);
+}
+//Function to process keypad inputs
+void process_user_input(char keypad_value_in, int ui_current_screen_in){
+    
+    if(keypad_value_in == 36){
+            if(lcd_timeout_flag == false){
+                switch (ui_current_screen_in){
+                    case 1:
+                        ui_screen2();
+                        ui_current_screen_in =2;
+                        break;
+                    case 2:
+                        ui_screen3();
+                        ui_current_screen_in =3;
+                        break;
+                    case 3:
+                        ui_screen4();
+                        ui_current_screen_in =4;
+                        break;    
+                }//switch block current ui screen
+                lcd_timeout.reset();
+                lcd_timeout.start();
+                wait(2);
+            }// if block lcdflag
+            else{
+                ui_screen1();
+                wait(5);    
+            }
+        }// if block 36 end 
+        
+        // check for setting screen press enter
+        if(keypad_value_in == 51){
+                //Disable peltier 
+                ui_settings();
+                wait(5);
+        }
+}
+
+
+
+
 //***************************PLACEHOLDER FUNCTION TO DISABLE EVERYTHING **********************
 void disable_everything(){
     
@@ -228,7 +433,9 @@
     
     
     wait(5);
+    ui_current_screen = 1;
     ui_screen1();
+    lcd_timeout.reset();
     wait(5);
     
     startup_flag = false ;  
@@ -240,6 +447,12 @@
         keypad_value = Keypad();
         //timer1ms.detach();
         
+        lcd_timeout_check();
+        process_user_input(keypad_value,ui_current_screen);
+        
+        
+        
+        //  -> Key pressed
         
     }//WHILE END