157 lines
4.4 KiB
Arduino
157 lines
4.4 KiB
Arduino
|
#define LANGUAGE_FILE "language_ES.h"
|
||
|
#include <SoftwareSerial.h>
|
||
|
#include <EEPROM.h>
|
||
|
#include <Wire.h> //I2C library
|
||
|
#include "LiquidCrystalShift.h"
|
||
|
#include "IRremote.h"
|
||
|
#include "constants.h"
|
||
|
#include "WiFlyUDP.h"
|
||
|
#include "TimerOne.h"
|
||
|
#include "pin_definition.h"
|
||
|
#include <avr/pgmspace.h>
|
||
|
|
||
|
#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;
|
||
|
boolean system_useSpeaker;
|
||
|
boolean frec=true;
|
||
|
boolean fpau=false;
|
||
|
unsigned int system_num_models;
|
||
|
unsigned int system_sel_model;
|
||
|
byte system_baudrate;
|
||
|
byte system_id = 0;
|
||
|
|
||
|
unsigned long remoterec;
|
||
|
unsigned long remotestop;
|
||
|
unsigned int lancrec;
|
||
|
unsigned int lancstop;
|
||
|
|
||
|
byte frame = 0;
|
||
|
byte seconds = 0;
|
||
|
byte minutes = 0;
|
||
|
byte hours = 0;
|
||
|
byte bit_count = 0;
|
||
|
byte morse_count = 0;
|
||
|
|
||
|
|
||
|
unsigned long timecode = 0;
|
||
|
unsigned long timeseconds = 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;
|
||
|
unsigned int rep = 1;
|
||
|
|
||
|
char ssid[33] = "";
|
||
|
char pass[33] = "";
|
||
|
uint16_t remote_Port;
|
||
|
uint16_t local_Port;
|
||
|
//char* ip_host = "172.26.0.187";
|
||
|
char* ip_host = "192.168.0.3";
|
||
|
|
||
|
WiFlyUDP udp(&Serial);
|
||
|
network_results networks;
|
||
|
|
||
|
void timerIsr()
|
||
|
{
|
||
|
if (start_video)
|
||
|
{
|
||
|
timecode++;
|
||
|
frame++;
|
||
|
if (frame>sistema) {frame=0; seconds++; timeseconds++; }
|
||
|
if (seconds>59) {seconds = 0; minutes++;}
|
||
|
if (minutes>59) {minutes = 0; hours++;}
|
||
|
if (hours>99) hours = 0;
|
||
|
if (timeseconds==(timetotalvideo-1)) lanc.println();
|
||
|
else if (timeseconds==(timetotalvideo)) {start_video=false; digitalWrite(PINS_BUZZER,LOW); lanc.println(lancstop,HEX);}
|
||
|
else if (timeseconds==(timeant-1)) lanc.println();
|
||
|
else if (timeseconds==timeant) { if (frec){lanc.println(lancrec,HEX); bit_count = 0; frames_ant=timecode; morse_count++;} if (fpau){lanc.println(lancstop,HEX);} frec=!frec; fpau=!fpau; timeant = timeant + (timepausevideo*frec + timerecvideo*fpau);}
|
||
|
if ((frec==false)&&(bit_count<16)&&((timecode-frames_ant)==1)){ frames_ant=timecode; uint16_t temp = (MORSE[morse_count]>>(15-bit_count))&0x0001; digitalWrite(PINS_BUZZER,temp); bit_count++;}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
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
|
||
|
}
|
||
|
|
||
|
void loop() {
|
||
|
controller_run();
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|