Translate

Saturday 17 May 2014

Room Management System – The Menu – part 8


In this post we change the way we deal with the sub menus. There fore, first thing we do is packing all the single variables holding the timer state into a 2-dimensional array. The first count is corresponding to our rooms again. The second is corresponding with the timers. The following array goes into the declaration part in the “Holiday timer settings” section. We can place it just above the array we have done in the last post. If you have different timers active, please set them accordingly, 0 for off, 1 for active and 2 for not used.

//Values setting the timers on or off

byte timer_active[10][4] = {

{1, 1, 1, 0}, //room 0 timers 0 to 3

{1, 1, 0, 0}, //room 1 timers 0 to 3

{1, 1, 1, 1}, //room 2 timers 0 to 3

{0, 1, 0, 0}, //room 3 timers 0 to 3

{1, 1, 2, 2}, //room 4 timers 0 to 3

{1, 1, 2, 2}, //room 5 timers 0 to 3

{1, 1, 2, 2}, //room 6 timers 0 to 3

{1, 0, 2, 2}, //room 7 timers 0 to 3

{1, 1, 2, 2}, //room 8 timers 0 to 3

{0, 0, 2, 2} //room 9 timers 0 to 3

}; 

In the next step we delete all the single declarations:

//////////////////////holiday timer settings//////////////////////

//>>>>>>>>>>>>>DELETE everything in this block<<<<<<<<<<<<<

////////////Room 1 (Bed 1) ///////////

byte room1MActive = 1; //Set to 1 if you want to process

//Timer will be ignored when set to 0

byte room1O1Active = 1; //Set to 1 if you want to process

//Timer will be ignored when set to 0

byte room102Active = 1; //Set to 1 if you want to process

byte room103Active = 0;

////////////Room 2 (Bed 2) ///////////

byte room2MActive = 1; //Set to 1 if you want to process

//Timer will be ignored when set to 0

byte room201Active = 1; //Set to 1 if you want to process

byte room202Active = 0;

byte room203Active = 0;

////////////Room 3 (Bed 3) ///////////

byte room3MActive = 1; //Set to 1 if you want to process

byte room301Active = 1; //Set to 1 if you want to process

byte room302Active = 1; //Set to 1 if you want to process

byte room303Active = 1; //Set to 1 if you want to process

///////////Room 4 {Living)

byte room4MActive = 0;

byte room401Active = 1; //Set to 1 if you want to process

byte room402Active = 0;

byte room403Active = 0;

//////////Room 5 (bath 1)//////////

byte room5MActive = 1; //Set to 1 if you want to process

byte room501Active = 1; //Set to 1 if you want to process

//////////Room 6 (bath 2)//////////

byte room6MActive = 1; //Set to 1 if you want to process

byte room601Active = 1; //Set to 1 if you want to process

//////////Room 7 (bath 3)//////////

byte room7MActive = 1; //Set to 1 if you want to process

byte room701Active = 1; //Set to 1 if you want to process

//Timer will be ignored when set to 0

//////////Room 8 (bath 4)//////////

byte room8MActive = 1; //Set to 1 if you want to process

byte room801Active = 0;

//////////Room 9 (Kitchen)//////////

byte room9MActive = 1; //Set to 1 if you want to process

byte room901Active = 1; //Set to 1 if you want to process

//////////Room 10 (corridor)///////

byte room10MActive = 0;

byte room1001Active = 0;

And here the complete revised section “Holiday timer settings”

//////////////////////holiday timer settings//////////////////////

byte timer_active[10][4] = {

{1, 1, 1, 0}, //room 0 timers 0 to 3

{1, 1, 0, 0}, //room 1 timers 0 to 3

{1, 1, 1, 1}, //room 2 timers 0 to 3

{0, 1, 0, 0}, //room 3 timers 0 to 3

{1, 1, 2, 2}, //room 4 timers 0 to 3

{1, 1, 2, 2}, //room 5 timers 0 to 3

{1, 1, 2, 2}, //room 6 timers 0 to 3

{1, 0, 2, 2}, //room 7 timers 0 to 3

{1, 1, 2, 2}, //room 8 timers 0 to 3

{0, 0, 2, 2} //room 9 timers 0 to 3

};

//Timer Settings room, timer, hour on, minute on, hour off, minute off

//We can enter values in all the timers. It will not effect unless

//the timer is set to 1 (active) in the array above

byte room_timers[10][4][4] = {

{

{5, 35, 6, 5}, //room 1 timer 1

{19, 35, 20, 15}, //room 1 timer 2

{21, 5, 21, 15}, //room 1 timer 3

{0, 0, 0, 0} //room 1 timer 4

},

{

{6, 30, 6, 50}, //room 2 timer 1

{19, 30, 20, 10}, //room 2 timer 2

{0, 0, 0, 0}, //room 2 timer 3

{0, 0, 0, 0} //room 2 timer 4

},

{

{5, 50, 6, 20}, //room 3 timer 1

{18, 10, 18, 25}, //room 3 timer 2

{19, 15, 19, 40}, //room 3 timer 3

{23, 20, 23, 35} //room 3 timer 4

},

{

{0, 0, 0, 0}, //room 4 timer 1

{17, 30, 23, 30}, //room 4 timer 2

{0, 0, 0, 0}, //room 4 timer 3

{0, 0, 0, 0} //room 4 timer 4

},

{

{5, 40, 5, 45}, //room 5 timer 1

{19, 55, 20, 10}, //room 5 timer 2

{0, 0, 0, 0}, //not used

{0, 0, 0, 0} //not used

},

{

{6, 35, 6, 45}, //room 6 timer 1

{19, 50, 20, 5}, //room 6 timer 2

{0, 0, 0, 0}, //not used

{0, 0, 0, 0} //not used

},

{

{6, 5, 6, 25}, //room 7 timer 1

{22, 50, 23, 15}, //room 7 timer 2

{0, 0, 0, 0}, //not used

{0, 0, 0, 0} //not used

},

{

{0, 0, 0, 0}, //room 8 timer 1

{22, 5, 22, 20}, //room 8 timer 2

{0, 0, 0, 0}, //not used

{0, 0, 0, 0} //not used

},

{

{5, 50, 6, 45}, //room 9 timer 1

{17, 45, 18, 30}, //room 9 timer 2

{0, 0, 0, 0}, //room 9 timer 3

{0, 0, 0, 0} //not used

},

{

{0, 0, 0, 0}, //room 10 timer 1

{0, 0, 0, 0}, //room 10 timer 2

{0, 0, 0, 0}, //not used

{0, 0, 0, 0} //not used

}

};

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

////////////////////////////DO NOT MODIVY BELOW HERE///////////////////////////////////////

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

Now we move down to the main loop where it says holiday lighting and look at the first room, first timer check:

if(room1MActive == 1 && currentHour >= room_timers[0][0][0] &&

currentHour <= (room_timers[0][0][2] + 1)){ //checking if we came passed

//the hour where the lights

//to be switched on

//checking the times

room1Lights = checkOnTime(room_timers[0][0][0], room_timers[0][0][1],

room_timers[0][0][2], room_timers[0][0][3]);

}

Here we need to update the var “room1MActive” to the new array timer_active[0][0], so the revised timer check reads:

if(timer_active[0][0] == 1 && currentHour >= room_timers[0][0][0] &&

currentHour <= (room_timers[0][0][2] + 1)){ //checking if we came passed

//the hour where the lights

//to be switched on

//checking the times

room1Lights = checkOnTime(room_timers[0][0][0], room_timers[0][0][1],

room_timers[0][0][2], room_timers[0][0][3]);

}

If we look at the two arrays timer_active[0][0] and room_timers[0][0][0], the first two counters will always match. Even in the room_timers[] array, the first counter corresponds with the room, the second with the timer, the same as the timer_active[] array. Not to go through all the timers in single rows, here the complete part with all the timer checks changed:

//////////////Holiday lighting/////////////////////////

if(switchState[20] == 1) { //check if the holiday switch

//is activated

lightOutput[14] = 0; //make sure the master relay is off

//Serial.print("Current date: ");

//Serial.print(days[currentDay - 1]);

//Serial.print(", ");

//Serial.print(currentDoM);

//Serial.print("/");

//Serial.print(currentMonth);

//Serial.print("/");

//Serial.println(currentYear);

//Serial.print("Current Time: ");

//Serial.print(currentHour);

//Serial.print(" : ");

//Serial.println(currentMinute);

//Serial.print("Photo cell switch: ");

//Serial.println(photocellSwitch);

//Serial.print("Light level room 1 after: ");

//Serial.println(lightLevel[0]);

//Serial.print("photocell switch: ");

//Serial.println(photocellSwitch);

//Serial.print("Light level room 3 after: ");

//Serial.println(lightLevel[2]);

//Serial.print("Light level room 4 after: ");

//Serial.println(lightLevel[3]);

///////Room 1 (Bed 1) /////////////

if(timer_active[0][0] == 1 && currentHour >= room_timers[0][0][0] &&

currentHour <= (room_timers[0][0][2] + 1)){ //checking if we came passed

//the hour where the lights

//to be switched on

//checking the times

room1Lights = checkOnTime(room_timers[0][0][0], room_timers[0][0][1],

room_timers[0][0][2], room_timers[0][0][3]);

}

if(timer_active[0][1] == 1 && currentHour >= room_timers[0][1][0] &&

currentHour <= (room_timers[0][1][2] + 1)){ //checking if we came passed

//the hour where the lights

//to be switched on

//checking the times

room1Lights = checkOnTime(room_timers[0][1][0], room_timers[0][1][1],

room_timers[0][1][2], room_timers[0][1][3]);

}

if(timer_active[0][2] == 1 && currentHour >= room_timers[0][2][0] &&

currentHour <= (room_timers[0][2][2] + 1)){ //checking if we came passed

//the hour where the lights

//to be switched on

//checking the times

room1Lights = checkOnTime(room_timers[0][2][0], room_timers[0][2][1],

room_timers[0][2][2], room_timers[0][2][3]);

}

if(timer_active[0][3] == 1 && currentHour >= room_timers[0][3][0] &&

currentHour <= (room_timers[0][3][2] + 1)){ //checking if we came passed

//the hour where the lights

//to be switched on

//checking the times

room1Lights = checkOnTime(room_timers[0][3][0], room_timers[0][3][1],

room_timers[0][3][2], room_timers[0][3][3]);

}

if(room1Lights == 1 && lightLevel[0] == 1){ //if with in the on time

lightOutput[0] =1; //switch on the lights

}

else {

lightOutput[0] = 0; //other keep them off

lightLevel[0] = 0;

}

////////Room 2 (Bed 2)//////////////

if(timer_active[1][0] ==1 && currentHour >= room_timers[1][0][0]

&& currentHour <= (room_timers[1][0][2] + 1)){

room2Lights = checkOnTime(room_timers[1][0][0], room_timers[1][0][1],

room_timers[1][0][2], room_timers[1][0][3]);

}

if(timer_active[1][1] == 1 && currentHour >= room_timers[1][1][0] &&

currentHour <= (room_timers[1][1][2] + 1)){

room2Lights = checkOnTime(room_timers[1][1][0], room_timers[1][1][1],

room_timers[1][1][2], room_timers[1][1][3]);

}

if(timer_active[1][2] == 1 && currentHour >= room_timers[1][2][0] &&

currentHour <= (room_timers[1][2][2] + 1)){

room2Lights = checkOnTime(room_timers[1][2][0], room_timers[1][2][1],

room_timers[1][2][2], room_timers[1][2][3]);

}

if(timer_active[1][3] == 1 && currentHour >= room_timers[1][3][0] &&

currentHour <= (room_timers[1][3][2] + 1)){

room2Lights = checkOnTime(room_timers[1][3][0], room_timers[1][3][1],

room_timers[1][3][2], room_timers[1][3][3]);

}

if(room2Lights == 1 && lightLevel[1] == 1){

lightOutput[1] = 2;

}

else {

lightOutput[1] = 0;

lightLevel[1] =0;

}

////////Room 3 (Bed 3) ////////////

if(timer_active[2][0] == 1 && currentHour >= room_timers[2][0][0] &&

currentHour <= (room_timers[2][0][2] + 1)){

room3Lights = checkOnTime(room_timers[2][0][0], room_timers[2][0][1],

room_timers[2][0][2], room_timers[2][0][3]);

}

if(timer_active[2][1] == 1 && currentHour >= room_timers[2][1][0] &&

currentHour <= (room_timers[2][1][2] + 1)){

room3Lights = checkOnTime(room_timers[2][1][0], room_timers[2][1][1],

room_timers[2][1][2], room_timers[2][1][3]);

}

if(timer_active[2][2] == 1 && currentHour >= room_timers[2][2][0] &&

currentHour <= (room_timers[2][2][2] + 1)){

room3Lights = checkOnTime(room_timers[2][2][0], room_timers[2][2][1],

room_timers[2][2][2], room_timers[2][2][3]);

}

if(timer_active[2][3] == 1 && currentHour >= room_timers[2][3][0] &&

currentHour <= (room_timers[2][3][2] + 1)){

room3Lights = checkOnTime(room_timers[2][3][0], room_timers[2][3][1],

room_timers[2][3][2], room_timers[2][3][3]);

}

if(room3Lights == 1 && lightLevel[2] == 1){

lightOutput[2] = 4;

}

else {

lightOutput[2] = 0;

lightLevel[2] = 0;

}

////////Room 4 (living)/////////////////////

if(timer_active[3][0] == 1 && currentHour >= room_timers[3][0][0] &&

currentHour <= (room_timers[3][0][2] + 1)){

room4Lights = checkOnTime(room_timers[3][0][0], room_timers[3][0][1],

room_timers[3][0][2], room_timers[3][0][3]);

}

if(timer_active[3][1] == 1 && currentHour >= room_timers[3][1][0] &&

currentHour <= (room_timers[3][1][2] + 1)){

room4Lights = checkOnTime(room_timers[3][1][0], room_timers[3][1][1],

room_timers[3][1][2], room_timers[3][1][3]);

}

if(timer_active[3][2] == 1 && currentHour >= room_timers[3][2][0] &&

currentHour <= (room_timers[3][2][2] + 1)){

room4Lights = checkOnTime(room_timers[3][2][0], room_timers[3][2][1],

room_timers[3][2][2], room_timers[3][2][3]);

}

if(timer_active[3][3] == 1 && currentHour >= room_timers[3][3][0] &&

currentHour <= (room_timers[3][3][2] + 1)){

room4Lights = checkOnTime(room_timers[3][3][0], room_timers[3][3][1],

room_timers[3][3][2], room_timers[3][3][3]);

}

if(room4Lights == 1 && lightLevel[3] == 1){

lightOutput[3] = 8;

}

else {

lightOutput[3] = 0;

lightLevel[3] = 0;

}

////////Room 5 (Bath 1)/////////////////////

if(timer_active[4][0] == 1 && currentHour >= room_timers[4][0][0] &&

currentHour <= (room_timers[4][0][2] + 1)){

room5Lights = checkOnTime(room_timers[4][0][0], room_timers[4][0][1],

room_timers[4][0][2], room_timers[4][0][3]);

}

if(timer_active[4][1] == 1 && currentHour >= room_timers[4][1][0] &&

currentHour <= (room_timers[4][1][2] + 1)){

room5Lights = checkOnTime(room_timers[4][1][0], room_timers[4][1][1],

room_timers[4][1][2], room_timers[4][1][3]);

}

if(room5Lights == 1 && lightLevel[4] == 1){

lightOutput[4] = 16;

}

else {

lightOutput[4] = 0;

lightLevel[4] =0;

}

////////Room 6 (Bath 2)/////////////////////

if(timer_active[5][0] == 1 && currentHour >= room_timers[5][0][0] &&

currentHour <= (room_timers[5][0][2] + 1)){

room6Lights = checkOnTime(room_timers[5][0][0], room_timers[5][0][1],

room_timers[5][0][2], room_timers[5][0][3]);

}

if(timer_active[5][1] == 1 && currentHour >= room_timers[5][1][0] &&

currentHour <= (room_timers[5][1][2] + 1)){

room6Lights = checkOnTime(room_timers[5][1][0], room_timers[5][1][1],

room_timers[5][1][2], room_timers[5][1][3]);

}

if(room6Lights == 1 && lightLevel[5] == 1){

lightOutput[5] = 32;

}

else {

lightOutput[5] = 0;

lightLevel[5] = 0;

}

////////Room 7 (Bath 3)/////////////////////

if(timer_active[6][0] == 1 && currentHour >= room_timers[6][0][0] &&

currentHour <= (room_timers[6][0][2])){

room7Lights = checkOnTime(room_timers[6][0][0], room_timers[6][0][1],

room_timers[6][0][2], room_timers[6][0][3]);

}

if(timer_active[6][1] == 1 && currentHour >= room_timers[6][1][0] &&

currentHour <= (room_timers[6][1][2] + 1)){

room7Lights = checkOnTime(room_timers[6][1][0], room_timers[6][1][1],

room_timers[6][1][2], room_timers[6][1][3]);

}

if(room7Lights == 1 && lightLevel[6] == 1){

lightOutput[6] = 64;

}

else {

lightOutput[6] = 0;

lightLevel[6] = 0;

}

////////Room 8 (Bath 4)/////////////////////

if(timer_active[7][0] == 1 && currentHour >= room_timers[7][0][0] &&

currentHour <= (room_timers[7][0][2] + 1)){

room8Lights = checkOnTime(room_timers[7][0][0], room_timers[7][0][1],

room_timers[7][0][2], room_timers[7][0][3]);

}

if(timer_active[7][1] == 1 && currentHour >= room_timers[7][1][0] &&

currentHour <= (room_timers[7][1][2] + 1)){

room8Lights = checkOnTime(room_timers[7][1][0], room_timers[7][1][1],

room_timers[7][1][2], room_timers[7][1][3]);

}

if(room8Lights == 1 && lightLevel[7] == 1){

lightOutput[7] = 128;

}

else {

lightOutput[7] = 0;

lightLevel[7] = 0;

}

////////Room 9 (kitchen)/////////////////////

if(timer_active[8][0] == 1 && currentHour >= room_timers[8][0][0] &&

currentHour <= (room_timers[8][0][2] + 1)){

room9Lights = checkOnTime(room_timers[8][0][0], room_timers[8][0][1],

room_timers[8][0][2], room_timers[8][0][3]);

}

if(timer_active[8][1] == 1 && currentHour >= room_timers[8][1][0] &&

currentHour <= (room_timers[8][1][2] + 1)){

room9Lights = checkOnTime(room_timers[8][1][0], room_timers[8][1][1],

room_timers[8][1][2], room_timers[8][1][3]);

}

if(room9Lights == 1 && lightLevel[8] == 1){

lightOutput[8] = 256;

}

else {

lightOutput[8] = 0;

lightLevel[8] = 0;

}

////////Room 10 (corridor)/////////////////////

if(timer_active[9][0] == 1 && currentHour >= room_timers[9][0][0] &&

currentHour <= (room_timers[9][0][2] + 1)){

room10Lights = checkOnTime(room_timers[9][0][0], room_timers[9][0][1],

room_timers[9][0][2], room_timers[9][0][3]);

}

if(timer_active[9][1] == 1 && currentHour >= room_timers[9][1][0] &&

currentHour <= (room_timers[9][1][2] + 1)){

room9Lights = checkOnTime(room_timers[9][1][0], room_timers[9][1][1],

room_timers[9][1][2], room_timers[9][1][3]);

}

if(room10Lights == 1 && lightLevel[9] == 1){

lightOutput[9] = 512;

}

else {

lightOutput[9] = 0;

lightLevel[9] = 0;

}

////////Outside lights////////////////////

Now we move down to the end of the selectMenu() and right after it, we start building a new function and call it “void get_submenu(byte room)”. Since we have everything packed nice in arrays with corresponding counters, we need only one variable to be passed on and that's the room we are dealing with.

Let's build the new function:

//function to show submenus for rooms

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]))));

//the room number we are passing on is the array counter. Why arrays start

//counting with 0 and not with 1, we have to add the 1 to the counter.

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

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

submenu++; //add 1 - move to the next sub menu point

if(submenu == 2){ //if we are at sub menu 2

lcd.clear();

//retrieve and print second sub menu point

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

//again conversion from array count to room no.

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

}

if(submenu == 3){ //if we are at sub menu 3

lcd.clear();

//retrieve and print second sub menu point

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

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

}

if(submenu == 4){ //if we are at sub menu 4

lcd.clear();

//retrieve and print second sub menu point

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

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

}

if(submenu == 5){ //if we are at sub menu 5

lcd.clear();

//retrieve and print second sub menu point

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

lcd.write(pgm_read_byte(&char_table[5])); //printing assigned room number 1

}

if(submenu == 6){ //if we are at sub menu 6

lcd.clear();

//retrieve and print second sub menu point

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

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

//since we have rooms using this timer and other not, we have to check

//if we can use the timer

if(timer_active[room][2] == 2){

lcd.setCursor(0, 1);

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

}

}

if(submenu == 7){ //if we are at sub menu 7

lcd.clear();

//retrieve and print second sub menu point

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

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

//since we have rooms using this timer and other not, we have to check

//if we can use the timer

if(timer_active[room][2] == 2){

lcd.setCursor(0, 1);

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

}

}

if(submenu == 8){ //if we are at sub menu 6

lcd.clear();

//retrieve and print second sub menu point

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

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

//since we have rooms using this timer and other not, we have to check

//if we can use the timer

if(timer_active[room][3] == 2){

lcd.setCursor(0, 1);

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

}

}

if(submenu == 9){ //if we are at sub menu 7

lcd.clear();

//retrieve and print second sub menu point

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

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

//since we have rooms using this timer and other not, we have to check

//if we can use the timer

if(timer_active[room][3] == 2){

lcd.setCursor(0, 1);

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

}

}

}

if(subButton == btnSelect){ //if we pressed btnSelect

if(submenu == 1){ //and submenu is 1

//call the function get_delay() to change the setting

//Please NOTE the change in the function call

//delayTime[n] = get_delay(9, n, dBed1);

//n is replaced by the passed on variable “room”,

//and the variable dBed1 is replaced by the array place holder

//holding the variable.

delayTime[room] = get_delay(9, room, delayTime[room]);

return;

}

if(submenu == 2){ //and sub menu is 2

//call the function get_offon to change the setting

//Please NOTE the change in the function call

//room(n)MActive = get_offon(10, n, room(n)MActive);

//we replace the variables room(n)MActive with the place holder of the array

//holding the value and n is replaced by the variable “room”.

//changes go for all following timer settings.

timer_active[room][0] = get_offon(10, room, timer_active[room][0]);

return;

}

if(submenu == 3){ //and submenu is 3

//call the function get_setTime() to change timer 1

//Please NOTE the changes in the function call. The value in the first array

//counter is again replaced with the variable “room”.

get_setTime(room_timers[room][0][0], room_timers[room][0][1],

room_timers[room][0][2], room_timers[room][0][3],

room, 0);

return;

}

if(submenu == 4){ //and submenu is 4

//call the function get_offon() to change the setting

timer_active[room][1] = get_offon(11, room, timer_active[room][1]);

return;

}

if(submenu == 5){ //and submenu is 5

//call the function get_setTime() to change timer 2

get_setTime(room_timers[room][1][0], room_timers[room][1][1],

room_timers[room][1][2], room_timers[room][1][3],

room, 1);

return;

}

if(submenu == 6 && timer_active[room][2] != 2){ //and submenu is 6

//call the function get_offon() to change the setting

timer_active[room][2] = get_offon(12, room, timer_active[room][2]);

return;

}

if(submenu == 7 && timer_active[room][2] != 2){ //and submenu == 7

//call function get_setTime() to change timer 3

get_setTime(room_timers[room][2][0], room_timers[room][2][1],

room_timers[room][2][2], room_timers[room][2][3],

room, 2);

return;

}

if(submenu == 8 && timer_active[room][3] != 2){ //and submenu is 6

//call the function get_offon() to change the setting

timer_active[room][3] = get_offon(25, room, timer_active[room][3]);

return;

}

if(submenu == 9 && timer_active[room][3] != 2){ //and submenu == 7

//call function get_setTime() to change timer 3

get_setTime(room_timers[room][3][0], room_timers[room][3][1],

room_timers[room][3][2], room_timers[room][3][3],

room, 3);

return;

}

}

}

}

Since we where building a function for the submenu, we can replace all submenus in the selectMenu() function with calling the just build function “get_submenu()”. Lets go up into the selectMenu() function and do the replacements:

if(button == btnSelect){ //if the select button is pressed

if(menuOption == 1){ //and menu option is 1

adjust_date_time(); //go to adjust date and time

return;

}

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

sensitivity = get_Timer(17, sensitivity, 0, 1000); //go to function

return;

}

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

photoCellCutOff = get_Timer(18, photoCellCutOff, 0, 1024); //go to function

return;

}

if(menuOption == 4) return; //and menu option is 4 return (not used)

if(menuOption == 5){ //and menu option is 5

photoOutsideOff = get_Timer(19, photoOutsideOff, 0, 1024); //go to function

return;

}

if(menuOption == 6) return; //and menu option is 6 return (not used)

//>>>>>>>>>>>>>Replace all the submenus<<<<<<<<<<<<<<<

//with the function calls below

if(menuOption == 7){ //and menu option is 7 (room 1)

get_submenu(0);

}

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

get_submenu(1);

} //submenu end

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

get_submenu(2);

} //submenu end

if(menuOption == 10){ //and menu option is 9 (room 4)

get_submenu(3);

}

if(menuOption == 11){ //and menu option is 11 (room 5)

get_submenu(4);

}

if(menuOption == 12){ //and menu option is 12 (room 6)

get_submenu(5);

} //submenu end

if(menuOption == 13){ //and menu option is 13 (room 7)

get_submenu(6);

} //submenu end

if(menuOption == 14){ //and menu option is 14 (room 8)

get_submenu(7);

} //submenu end

if(menuOption == 15){ //and menu option is 15 (room 9)

get_submenu(8);

} //submenu end

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

get_submenu(9);

} //submenu end

//>>>>>>>>>>>>>Replacement ends here<<<<<<<<<<<<<

}

}

}

Now a quick look in the function get_offon() where we need to do a small alteration.

The statement lcd.print(room);

has to change to

lcd.print(room + 1);


//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

lcd.print(room + 1);

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

The same thing we need to do in the function get_delay():


int get_delay(byte info, byte room, int reading){

byte subButton = 0; //resetting the button value

byte value = reading / 60; //converting to Minutes

lcd.clear(); //clear screen

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

lcd.print(room + 1); //<<<<<<<<<<<<<NOTE the change here<<<<<<<<<<<<<<

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

As mentioned in the last post, I am working currently on more optimisation of the code and using EEPROM to store the values controlled by the menu.

No comments:

Post a Comment