Project Autus - Automated Plant Chamber
Fork of keypad_test by
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)
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.
Diff: main.cpp
- Revision:
- 37:892872c3fa96
- Parent:
- 36:ce0ca02a8253
- Child:
- 38:9f4107db1bff
diff -r ce0ca02a8253 -r 892872c3fa96 main.cpp --- a/main.cpp Sun Apr 13 09:06:37 2014 +0000 +++ b/main.cpp Mon Apr 14 00:52:14 2014 +0000 @@ -67,13 +67,18 @@ //GLOBAL VARS float current_water_level = 0; bool lcd_timeout_flag=false; - +int led_set_time=0; +int led_off_time=0; +bool lights_startup_flag=true; +int sensor_function_call_time=0; //SAFETY LIMITS const float max_peltier_temp = 68 ; //CELCIUS 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 const char status = 'F'; //For bluetooth Serial +const int led_lights_timeout=5; // Timeout afterwhich to turn off/on lights +const int sensor_function_call_timeout=3; //Timeout for sensorcall and function //*************************FUNCTION CALLBACK FOR SERIAL INTTERUPTS******************************** void callback_bluetooth() { @@ -117,6 +122,16 @@ } //****************************Functions that perform tasks************************************** +//CYCLE AIR +void cycleair(){ + + //Turn on fan + cycle_air_on(); + wait(CYCLE_AIR_TIME); + //turn of fan + cycle_air_off(); + +} //Water Plants void waterplants(){ @@ -155,11 +170,13 @@ if (watered_plant1 == true){ if(abs(hour-watered_plant1_time)>MAX_WATERING_TIME_GAP){ watered_plant1 = false; + cycleair(); } } if (watered_plant2 == true){ if(abs(hour-watered_plant2_time)>MAX_WATERING_TIME_GAP){ watered_plant2 = false; + cycleair(); } } @@ -178,16 +195,7 @@ } } -//CYCLE AIR -void cycleair(){ - - //Turn on fan - cycle_air_on(); - wait(CYCLE_AIR_TIME); - //turn of fan - cycle_air_off(); - -} + //**********************************LCD TIMEOUT FUNCTION********************************* void lcd_timeout_check(){ @@ -413,6 +421,7 @@ //Disable peltier,vac,fans,pumps,lights. pumps(false,false,false,false); peltier(false,false,false,false,0); + cycle_air_off(); } @@ -480,7 +489,7 @@ lcd.locate(0,0); lcd.printf("Air Humidity"); - //airhumidity(); + airhumidity(); wait(2); lcd.cls(); @@ -493,7 +502,7 @@ lcd.cls(); lcd.locate(0,0); lcd.printf("Testing Lights"); - //led_test(); + led_test(); //INTILIZE SERIAL PARAMETERS @@ -512,7 +521,7 @@ lcd_timeout.reset(); wait(5); - startup_flag = false ; + //startup_flag = false ; timer1ms.attach(&timer1, 0.001); //interrupt attached function(timer) with interval (1 ms) led_blue_pulsewidth=50; led_blue.period_us(1000); @@ -546,6 +555,9 @@ //printf("%c\n\r",keypad_value); } else if ( (keypad_value==68) && (ui_current_screen==3)) { + red_light_value = MAX_RED_LIGHT; + blue_light_value = MAX_BLUE_LIGHT; + green_light_value = MAX_GREEN_LIGHT; ui_screen4(); ui_current_screen=1; wait(5); @@ -573,6 +585,40 @@ printf("%d\n\r",keypad_value); // -> Key pressed + //LEDS Timeout functions + if(led_set_flag == false){ + if( (abs(hour-led_off_time) > led_lights_timeout)||lights_startup_flag ==true){ + // printf("MINON%d\n\r",::min); + set_leds(); + led_set_time = hour; + lights_startup_flag = false; + // printf("SETLEDS\n\r"); + } + + } + if(led_set_flag ==true){ + if(abs(hour-led_set_time) > led_lights_timeout){ + // printf("MINOFF %d\n\r",::min); + turn_off_leds(); + led_off_time = hour; + led_set_flag =false; + // printf("OFF\n\r"); + } + } + //printf("MINOFF %d\n\r",::min); + if( (abs(::min-sensor_function_call_time) > sensor_function_call_timeout) || startup_flag==true){ + lcd.cls(); + lcd.locate(0,0); + lcd.printf("Updating Values"); + lcd.locate(0,1); + lcd.printf("Performing func"); + read_sensors(); + airhumidity(); + sensor_function_call_time=::min; + lcd.cls(); + } + printf("MIN: %d\n\r",::min); + startup_flag = false ; }//WHILE END