495 lines
15 KiB
C++
495 lines
15 KiB
C++
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: ");
|
|
|
|
int temp = hours;
|
|
if (temp<10) lcd.print("0");
|
|
lcd.print(temp);
|
|
lcd.print(":");
|
|
|
|
temp = minutes;
|
|
if (temp<10) lcd.print("0");
|
|
lcd.print(temp);
|
|
lcd.print(":");
|
|
|
|
temp = seconds;
|
|
if (temp<10) lcd.print("0");
|
|
lcd.print(temp);
|
|
lcd.print(":");
|
|
|
|
temp = frame;
|
|
if (temp<10) lcd.print("0");
|
|
lcd.print(temp);
|
|
|
|
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);
|
|
|
|
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_showIntervalMenu();
|
|
if(currentOption==2); //controller_showAudioTriggerMenu();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// 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) { lcd.print(MSG_BACKLIGHT); display_printBoolean(system_useBacklight); }
|
|
if (currentOption==1) { lcd.print(MSG_SPEAKER); display_printBoolean(system_useSpeaker); }
|
|
if (currentOption==2) { lcd.print(MSG_CFG_VIDEO); }
|
|
if (currentOption==3) { lcd.print(MSG_CFG_NETWORK); }
|
|
if (currentOption==4) { lcd.print(MSG_VERSION); }
|
|
|
|
keyboard_waitForAnyKey();
|
|
|
|
if(lastKey==KEY_A) circularList_decrementBy(¤tOption, 0, 4, 1);
|
|
if(lastKey==KEY_B) circularList_incrementBy(¤tOption, 0, 4, 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_videoConfig();
|
|
if(currentOption==3) controller_cfg_network();
|
|
if(currentOption==4) ver_version();
|
|
}
|
|
}
|
|
}
|
|
|
|
//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_models)
|
|
{
|
|
lcd.print(MSG_NEW_MODEL);
|
|
address_model = EEI2C_ADDR_MODELS + 80*currentOption;
|
|
}
|
|
else if(currentOption < system_models){
|
|
address_model = EEI2C_ADDR_MODELS + 80*currentOption;
|
|
display_model_EEPROM(address_model);
|
|
}
|
|
else if(currentOption==system_models + 1) lcd.print("Borrar modelo");
|
|
|
|
keyboard_waitForAnyKey();
|
|
|
|
if(lastKey==KEY_A) circularList_decrementBy(¤tOption, 0, system_models + 1, 1);
|
|
if(lastKey==KEY_B) circularList_incrementBy(¤tOption, 0, system_models + 1, 1);
|
|
if(lastKey==KEY_C) { /*config_saveBackup_system()*/; exit = true; }
|
|
if(lastKey==KEY_D) {
|
|
if (currentOption < system_models)controller_videoModel(address_model);
|
|
if (currentOption == system_models) {clear_model(address_model); system_models = system_models + 1; controller_videoModel(address_model);}
|
|
if (currentOption == system_models + 1) {remove_model(); currentOption=0;};
|
|
}
|
|
}
|
|
}
|
|
|
|
//Control de los diferentes modelos (Editar, borrar, etc)
|
|
|
|
void controller_videoModel(long int address_model){
|
|
|
|
byte currentOption = 0;
|
|
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("Stop remote");
|
|
temp_address = address_model+16;
|
|
if (print_ir == false)
|
|
{
|
|
remotestop = display_printEEPROM(temp_address);
|
|
}
|
|
else
|
|
{
|
|
saveEEPROM(results.value,temp_address);
|
|
remotestop = display_printEEPROM(temp_address);
|
|
print_ir = false;
|
|
}
|
|
}
|
|
if (currentOption==2) {
|
|
display_printTitle("Rec remote");
|
|
temp_address = address_model+32;
|
|
if (print_ir == false)
|
|
{
|
|
remoterec=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("Stop lanc");
|
|
temp_address = address_model+48;
|
|
lancstop = display_printEEPROM(temp_address);
|
|
}
|
|
if (currentOption==4) {
|
|
print_ir = false;
|
|
display_printTitle("Rec lanc");
|
|
temp_address = address_model+64;
|
|
lancrec = 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(remotestop, 32);
|
|
if(currentOption==2) irsend.sendNEC(remoterec, 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("Borrar modelo");
|
|
if(currentOption < system_models){
|
|
address_model = EEI2C_ADDR_MODELS + 80*currentOption;
|
|
display_model_EEPROM(address_model);
|
|
}
|
|
keyboard_waitForAnyKey();
|
|
if(lastKey==KEY_A) circularList_decrementBy(¤tOption, 0, system_models-1, 1);
|
|
if(lastKey==KEY_B) circularList_incrementBy(¤tOption, 0, system_models-1, 1);
|
|
if(lastKey==KEY_C) exit = true;
|
|
if(lastKey==KEY_D) {erase_model(currentOption); currentOption--;};
|
|
}
|
|
}
|
|
|
|
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);
|
|
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);
|
|
//writeEEPROM(eeprom, address_model, currentOption);
|
|
display_printTitle(MSG_EDIT_LANC);
|
|
display_printEEPROM(address_model);
|
|
//lcd.print(currentOption,HEX);
|
|
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);}}
|
|
}
|
|
}
|
|
|
|
void edit_pass(){
|
|
byte pos=0;
|
|
char currentOption = pass[pos];
|
|
for(boolean exit = false;!exit;){
|
|
pass[pos]=currentOption;
|
|
display_printTitle(MSG_EDIT_NAME);
|
|
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_id(){
|
|
byte pos=0;
|
|
for(boolean exit = false;!exit;){
|
|
//writeEEPROM(eeprom, address_model, currentOption);
|
|
display_printTitle(MSG_EDIT_ID);
|
|
lcd.print(id,HEX);
|
|
keyboard_waitForAnyKey();
|
|
if(lastKey==KEY_A) circularList_incrementBy(&id, 0, 255, 1);
|
|
if(lastKey==KEY_B) circularList_decrementBy(&id, 0, 255, 1);
|
|
if(lastKey==KEY_C) {exit = true;}
|
|
}
|
|
}
|
|
|
|
//Visualizacion de la version del sistema operativo
|
|
|
|
void ver_version(){
|
|
display_vdossier();
|
|
for(boolean exit = false;!exit;){
|
|
keyboard_waitForAnyKey();
|
|
if(lastKey==KEY_C) { exit = true; }
|
|
}
|
|
}
|
|
|
|
//Menu de Red
|
|
|
|
void controller_cfg_network(){
|
|
|
|
byte currentOption = 0;
|
|
|
|
for(boolean exit = false;!exit;){
|
|
|
|
display_printTitle(MSG_CFG_NETWORK);
|
|
|
|
// Show menu option
|
|
if (currentOption==0) { lcd.print(MSG_ID);}
|
|
if (currentOption==1) { lcd.print(MSG_IP);}
|
|
if (currentOption==2) { lcd.print(MSG_NETWORK);}
|
|
if (currentOption==3) { lcd.print(MSG_NEW_NETWORK);}
|
|
if (currentOption==4) { lcd.print(MSG_BAUDRATE); }
|
|
|
|
keyboard_waitForAnyKey();
|
|
|
|
if(lastKey==KEY_A) circularList_decrementBy(¤tOption, 0, 4, 1);
|
|
if(lastKey==KEY_B) circularList_incrementBy(¤tOption, 0, 4, 1);
|
|
if(lastKey==KEY_C) { config_saveBackup_system(); exit = true; }
|
|
if(lastKey==KEY_D) {
|
|
|
|
if(currentOption==0) controller_id();
|
|
if(currentOption==1) controller_ip();
|
|
if(currentOption==2) controller_network();
|
|
if(currentOption==3) controller_new_network();
|
|
if(currentOption==4) controller_baudrate();
|
|
}
|
|
}
|
|
}
|
|
|
|
void controller_id(){
|
|
for(boolean exit = false;!exit;){
|
|
display_printTitle(MSG_ID);
|
|
lcd.print(id, HEX);
|
|
keyboard_waitForAnyKey();
|
|
if(lastKey==KEY_C) { exit = true; }
|
|
if(lastKey==KEY_D) edit_id();
|
|
}
|
|
}
|
|
|
|
void controller_ip(){
|
|
for(boolean exit = false;!exit;){
|
|
display_printTitle(MSG_IP);
|
|
lcd.print(udp.ip());
|
|
keyboard_waitForAnyKey();
|
|
if(lastKey==KEY_C) { exit = true; }
|
|
}
|
|
}
|
|
|
|
void controller_baudrate(){
|
|
byte currentOption = 0;
|
|
while (currentOption<4)
|
|
{
|
|
if (baudrate==vel[currentOption]) break;
|
|
else currentOption++;
|
|
}
|
|
for(boolean exit = false;!exit;){
|
|
display_printTitle(MSG_BAUDRATE);
|
|
lcd.print(vel[currentOption]);
|
|
keyboard_waitForAnyKey();
|
|
if(lastKey==KEY_A) circularList_decrementBy(¤tOption, 0, 3, 1);
|
|
if(lastKey==KEY_B) circularList_incrementBy(¤tOption, 0, 3, 1);
|
|
if(lastKey==KEY_C) { exit = true; }
|
|
if(lastKey==KEY_D)
|
|
{
|
|
long baudrate_temp=vel[currentOption];
|
|
if (udp.baudrate(baudrate_temp))
|
|
{
|
|
baudrate=baudrate_temp;
|
|
Serial.begin(baudrate);
|
|
lcd.clear();
|
|
lcd.print("vel. cambiada");
|
|
delay(2000);
|
|
}
|
|
else
|
|
{
|
|
lcd.clear();
|
|
lcd.print("Error cambiando");
|
|
delay(2000);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void controller_network(){
|
|
byte currentOption = 0;
|
|
for(boolean exit = false;!exit;){
|
|
display_printTitle(MSG_NETWORK);
|
|
|
|
// Show menu option
|
|
if (currentOption==0) { lcd.print("Ssid");}
|
|
if (currentOption==1) { lcd.print("Passphrase");}
|
|
if (currentOption==2) { lcd.print("Reconectar");}
|
|
|
|
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_ssid();
|
|
if(currentOption==1) controller_pass();
|
|
if(currentOption==2) display_WiFlyConnecting(&baudrate);
|
|
}
|
|
}
|
|
}
|
|
|
|
void controller_ssid(){
|
|
for(boolean exit = false;!exit;){
|
|
display_printTitle("Ssid");
|
|
lcd.print(ssid);
|
|
keyboard_waitForAnyKey();
|
|
if(lastKey==KEY_C) exit = true;
|
|
}
|
|
}
|
|
|
|
void controller_pass(){
|
|
for(boolean exit = false;!exit;){
|
|
display_printTitle("Passphrase");
|
|
lcd.print(pass);
|
|
keyboard_waitForAnyKey();
|
|
if(lastKey==KEY_C) exit = true;
|
|
if(lastKey==KEY_D) edit_pass();
|
|
}
|
|
}
|
|
|
|
void controller_new_network(){
|
|
byte currentOption = 0;
|
|
network_results networks;
|
|
display_printTitle(MSG_NEW_NETWORK);
|
|
lcd.print("Buscando...");
|
|
byte nets = udp.scan(&networks);
|
|
if (nets == 0)
|
|
{
|
|
display_printTitle(MSG_NEW_NETWORK);
|
|
lcd.print("Sin redes");
|
|
for(boolean exit = false;!exit;){
|
|
keyboard_waitForAnyKey();
|
|
if(lastKey==KEY_C) { exit = true; }
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for(boolean exit = false;!exit;){
|
|
display_printTitle(MSG_NEW_NETWORK);
|
|
lcd.print(currentOption);
|
|
lcd.print(".");
|
|
lcd.print(networks.ssid[currentOption]);
|
|
keyboard_waitForAnyKey();
|
|
if(lastKey==KEY_A) if (nets>1) 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) { ssid = networks.ssid[currentOption]; for (int i=0; i<=32; i++) pass[i]=' '; pass[33]='\x00'; edit_pass();}
|
|
}
|
|
}
|
|
}
|
|
|