#define LANGUAGE_FILE "language_ES.h" #include #include #include //I2C library #include "LiquidCrystalShift.h" #include "IRremote.h" #include "constants.h" #include "WiFlyUDP.h" #include "TimerOne.h" #include "pin_definition.h" #include #include LANGUAGE_FILE // Global variables byte lastKey = NO_KEY; // Last key pressed boolean flagHoldKey = false; // Flag to ignore keys after a hold key boolean start_video = false; // Flag to ignore keys after a hold key boolean start_photo = false; // Flag to ignore keys after a hold key int batmax; // Nivel maximo de bateria int batmin; // Nivel minimo de bateria //Variables de configuracion boolean system_useBacklight; // Luz LCD ON/OFF boolean system_useSpeaker; // Speaker ON/OFF unsigned int system_num_models; // Numero de modelos en la EEPROM unsigned int system_sel_model; // Modelo de camara seleccionado byte system_baudrate; // Baudrate del Wifly byte system_id; // Identificador del sistema boolean system_mode; // Selector modo video/foto boolean frec=true; boolean read_serial=false; unsigned long remoterec; unsigned long remotestop; unsigned int lancrec; unsigned int lancstop; byte frame = 0; byte bit_count = 0; byte morse_count = 0; byte model_count = 0; byte byte_count = 0; unsigned long timecode = 0; unsigned long timeseconds = 0; unsigned long timeseconds_next = 0; unsigned long frames_ant=0; unsigned long timetotalvideo = 0; unsigned long timerecvideo = 0; unsigned long timepausevideo = 0; unsigned long timetotalphoto = 0; unsigned long timeflash = 0; unsigned long timeant = 0; unsigned long timeframe = 0; char ssid[33] = ""; char pass[33] = ""; uint16_t remote_Port; uint16_t local_Port; char ip_host[16] = ""; WiFlyUDP udp(&Serial); network_results networks; void timerIsr() { sei(); if(read_serial) { if(Serial.available()>0) { char inByte; inByte = Serial.read(); test_model(inByte); test_ip(inByte); test_rec(inByte); } } if (start_video) video_rec(); } boolean WiFly_detect(byte *baudrate) { boolean detect=false; byte baudrate_ini = *baudrate; Serial.begin(vel[*baudrate]); delay(100); detect = udp.enterCommandMode(); if (!detect) { circularList_incrementBy(&(*baudrate), 0, 3, 1); Serial.begin(vel[*baudrate]); while ((*baudrate!=baudrate_ini)&&(!detect)) { detect = udp.enterCommandMode(); if (!detect) { circularList_incrementBy(&(*baudrate), 0, 3, 1); Serial.begin(vel[*baudrate]); } } } return(detect); } void ini() { lanc.begin(9600); Wire.begin(); // Iniciar librerias i2c Timer1.initialize(1000000/sistema); // set a timer of length 1000000 microseconds (or 1 sec - or 1Hz) Timer1.attachInterrupt( timerIsr ); // attach the service routine here for(int i=0; i<=4; i++) { pinMode(bot[i], INPUT); digitalWrite(bot[i],HIGH); } pinMode(xbee_cts, INPUT); pinMode(PINS_BUZZER, OUTPUT); lcd.shiftWrite(red, HIGH); lcd.shiftWrite(green, HIGH); lcd.begin(16, 2); // set up the LCD's number of columns and rows: lcd.shiftWrite(LCD_L, LOW); config_init(); // EPRROM init calibrate_level_battery(); display_vdossier(); } void setup() { ini(); if(WiFly_detect(&system_baudrate)) { //display_WiFlyResetting(&system_baudrate); display_WiFlyConnecting(&system_baudrate); } else { lcd.clear(); display_print(MSG_FAIL_WIFLY); //MSG_FAIL_WIFLY/*7*/ delay(2000); } lcd.shiftWrite(LCD_L, !system_useBacklight); system_beep(200); irrecv.enableIRIn(); // Start the receiver read_serial=true; } void loop() { controller_run(); }