Translate

Friday 6 June 2014

Room Management System – Menu part 13


Today we are adding the missing function for the outside light and we'll be adding the code to make the restart delay timer for the ac as compressor protection optional. But first the light. Since we are dealing with lights again, we can use the submenu we are using for the rest of the lights. The only thing wee need to take out is the delay timer for the PIR's.

Lets jump straight down to the end of the selectMenu function:

 if(menuOption == 19){ //and menu option is 19 (AC room 2)

get_ac_sub(11);

//submenu end

}

if(menuOption == 20){ //and menu option is 20 (AC room 3)

get_ac_sub(12);

//submenu end

}

if(menuOption == 21){ //and menu option is 21 (AC room 4)

get_ac_sub(13);

//submenu end

}

//>>>>>>>>>>>>>ADDDITION start here<<<<<<<<<<<<<

if(menuOption == 22){ //and menu option is 16

get_submenu(15);

} //submenu end

//>>>>>>>>>>>>>ADDITION ends here<<<<<<<<<<<<<<

}

}

}

Now we go into the get_submenu function:

void get_submenu(byte room){

byte subButton = 0; //resetting the button var

submenu = 1; //submenu counter

lcd.clear(); //clear screen

//retrieving and printing first sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[0]))));

lcd.print(room + 1); //printing assigned room number

if(room == 15){ //<<<<<<<<<<<<<ADD the if-statement<<<<<<<<<<<<<<

lcd.setCursor(0, 1); //set cursor to column 0, row 1

//retrieve and print not used

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[0])))); //print not used

}//<<<<<<<<<<<<<<Addition ends here<<<<<<<<<<<<<

while(submenu < submenus){ //loop through the sub menu points

subButton = read_act_buttons(); //checking for pressed buttons

if(subButton == btnMenu){ //if button Menu was pressed

We stay in the same function, just go down a little more:

void get_submenu(byte room){

byte subButton = 0; //resetting the button var

submenu = 1; //submenu counter

lcd.clear(); //clear screen

//retrieving and printing first sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[0]))));

lcd.print(room + 1); //printing assigned room number

if(room == 15){ //<<<<<<<<<<<<<ADD the if-statement<<<<<<<<<<<<<<

lcd.setCursor(0, 1); //set cursor to column 0, row 1

//retrieve and print not used

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[0])))); //print not used

}//<<<<<<<<<<<<<<Addition ends here<<<<<<<<<<<<<

while(submenu < submenus){ //loop through the sub menu points

subButton = read_act_buttons(); //checking for pressed buttons

if(subButton == btnMenu){ //if button Menu was pressed

So far so good, now we are converting the compressor protecting delay timer to an selectable option. We add it as option to the AC - setup menu. Therefore we go back to the declaration part into the “menu and user interface” section:

///////////////////Menu and user interface/////////////////////////////////

///////////////////////////////////////////////////////////////////////////

const byte btnMenu = 1; //defining the menu button – moves through the menu

const byte btnSearch = 2; //defining the search button – moves through values

const byte btnSelect = 3; //defining the select button – selects a menu or a value

const byte btnNone = 0; //defining the non button pressed var

int act_key_in = 0; //var holding the key related sensor reading

byte menuOption = 0; //var to count current menu option

const byte menuOptions = 22; //available menu options

byte submenu = 0; //var to count current submenu option

const byte submenus = 9; //available submenu options

byte acSetup = 0; //var to count current ac setup menu options

const byte acSetups = 5; //<<<<<<<<<<<<<CHANGE acSetups = 4; to acSetups = 5;

byte acSubOption = 0; //var to count current ac sub menu options

Just below here, we add another line to the message table:

//Storing some menu messages in the program memory

prog_char msg_0[] PROGMEM = "Not Used";

prog_char msg_1[] PROGMEM = "Saving....";

prog_char msg_2[] PROGMEM = "Setup mode";

prog_char msg_3[] PROGMEM = "Starting....";

prog_char msg_4[] PROGMEM = "RMU 1.4.2";

prog_char msg_5[] PROGMEM = "Weekday";

prog_char msg_6[] PROGMEM = "On TIMER Off";

prog_char msg_7[] PROGMEM = "Off ";

prog_char msg_8[] PROGMEM = "Active";

prog_char msg_9[] PROGMEM = "PIR Delay R";

prog_char msg_10[] PROGMEM = "T1 On/Off R";

prog_char msg_11[] PROGMEM = "T2 On/Off R";

prog_char msg_12[] PROGMEM = "T3 On/Off R";

prog_char msg_13[] PROGMEM = "ADJ Hour On";

prog_char msg_14[] PROGMEM = "ADJ Minute On";

prog_char msg_15[] PROGMEM = "ADJ Hour Off";

prog_char msg_16[] PROGMEM = "ADJ Minute Off";

prog_char msg_17[] PROGMEM = "Set Sensitivity";

prog_char msg_18[] PROGMEM = "Set photocell R";

prog_char msg_19[] PROGMEM = "Set photocell O";

prog_char msg_20[] PROGMEM = "ADJ Time Minute";

prog_char msg_21[] PROGMEM = "ADJ Time Hour";

prog_char msg_22[] PROGMEM = "ADJ Date Day";

prog_char msg_23[] PROGMEM = "ADJ Date Month";

prog_char msg_24[] PROGMEM = "ADJ Date Year";

prog_char msg_25[] PROGMEM = "T4 On/Off R";

prog_char msg_26[] PROGMEM = "ADJ AC Mode";

prog_char msg_27[] PROGMEM = "AC Set Temp";

prog_char msg_28[] PROGMEM = "AC Switch Delay";

prog_char msg_29[] PROGMEM = "AC Seas 1 Start";

prog_char msg_30[] PROGMEM = "AC Seas 1 End";

prog_char msg_31[] PROGMEM = "AC Seas 2 Start";

prog_char msg_32[] PROGMEM = "AC Seas 2 End";

prog_char msg_33[] PROGMEM = "AC Seas 3 Start";

prog_char msg_34[] PROGMEM = "AC Seas 3 End";

prog_char msg_35[] PROGMEM = "AC Seas 4 Start";

prog_char msg_36[] PROGMEM = "AC Seas 4 End";

prog_char msg_37[] PROGMEM = "AC Off delay";

prog_char msg_38[] PROGMEM = "AC master byp";

//>>>>>>>>>>>>>>ADD the line below<<<<<<<<<<<<<<

prog_char msg_39[] PROGMEM = "AC Comp protect";

//Creating the table for the stored menu messages

PROGMEM const char *msg_table[] = {

msg_0,

msg_1,

msg_2,

msg_3,

msg_4,

msg_5,

msg_6,

msg_7,

msg_8,

msg_9,

msg_10,

msg_11,

msg_12,

msg_13,

msg_14,

msg_15,

msg_16,

msg_17,

msg_18,

msg_19,

msg_20,

msg_21,

msg_22,

msg_23,

msg_24,

msg_25,

msg_26,

msg_27,

msg_28,

msg_29,

msg_30,

msg_31,

msg_32,

msg_33,

msg_34,

msg_35,

msg_36,

msg_37,

msg_38, //Don't forget to add ','

//>>>>>>>>>>>>>>ADD the line below<<<<<<<<<<<<<<<

msg_39

};

Now e go down a little further to the ac_setup table:

//storing the ac setup menu

prog_char ac_setup_0[] PROGMEM = "AC Mode";

prog_char ac_setup_1[] PROGMEM = "Set Temp";

prog_char ac_setup_2[] PROGMEM = "Seasons";

prog_char ac_setup_3[] PROGMEM = "Switch Delay";

//>>>>>>>>>>>>ADD the line below<<<<<<<<<<<<<

prog_char ac_setup_4[] PROGMEM = "Start Delay";

PROGMEM const char *ac_setup_table[] = {

ac_setup_0,

ac_setup_1,

ac_setup_2,

ac_setup_3, //<<<<<<<<<<<<<Don”t forget to add ','

//>>>>>>>>>>>>>Add the line below<<<<<<<<<<<<<

ac_setup_4

};

From here we move down to the get_ac_setup() function:

void get_ac_setup(){

byte subButton = 0;

acSetup = 1; //submenu counter (AC Mode)

lcd.clear(); //clear screen

//retrieving and printing first sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(ac_setup_table[0]))));

while(acSetup <= acSetups){ //loop through the submenu points

subButton = read_act_buttons(); //checking for pressed buttons

if(subButton == btnMenu){ //if button menu was pressed

acSetup++; //add 1 - move to the next point

lcd.clear();

//printing and retrieving the menu points

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(ac_setup_table[acSetup - 1]))));

}

if(subButton == btnSelect){ //if btn select was pressed

switch(acSetup){ //going right through the options

case 1:

//call the function get_timer() to update settings

ac_op_mode = get_Timer(26, ac_op_mode, 1, 4);

return;

case 2:

//call the function get_timer() to update settings

ac_set_temp = get_Timer(27, ac_set_temp, 18, 32);

return;

case 3:

adj_seasons();

return;

case 4:

//call the function get_timer() to update settings

acSwitchDelay = get_Timer(28, acSwitchDelay, 1, 5);

return;

//>>>>>>>>>>>>>Addition starts here<<<<<<<<<<<<<<

case 5:

//call the function get_offon() tu update settings

startDelay = get_offon(39, 0, startDelay);

return;

//>>>>>>>>>>>>>>Addition ends here<<<<<<<<<<<<<<

}

}

}

}

If you did pay attention, you know already that there is something wrong again. The function get_offon() get passed 3 variables, first the counter to retrieve the info text from the program memory, second the room counter and last the current value of the variable we need to change. As room counter we pass now 99 but the last counter adjusting something is 15, the outside lights. OK, I could have made it 50 or what ever number which is not used. The 99 only indicates, that this variable is not for a particular room. It's a general setup concerning 4 AC-units in this case. Now we have to go to the get_offon() function and update it accordingly:

//function to set a timer active / inactive

byte get_offon(byte info, byte room, byte reading){

byte subButton = 0; //resetting button value

lcd.clear(); //clear screen

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[info])))); //print passed info text

if(room >= 10 && room <= 13){ //calculating room for AC units

lcd.print(room - 9); //AC room

}

//>>>>>>>>>>>>>>>ADDITION starts here<<<<<<<<<<<<<<

else if(room == 0){

lcd.print(" ");

}

//>>>>>>>>>>>>>>Addition ends here<<<<<<<<<<<<<<<

else{

lcd.print(room + 1); //light room

}

lcd.setCursor(0, 1); //set cursor to second row column 1

if(reading != 1) lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[7])))); //if value is not 1 timer is off

//print off

if(reading == 1) lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[8])))); //if timer is 1, timer is active

//print active

In this case we are passing the room number only to be printed in the info text line. The only thing I did is adding a little if – statement, stating not to print a number if the variable 99 is passed on.

Let's start with changing the operation mode 1 of the ac_read() function:

unsigned long ac_read(byte readSw, byte room){

byte periode = get_ac_periode(); //function call to check time periode (season)

//check if a forced switch on is defined and the set temperature

if(ac_forced_on[room-10][0] != 99 && checkOnTime(room_timers[room][periode][0], room_timers[room][periode][1],

room_timers[room][periode][2], room_timers[room][periode][3]) == 1 &&

temperatur1 >= ac_set_temp){

priorityStatus[room] = 1; //set priority status to 1 if yes

}

else{

priorityStatus[room] = 0; //set priority status to 0 if no

}

if(ac_op_mode == 1){

//>>>>>>>>>>>>>>Added “&& startDelay == 1” to the if statement<<<<<<<<<<<<<<<

if(switchState[readSw] == 1 && lightStatus[14] == 1 && startDelay == 1){ //Checking if readswitches are activated //and the master relay is on AC room 1 (bed1)

if(allTimer(lastRun[room - 10], 480)){ //check if 8 minute lock is passed since last run

lightOutput[room] = outputValues[room]; //providing the ability to

//switch on the AC

lightStatus[room] = 1; //setting the light (AC) status

roomTimer[room] = millis()/1000; //setting the timer

lastRun[room - 10] = 0;

}

else{

lightOutput[room] = 0; //cancelling ability to switch on the

//AC

lightStatus[room] = 0; //resetting the light (AC) status

roomTimer[room] = 0;

}

}

//>>>>>>>>>>>>>>Addition starts here<<<<<<<<<<<<<<<

else if(switchState[readSw] == 1 && lightStatus[14] == 1 && startDelay == 0){

lightOutput[room] = outputValues[room]; //providing the ability to

//switch on the AC

lightStatus[room] = 1; //setting the light (AC) status

roomTimer[room] = millis()/1000; //setting the timer

lastRun[room - 10] = 0;

}

//>>>>>>>>>>>>>>Addition ends here<<<<<<<<<<<<<<<

else if(switchState[readSw] == 0 && lightStatus[14] == 1){ //if a door is opened and the master

//relay is on

if(allTimer(roomTimer[room], delayTime[room])){ //checking the time limit

lightOutput[room] = 0; //cancelling ability to switch on the

//AC

lightStatus[room] = 0; //resetting the light (AC) status

roomTimer[room] = 0; //resetting the timer

lastRun[room - 10] = millis()/1000;

}

}

return lightOutput[room];

}

else if(ac_op_mode == 2){

In the operating mode 2 we need to do a few more changes to make the compressor protection delay a option:

else if(ac_op_mode == 2){

if(ac_master_bypass[room - 10] == 0){ //check if the master bypass is set

if(switchState[readSw] == 1 && lightStatus[14] == 1 && startDelay == 1){ //Checking if readswitches are activated

if(checkOnTime(room_timers[room][periode][0], room_timers[room][periode][1], //checking if AC is allowed to run

room_timers[room][periode][2], room_timers[room][periode][3]) == 1){

if(allTimer(lastRun[room - 10], 480)){ //check if 8 minute lock is passed since last run

lightOutput[room] = outputValues[room]; //switch on the AC

lightStatus[room] = 1; //setting the light (AC) status

roomTimer[room] = millis()/1000; //setting the timer

lastRun[room - 10] = 0;

}

else{

lightOutput[room] = 0; //keep it off

lightStatus[room] = 0;

}

}

}

else if(switchState[readSw] == 1 && priorityStatus[room] == 1 && startDelay == 1){ //if doors and windows are closed and priority is set

if(currentHour >= ac_forced_on[room-10][0] && currentMinute >= ac_forced_on[room-10][1]){ //check if it's time to start

if(allTimer(lastRun[room - 10], 480)){ //check if 8 minute lock is passed since last run

lightOutput[room] = outputValues[room]; //switch on the AC

lightStatus[room] = 1; //setting the light (AC) status

roomTimer[room] = millis()/1000; //setting the timer

lastRun[room - 10] = 0;

}

else{

lightOutput[room] = 0; //keep it off

lightStatus[room] = 0;

}

}

else{

lightOutput[room] = 0; //keep it off

lightStatus[room] = 0; //setting the light (AC) status

roomTimer[room] = 0; //resetting the room timer

}

}

if(switchState[readSw] == 1 && lightStatus[14] == 1 && startDelay == 0){

if(checkOnTime(room_timers[room][periode][0], room_timers[room][periode][1], //checking if AC is allowed to run

room_timers[room][periode][2], room_timers[room][periode][3]) == 1){

lightOutput[room] = outputValues[room]; //switch on the AC

lightStatus[room] = 1; //setting the light (AC) status

roomTimer[room] = millis()/1000; //setting the timer

lastRun[room - 10] = 0;

}

}

else if(switchState[readSw] == 1 && priorityStatus[room] == 1 && startDelay == 0){

if(checkOnTime(room_timers[room][periode][0], room_timers[room][periode][1], //checking if AC is allowed to run

room_timers[room][periode][2], room_timers[room][periode][3]) == 1){

lightOutput[room] = outputValues[room]; //switch on the AC

lightStatus[room] = 1; //setting the light (AC) status

roomTimer[room] = millis()/1000; //setting the timer

lastRun[room - 10] = 0;

}

}

else if(switchState[readSw] == 0 && lightStatus[14] == 1){ //if a door is opened and the master

//relay is on

//delay time

if(allTimer(roomTimer[room], delayTime[room])){ //checking the time limit

lightOutput[room] = 0; //cancelling ability to switch on the

//AC

lightStatus[room] = 0; //resetting the light (AC) status

roomTimer[room] = 0; //resetting the timer

lastRun[room - 10] = millis()/1000;

}

}

}

else if(ac_master_bypass[room - 10] == 1){ //if master relay bypass is on

if(switchState[readSw] == 1 && startDelay == 1){ //Checking if readswitches are activated

if(checkOnTime(room_timers[room][periode][0], room_timers[room][periode][1],

room_timers[room][periode][2], room_timers[room][periode][3]) == 1 &&

temperatur1 >= ac_set_temp){

if(allTimer(lastRun[room - 10], 480)){ //check if 8 minute lock is passed since last run

lightOutput[room] = outputValues[room]; //switch on the AC

lightStatus[room] = 1; //setting the light (AC) status

roomTimer[room] = millis()/1000; //setting the timer

lastRun[room - 10] = 0;

}

else{

lightOutput[room] = 0; //keep it off

lightStatus[room] = 0;

}

}

}

else if(switchState[readSw] == 1 && startDelay == 0){

lightOutput[room] = outputValues[room]; //switch on the AC

lightStatus[room] = 1; //setting the light (AC) status

roomTimer[room] = millis()/1000; //setting the timer

lastRun[room - 10] = 0;

}

else if(switchState[readSw] == 0){ //if a door is opened and the master

//relay is on

//delay time

if(allTimer(roomTimer[room], delayTime[room])){ //checking the time limit

lightOutput[room] = 0; //cancelling ability to switch on the

//AC

lightStatus[room] = 0; //resetting the light (AC) status

roomTimer[room] = 0; //resetting the timer

lastRun[room - 10] = millis() / 1000;

}

}

}

return lightOutput[room];

}

In here we need to add “&& startDelay == 1” to the current statements where the AC is switched on and we have to add the same statement as a else if(condition && condition && startDelay == 0){
and type in the same code except for running it through the if(allTimer(lastRun[room - 10], 480)){ 8 minute start up delay. That is basicly the same for operation mode 3:


else if(ac_op_mode == 3){ //AC operating mode 3

lightOutput[room] = 0; //Setting the lightOutput to 0

if(startDelay == 1){

if(roomLight[room] == 1 && lastRun[room - 10] == 0){ //if a "on" command was given and the time since last run is more than 8 minutes

if(allTimer(roomTimer[room], acSwitchDelay)){

lightStatus[room] = 1; //set AC status to on

roomLight[room] = 0; //cancel "on" command

return 0; //return 0

}

else{

return outputValues[room]; //pulse the switch while "on" command active

}

}

if(roomLight[room] == 1 && lastRun[room - 10] != 0){ //if a "on" command was given and the time since last run is less than 8 minutes

/*currentTime = millis()/1000; //setting time for reference

endTime = currentTime - lastRun[room - 10]; //compare time with last switch off time

if(endTime >= 480) lastRun[room - 10] = 0; */ //if last switch off is 8 minutes ore longer

if(allTimer(lastRun[room - 10], 480)) lastRun[room - 10] = 0;

return 0; //return 0

}

}

if(startDelay == 0){

if(roomLight[room] == 1){ //if a "on" command was given

if(allTimer(roomTimer[room], acSwitchDelay)){

lightStatus[room] = 1; //set AC status to on

roomLight[room] = 0; //cancel "on" command

return 0; //return 0

}

else{

return outputValues[room]; //pulse the switch while "on" command active

}

}

}

if(roomLight[room] == 2){ //if an "off" command was given check delay timer

/*currentTime = millis()/1000; //set time for reference

endTime = currentTime - roomTimer[room]; //compare reference with set off delay

if(endTime >= delayTime[room]){ */ //check if it matches allowed difference

if(allTimer(roomTimer[room], delayTime[room])){

roomLight[room] = 3; //final command to switch off

return 0; //return 0

}

else{

roomLight[room] = 2; //keep the status

return 0; //return 0

}

}

if(roomLight[room] == 3){ //final off command given

if(allTimer(roomTimer[room], acSwitchDelay)){

lightStatus[room] = 0; //reset command status

roomLight[room] = 0; //reset AC status

lastRun[room - 10] = millis()/1000; //set switch off time

return 0; //return 0

}

else{

return outputValues[room]; //pulse the switch

}

}

if(ac_master_bypass[room-10] == 0){

if(lightStatus[room] == 0 && roomLight[room] == 0){

if(switchState[readSw] == 1 && lightStatus[14] == 1 &&

temperatur1 >= ac_set_temp && priorityStatus[room] == 0){

if(checkOnTime(room_timers[room][periode][0], room_timers[room][periode][1], //checking if AC is allowed to run

room_timers[room][periode][2], room_timers[room][periode][3]) == 1){

roomLight[room] = 1;

roomTimer[room] = millis()/1000;

return 0;

}

else {

return 0;

}

}

if(switchState[readSw] == 1 && priorityStatus[room] == 1 &&

temperatur1 >= ac_set_temp){

if(currentHour >= ac_forced_on[room-10][0] &&

currentMinute >= ac_forced_on[room-10][1]){ //check if it's time to start

roomLight[room] = 1;

roomTimer[room] = millis()/1000;

return 0;

}

else {

return 0;

}

}

}

if(lightStatus[room] == 1 && roomLight[room] == 0){

if(currentHour == room_timers[room][periode][2] && //if the allowed running limit is reached

currentMinute >= room_timers[room][periode][3]){

roomLight[room] = 2;

roomTimer[room] = millis()/1000;

return 0;

}

else{

return 0;

}

if(priorityStatus[room] == 1 && switchState[readSw] == 0){

roomLight[room] = 2;

roomTimer[room] = millis()/1000;

return 0;

}

else{

return 0;

}

if(priorityStatus[room] == 0){

if(switchState[readSw] == 0 | lightStatus[14] == 0){

roomLight[room] = 2;

roomTimer[room] = millis()/1000;

return 0;

}

else{

return 0;

}

}

}

}

}

return 0;

}



No comments:

Post a Comment