In the final menu post, we make changes
permanent saving them back to the EEPROM. There fore we jump down to
the selectMenu() function, where we add after every adjusting
function call returning a value the command to update the value in
the EEPROM like:
sensitivity = get_Timer(17, sensitivity, 0, 1000); //go to function
In the above statement the function
timer returns the updated value for sensitivity. Since the variable
sensitivity is updated, we use it to also update the value stored in
the EEPROM and because the value contained in sensitivity can be
anything between 0 and 1000, we treat it as integer and call the
function Mem_updateInt(Sensitivity_ADDR, sensitivity). Now the
function Mem_updateInt checks if the value has changed and only
writes the value to the EEPROM if it did. As variables we have to
pass on the eeprom address holding the value which is easy since we
used the variable name and added just a _ADDR to it to store the
address in the eeprom holding the value and we need to pass the
updated value. I this case the updated variable sensitivity. The
whole statement reads like that:
sensitivity = get_Timer(17, sensitivity, 0, 1000); //go to function Mem_updateInt(Sensitivity_ADDR, sensitivity);
This we have to do with all the
adjusting functions returning a value:
case 21: //menu point with option arrow right case 22: //menu point with option arrow right lcd.setCursor(15,0); //set cursor column 15, row 0 //retrieve and print "arrow right" lcd.write(pgm_read_byte(&char_table[0])); break; } } if(button == btnSelect){ //if the select button is pressed if(menuOption == 1){ //amd menu option is 1 adjust_date_time(); //go to ajdust date and time return; } if(menuOption == 2){ //and menu option is 2 sensitivity = get_Timer(17, sensitivity, 0, 1000); //go to function Mem_updateInt(Sensitivity_ADDR, sensitivity); return; } if(menuOption == 3){ //and menu option is 3 photoCellCutOff = get_Timer(18, photoCellCutOff, 0, 1024); //go to function Mem_updateInt(photoCellCutOff_ADDR, photoCellCutOff); 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 Mem_updateInt(photoOutsideOff_ADDR, photoOutsideOff); return; } if(menuOption == 6) return; //and menu option is 6 return (not used) 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 if(menuOption == 17){ //and menu option is 17 (AC setup) get_ac_setup(); //submenu end } if(menuOption == 18){ //and menu option is 18 (AC room 1) get_ac_sub(10); //submenu end } 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 } if(menuOption == 22){ //and menu option is 16 (room 10) get_submenu(15); } //submenu end } } }
in the function selectMenu() it effects
the menu options 2, 3, and 5. In the get_submenu() function the
submenu options 1, 2, 4, 6 and 8 are effected:
case 9: //menu point + checking timer 3 options if(timer_active[room][3] == 2){ //if set to 2 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 } break; case 10: 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 break; } } if(subButton == btnSelect){ //if we pressed btnSelect if(submenu == 1){ //and submenu is 1 //call the function get_delay() to change the setting if(room == 15) return; delayTime[room] = get_delay(9, room, delayTime[room]); Mem_updateInt(delayTime_ADDR[room], delayTime[room]); return; } if(submenu == 2){ //and sub menu is 2 //call the function get_offon to change the setting timer_active[room][0] = get_offon(10, room, timer_active[room][0]); Mem_updateByte(pgm_read_byte(&(timer_active_ADDR[room][0])), timer_active[room][0]); return; } if(submenu == 3){ //and submenu is 3 //call the function get_setTime() to change timer 1 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]); Mem_updateByte(pgm_read_byte(&(timer_active_ADDR[room][1])), 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]); Mem_updateByte(pgm_read_byte(&(timer_active_ADDR[room][2])), 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]); Mem_updateByte(pgm_read_byte(&(timer_active_ADDR[room][3])), 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; } if(submenu == 10) return; } } }
in the get_ac_setup() function all menu
options need the update statement for the EEPROM.
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); Mem_updateByte(ac_op_mode_ADDR, ac_op_mode); return; case 2: //call the function get_timer() to update settings ac_set_temp = get_Timer(27, ac_set_temp, 18, 32); Mem_updateByte(ac_set_temp_ADDR, ac_set_temp); return; case 3: adj_seasons(); return; case 4: //call the function get_timer() to update settings acSwitchDelay = get_Timer(28, acSwitchDelay, 1, 5); Mem_updateByte(acSwitchDelay_ADDR, acSwitchDelay); return; case 5: //call the function get_offon() tu update settings startDelay = get_offon(39, 0, startDelay); Mem_updateByte(startDelay_ADDR, startDelay); return; } } } }
In the get_ac_sub() function we need to
add the update statement to the menu options 1, 2, 3, 5, 7 and 9.
lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(ac_sub_table[acSubOption - 1])))); lcd.print(room - 9); //printing assigned room number } if(subButton == btnSelect){ switch(acSubOption){ case 1: //only sub menu point no option //call the function get_delay() to change the setting delayTime[room] = get_delay(37, room, delayTime[room]); Mem_updateInt(pgm_read_byte(&(delayTime_ADDR[room])), delayTime[room]); return; case 2: //only sub menu point no option //call the function get_offon to change setting ac_master_bypass[room - 10] = get_offon(38, room, ac_master_bypass[room - 10]); Mem_updateByte(pgm_read_byte(&(ac_master_bypass_ADDR[room - 10])), ac_master_bypass[room - 10]); return; case 3: //only sub menu point no option //call the function get_offon to change setting timer_active[room][0] = get_offon(10, room, timer_active[room][0]); Mem_updateByte(pgm_read_byte(&(timer_active_ADDR[room][0])), timer_active[room][0]); return; case 4: //only sub menu point no option //call the function get_setTime() to change timer 1 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; case 5: //only sub menu point no option //call the function get_offon() to change the setting timer_active[room][1] = get_offon(11, room, timer_active[room][1]); Mem_updateByte(pgm_read_byte(&(timer_active_ADDR[room][1])), timer_active[room][1]); return; case 6: //only sub menu point no option //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; case 7: //only sub menu point no option //call the function get_offon() to change the setting timer_active[room][2] = get_offon(12, room, timer_active[room][2]); Mem_updateByte(pgm_read_byte(&(timer_active_ADDR[room][2])), timer_active[room][2]); return; case 8: //only sub menu point no option //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; case 9: //only sub menu point no option //call the function get_offon() to change the setting timer_active[room][3] = get_offon(25, room, timer_active[room][3]); Mem_updateByte(pgm_read_byte(&(timer_active_ADDR[room][3])), timer_active[room][3]); return; case 10: //only sub menu point no option //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; } } } }
Now we move down to the function
adj_season(). Here we need to add the update statements for the
EEPROM in the adjusting function:
void adj_seasons(){ byte subButton = 0; //set button var to 0 ac_periode[0][0] = get_Timer(29, ac_periode[0][0], 0, 13); //get the first value if(ac_periode[0][0] >= 0 && ac_periode[0][0] <= 12){ //check if it is within range if(ac_periode[0][0] == 12){ //predefine closing value ac_periode[0][1] = 1; ac_periode[0][1] = get_Timer(30, ac_periode[0][1], 1, 13); } else if(ac_periode[0][0] != 12){ ac_periode[0][1] = ac_periode[0][0] + 1; ac_periode[0][1] = get_Timer(30, ac_periode[0][1], ac_periode[0][1], 13); } if(ac_periode[0][1] >= 0 && ac_periode[0][1] <= 12){ ac_periode[1][0] = get_Timer(31, ac_periode[1][0], 0, 13); if(ac_periode[1][0] >= 0 && ac_periode[1][0] <= 12){ if(ac_periode[1][0] == 12){ ac_periode[1][1] = 1; ac_periode[1][1] = get_Timer(32, ac_periode[1][1], 1, 13); } else if(ac_periode[1][0] != 12){ ac_periode[1][1] = ac_periode[1][0] + 1; ac_periode[1][1] = get_Timer(32, ac_periode[1][1], ac_periode[0][1], 13); } if(ac_periode[1][1] >= 0 && ac_periode[1][1] <= 12){ ac_periode[2][0] = get_Timer(33, ac_periode[2][0], 0, 13); if(ac_periode[2][0] >= 0 && ac_periode[2][0] <= 12){ if(ac_periode[2][0] == 12){ ac_periode[2][1] = 1; ac_periode[2][1] = get_Timer(34, ac_periode[2][1], 1, 13); } else if(ac_periode[2][0] != 12){ ac_periode[2][1] = ac_periode[2][0] + 1; ac_periode[2][1] = get_Timer(34, ac_periode[2][1], ac_periode[2][1], 13); } if(ac_periode[2][1] >= 0 && ac_periode[2][1] <= 12){ ac_periode[3][0] = get_Timer(35, ac_periode[3][0], 0, 13); if(ac_periode[3][0] >= 0 && ac_periode[3][0] <= 12){ if(ac_periode[3][0] == 12){ ac_periode[3][1] = 1; ac_periode[3][1] = get_Timer(36, ac_periode[3][1], 1, 13); } else if(ac_periode[3][0] != 12){ ac_periode[3][1] = ac_periode[2][0] + 1; ac_periode[3][1] = get_Timer(36, ac_periode[3][1], ac_periode[3][1], 13); } lcd.clear(); if(ac_periode[0][0] < 10) lcd.write(pgm_read_byte(&char_table[2])); //print 0 lcd.print(ac_periode[0][0]); lcd.print(" | "); if(ac_periode[0][1] < 10) lcd.write(pgm_read_byte(&char_table[2])); //print 0 lcd.print(ac_periode[0][1]); lcd.print(" "); if(ac_periode[1][0] < 10) lcd.write(pgm_read_byte(&char_table[2])); //print 0 lcd.print(ac_periode[1][0]); lcd.print(" | "); if(ac_periode[1][1] < 10) lcd.write(pgm_read_byte(&char_table[2])); //print 0 lcd.print(ac_periode[1][1]); lcd.setCursor(0, 1); if(ac_periode[2][0] < 10) lcd.write(pgm_read_byte(&char_table[2])); //print 0 lcd.print(ac_periode[2][0]); lcd.print(" | "); if(ac_periode[2][1] < 10) lcd.write(pgm_read_byte(&char_table[2])); //print 0 lcd.print(ac_periode[2][1]); lcd.print(" "); if(ac_periode[3][0] < 10) lcd.write(pgm_read_byte(&char_table[2])); //print 0 lcd.print(ac_periode[3][0]); lcd.print(" | "); if(ac_periode[3][1] < 10) lcd.write(pgm_read_byte(&char_table[2])); //print 0 lcd.print(ac_periode[3][1]); while(subButton != btnSelect){ lcd.clear(); lcd.print(strcpy_P(buffer_M, (char*)pgm_read_word(&(msg_table[1])))); //save the values //>>>>>>>>>>>>>ADDITION starts here<<<<<<<<<<<<< Mem_updateByte(pgm_read_byte(&(ac_periode_ADDR[0][0])), ac_periode[0][0]); Mem_updateByte(pgm_read_byte(&(ac_periode_ADDR[0][1])), ac_periode[0][1]); Mem_updateByte(pgm_read_byte(&(ac_periode_ADDR[1][0])), ac_periode[1][0]); Mem_updateByte(pgm_read_byte(&(ac_periode_ADDR[1][1])), ac_periode[1][1]); Mem_updateByte(pgm_read_byte(&(ac_periode_ADDR[2][0])), ac_periode[2][0]); Mem_updateByte(pgm_read_byte(&(ac_periode_ADDR[2][1])), ac_periode[2][1]); Mem_updateByte(pgm_read_byte(&(ac_periode_ADDR[3][0])), ac_periode[3][0]); Mem_updateByte(pgm_read_byte(&(ac_periode_ADDR[3][1])), ac_periode[3][1]); //>>>>>>>>>>>>>Addition ends here<<<<<<<<<<<<<< delay(1000); return; } } } } } } } } }
The same goes for the function
get_setTime(). Even here we need to ad the update statements in to
the adjusting function:
byte get_setTime( byte onTimeH, byte onTimeM, byte offTimeH, byte offTimeM, byte room, byte timer){ byte subButton = 0; onTimeH = get_Timer(13, onTimeH, 0, 24); if(onTimeH >= 0 && onTimeH < 24){ onTimeM = get_Timer(14, onTimeM, 0, 60); if(onTimeM < 60){ offTimeH = get_Timer(15, offTimeH, 0, 24); if(offTimeH >= 0 && offTimeH < 24){ offTimeM = get_Timer(16, offTimeM, 0, 60); if(offTimeM < 60){ lcd.clear(); lcd.print(strcpy_P(buffer_M, (char*)pgm_read_word(&(msg_table[6])))); lcd.setCursor(0, 1); if(onTimeH < 10) lcd.write(pgm_read_byte(&char_table[2])); //print 0 lcd.print(onTimeH); lcd.write(pgm_read_byte(&char_table[3])); //print seperator if(onTimeM < 10) lcd.write(pgm_read_byte(&char_table[2])); //print 0 lcd.print(onTimeM); lcd.setCursor(11, 1); if(offTimeH < 10) lcd.write(pgm_read_byte(&char_table[2])); //print 0 lcd.print(offTimeH); lcd.write(pgm_read_byte(&char_table[3])); //print seperator if(offTimeM < 10) lcd.write(pgm_read_byte(&char_table[2])); //print 0 lcd.print(offTimeM); while(subButton != btnSelect){ subButton = read_act_buttons(); if(subButton == btnMenu) return 0; if(subButton == btnSelect){ lcd.clear(); lcd.print(strcpy_P(buffer_M, (char*)pgm_read_word(&(msg_table[1])))); delay(1000); Mem_updateByte(pgm_read_byte(&(room_timers_ADDR[room][timer][0])), onTimeH); //<<<<<<<<<<<<<ADD<<<<<<<<<<<<<< room_timers[room][timer][0] = onTimeH; Mem_updateByte(pgm_read_byte(&(room_timers_ADDR[room][timer][1])), onTimeM); //<<<<<<<<<<<<<ADD<<<<<<<<<<<<< room_timers[room][timer][1] = onTimeM; Mem_updateByte(pgm_read_byte(&(room_timers_ADDR[room][timer][2])), offTimeH); //<<<<<<<<<<<<<ADD<<<<<<<<<<<<<< room_timers[room][timer][2] = offTimeH; Mem_updateByte(pgm_read_byte(&(room_timers_ADDR[room][timer][3])), offTimeM); //<<<<<<<<<<<<<ADD<<<<<<<<<<<<< room_timers[room][timer][3] = offTimeM; return 0; } } } } } } }
No comments:
Post a Comment