void circularList_incrementBy(byte *value, byte minimun, byte maximun, byte incrementBy) { if (*value+incrementBy > maximun) *value = minimun; else *value = *value+incrementBy; } // decrement the value of a variable using minimun and maximun limits void circularList_decrementBy(byte *value, byte minimun, byte maximun, byte decrementBy) { if ((*value < minimun) || (*value < decrementBy)) *value = maximun; else *value = *value-decrementBy; } // increment the value of a variable using minimun and maximun limits void circularList_incrementBy(unsigned int *value, unsigned int minimun, unsigned int maximun, byte incrementBy) { if (*value+incrementBy > maximun) *value = minimun; else *value = *value+incrementBy; } // decrement the value of a variable using minimun and maximun limits void circularList_decrementBy(unsigned int *value, unsigned int minimun, unsigned int maximun, byte decrementBy) { if ((*value < minimun) || (*value < decrementBy)) *value = maximun; else *value = *value-decrementBy; } void circularList_incrementBy_ASCII(char *value) { if (*value >= 122) *value = 32; else if (*value <= 32) *value = 48; else if (*value == 57) *value = 65; else if (*value == 90) *value = 97; else *value = *value + 1; } void circularList_decrementBy_ASCII(char *value) { if (*value <= 32) *value = 122; else if (*value <= 48) *value = 32; else if (*value == 65) *value = 57; else if (*value == 97) *value = 90; else *value = *value - 1; } //Pantalla principal. void controller_run(){ lcd.clear(); do{ keyboard_scan(); lcd.setCursor(0, 0); level_bat(batmin,batmax); lcd.setCursor(0, 1); lcd.print("TC: "); display_time(timeseconds); lcd.print(":"); if (frame<10) lcd.print("0"); lcd.print(frame); if(lastKey==KEY_C) backlight_toggle(); } while ((lastKey==NO_KEY)||(lastKey==KEY_C)); controller_showMainMenu(); } // Menu principal void controller_showMainMenu(){ byte currentOption = 0; for(boolean exit = false;!exit;){ display_printTitle(MSG_MAIN_MENU); //MSG_MAIN_MENU //display_printEnumeration(currentOption, &MSG_SHOWMAINMENU[currentOption + 1]); if(currentOption==0) display_printEnumeration(0, MSG_SYSTEM_CONFIG); if(currentOption==1) display_printEnumeration(1, MSG_GRAB_VIDEO); if(currentOption==2) display_printEnumeration(2, MSG_CAPT_FOTO); keyboard_waitForAnyKey(); if(lastKey==KEY_A) circularList_decrementBy(¤tOption, 0, 2, 1); if(lastKey==KEY_B) circularList_incrementBy(¤tOption, 0, 2, 1); if(lastKey==KEY_C) exit = true; if(lastKey==KEY_D) { if(currentOption==0) controller_showSystemConfig(); if(currentOption==1) controller_showVideoMenu(); if(currentOption==2) controller_showPhotoMenu(); } } } void controller_VideoSelect(){ byte currentOption = 0; unsigned int address_model; for(boolean exit = false;!exit;) { display_printTitle(MSG_MODEL); if (system_num_models>0) { if(currentOption < system_num_models){ address_model = EEI2C_ADDR_MODELS + 80*currentOption; display_model_EEPROM(address_model); } keyboard_waitForAnyKey(); if(lastKey==KEY_A) circularList_decrementBy(¤tOption, 0, system_num_models - 1, 1); if(lastKey==KEY_B) circularList_incrementBy(¤tOption, 0, system_num_models - 1, 1); if(lastKey==KEY_C) { exit = true; } if(lastKey==KEY_D) { system_sel_model=currentOption; config_saveBackup_system(); } } else { lcd.print(F("Vacio")); keyboard_waitForAnyKey(); if(lastKey==KEY_C) { exit = true; } } } } // Menu de Video void controller_showVideoMenu(){ byte currentOption = 0; for(boolean exit = false;!exit;){ display_printTitle(MSG_GRAB_VIDEO); // Show menu option if (currentOption==0) { display_print_Model();} else if (currentOption==1) {display_print(MSG_MODE); if(system_mode) display_print(MSG_LANC); else display_print(MSG_IR);} else if (currentOption==2) {lcd.print(F("TT: ")); display_time(timetotalvideo);} else if (currentOption==3) {lcd.print(F("TR: ")); display_time(timerecvideo);} else if (currentOption==4) {lcd.print(F("TP: ")); display_time(timepausevideo);} else if (currentOption==5) {if(!start_video) lcd.print(F("Iniciar")); else lcd.print(F("Parar"));} keyboard_waitForAnyKey(); if(lastKey==KEY_A) circularList_decrementBy(¤tOption, 0, 5, 1); if(lastKey==KEY_B) circularList_incrementBy(¤tOption, 0, 5, 1); if(lastKey==KEY_C) { exit = true; } if(lastKey==KEY_D) { if(currentOption==0) controller_VideoSelect(); if(currentOption==1) {system_mode=!system_mode; config_saveBackup_system();} if(currentOption==2) edit_time(&timetotalvideo); if(currentOption==3) edit_time(&timerecvideo); if(currentOption==4) edit_time(&timepausevideo); if(currentOption==5) { if(!start_video) { timecode=0; timeseconds = 0; timeseconds_next = 0; frames_ant=timecode; frame = 0; timeant = 0; frec=true; if (system_mode) { Serial3.println(); delay(100); } bit_count = 0; morse_count = -1; start_video=true; st_time = true; digitalWrite(red, LOW); digitalWrite(green, HIGH); } else { start_video=false; st_time = false; digitalWrite(red, HIGH); digitalWrite(green, HIGH); digitalWrite(aud,LOW); digitalWrite(lamp,LOW); if (system_useSpeaker)digitalWrite(PINS_BUZZER,LOW); if (system_mode) { Serial3.println(); delay(100); Serial3.println(lancstop, HEX); } else irsend.sendNEC(remotestop, 32); } } } } } // Menu de foto void controller_showPhotoMenu(){ byte currentOption = 0; for(boolean exit = false;!exit;){ display_printTitle(MSG_CAPT_FOTO); if (currentOption==0) {lcd.print(F("TT: ")); display_time(timetotalphoto);} else if (currentOption==1) {lcd.print(F("TF: ")); display_time(timeflash);} else if (currentOption==2) {if(!start_photo) lcd.print(F("Iniciar")); else lcd.print(F("Parar"));} keyboard_waitForAnyKey(); if(lastKey==KEY_A) circularList_decrementBy(¤tOption, 0, 2, 1); if(lastKey==KEY_B) circularList_incrementBy(¤tOption, 0, 2, 1); if(lastKey==KEY_C) { config_saveBackup_system(); exit = true; } if(lastKey==KEY_D) { if(currentOption==0) edit_time(&timetotalphoto); if(currentOption==1) edit_time(&timeflash); if(currentOption==2) { if(!start_photo) { timecode=0; timeseconds = 0; frame = 0; //lanc.println(lancrec, HEX); start_photo=true; } else { start_photo=false; //lanc.println(); delay(100); //lanc.println(lancstop, HEX); } } } } } // Menu de Configuracion void controller_showSystemConfig(){ byte currentOption = 0; for(boolean exit = false;!exit;){ display_printTitle(MSG_SYSTEM_CONFIG); // Show menu option if (currentOption==0) { display_print(MSG_BACKLIGHT); display_printBoolean(system_useBacklight); } else if (currentOption==1) { display_print(MSG_SPEAKER); display_printBoolean(system_useSpeaker); } else if (currentOption==2){ display_print(MSG_VOL); if (system_vol>99)lcd.setCursor(12, 1); else if (system_vol>9)lcd.setCursor(13, 1); else lcd.setCursor(14, 1);lcd.print(system_vol); lcd.print("%");} else if (currentOption==3){ display_print(MSG_CFG_VIDEO); } else if (currentOption==4){ display_print(MSG_CFG_NETWORK); } else if (currentOption==5){ display_print(MSG_VERSION); } keyboard_waitForAnyKey(); if(lastKey==KEY_A) circularList_decrementBy(¤tOption, 0, 5, 1); if(lastKey==KEY_B) circularList_incrementBy(¤tOption, 0, 5, 1); if(lastKey==KEY_C) { config_saveBackup_system(); exit = true; } if(lastKey==KEY_D) { if(currentOption==0) backlight_toggle(); if(currentOption==1) system_useSpeaker = !system_useSpeaker; if(currentOption==2) controller_vol(); if(currentOption==3) controller_videoConfig(); if(currentOption==4) controller_cfg_network(); if(currentOption==5) ver_version(); } } } void controller_vol(){ unsigned int address_model; for(boolean exit = false;!exit;){ display_printTitle(MSG_VOL); if (system_vol>99)lcd.setCursor(12, 1); else if (system_vol>9)lcd.setCursor(13, 1); else lcd.setCursor(14, 1); lcd.print(system_vol); lcd.print("%"); keyboard_waitForAnyKey(); if(lastKey==KEY_A) { if (system_vol<100) system_vol++; writeMCP(mcp, 0x00, map(system_vol, 0, 100, 0, 255));} if(lastKey==KEY_B) { if (system_vol>0)system_vol--; writeMCP(mcp, 0x00, map(system_vol, 0, 100, 0, 255));} if(lastKey==KEY_C) { config_saveBackup_system(); exit = true; } } } //Seleccion de modelo de Camara void controller_videoConfig(){ byte currentOption = 0; unsigned int address_model; for(boolean exit = false;!exit;){ display_printTitle(MSG_CFG_VIDEO); // Show menu option if (currentOption==system_num_models) { display_print(MSG_NEW_MODEL); address_model = EEI2C_ADDR_MODELS + 80*currentOption; } else if(currentOption < system_num_models){ address_model = EEI2C_ADDR_MODELS + 80*currentOption; display_model_EEPROM(address_model); } else if(currentOption==system_num_models + 1) display_print(MSG_ERASE_MODEL); keyboard_waitForAnyKey(); if(lastKey==KEY_A) circularList_decrementBy(¤tOption, 0, system_num_models + 1, 1); if(lastKey==KEY_B) circularList_incrementBy(¤tOption, 0, system_num_models + 1, 1); if(lastKey==KEY_C) { /*config_saveBackup_system()*/; exit = true; } if(lastKey==KEY_D) { if (currentOption < system_num_models)controller_videoModel(address_model); if (currentOption == system_num_models) {clear_model(address_model); system_num_models = system_num_models + 1; controller_videoModel(address_model);} if (currentOption == system_num_models + 1) {if (system_num_models>0){remove_model(); currentOption=0;}}; } } } //Control de los diferentes modelos (Editar, borrar, etc) void controller_videoModel(long int address_model){ byte currentOption = 0; unsigned long temp_remote; unsigned int temp_address; boolean print_ir = false; for(boolean exit = false;!exit;){ lcd.clear(); // Show menu option if (currentOption==0) { print_ir = false; display_printTitle(MSG_MODEL); display_model_EEPROM(address_model);} if (currentOption==1) { display_printTitle(MSG_STOP_REMOTE); temp_address = address_model+16; if (print_ir == false) { remotestop = display_printEEPROM(temp_address); } else { saveEEPROM(results.value,temp_address); temp_remote = display_printEEPROM(temp_address); print_ir = false; } } if (currentOption==2) { display_printTitle(MSG_REC_REMOTE); temp_address = address_model+32; if (print_ir == false) { temp_remote=display_printEEPROM(temp_address); } else { saveEEPROM(results.value,temp_address); remoterec=display_printEEPROM(temp_address); print_ir = false; } } if (currentOption==3) { print_ir = false; display_printTitle(MSG_STOP_LANC); temp_address = address_model+48; display_printEEPROM(temp_address); } if (currentOption==4) { print_ir = false; display_printTitle(MSG_REC_LANC); temp_address = address_model+64; display_printEEPROM(temp_address); } keyboard_IR(&print_ir); if(lastKey==KEY_A) circularList_decrementBy(¤tOption, 0, 4, 1); if(lastKey==KEY_B) circularList_incrementBy(¤tOption, 0, 4, 1); if(lastKey==KEY_C) {exit = true; config_saveBackup_system();} if(lastKey==KEY_D) { if(currentOption==0) edit_name(address_model); if(currentOption==1) irsend.sendNEC(temp_remote, 32); if(currentOption==2) irsend.sendNEC(temp_remote, 32); if(currentOption==3) edit_code(temp_address); if(currentOption==4) edit_code(temp_address); irrecv.enableIRIn(); } } } void remove_model(){ byte currentOption = 0; unsigned int address_model; for(boolean exit = false;!exit;){ display_printTitle(MSG_ERASE_MODEL); if(currentOption < system_num_models){ address_model = EEI2C_ADDR_MODELS + 80*currentOption; display_model_EEPROM(address_model); } keyboard_waitForAnyKey(); if(lastKey==KEY_A) circularList_decrementBy(¤tOption, 0, system_num_models-1, 1); if(lastKey==KEY_B) circularList_incrementBy(¤tOption, 0, system_num_models-1, 1); if(lastKey==KEY_C) exit = true; if(lastKey==KEY_D) {erase_model(currentOption); currentOption--; exit = true;} } } void edit_name(long int address_model){ byte pos=0; char currentOption = readEEPROM(eeprom, address_model+pos); for(boolean exit = false;!exit;){ writeEEPROM(eeprom, address_model + pos, currentOption); display_printTitle(MSG_EDIT_NAME); //MSG_EDIT_NAME display_model_EEPROM(address_model); keyboard_waitForAnyKey(); if(lastKey==KEY_A) circularList_decrementBy_ASCII(¤tOption); if(lastKey==KEY_B) circularList_incrementBy_ASCII(¤tOption); if(lastKey==KEY_C) {exit = true;} if(lastKey==KEY_D) {pos=pos+1; currentOption=readEEPROM(eeprom, address_model+pos);} } } void edit_code(long int address_model){ byte pos=0; byte currentOption = readEEPROM(eeprom, address_model); for(boolean exit = false;!exit;){ if (pos < 2) writeEEPROM(eeprom, address_model + pos, currentOption); writeEEPROM(eeprom, address_model + 2, 0x0D); display_printTitle(MSG_EDIT_LANC); display_printEEPROM(address_model); keyboard_waitForAnyKey(); if(lastKey==KEY_A) circularList_incrementBy(¤tOption, 0, 255, 1); if(lastKey==KEY_B) circularList_decrementBy(¤tOption, 0, 255, 1); if(lastKey==KEY_C) {exit = true;} if(lastKey==KEY_D) { pos=pos+1; currentOption = readEEPROM(eeprom, address_model + pos); if(pos>=2) { //lanc.print(readEEPROM(eeprom, address_model),HEX); lanc.println(readEEPROM(eeprom, address_model+1),HEX); int lanctemp = word(readEEPROM(eeprom, address_model),readEEPROM(eeprom, address_model + 1)); Serial3.println(lanctemp, HEX); //Serial.println(lanctemp, HEX); } } } } void edit_pass(){ byte pos=0; char currentOption = pass[pos]; for(boolean exit = false;!exit;){ pass[pos]=currentOption; display_printTitle(MSG_EDIT_PASS); lcd.print(pass); keyboard_waitForAnyKey(); if(lastKey==KEY_A) circularList_decrementBy_ASCII(¤tOption); if(lastKey==KEY_B) circularList_incrementBy_ASCII(¤tOption); if(lastKey==KEY_C) {/*pass[pos+1]='\x00';*/ exit = true;} if(lastKey==KEY_D) {pos=pos+1; currentOption=pass[pos];} } } void edit_time(unsigned long *time){ long int currentOption = 3600; int pos=0; for(boolean exit = false;!exit;){ display_printTitle(MSG_EDIT_TIME); display_time(*time) ; keyboard_waitForAnyKey(); if(lastKey==KEY_A) *time=*time+currentOption; else if(lastKey==KEY_B) {if (*time1) circularList_decrementBy(¤tOption, 0, nets-1, 1); if(lastKey==KEY_B) if (nets>1) circularList_incrementBy(¤tOption, 0, nets-1, 1); if(lastKey==KEY_C) { config_saveBackup_system(); exit = true; } if(lastKey==KEY_D) { char* ssid_temp = networks.ssid[currentOption]; for(int i=0; i<32; i++) ssid[i]='\x00'; for(int i=0; i