CODIGO FINAL PROYECTO

Dependencies:   mbed MMA8451Q

Committer:
matirodriguez
Date:
Wed Nov 20 13:14:55 2019 +0000
Revision:
0:1a9bfeb27157
CODIGO FINAL PROPYECTO;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
matirodriguez 0:1a9bfeb27157 1 #include "mbed.h"
matirodriguez 0:1a9bfeb27157 2 #include "MMA8451Q.h"
matirodriguez 0:1a9bfeb27157 3 #define MMA8451_I2C_ADDRESS (0x1d<<1)
matirodriguez 0:1a9bfeb27157 4 #define HABILITADO 1
matirodriguez 0:1a9bfeb27157 5 #define DESHABILITADO 2
matirodriguez 0:1a9bfeb27157 6 #define NADA 0
matirodriguez 0:1a9bfeb27157 7 #define PASOS_MINIMOS 16
matirodriguez 0:1a9bfeb27157 8 #define APP 5
matirodriguez 0:1a9bfeb27157 9 #define CONTROL 6
matirodriguez 0:1a9bfeb27157 10 #define LOOP 7
matirodriguez 0:1a9bfeb27157 11 #define DERECHA 0
matirodriguez 0:1a9bfeb27157 12 #define IZQUIERDA 1
matirodriguez 0:1a9bfeb27157 13 #define MOVIENDO 1
matirodriguez 0:1a9bfeb27157 14 #define QUIETO 0
matirodriguez 0:1a9bfeb27157 15 #define VALORES_MOTOR 1
matirodriguez 0:1a9bfeb27157 16 #define VELOCIDAD_MOTOR 2
matirodriguez 0:1a9bfeb27157 17 #define MODO_DE_CONTROL 3
matirodriguez 0:1a9bfeb27157 18 #define CONF_LOOP 4
matirodriguez 0:1a9bfeb27157 19 #define MAX_SLIDE 62755
matirodriguez 0:1a9bfeb27157 20 #define MAX_TILT 3150
matirodriguez 0:1a9bfeb27157 21 #define MAX_PAN 3200
matirodriguez 0:1a9bfeb27157 22 #define PUNTO_E 5
matirodriguez 0:1a9bfeb27157 23 #define TIME_LAPSE 8
matirodriguez 0:1a9bfeb27157 24
matirodriguez 0:1a9bfeb27157 25 /*
matirodriguez 0:1a9bfeb27157 26 Loop
matirodriguez 0:1a9bfeb27157 27
matirodriguez 0:1a9bfeb27157 28 */
matirodriguez 0:1a9bfeb27157 29
matirodriguez 0:1a9bfeb27157 30 enum {START,
matirodriguez 0:1a9bfeb27157 31 SLIDE,
matirodriguez 0:1a9bfeb27157 32 S1,
matirodriguez 0:1a9bfeb27157 33 S2,
matirodriguez 0:1a9bfeb27157 34 S3,
matirodriguez 0:1a9bfeb27157 35 TILT,
matirodriguez 0:1a9bfeb27157 36 T1,
matirodriguez 0:1a9bfeb27157 37 T2,
matirodriguez 0:1a9bfeb27157 38 T3,
matirodriguez 0:1a9bfeb27157 39 PAN,
matirodriguez 0:1a9bfeb27157 40 P1,
matirodriguez 0:1a9bfeb27157 41 P2,
matirodriguez 0:1a9bfeb27157 42 P3,
matirodriguez 0:1a9bfeb27157 43 BOTONES,
matirodriguez 0:1a9bfeb27157 44 B1,
matirodriguez 0:1a9bfeb27157 45 B2,
matirodriguez 0:1a9bfeb27157 46 CRC,
matirodriguez 0:1a9bfeb27157 47 FIN,
matirodriguez 0:1a9bfeb27157 48 V1,
matirodriguez 0:1a9bfeb27157 49 INICIO,
matirodriguez 0:1a9bfeb27157 50 V2,
matirodriguez 0:1a9bfeb27157 51 HAB_JOYSTICK,
matirodriguez 0:1a9bfeb27157 52 LOOP_HAB,
matirodriguez 0:1a9bfeb27157 53 L_DELAY1,
matirodriguez 0:1a9bfeb27157 54 L_DELAY2,
matirodriguez 0:1a9bfeb27157 55 LD_UNIDAD,
matirodriguez 0:1a9bfeb27157 56 L_TIMEOUT1,
matirodriguez 0:1a9bfeb27157 57 L_TIMEOUT2,
matirodriguez 0:1a9bfeb27157 58 LT_UNIDAD,
matirodriguez 0:1a9bfeb27157 59 PUNTOE,
matirodriguez 0:1a9bfeb27157 60 PRECISION,
matirodriguez 0:1a9bfeb27157 61 TIMELAPSE,
matirodriguez 0:1a9bfeb27157 62 T_LADO,
matirodriguez 0:1a9bfeb27157 63 T_DURACION,
matirodriguez 0:1a9bfeb27157 64 T_DURACION2,
matirodriguez 0:1a9bfeb27157 65 T_UNIDAD,
matirodriguez 0:1a9bfeb27157 66 T_MODO
matirodriguez 0:1a9bfeb27157 67 };
matirodriguez 0:1a9bfeb27157 68
matirodriguez 0:1a9bfeb27157 69 enum {
matirodriguez 0:1a9bfeb27157 70 ESPERO, PASO, DELAY, RIGHT, LEFT, HOLD
matirodriguez 0:1a9bfeb27157 71 };
matirodriguez 0:1a9bfeb27157 72
matirodriguez 0:1a9bfeb27157 73
matirodriguez 0:1a9bfeb27157 74 AnalogIn ana(PTB0);
matirodriguez 0:1a9bfeb27157 75
matirodriguez 0:1a9bfeb27157 76 // -------------- Manejo Slide
matirodriguez 0:1a9bfeb27157 77
matirodriguez 0:1a9bfeb27157 78 DigitalOut Slide_dir(PTC7);
matirodriguez 0:1a9bfeb27157 79 DigitalOut Slide_step(PTC0);
matirodriguez 0:1a9bfeb27157 80
matirodriguez 0:1a9bfeb27157 81 DigitalIn fc1(PTC13);
matirodriguez 0:1a9bfeb27157 82 DigitalIn fc2(PTC12);
matirodriguez 0:1a9bfeb27157 83
matirodriguez 0:1a9bfeb27157 84 void MAQ_VSlide(int velocidad_deseada, int direccion); //Maquina de estados que controlará el motor de slide por Velocidad ( usada por los joysticks )
matirodriguez 0:1a9bfeb27157 85 void timeoutVSlide(); // Funcion que será llamada por el Timeout que use para realizar los pasos del motor de slide
matirodriguez 0:1a9bfeb27157 86 void paso_VSlide(); // Funcion que será llamada por un ticker para que todos los pasos se realicen cada el mismo tiempo, y no dependiendo de la velocidad
matirodriguez 0:1a9bfeb27157 87
matirodriguez 0:1a9bfeb27157 88 Ticker ticker_VSlide; // Ticker que llamará la funcion paso_VSlide() cada 10ms
matirodriguez 0:1a9bfeb27157 89 Timeout VSlide; // Timeout que usaré para cambiar de estado en la maquina de control por velocidad
matirodriguez 0:1a9bfeb27157 90
matirodriguez 0:1a9bfeb27157 91 int estado_VSlide = ESPERO; // Variable que indica el estado en el que se encuentra la maquina de estados
matirodriguez 0:1a9bfeb27157 92 int hab_maq_VSlide = DESHABILITADO; // Habilitacion de dicha maquina de estados
matirodriguez 0:1a9bfeb27157 93 int timeout_VSlide = DESHABILITADO; // Variable que que se habilitará cuando el tiempo establecido en el Timeout se cumpla ( usada para cambiar de estado)
matirodriguez 0:1a9bfeb27157 94 int direccion_VSlide = DERECHA; // Variable que voy a usar para indicar la direccion que tendrá el giro del motor
matirodriguez 0:1a9bfeb27157 95 int velocidad_VSlide = 1; // Variable que voy a usar para indicar la velocidad a la que quiero que se mueva el motor
matirodriguez 0:1a9bfeb27157 96 volatile int incremento_VSlide = DESHABILITADO;// Variable que voy a usar para realizar los pasos siempre cada el mismo tiempo, y no cada vez mas rapido.
matirodriguez 0:1a9bfeb27157 97 int stop_VSlide = MOVIENDO; // Variable que me indicará si el motor se esta moviendo o esta quieto, para poder cambiar de modo SOLO cuando se encuente quieto
matirodriguez 0:1a9bfeb27157 98 int intensidad_VSlide = 10; // Variable que indica el que tan rapido es el multiplicador de la velocidad del joystick ( Varia de 1 (lento) a 10 (rapido))
matirodriguez 0:1a9bfeb27157 99
matirodriguez 0:1a9bfeb27157 100 // -------------- Manejo Tilt
matirodriguez 0:1a9bfeb27157 101
matirodriguez 0:1a9bfeb27157 102 DigitalOut Tilt_dir(PTC4);
matirodriguez 0:1a9bfeb27157 103 DigitalOut Tilt_step(PTC3);
matirodriguez 0:1a9bfeb27157 104
matirodriguez 0:1a9bfeb27157 105 DigitalIn opto_tilt(PTC2);
matirodriguez 0:1a9bfeb27157 106
matirodriguez 0:1a9bfeb27157 107 void MAQ_VTilt(int velocidad_deseada, int direccion); //Maquina de estados que controlará el motor de slide por Velocidad ( usada por los joysticks )
matirodriguez 0:1a9bfeb27157 108 void timeoutVTilt(); // Funcion que será llamada por el Timeout que use para realizar los pasos del motor de slide
matirodriguez 0:1a9bfeb27157 109 void paso_VTilt(); // Funcion que será llamada por un ticker para que todos los pasos se realicen cada el mismo tiempo, y no dependiendo de la velocidad
matirodriguez 0:1a9bfeb27157 110
matirodriguez 0:1a9bfeb27157 111 Ticker ticker_VTilt; // Ticker que llamará la funcion paso_VSlide() cada 10ms
matirodriguez 0:1a9bfeb27157 112 Timeout VTilt; // Timeout que usaré para cambiar de estado en la maquina de control por velocidad
matirodriguez 0:1a9bfeb27157 113
matirodriguez 0:1a9bfeb27157 114 int estado_VTilt = ESPERO; // Variable que indica el estado en el que se encuentra la maquina de estados
matirodriguez 0:1a9bfeb27157 115 int hab_maq_VTilt = DESHABILITADO; // Habilitacion de dicha maquina de estados
matirodriguez 0:1a9bfeb27157 116 int timeout_VTilt = DESHABILITADO; // Variable que que se habilitará cuando el tiempo establecido en el Timeout se cumpla ( usada para cambiar de estado)
matirodriguez 0:1a9bfeb27157 117 int direccion_VTilt = DERECHA; // Variable que voy a usar para indicar la direccion que tendrá el giro del motor
matirodriguez 0:1a9bfeb27157 118 int velocidad_VTilt = 1; // Variable que voy a usar para indicar la velocidad a la que quiero que se mueva el motor
matirodriguez 0:1a9bfeb27157 119 volatile int incremento_VTilt = DESHABILITADO;// Variable que voy a usar para realizar los pasos siempre cada el mismo tiempo, y no cada vez mas rapido.
matirodriguez 0:1a9bfeb27157 120 int stop_VTilt = MOVIENDO; // Variable que me indicará si el motor se esta moviendo o esta quieto, para poder cambiar de modo SOLO cuando se encuente quieto
matirodriguez 0:1a9bfeb27157 121 int intensidad_VTilt = 10; // Variable que indica el que tan rapido es el multiplicador de la velocidad del joystick ( Varia de 1 (lento) a 10 (rapido))
matirodriguez 0:1a9bfeb27157 122
matirodriguez 0:1a9bfeb27157 123 // -------------- Manejo Pan
matirodriguez 0:1a9bfeb27157 124
matirodriguez 0:1a9bfeb27157 125 DigitalOut Pan_dir(PTC6);
matirodriguez 0:1a9bfeb27157 126 DigitalOut Pan_step(PTC5);
matirodriguez 0:1a9bfeb27157 127
matirodriguez 0:1a9bfeb27157 128 DigitalIn opto_pan(PTC1);
matirodriguez 0:1a9bfeb27157 129
matirodriguez 0:1a9bfeb27157 130 void MAQ_VPan(int velocidad_deseada, int direccion); //Maquina de estados que controlará el motor de slide por Velocidad ( usada por los joysticks )
matirodriguez 0:1a9bfeb27157 131 void timeoutVPan(); // Funcion que será llamada por el Timeout que use para realizar los pasos del motor de slide
matirodriguez 0:1a9bfeb27157 132 void paso_VPan(); // Funcion que será llamada por un ticker para que todos los pasos se realicen cada el mismo tiempo, y no dependiendo de la velocidad
matirodriguez 0:1a9bfeb27157 133
matirodriguez 0:1a9bfeb27157 134 Ticker ticker_VPan; // Ticker que llamará la funcion paso_VSlide() cada 10ms
matirodriguez 0:1a9bfeb27157 135 Timeout VPan; // Timeout que usaré para cambiar de estado en la maquina de control por velocidad
matirodriguez 0:1a9bfeb27157 136
matirodriguez 0:1a9bfeb27157 137 int estado_VPan = ESPERO; // Variable que indica el estado en el que se encuentra la maquina de estados
matirodriguez 0:1a9bfeb27157 138 int hab_maq_VPan = DESHABILITADO; // Habilitacion de dicha maquina de estados
matirodriguez 0:1a9bfeb27157 139 int timeout_VPan = DESHABILITADO; // Variable que que se habilitará cuando el tiempo establecido en el Timeout se cumpla ( usada para cambiar de estado)
matirodriguez 0:1a9bfeb27157 140 int direccion_VPan = DERECHA; // Variable que voy a usar para indicar la direccion que tendrá el giro del motor
matirodriguez 0:1a9bfeb27157 141 int velocidad_VPan = 1; // Variable que voy a usar para indicar la velocidad a la que quiero que se mueva el motor
matirodriguez 0:1a9bfeb27157 142 volatile int incremento_VPan = DESHABILITADO;// Variable que voy a usar para realizar los pasos siempre cada el mismo tiempo, y no cada vez mas rapido.
matirodriguez 0:1a9bfeb27157 143 int stop_VPan = MOVIENDO; // Variable que me indicará si el motor se esta moviendo o esta quieto, para poder cambiar de modo SOLO cuando se encuente quieto
matirodriguez 0:1a9bfeb27157 144 int intensidad_VPan = 10; // Variable que indica el que tan rapido es el multiplicador de la velocidad del joystick ( Varia de 1 (lento) a 10 (rapido))
matirodriguez 0:1a9bfeb27157 145
matirodriguez 0:1a9bfeb27157 146 // -------------- Modo joystick
matirodriguez 0:1a9bfeb27157 147
matirodriguez 0:1a9bfeb27157 148 RawSerial control(PTA2, PTA1); // Puerto serie para recibir datos del control, no se utiliza el Tx
matirodriguez 0:1a9bfeb27157 149 RawSerial app(PTE0, PTE1); // Puerto serie para recibir Y enviar datos a la aplicacion via bluetooth
matirodriguez 0:1a9bfeb27157 150
matirodriguez 0:1a9bfeb27157 151 int joystick_VSlide = 120; // Variable que guarda el valor del joystick recibido por el HC-11
matirodriguez 0:1a9bfeb27157 152 int app_VSlide = 120; // Variable que guarda el valor del joystick recibido por la aplicacion via bluetooth
matirodriguez 0:1a9bfeb27157 153
matirodriguez 0:1a9bfeb27157 154 int joystick_VTilt = 120; // Variable que guarda el valor del joystick recibido por el HC-11
matirodriguez 0:1a9bfeb27157 155 int app_VTilt = 120; // Variable que guarda el valor del joystick recibido por la aplicacion via bluetooth
matirodriguez 0:1a9bfeb27157 156
matirodriguez 0:1a9bfeb27157 157 int joystick_VPan = 120; // Variable que guarda el valor del joystick recibido por el HC-11
matirodriguez 0:1a9bfeb27157 158 int app_VPan = 120; // Variable que guarda el valor del joystick recibido por la aplicacion via bluetooth
matirodriguez 0:1a9bfeb27157 159
matirodriguez 0:1a9bfeb27157 160 int pasos_slide = 0;
matirodriguez 0:1a9bfeb27157 161 int pasos_tilt = 0;
matirodriguez 0:1a9bfeb27157 162 int pasos_pan = 0;
matirodriguez 0:1a9bfeb27157 163
matirodriguez 0:1a9bfeb27157 164 void control_joystick();
matirodriguez 0:1a9bfeb27157 165 void control_app();
matirodriguez 0:1a9bfeb27157 166
matirodriguez 0:1a9bfeb27157 167 void MAQ_recepcion_control();
matirodriguez 0:1a9bfeb27157 168 void MAQ_recepcion_app();
matirodriguez 0:1a9bfeb27157 169
matirodriguez 0:1a9bfeb27157 170 void interrupcion_control();
matirodriguez 0:1a9bfeb27157 171 void interrupcion_app();
matirodriguez 0:1a9bfeb27157 172
matirodriguez 0:1a9bfeb27157 173 volatile char ingreso_control; // En la variable 'ingreso_control' e 'ingreso_app' el valor 0 representa que no se ingresó nada
matirodriguez 0:1a9bfeb27157 174 volatile char ingreso_app; // En la variable 'ingreso_control' e 'ingreso_app' el valor 0 representa que no se ingresó nada
matirodriguez 0:1a9bfeb27157 175
matirodriguez 0:1a9bfeb27157 176 int estado_recepcion_app = START;
matirodriguez 0:1a9bfeb27157 177 int estado_recepcion_control = START;
matirodriguez 0:1a9bfeb27157 178
matirodriguez 0:1a9bfeb27157 179 int modo_de_funcionamiento = APP;
matirodriguez 0:1a9bfeb27157 180 int modo_de_funcionamiento_actual = APP;
matirodriguez 0:1a9bfeb27157 181
matirodriguez 0:1a9bfeb27157 182 PinName const SDA = PTE25;
matirodriguez 0:1a9bfeb27157 183 PinName const SCL = PTE24;
matirodriguez 0:1a9bfeb27157 184
matirodriguez 0:1a9bfeb27157 185 MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS);
matirodriguez 0:1a9bfeb27157 186 void acelerometro();
matirodriguez 0:1a9bfeb27157 187 Ticker giroscopo;
matirodriguez 0:1a9bfeb27157 188
matirodriguez 0:1a9bfeb27157 189
matirodriguez 0:1a9bfeb27157 190 enum {NUNCA, SEGUNDOS, MINUTOS, HORAS};
matirodriguez 0:1a9bfeb27157 191 int loop = DESHABILITADO;
matirodriguez 0:1a9bfeb27157 192 int loopRetraso = 0;
matirodriguez 0:1a9bfeb27157 193 int loopRetrasoUnidadDeTiempo = SEGUNDOS;
matirodriguez 0:1a9bfeb27157 194 int loopDetenerseUnidadDeTiempo = SEGUNDOS;
matirodriguez 0:1a9bfeb27157 195 int loopDetenerse = NUNCA;
matirodriguez 0:1a9bfeb27157 196 void control_loop();
matirodriguez 0:1a9bfeb27157 197 Timeout desactivar_loop;
matirodriguez 0:1a9bfeb27157 198 Timeout retraso_loop;
matirodriguez 0:1a9bfeb27157 199
matirodriguez 0:1a9bfeb27157 200 void off_loop();
matirodriguez 0:1a9bfeb27157 201 void MAQ_loop();
matirodriguez 0:1a9bfeb27157 202 int estado_maq_loop = ESPERO;
matirodriguez 0:1a9bfeb27157 203 int flag_delay_loop = DESHABILITADO;
matirodriguez 0:1a9bfeb27157 204 void delay_loop()
matirodriguez 0:1a9bfeb27157 205 {
matirodriguez 0:1a9bfeb27157 206 flag_delay_loop = HABILITADO;
matirodriguez 0:1a9bfeb27157 207 }
matirodriguez 0:1a9bfeb27157 208 void secuencia_inicio();
matirodriguez 0:1a9bfeb27157 209
matirodriguez 0:1a9bfeb27157 210 int punto_especifico = DESHABILITADO;
matirodriguez 0:1a9bfeb27157 211 int posicion_slide = 0;
matirodriguez 0:1a9bfeb27157 212 int posicion_pan = 0;
matirodriguez 0:1a9bfeb27157 213 void control_pe();
matirodriguez 0:1a9bfeb27157 214
matirodriguez 0:1a9bfeb27157 215 int tiempoTimelapse = 0;
matirodriguez 0:1a9bfeb27157 216 int unidadtiempoTimelapse = 0;
matirodriguez 0:1a9bfeb27157 217 int lado_Timelapse = 0;
matirodriguez 0:1a9bfeb27157 218 int modo_Timelapse = 0;
matirodriguez 0:1a9bfeb27157 219 int stateTimelapse = DESHABILITADO;
matirodriguez 0:1a9bfeb27157 220 int flag_timelapse = 0;
matirodriguez 0:1a9bfeb27157 221 void inicio_timelapse();
matirodriguez 0:1a9bfeb27157 222
matirodriguez 0:1a9bfeb27157 223 int main()
matirodriguez 0:1a9bfeb27157 224 {
matirodriguez 0:1a9bfeb27157 225
matirodriguez 0:1a9bfeb27157 226 control.baud(115200);
matirodriguez 0:1a9bfeb27157 227 control.attach(&interrupcion_control, Serial::RxIrq);
matirodriguez 0:1a9bfeb27157 228 app.baud(115200);
matirodriguez 0:1a9bfeb27157 229 app.attach(&interrupcion_app, Serial::RxIrq);
matirodriguez 0:1a9bfeb27157 230
matirodriguez 0:1a9bfeb27157 231 ticker_VSlide.attach_us(&paso_VSlide,10000);
matirodriguez 0:1a9bfeb27157 232 ticker_VTilt.attach_us(&paso_VTilt,1000);
matirodriguez 0:1a9bfeb27157 233 ticker_VPan.attach_us(&paso_VPan,1000);
matirodriguez 0:1a9bfeb27157 234 giroscopo.attach(&acelerometro,0.65);
matirodriguez 0:1a9bfeb27157 235 fc1.mode(PullUp);
matirodriguez 0:1a9bfeb27157 236 fc2.mode(PullUp);
matirodriguez 0:1a9bfeb27157 237
matirodriguez 0:1a9bfeb27157 238 secuencia_inicio();
matirodriguez 0:1a9bfeb27157 239
matirodriguez 0:1a9bfeb27157 240
matirodriguez 0:1a9bfeb27157 241 while(1) {
matirodriguez 0:1a9bfeb27157 242 // SIEMPRE leo los datos que me llegan de la APP
matirodriguez 0:1a9bfeb27157 243 if(ingreso_control != NADA) { // Cuando recibo algo en el puerto serie, lo leo.
matirodriguez 0:1a9bfeb27157 244 MAQ_recepcion_control();
matirodriguez 0:1a9bfeb27157 245 ingreso_control = NADA;
matirodriguez 0:1a9bfeb27157 246 }
matirodriguez 0:1a9bfeb27157 247 // SIEMPRE leo los datos que me llegan del control remoto, siempre y cuando esté prendido
matirodriguez 0:1a9bfeb27157 248 if(ingreso_app != NADA) { // Cuando recibo algo en el puerto serie, lo leo.
matirodriguez 0:1a9bfeb27157 249 MAQ_recepcion_app();
matirodriguez 0:1a9bfeb27157 250 ingreso_app = NADA;
matirodriguez 0:1a9bfeb27157 251 }
matirodriguez 0:1a9bfeb27157 252 if(modo_de_funcionamiento_actual != modo_de_funcionamiento) { // Si recibo orden para cambiar de modo, llevo el slide a un "modo seguro" de stop
matirodriguez 0:1a9bfeb27157 253 hab_maq_VSlide = DESHABILITADO; // Deshabilito la maquina
matirodriguez 0:1a9bfeb27157 254 velocidad_VSlide = 0; // Seteo la velocidad en 0
matirodriguez 0:1a9bfeb27157 255 hab_maq_VTilt = DESHABILITADO; // Deshabilito la maquina
matirodriguez 0:1a9bfeb27157 256 velocidad_VTilt = 0; // Seteo la velocidad en 0
matirodriguez 0:1a9bfeb27157 257 hab_maq_VPan = DESHABILITADO; // Deshabilito la maquina
matirodriguez 0:1a9bfeb27157 258 velocidad_VPan = 0; // Seteo la velocidad en 0
matirodriguez 0:1a9bfeb27157 259 MAQ_VSlide(velocidad_VSlide,direccion_VSlide);
matirodriguez 0:1a9bfeb27157 260 MAQ_VTilt(velocidad_VTilt*0.1,direccion_VTilt);
matirodriguez 0:1a9bfeb27157 261 MAQ_VPan(velocidad_VPan*0.1,direccion_VPan);
matirodriguez 0:1a9bfeb27157 262 if((stop_VSlide == QUIETO)&&(stop_VTilt == QUIETO)&&(stop_VPan == QUIETO)) {
matirodriguez 0:1a9bfeb27157 263 // Reseteo la variable que indica el modo a un estado false.
matirodriguez 0:1a9bfeb27157 264 // Cambio la variable del switch de modo
matirodriguez 0:1a9bfeb27157 265 modo_de_funcionamiento_actual = modo_de_funcionamiento;
matirodriguez 0:1a9bfeb27157 266 }
matirodriguez 0:1a9bfeb27157 267 } else if(modo_de_funcionamiento_actual == modo_de_funcionamiento) { // Si no se tiene que cambiar de modo, sigo interpretando los datos recibidos
matirodriguez 0:1a9bfeb27157 268 switch(modo_de_funcionamiento) { // Vario la interpretacion de datos dependiendo lo que se elija en la app
matirodriguez 0:1a9bfeb27157 269 // Le envio a la app que modo hay actualmente
matirodriguez 0:1a9bfeb27157 270 case APP: // Caso: Controlado por APP
matirodriguez 0:1a9bfeb27157 271 if(loop == HABILITADO) {
matirodriguez 0:1a9bfeb27157 272 switch(punto_especifico) {
matirodriguez 0:1a9bfeb27157 273 case HABILITADO:
matirodriguez 0:1a9bfeb27157 274 control_pe();
matirodriguez 0:1a9bfeb27157 275 break;
matirodriguez 0:1a9bfeb27157 276 case DESHABILITADO:
matirodriguez 0:1a9bfeb27157 277 control_loop();
matirodriguez 0:1a9bfeb27157 278 break;
matirodriguez 0:1a9bfeb27157 279 }
matirodriguez 0:1a9bfeb27157 280
matirodriguez 0:1a9bfeb27157 281 MAQ_loop();
matirodriguez 0:1a9bfeb27157 282 MAQ_VTilt(velocidad_VTilt*0.1,direccion_VTilt);
matirodriguez 0:1a9bfeb27157 283 MAQ_VPan(velocidad_VPan*0.1,direccion_VPan);
matirodriguez 0:1a9bfeb27157 284 MAQ_VSlide(velocidad_VSlide,direccion_VSlide);
matirodriguez 0:1a9bfeb27157 285 } else {
matirodriguez 0:1a9bfeb27157 286 if(stateTimelapse == DESHABILITADO) {
matirodriguez 0:1a9bfeb27157 287 flag_timelapse = 0;
matirodriguez 0:1a9bfeb27157 288 control_app();
matirodriguez 0:1a9bfeb27157 289 MAQ_VSlide(velocidad_VSlide,direccion_VSlide);
matirodriguez 0:1a9bfeb27157 290 MAQ_VTilt(velocidad_VTilt*0.1,direccion_VTilt);
matirodriguez 0:1a9bfeb27157 291 MAQ_VPan(velocidad_VPan*0.1,direccion_VPan);
matirodriguez 0:1a9bfeb27157 292 } else {
matirodriguez 0:1a9bfeb27157 293 if(flag_timelapse == 0){
matirodriguez 0:1a9bfeb27157 294 flag_timelapse = 1;
matirodriguez 0:1a9bfeb27157 295 inicio_timelapse();
matirodriguez 0:1a9bfeb27157 296
matirodriguez 0:1a9bfeb27157 297 }
matirodriguez 0:1a9bfeb27157 298
matirodriguez 0:1a9bfeb27157 299
matirodriguez 0:1a9bfeb27157 300 }
matirodriguez 0:1a9bfeb27157 301 }
matirodriguez 0:1a9bfeb27157 302
matirodriguez 0:1a9bfeb27157 303 break;
matirodriguez 0:1a9bfeb27157 304 case CONTROL: // Caso: Controlado por Control remoto
matirodriguez 0:1a9bfeb27157 305 control_joystick();
matirodriguez 0:1a9bfeb27157 306 MAQ_VSlide(velocidad_VSlide,direccion_VSlide);
matirodriguez 0:1a9bfeb27157 307 MAQ_VTilt(velocidad_VTilt*0.1,direccion_VTilt);
matirodriguez 0:1a9bfeb27157 308 MAQ_VPan(velocidad_VPan*0.1,direccion_VPan);
matirodriguez 0:1a9bfeb27157 309 break;
matirodriguez 0:1a9bfeb27157 310 }
matirodriguez 0:1a9bfeb27157 311 }
matirodriguez 0:1a9bfeb27157 312 }
matirodriguez 0:1a9bfeb27157 313 }
matirodriguez 0:1a9bfeb27157 314 void inicio_timelapse()
matirodriguez 0:1a9bfeb27157 315 {
matirodriguez 0:1a9bfeb27157 316 switch(lado_Timelapse) {
matirodriguez 0:1a9bfeb27157 317 case IZQUIERDA:
matirodriguez 0:1a9bfeb27157 318 for(; (pasos_slide > ((MAX_SLIDE * 1)/40));) {
matirodriguez 0:1a9bfeb27157 319 MAQ_VSlide(1000,DERECHA);
matirodriguez 0:1a9bfeb27157 320 }
matirodriguez 0:1a9bfeb27157 321 break;
matirodriguez 0:1a9bfeb27157 322 case DERECHA:
matirodriguez 0:1a9bfeb27157 323 for(; (pasos_slide < ((MAX_SLIDE * 39)/40));) {
matirodriguez 0:1a9bfeb27157 324 MAQ_VSlide(1000,IZQUIERDA);
matirodriguez 0:1a9bfeb27157 325 }
matirodriguez 0:1a9bfeb27157 326 break;
matirodriguez 0:1a9bfeb27157 327 }
matirodriguez 0:1a9bfeb27157 328 }
matirodriguez 0:1a9bfeb27157 329 void control_pe()
matirodriguez 0:1a9bfeb27157 330 {
matirodriguez 0:1a9bfeb27157 331 hab_maq_VPan = HABILITADO; // Habilito la maquina de estados de manejo por velocidad
matirodriguez 0:1a9bfeb27157 332 if(pasos_slide > posicion_slide) {
matirodriguez 0:1a9bfeb27157 333 if((direccion_VPan == IZQUIERDA)&&(pasos_tilt < ((MAX_TILT * 39)/40))) {
matirodriguez 0:1a9bfeb27157 334 direccion_VPan = IZQUIERDA; // Establezco la direccion correspondiente del giro del motor
matirodriguez 0:1a9bfeb27157 335 velocidad_VPan = 500 * (pasos_pan * 100)/(MAX_PAN / 2) * (pasos_slide * 100)/(MAX_SLIDE / 2); // Seteo la velocidad, dependiendo del nivel ( de 0 a 10 ) y del valor analogico del joystick
matirodriguez 0:1a9bfeb27157 336 } else {
matirodriguez 0:1a9bfeb27157 337 direccion_VPan = DERECHA;
matirodriguez 0:1a9bfeb27157 338 }
matirodriguez 0:1a9bfeb27157 339 } else {
matirodriguez 0:1a9bfeb27157 340 if((direccion_VPan == DERECHA)&&(pasos_tilt > ((MAX_TILT * 1)/ 40))) {
matirodriguez 0:1a9bfeb27157 341 direccion_VPan = DERECHA; // Establezco la direccion correspondiente del giro del motor
matirodriguez 0:1a9bfeb27157 342 velocidad_VPan = 500 * (pasos_pan * 100)/(MAX_PAN / 2) * (pasos_slide * 100)/(MAX_SLIDE / 2); // Seteo la velocidad, dependiendo del nivel ( de 0 a 10 ) y del valor analogico del joystick
matirodriguez 0:1a9bfeb27157 343 } else {
matirodriguez 0:1a9bfeb27157 344 direccion_VPan = IZQUIERDA;
matirodriguez 0:1a9bfeb27157 345 }
matirodriguez 0:1a9bfeb27157 346 }
matirodriguez 0:1a9bfeb27157 347 }
matirodriguez 0:1a9bfeb27157 348
matirodriguez 0:1a9bfeb27157 349 void off_loop()
matirodriguez 0:1a9bfeb27157 350 {
matirodriguez 0:1a9bfeb27157 351 loop = DESHABILITADO;
matirodriguez 0:1a9bfeb27157 352 app.putc('$');
matirodriguez 0:1a9bfeb27157 353 app.putc('L');
matirodriguez 0:1a9bfeb27157 354 app.putc('0');
matirodriguez 0:1a9bfeb27157 355 app.putc('e');
matirodriguez 0:1a9bfeb27157 356 app.putc('!');
matirodriguez 0:1a9bfeb27157 357 }
matirodriguez 0:1a9bfeb27157 358 void MAQ_loop()
matirodriguez 0:1a9bfeb27157 359 {
matirodriguez 0:1a9bfeb27157 360 static int prox_dir = DERECHA;
matirodriguez 0:1a9bfeb27157 361 switch(estado_maq_loop) {
matirodriguez 0:1a9bfeb27157 362 case ESPERO:
matirodriguez 0:1a9bfeb27157 363
matirodriguez 0:1a9bfeb27157 364 estado_maq_loop = RIGHT;
matirodriguez 0:1a9bfeb27157 365
matirodriguez 0:1a9bfeb27157 366 break;
matirodriguez 0:1a9bfeb27157 367 case RIGHT:
matirodriguez 0:1a9bfeb27157 368
matirodriguez 0:1a9bfeb27157 369 if(pasos_slide < ((MAX_SLIDE * 39)/40)) {
matirodriguez 0:1a9bfeb27157 370 hab_maq_VSlide = HABILITADO; // Habilito la maquina de estados de manejo por velocidad
matirodriguez 0:1a9bfeb27157 371 direccion_VSlide = DERECHA; // Establezco la direccion correspondiente del giro del motor
matirodriguez 0:1a9bfeb27157 372 velocidad_VSlide = intensidad_VSlide * 100; // Seteo la velocidad, dependiendo del nivel ( de 0 a 10 ) y del valor analogico del joystick
matirodriguez 0:1a9bfeb27157 373 } else {
matirodriguez 0:1a9bfeb27157 374 velocidad_VSlide = 0;
matirodriguez 0:1a9bfeb27157 375 direccion_VSlide = DERECHA;
matirodriguez 0:1a9bfeb27157 376 hab_maq_VTilt = DESHABILITADO; // Deshabilito la maquina
matirodriguez 0:1a9bfeb27157 377 if(stop_VSlide == QUIETO) {
matirodriguez 0:1a9bfeb27157 378 estado_maq_loop = HOLD;
matirodriguez 0:1a9bfeb27157 379 switch(loopRetrasoUnidadDeTiempo) {
matirodriguez 0:1a9bfeb27157 380 case SEGUNDOS:
matirodriguez 0:1a9bfeb27157 381 retraso_loop.attach(&delay_loop,loopRetraso);
matirodriguez 0:1a9bfeb27157 382 break;
matirodriguez 0:1a9bfeb27157 383 case MINUTOS:
matirodriguez 0:1a9bfeb27157 384 retraso_loop.attach(&delay_loop,loopRetraso*60);
matirodriguez 0:1a9bfeb27157 385 break;
matirodriguez 0:1a9bfeb27157 386 case HORAS:
matirodriguez 0:1a9bfeb27157 387 retraso_loop.attach(&delay_loop,loopRetraso * 60); // Falta multiplicar por 60 mas
matirodriguez 0:1a9bfeb27157 388 break;
matirodriguez 0:1a9bfeb27157 389
matirodriguez 0:1a9bfeb27157 390 }
matirodriguez 0:1a9bfeb27157 391 prox_dir = IZQUIERDA;
matirodriguez 0:1a9bfeb27157 392 }
matirodriguez 0:1a9bfeb27157 393 }
matirodriguez 0:1a9bfeb27157 394 break;
matirodriguez 0:1a9bfeb27157 395 case HOLD:
matirodriguez 0:1a9bfeb27157 396 if(flag_delay_loop == HABILITADO) {
matirodriguez 0:1a9bfeb27157 397 flag_delay_loop = DESHABILITADO;
matirodriguez 0:1a9bfeb27157 398 switch(prox_dir) {
matirodriguez 0:1a9bfeb27157 399 case DERECHA:
matirodriguez 0:1a9bfeb27157 400 estado_maq_loop = RIGHT;
matirodriguez 0:1a9bfeb27157 401 break;
matirodriguez 0:1a9bfeb27157 402 case IZQUIERDA:
matirodriguez 0:1a9bfeb27157 403 estado_maq_loop = LEFT;
matirodriguez 0:1a9bfeb27157 404 break;
matirodriguez 0:1a9bfeb27157 405 }
matirodriguez 0:1a9bfeb27157 406 }
matirodriguez 0:1a9bfeb27157 407 break;
matirodriguez 0:1a9bfeb27157 408 case LEFT:
matirodriguez 0:1a9bfeb27157 409 if(pasos_slide > ((MAX_SLIDE * 1)/ 40)) {
matirodriguez 0:1a9bfeb27157 410 hab_maq_VSlide = HABILITADO; // Habilito la maquina de estados de manejo por velocidad
matirodriguez 0:1a9bfeb27157 411 direccion_VSlide = IZQUIERDA; // Establezco la direccion correspondiente del giro del motor
matirodriguez 0:1a9bfeb27157 412 velocidad_VSlide = intensidad_VSlide * 100; // Seteo la velocidad, dependiendo del nivel ( de 0 a 10 ) y del valor analogico del joystick
matirodriguez 0:1a9bfeb27157 413 } else {
matirodriguez 0:1a9bfeb27157 414 velocidad_VSlide = 0;
matirodriguez 0:1a9bfeb27157 415 direccion_VSlide = IZQUIERDA;
matirodriguez 0:1a9bfeb27157 416 hab_maq_VTilt = DESHABILITADO; // habilito la maquina
matirodriguez 0:1a9bfeb27157 417 if(stop_VSlide == QUIETO) {
matirodriguez 0:1a9bfeb27157 418 estado_maq_loop = HOLD;
matirodriguez 0:1a9bfeb27157 419 switch(loopRetrasoUnidadDeTiempo) {
matirodriguez 0:1a9bfeb27157 420 case SEGUNDOS:
matirodriguez 0:1a9bfeb27157 421 retraso_loop.attach(&delay_loop,loopRetraso);
matirodriguez 0:1a9bfeb27157 422 break;
matirodriguez 0:1a9bfeb27157 423 case MINUTOS:
matirodriguez 0:1a9bfeb27157 424 retraso_loop.attach(&delay_loop,loopRetraso*60);
matirodriguez 0:1a9bfeb27157 425 break;
matirodriguez 0:1a9bfeb27157 426 case HORAS:
matirodriguez 0:1a9bfeb27157 427 retraso_loop.attach(&delay_loop,loopRetraso * 60); // Falta multiplicar por 60 mas
matirodriguez 0:1a9bfeb27157 428 break;
matirodriguez 0:1a9bfeb27157 429 }
matirodriguez 0:1a9bfeb27157 430 prox_dir = DERECHA;
matirodriguez 0:1a9bfeb27157 431 }
matirodriguez 0:1a9bfeb27157 432 }
matirodriguez 0:1a9bfeb27157 433 break;
matirodriguez 0:1a9bfeb27157 434
matirodriguez 0:1a9bfeb27157 435 }
matirodriguez 0:1a9bfeb27157 436
matirodriguez 0:1a9bfeb27157 437 }
matirodriguez 0:1a9bfeb27157 438 void secuencia_inicio()
matirodriguez 0:1a9bfeb27157 439 {
matirodriguez 0:1a9bfeb27157 440 int hab_slide = 1;
matirodriguez 0:1a9bfeb27157 441 int hab_pan = 1;
matirodriguez 0:1a9bfeb27157 442 int hab_tilt = 1;
matirodriguez 0:1a9bfeb27157 443 hab_maq_VSlide = 1;
matirodriguez 0:1a9bfeb27157 444 hab_maq_VTilt = 1;
matirodriguez 0:1a9bfeb27157 445 hab_maq_VPan = 1;
matirodriguez 0:1a9bfeb27157 446 while(1) {
matirodriguez 0:1a9bfeb27157 447
matirodriguez 0:1a9bfeb27157 448 if((fc1 == 0)||(fc2 == 0)) {
matirodriguez 0:1a9bfeb27157 449 hab_slide = 0;
matirodriguez 0:1a9bfeb27157 450 } else {
matirodriguez 0:1a9bfeb27157 451 if(hab_slide == 1) {
matirodriguez 0:1a9bfeb27157 452 MAQ_VSlide(1000,1);
matirodriguez 0:1a9bfeb27157 453 }
matirodriguez 0:1a9bfeb27157 454 }
matirodriguez 0:1a9bfeb27157 455 if(opto_tilt != 1) {
matirodriguez 0:1a9bfeb27157 456 if(hab_tilt == 1) {
matirodriguez 0:1a9bfeb27157 457 MAQ_VTilt(100,1);
matirodriguez 0:1a9bfeb27157 458 }
matirodriguez 0:1a9bfeb27157 459 } else {
matirodriguez 0:1a9bfeb27157 460 hab_tilt = 0;
matirodriguez 0:1a9bfeb27157 461 }
matirodriguez 0:1a9bfeb27157 462 if(opto_pan != 1) {
matirodriguez 0:1a9bfeb27157 463 if(hab_pan == 1) {
matirodriguez 0:1a9bfeb27157 464 MAQ_VPan(100,1);
matirodriguez 0:1a9bfeb27157 465 }
matirodriguez 0:1a9bfeb27157 466 } else {
matirodriguez 0:1a9bfeb27157 467 hab_pan = 0;
matirodriguez 0:1a9bfeb27157 468 }
matirodriguez 0:1a9bfeb27157 469 if((hab_slide == 0)&&(hab_tilt == 0)&&(hab_pan == 0)) {
matirodriguez 0:1a9bfeb27157 470 break;
matirodriguez 0:1a9bfeb27157 471 }
matirodriguez 0:1a9bfeb27157 472 }
matirodriguez 0:1a9bfeb27157 473 estado_VSlide = ESPERO; // Vuelvo al estado de reset
matirodriguez 0:1a9bfeb27157 474 estado_VTilt = ESPERO; // Vuelvo al estado de reset
matirodriguez 0:1a9bfeb27157 475 estado_VPan = ESPERO; // Vuelvo al estado de reset
matirodriguez 0:1a9bfeb27157 476
matirodriguez 0:1a9bfeb27157 477 hab_slide = 1;
matirodriguez 0:1a9bfeb27157 478 hab_tilt = 1;
matirodriguez 0:1a9bfeb27157 479 hab_pan = 1;
matirodriguez 0:1a9bfeb27157 480
matirodriguez 0:1a9bfeb27157 481 pasos_slide = 0;
matirodriguez 0:1a9bfeb27157 482 pasos_tilt = 0;
matirodriguez 0:1a9bfeb27157 483 pasos_pan = 0;
matirodriguez 0:1a9bfeb27157 484
matirodriguez 0:1a9bfeb27157 485 while(1) {
matirodriguez 0:1a9bfeb27157 486 if(pasos_slide < (MAX_SLIDE / 2)) {
matirodriguez 0:1a9bfeb27157 487 MAQ_VSlide(1000,0);
matirodriguez 0:1a9bfeb27157 488 } else {
matirodriguez 0:1a9bfeb27157 489 hab_slide = 0;
matirodriguez 0:1a9bfeb27157 490 }
matirodriguez 0:1a9bfeb27157 491 if(pasos_tilt < (MAX_TILT / 2)) {
matirodriguez 0:1a9bfeb27157 492 MAQ_VTilt(100,0);
matirodriguez 0:1a9bfeb27157 493 } else {
matirodriguez 0:1a9bfeb27157 494 hab_tilt = 0;
matirodriguez 0:1a9bfeb27157 495 }
matirodriguez 0:1a9bfeb27157 496 if(pasos_pan < (MAX_PAN / 2)) {
matirodriguez 0:1a9bfeb27157 497 MAQ_VPan(100,0);
matirodriguez 0:1a9bfeb27157 498 } else {
matirodriguez 0:1a9bfeb27157 499 hab_pan = 0;
matirodriguez 0:1a9bfeb27157 500 }
matirodriguez 0:1a9bfeb27157 501 if((hab_slide == 0)&&(hab_tilt == 0)&&(hab_pan == 0)) {
matirodriguez 0:1a9bfeb27157 502 break;
matirodriguez 0:1a9bfeb27157 503 }
matirodriguez 0:1a9bfeb27157 504
matirodriguez 0:1a9bfeb27157 505 }
matirodriguez 0:1a9bfeb27157 506 app.putc('a');
matirodriguez 0:1a9bfeb27157 507
matirodriguez 0:1a9bfeb27157 508 }
matirodriguez 0:1a9bfeb27157 509 void interrupcion_control()
matirodriguez 0:1a9bfeb27157 510 {
matirodriguez 0:1a9bfeb27157 511 ingreso_control = control.getc();
matirodriguez 0:1a9bfeb27157 512 }
matirodriguez 0:1a9bfeb27157 513 void interrupcion_app()
matirodriguez 0:1a9bfeb27157 514 {
matirodriguez 0:1a9bfeb27157 515 ingreso_app = app.getc();
matirodriguez 0:1a9bfeb27157 516 }
matirodriguez 0:1a9bfeb27157 517 void acelerometro()
matirodriguez 0:1a9bfeb27157 518 {
matirodriguez 0:1a9bfeb27157 519 float x, grados;
matirodriguez 0:1a9bfeb27157 520 int d,u;
matirodriguez 0:1a9bfeb27157 521 x = abs(acc.getAccX());
matirodriguez 0:1a9bfeb27157 522 grados = x * 90;
matirodriguez 0:1a9bfeb27157 523 app.putc('$');
matirodriguez 0:1a9bfeb27157 524 app.putc('I');
matirodriguez 0:1a9bfeb27157 525 app.putc('S');
matirodriguez 0:1a9bfeb27157 526 d = grados / 10;
matirodriguez 0:1a9bfeb27157 527 u = grados - d * 10;
matirodriguez 0:1a9bfeb27157 528 app.putc(0 + 0x30);
matirodriguez 0:1a9bfeb27157 529 app.putc(d + 0x30);
matirodriguez 0:1a9bfeb27157 530 app.putc(u + 0x30);
matirodriguez 0:1a9bfeb27157 531 app.putc('e');
matirodriguez 0:1a9bfeb27157 532 app.putc('!');
matirodriguez 0:1a9bfeb27157 533
matirodriguez 0:1a9bfeb27157 534 }
matirodriguez 0:1a9bfeb27157 535 void control_joystick()
matirodriguez 0:1a9bfeb27157 536 {
matirodriguez 0:1a9bfeb27157 537 if((joystick_VSlide >= 0)&&(joystick_VSlide <= 112)) { // Rango del joystick que se mueve hacia una direccion
matirodriguez 0:1a9bfeb27157 538
matirodriguez 0:1a9bfeb27157 539 hab_maq_VSlide = HABILITADO; // Habilito la maquina de estados de manejo por velocidad
matirodriguez 0:1a9bfeb27157 540 direccion_VSlide = DERECHA; // Establezco la direccion correspondiente del giro del motor
matirodriguez 0:1a9bfeb27157 541 velocidad_VSlide = intensidad_VSlide * (109 - joystick_VSlide); // Seteo la velocidad, dependiendo del nivel ( de 0 a 10 ) y del valor analogico del joystick
matirodriguez 0:1a9bfeb27157 542 }
matirodriguez 0:1a9bfeb27157 543 if((joystick_VSlide >= 115)&&(joystick_VSlide <= 140)) { // Rango del joystick donde se encuentra estable el motor
matirodriguez 0:1a9bfeb27157 544 hab_maq_VSlide = DESHABILITADO; // Deshabilito la maquina
matirodriguez 0:1a9bfeb27157 545 velocidad_VSlide = 0; // Seteo la velocidad en 0
matirodriguez 0:1a9bfeb27157 546 }
matirodriguez 0:1a9bfeb27157 547 if((joystick_VSlide >= 145)&&(joystick_VSlide <= 255)) { // Rango del joystick que se mueve hacia la otra direccion
matirodriguez 0:1a9bfeb27157 548 hab_maq_VSlide = HABILITADO; // Habilito la maquina de estados de manejo por velocidad
matirodriguez 0:1a9bfeb27157 549 direccion_VSlide = IZQUIERDA; // Establezco la direccion correspondiente del giro del motor
matirodriguez 0:1a9bfeb27157 550 velocidad_VSlide = intensidad_VSlide * (joystick_VSlide - 149); // Seteo la velocidad, dependiendo del nivel ( de 0 a 10 ) y del valor analogico del joystick
matirodriguez 0:1a9bfeb27157 551 }
matirodriguez 0:1a9bfeb27157 552 if((joystick_VTilt >= 0)&&(joystick_VTilt <= 112)) { // Rango del joystick que se mueve hacia una direccion
matirodriguez 0:1a9bfeb27157 553
matirodriguez 0:1a9bfeb27157 554 hab_maq_VTilt = HABILITADO; // Habilito la maquina de estados de manejo por velocidad
matirodriguez 0:1a9bfeb27157 555 direccion_VTilt = DERECHA; // Establezco la direccion correspondiente del giro del motor
matirodriguez 0:1a9bfeb27157 556 velocidad_VTilt = intensidad_VTilt * (109 - joystick_VTilt); // Seteo la velocidad, dependiendo del nivel ( de 0 a 10 ) y del valor analogico del joystick
matirodriguez 0:1a9bfeb27157 557 }
matirodriguez 0:1a9bfeb27157 558 if((joystick_VTilt >= 115)&&(joystick_VTilt <= 140)) { // Rango del joystick donde se encuentra estable el motor
matirodriguez 0:1a9bfeb27157 559 hab_maq_VTilt = DESHABILITADO; // Deshabilito la maquina
matirodriguez 0:1a9bfeb27157 560 velocidad_VTilt = 0; // Seteo la velocidad en 0
matirodriguez 0:1a9bfeb27157 561 }
matirodriguez 0:1a9bfeb27157 562 if((joystick_VTilt >= 145)&&(joystick_VTilt <= 255)) { // Rango del joystick que se mueve hacia la otra direccion
matirodriguez 0:1a9bfeb27157 563 hab_maq_VTilt = HABILITADO; // Habilito la maquina de estados de manejo por velocidad
matirodriguez 0:1a9bfeb27157 564 direccion_VTilt = IZQUIERDA; // Establezco la direccion correspondiente del giro del motor
matirodriguez 0:1a9bfeb27157 565 velocidad_VTilt = intensidad_VTilt * (joystick_VTilt - 149); // Seteo la velocidad, dependiendo del nivel ( de 0 a 10 ) y del valor analogico del joystick
matirodriguez 0:1a9bfeb27157 566 }
matirodriguez 0:1a9bfeb27157 567 if((joystick_VPan >= 0)&&(joystick_VPan <= 112)) { // Rango del joystick que se mueve hacia una direccion
matirodriguez 0:1a9bfeb27157 568
matirodriguez 0:1a9bfeb27157 569 hab_maq_VPan = HABILITADO; // Habilito la maquina de estados de manejo por velocidad
matirodriguez 0:1a9bfeb27157 570 direccion_VPan = DERECHA; // Establezco la direccion correspondiente del giro del motor
matirodriguez 0:1a9bfeb27157 571 velocidad_VPan = intensidad_VPan * (109 - joystick_VPan); // Seteo la velocidad, dependiendo del nivel ( de 0 a 10 ) y del valor analogico del joystick
matirodriguez 0:1a9bfeb27157 572 }
matirodriguez 0:1a9bfeb27157 573 if((joystick_VPan >= 115)&&(joystick_VPan <= 140)) { // Rango del joystick donde se encuentra estable el motor
matirodriguez 0:1a9bfeb27157 574 hab_maq_VPan = DESHABILITADO; // Deshabilito la maquina
matirodriguez 0:1a9bfeb27157 575 velocidad_VPan = 0; // Seteo la velocidad en 0
matirodriguez 0:1a9bfeb27157 576 }
matirodriguez 0:1a9bfeb27157 577 if((joystick_VPan >= 145)&&(joystick_VPan <= 255)) { // Rango del joystick que se mueve hacia la otra direccion
matirodriguez 0:1a9bfeb27157 578 hab_maq_VPan = HABILITADO; // Habilito la maquina de estados de manejo por velocidad
matirodriguez 0:1a9bfeb27157 579 direccion_VPan = IZQUIERDA; // Establezco la direccion correspondiente del giro del motor
matirodriguez 0:1a9bfeb27157 580 velocidad_VPan = intensidad_VPan * (joystick_VPan - 149); // Seteo la velocidad, dependiendo del nivel ( de 0 a 10 ) y del valor analogico del joystick
matirodriguez 0:1a9bfeb27157 581 }
matirodriguez 0:1a9bfeb27157 582
matirodriguez 0:1a9bfeb27157 583 }
matirodriguez 0:1a9bfeb27157 584 void control_loop()
matirodriguez 0:1a9bfeb27157 585 {
matirodriguez 0:1a9bfeb27157 586 if((app_VTilt >= 0)&&(app_VTilt <= 112)) { // Rango del joystick que se mueve hacia una direccion
matirodriguez 0:1a9bfeb27157 587 if(pasos_tilt < ((MAX_TILT * 39)/40)) {
matirodriguez 0:1a9bfeb27157 588 hab_maq_VTilt = HABILITADO; // Habilito la maquina de estados de manejo por velocidad
matirodriguez 0:1a9bfeb27157 589 direccion_VTilt = DERECHA; // Establezco la direccion correspondiente del giro del motor
matirodriguez 0:1a9bfeb27157 590 velocidad_VTilt = intensidad_VTilt * (109 - app_VTilt); // Seteo la velocidad, dependiendo del nivel ( de 0 a 10 ) y del valor analogico del joystick
matirodriguez 0:1a9bfeb27157 591 } else {
matirodriguez 0:1a9bfeb27157 592 hab_maq_VTilt = DESHABILITADO; // Deshabilito la maquina
matirodriguez 0:1a9bfeb27157 593 velocidad_VTilt = 0; // Seteo la velocidad en 0
matirodriguez 0:1a9bfeb27157 594 }
matirodriguez 0:1a9bfeb27157 595 }
matirodriguez 0:1a9bfeb27157 596 if((app_VTilt >= 115)&&(app_VTilt <= 140)) { // Rango del joystick donde se encuentra estable el motor
matirodriguez 0:1a9bfeb27157 597 hab_maq_VTilt = DESHABILITADO; // Deshabilito la maquina
matirodriguez 0:1a9bfeb27157 598 velocidad_VTilt = 0; // Seteo la velocidad en 0
matirodriguez 0:1a9bfeb27157 599 }
matirodriguez 0:1a9bfeb27157 600 if((app_VTilt >= 145)&&(app_VTilt <= 255)) { // Rango del joystick que se mueve hacia la otra direccion
matirodriguez 0:1a9bfeb27157 601 if(pasos_tilt > ((MAX_TILT * 1)/ 40)) {
matirodriguez 0:1a9bfeb27157 602 hab_maq_VTilt = HABILITADO; // Habilito la maquina de estados de manejo por velocidad
matirodriguez 0:1a9bfeb27157 603 direccion_VTilt = IZQUIERDA; // Establezco la direccion correspondiente del giro del motor
matirodriguez 0:1a9bfeb27157 604 velocidad_VTilt = intensidad_VTilt * (app_VTilt - 149); // Seteo la velocidad, dependiendo del nivel ( de 0 a 10 ) y del valor analogico del joystick
matirodriguez 0:1a9bfeb27157 605 } else {
matirodriguez 0:1a9bfeb27157 606 hab_maq_VTilt = DESHABILITADO; // Deshabilito la maquina
matirodriguez 0:1a9bfeb27157 607 velocidad_VTilt = 0; // Seteo la velocidad en 0
matirodriguez 0:1a9bfeb27157 608 }
matirodriguez 0:1a9bfeb27157 609 }
matirodriguez 0:1a9bfeb27157 610 //--
matirodriguez 0:1a9bfeb27157 611 if((app_VPan >= 0)&&(app_VPan <= 112)) { // Rango del joystick que se mueve hacia una direccion
matirodriguez 0:1a9bfeb27157 612 if(pasos_pan < ((MAX_PAN * 39)/40)) {
matirodriguez 0:1a9bfeb27157 613 hab_maq_VPan = HABILITADO; // Habilito la maquina de estados de manejo por velocidad
matirodriguez 0:1a9bfeb27157 614 direccion_VPan = DERECHA; // Establezco la direccion correspondiente del giro del motor
matirodriguez 0:1a9bfeb27157 615 velocidad_VPan = intensidad_VPan * (109 - app_VPan); // Seteo la velocidad, dependiendo del nivel ( de 0 a 10 ) y del valor analogico del joystick
matirodriguez 0:1a9bfeb27157 616 } else {
matirodriguez 0:1a9bfeb27157 617 hab_maq_VPan = DESHABILITADO; // Deshabilito la maquina
matirodriguez 0:1a9bfeb27157 618 velocidad_VPan = 0; // Seteo la velocidad en 0
matirodriguez 0:1a9bfeb27157 619 }
matirodriguez 0:1a9bfeb27157 620 }
matirodriguez 0:1a9bfeb27157 621 if((app_VPan >= 115)&&(app_VPan <= 140)) { // Rango del joystick donde se encuentra estable el motor
matirodriguez 0:1a9bfeb27157 622 hab_maq_VPan = DESHABILITADO; // Deshabilito la maquina
matirodriguez 0:1a9bfeb27157 623 velocidad_VPan = 0; // Seteo la velocidad en 0
matirodriguez 0:1a9bfeb27157 624 }
matirodriguez 0:1a9bfeb27157 625 if((app_VPan >= 145)&&(app_VPan <= 255)) { // Rango del joystick que se mueve hacia la otra direccion
matirodriguez 0:1a9bfeb27157 626 if(pasos_pan > ((MAX_PAN * 1)/ 40)) {
matirodriguez 0:1a9bfeb27157 627 hab_maq_VPan = HABILITADO; // Habilito la maquina de estados de manejo por velocidad
matirodriguez 0:1a9bfeb27157 628 direccion_VPan = IZQUIERDA; // Establezco la direccion correspondiente del giro del motor
matirodriguez 0:1a9bfeb27157 629 velocidad_VPan = intensidad_VPan * (app_VPan - 149); // Seteo la velocidad, dependiendo del nivel ( de 0 a 10 ) y del valor analogico del joystick
matirodriguez 0:1a9bfeb27157 630 } else {
matirodriguez 0:1a9bfeb27157 631 hab_maq_VPan = DESHABILITADO; // Deshabilito la maquina
matirodriguez 0:1a9bfeb27157 632 velocidad_VPan = 0; // Seteo la velocidad en 0
matirodriguez 0:1a9bfeb27157 633 }
matirodriguez 0:1a9bfeb27157 634 }
matirodriguez 0:1a9bfeb27157 635 }
matirodriguez 0:1a9bfeb27157 636 void control_app()
matirodriguez 0:1a9bfeb27157 637 {
matirodriguez 0:1a9bfeb27157 638 if((app_VSlide >= 0)&&(app_VSlide <= 112)) { // Rango del joystick que se mueve hacia una direccion
matirodriguez 0:1a9bfeb27157 639 if(pasos_slide < ((MAX_SLIDE * 39)/40)) {
matirodriguez 0:1a9bfeb27157 640 hab_maq_VSlide = HABILITADO; // Habilito la maquina de estados de manejo por velocidad
matirodriguez 0:1a9bfeb27157 641 direccion_VSlide = DERECHA; // Establezco la direccion correspondiente del giro del motor
matirodriguez 0:1a9bfeb27157 642 velocidad_VSlide = intensidad_VSlide * (109 - app_VSlide); // Seteo la velocidad, dependiendo del nivel ( de 0 a 10 ) y del valor analogico del joystick
matirodriguez 0:1a9bfeb27157 643 } else {
matirodriguez 0:1a9bfeb27157 644 hab_maq_VSlide = DESHABILITADO; // Deshabilito la maquina
matirodriguez 0:1a9bfeb27157 645 velocidad_VSlide = 0; // Seteo la velocidad en 0
matirodriguez 0:1a9bfeb27157 646 }
matirodriguez 0:1a9bfeb27157 647 }
matirodriguez 0:1a9bfeb27157 648 if((app_VSlide >= 115)&&(app_VSlide <= 140)) { // Rango del joystick donde se encuentra estable el motor
matirodriguez 0:1a9bfeb27157 649 hab_maq_VSlide = DESHABILITADO; // Deshabilito la maquina
matirodriguez 0:1a9bfeb27157 650 velocidad_VSlide = 0; // Seteo la velocidad en 0
matirodriguez 0:1a9bfeb27157 651 }
matirodriguez 0:1a9bfeb27157 652 if((app_VSlide >= 145)&&(app_VSlide <= 255)) { // Rango del joystick que se mueve hacia la otra direccion
matirodriguez 0:1a9bfeb27157 653 if(pasos_slide > ((MAX_SLIDE * 1)/ 40)) {
matirodriguez 0:1a9bfeb27157 654 hab_maq_VSlide = HABILITADO; // Habilito la maquina de estados de manejo por velocidad
matirodriguez 0:1a9bfeb27157 655 direccion_VSlide = IZQUIERDA; // Establezco la direccion correspondiente del giro del motor
matirodriguez 0:1a9bfeb27157 656 velocidad_VSlide = intensidad_VSlide * (app_VSlide - 149); // Seteo la velocidad, dependiendo del nivel ( de 0 a 10 ) y del valor analogico del joystick
matirodriguez 0:1a9bfeb27157 657 } else {
matirodriguez 0:1a9bfeb27157 658 hab_maq_VSlide = DESHABILITADO; // Deshabilito la maquina
matirodriguez 0:1a9bfeb27157 659 velocidad_VSlide = 0; // Seteo la velocidad en 0
matirodriguez 0:1a9bfeb27157 660 }
matirodriguez 0:1a9bfeb27157 661 }
matirodriguez 0:1a9bfeb27157 662 //--
matirodriguez 0:1a9bfeb27157 663 if((app_VTilt >= 0)&&(app_VTilt <= 112)) { // Rango del joystick que se mueve hacia una direccion
matirodriguez 0:1a9bfeb27157 664 if(pasos_tilt < ((MAX_TILT * 39)/40)) {
matirodriguez 0:1a9bfeb27157 665 hab_maq_VTilt = HABILITADO; // Habilito la maquina de estados de manejo por velocidad
matirodriguez 0:1a9bfeb27157 666 direccion_VTilt = DERECHA; // Establezco la direccion correspondiente del giro del motor
matirodriguez 0:1a9bfeb27157 667 velocidad_VTilt = intensidad_VTilt * (109 - app_VTilt); // Seteo la velocidad, dependiendo del nivel ( de 0 a 10 ) y del valor analogico del joystick
matirodriguez 0:1a9bfeb27157 668 } else {
matirodriguez 0:1a9bfeb27157 669 hab_maq_VTilt = DESHABILITADO; // Deshabilito la maquina
matirodriguez 0:1a9bfeb27157 670 velocidad_VTilt = 0; // Seteo la velocidad en 0
matirodriguez 0:1a9bfeb27157 671 }
matirodriguez 0:1a9bfeb27157 672 }
matirodriguez 0:1a9bfeb27157 673 if((app_VTilt >= 115)&&(app_VTilt <= 140)) { // Rango del joystick donde se encuentra estable el motor
matirodriguez 0:1a9bfeb27157 674 hab_maq_VTilt = DESHABILITADO; // Deshabilito la maquina
matirodriguez 0:1a9bfeb27157 675 velocidad_VTilt = 0; // Seteo la velocidad en 0
matirodriguez 0:1a9bfeb27157 676 }
matirodriguez 0:1a9bfeb27157 677 if((app_VTilt >= 145)&&(app_VTilt <= 255)) { // Rango del joystick que se mueve hacia la otra direccion
matirodriguez 0:1a9bfeb27157 678 if(pasos_tilt > ((MAX_TILT * 1)/ 40)) {
matirodriguez 0:1a9bfeb27157 679 hab_maq_VTilt = HABILITADO; // Habilito la maquina de estados de manejo por velocidad
matirodriguez 0:1a9bfeb27157 680 direccion_VTilt = IZQUIERDA; // Establezco la direccion correspondiente del giro del motor
matirodriguez 0:1a9bfeb27157 681 velocidad_VTilt = intensidad_VTilt * (app_VTilt - 149); // Seteo la velocidad, dependiendo del nivel ( de 0 a 10 ) y del valor analogico del joystick
matirodriguez 0:1a9bfeb27157 682 } else {
matirodriguez 0:1a9bfeb27157 683 hab_maq_VTilt = DESHABILITADO; // Deshabilito la maquina
matirodriguez 0:1a9bfeb27157 684 velocidad_VTilt = 0; // Seteo la velocidad en 0
matirodriguez 0:1a9bfeb27157 685 }
matirodriguez 0:1a9bfeb27157 686 }
matirodriguez 0:1a9bfeb27157 687 //--
matirodriguez 0:1a9bfeb27157 688 if((app_VPan >= 0)&&(app_VPan <= 112)) { // Rango del joystick que se mueve hacia una direccion
matirodriguez 0:1a9bfeb27157 689 if(pasos_pan < ((MAX_PAN * 39)/40)) {
matirodriguez 0:1a9bfeb27157 690 hab_maq_VPan = HABILITADO; // Habilito la maquina de estados de manejo por velocidad
matirodriguez 0:1a9bfeb27157 691 direccion_VPan = DERECHA; // Establezco la direccion correspondiente del giro del motor
matirodriguez 0:1a9bfeb27157 692 velocidad_VPan = intensidad_VPan * (109 - app_VPan); // Seteo la velocidad, dependiendo del nivel ( de 0 a 10 ) y del valor analogico del joystick
matirodriguez 0:1a9bfeb27157 693 } else {
matirodriguez 0:1a9bfeb27157 694 hab_maq_VPan = DESHABILITADO; // Deshabilito la maquina
matirodriguez 0:1a9bfeb27157 695 velocidad_VPan = 0; // Seteo la velocidad en 0
matirodriguez 0:1a9bfeb27157 696 }
matirodriguez 0:1a9bfeb27157 697 }
matirodriguez 0:1a9bfeb27157 698 if((app_VPan >= 115)&&(app_VPan <= 140)) { // Rango del joystick donde se encuentra estable el motor
matirodriguez 0:1a9bfeb27157 699 hab_maq_VPan = DESHABILITADO; // Deshabilito la maquina
matirodriguez 0:1a9bfeb27157 700 velocidad_VPan = 0; // Seteo la velocidad en 0
matirodriguez 0:1a9bfeb27157 701 }
matirodriguez 0:1a9bfeb27157 702 if((app_VPan >= 145)&&(app_VPan <= 255)) { // Rango del joystick que se mueve hacia la otra direccion
matirodriguez 0:1a9bfeb27157 703 if(pasos_pan > ((MAX_PAN * 1)/ 15)) {
matirodriguez 0:1a9bfeb27157 704 hab_maq_VPan = HABILITADO; // Habilito la maquina de estados de manejo por velocidad
matirodriguez 0:1a9bfeb27157 705 direccion_VPan = IZQUIERDA; // Establezco la direccion correspondiente del giro del motor
matirodriguez 0:1a9bfeb27157 706 velocidad_VPan = intensidad_VPan * (app_VPan - 149); // Seteo la velocidad, dependiendo del nivel ( de 0 a 10 ) y del valor analogico del joystick
matirodriguez 0:1a9bfeb27157 707 } else {
matirodriguez 0:1a9bfeb27157 708 hab_maq_VPan = DESHABILITADO; // Deshabilito la maquina
matirodriguez 0:1a9bfeb27157 709 velocidad_VPan = 0; // Seteo la velocidad en 0
matirodriguez 0:1a9bfeb27157 710 }
matirodriguez 0:1a9bfeb27157 711 }
matirodriguez 0:1a9bfeb27157 712 }
matirodriguez 0:1a9bfeb27157 713 void timeoutVSlide()
matirodriguez 0:1a9bfeb27157 714 {
matirodriguez 0:1a9bfeb27157 715 timeout_VSlide = HABILITADO; // Aviso que pasó el tiempo que se estableció
matirodriguez 0:1a9bfeb27157 716 }
matirodriguez 0:1a9bfeb27157 717 void paso_VSlide()
matirodriguez 0:1a9bfeb27157 718 {
matirodriguez 0:1a9bfeb27157 719 incremento_VSlide = HABILITADO; // Aviso que se puede incrementar la velocidad del motor
matirodriguez 0:1a9bfeb27157 720 }
matirodriguez 0:1a9bfeb27157 721 void timeoutVTilt()
matirodriguez 0:1a9bfeb27157 722 {
matirodriguez 0:1a9bfeb27157 723 timeout_VTilt = HABILITADO; // Aviso que pasó el tiempo que se estableció
matirodriguez 0:1a9bfeb27157 724 }
matirodriguez 0:1a9bfeb27157 725 void paso_VTilt()
matirodriguez 0:1a9bfeb27157 726 {
matirodriguez 0:1a9bfeb27157 727 incremento_VTilt = HABILITADO; // Aviso que se puede incrementar la velocidad del motor
matirodriguez 0:1a9bfeb27157 728 }
matirodriguez 0:1a9bfeb27157 729 void timeoutVPan()
matirodriguez 0:1a9bfeb27157 730 {
matirodriguez 0:1a9bfeb27157 731 timeout_VPan = HABILITADO; // Aviso que pasó el tiempo que se estableció
matirodriguez 0:1a9bfeb27157 732 }
matirodriguez 0:1a9bfeb27157 733 void paso_VPan()
matirodriguez 0:1a9bfeb27157 734 {
matirodriguez 0:1a9bfeb27157 735 incremento_VPan = HABILITADO; // Aviso que se puede incrementar la velocidad del motor
matirodriguez 0:1a9bfeb27157 736 }
matirodriguez 0:1a9bfeb27157 737 void MAQ_VSlide(int velocidad_deseada, int direccion)
matirodriguez 0:1a9bfeb27157 738 {
matirodriguez 0:1a9bfeb27157 739 // Para que no existan cambios bruscos de velocidad, voy a ir incrementando el valor actual de la misma hasta llegar al punto que deseo.
matirodriguez 0:1a9bfeb27157 740 // De esta forma, seteo dos variables para poder lograr ese efecto.
matirodriguez 0:1a9bfeb27157 741 // Además, yo voy a querer que el motor no se detenga de golpe, asi que aprovecho este ultimo metodo para realizar esa operacion.
matirodriguez 0:1a9bfeb27157 742
matirodriguez 0:1a9bfeb27157 743 static int ticker_actual = 0; // Variable que me indicará el valor actual de tiempo de ticker (en micro-segundos)
matirodriguez 0:1a9bfeb27157 744 static int ticker_deseado = 0; // Variable que me indicará el valor deseado de tiempo de ticker (en micro-segundos), depèndiendo del joystick y de la pausa que se desee lograr
matirodriguez 0:1a9bfeb27157 745
matirodriguez 0:1a9bfeb27157 746 switch(estado_VSlide) {
matirodriguez 0:1a9bfeb27157 747
matirodriguez 0:1a9bfeb27157 748 case ESPERO: // Caso: Espero habilitacion de la maquina.
matirodriguez 0:1a9bfeb27157 749
matirodriguez 0:1a9bfeb27157 750 stop_VSlide = QUIETO; // Indico que la maquina no se activo todavia
matirodriguez 0:1a9bfeb27157 751
matirodriguez 0:1a9bfeb27157 752 if(hab_maq_VSlide == HABILITADO) {
matirodriguez 0:1a9bfeb27157 753
matirodriguez 0:1a9bfeb27157 754 Slide_dir = direccion; // Establezco la salida fisica igual a la direccion que se indicó en la función
matirodriguez 0:1a9bfeb27157 755
matirodriguez 0:1a9bfeb27157 756 ticker_actual = 1999; // Seteo la velocidad de inicio como una lo suficientemente lenta como para considerar el motor "parado"
matirodriguez 0:1a9bfeb27157 757
matirodriguez 0:1a9bfeb27157 758 ticker_deseado = (1100 - velocidad_deseada); // Seteo el tiempo del ticker deseado, dependiendo del valor de velocidad que se haya ingresado en la funcion.
matirodriguez 0:1a9bfeb27157 759
matirodriguez 0:1a9bfeb27157 760 timeout_VSlide = DESHABILITADO; // Reseteo el Flag del timeout
matirodriguez 0:1a9bfeb27157 761
matirodriguez 0:1a9bfeb27157 762 VSlide.attach_us(&timeoutVSlide, ticker_actual); // Seteo el tiempo para con el que se realizarán los cambios de estado
matirodriguez 0:1a9bfeb27157 763
matirodriguez 0:1a9bfeb27157 764 estado_VSlide = PASO; // Cambio de estado
matirodriguez 0:1a9bfeb27157 765
matirodriguez 0:1a9bfeb27157 766 stop_VSlide = MOVIENDO; // Indico que el motor se esta moviendo
matirodriguez 0:1a9bfeb27157 767 }
matirodriguez 0:1a9bfeb27157 768 break;
matirodriguez 0:1a9bfeb27157 769
matirodriguez 0:1a9bfeb27157 770 case PASO: // Caso: pongo la salida de step en 1
matirodriguez 0:1a9bfeb27157 771
matirodriguez 0:1a9bfeb27157 772 Slide_step = 1; // Pongo la salida de step en 1
matirodriguez 0:1a9bfeb27157 773
matirodriguez 0:1a9bfeb27157 774 if(timeout_VSlide == HABILITADO) { // Transicion a otro estado: cuando pasó el tiempo establecido en el ticker
matirodriguez 0:1a9bfeb27157 775
matirodriguez 0:1a9bfeb27157 776 timeout_VSlide = DESHABILITADO; // Reseteo el Flag del timeout
matirodriguez 0:1a9bfeb27157 777
matirodriguez 0:1a9bfeb27157 778 if(velocidad_deseada != 0) { // Siempre que la velocidad sea distinta de 0, es decir, que el joystick no esté en el estado de reposo
matirodriguez 0:1a9bfeb27157 779
matirodriguez 0:1a9bfeb27157 780 ticker_deseado = (1100 - velocidad_deseada); // Seteo el tiempo del ticker deseado, dependiendo del valor de velocidad que se haya ingresado en la funcion.
matirodriguez 0:1a9bfeb27157 781
matirodriguez 0:1a9bfeb27157 782 } else {
matirodriguez 0:1a9bfeb27157 783 ticker_deseado = 2000; // Si se desea el motor, establezco el ticker a un tiempo que sea tan lento como para considerar el motor parado
matirodriguez 0:1a9bfeb27157 784 }
matirodriguez 0:1a9bfeb27157 785
matirodriguez 0:1a9bfeb27157 786 if(Slide_dir != direccion) { // Caso de que la direccion deseada no sea la direccion ACTUAL del motor
matirodriguez 0:1a9bfeb27157 787 // En este caso, primero debo detener el motor para poder así comenzar otra vez con el giro
matirodriguez 0:1a9bfeb27157 788
matirodriguez 0:1a9bfeb27157 789 if(incremento_VSlide == HABILITADO) { // Si pasó el tiempo suficiente como para poder incrementar o disminuir la velocidad:
matirodriguez 0:1a9bfeb27157 790 incremento_VSlide = DESHABILITADO; // Limpio el Flag
matirodriguez 0:1a9bfeb27157 791 ticker_actual = ticker_actual + 10; // Incremento el ticker. Esto hará que cada vez el motor gire mas lento
matirodriguez 0:1a9bfeb27157 792 }
matirodriguez 0:1a9bfeb27157 793 if(ticker_actual >= 2000) { // Cuando considero que el motor está casi detenido:
matirodriguez 0:1a9bfeb27157 794 Slide_dir = direccion; // Cambio la direccion
matirodriguez 0:1a9bfeb27157 795 }
matirodriguez 0:1a9bfeb27157 796 } else if(Slide_dir == direccion) { // Caso de que la direccion sea la misma que la deseada:
matirodriguez 0:1a9bfeb27157 797 // En este caso, voy a aumentar o disminuir la velocidad dependiendo de lo que se desee
matirodriguez 0:1a9bfeb27157 798
matirodriguez 0:1a9bfeb27157 799 if(ticker_actual > ticker_deseado) { // Si el motor esta yendo mas lento que lo que yo deseo:
matirodriguez 0:1a9bfeb27157 800 if(incremento_VSlide == HABILITADO) { // Y me encuentro habilitado para incrementar:
matirodriguez 0:1a9bfeb27157 801 incremento_VSlide = DESHABILITADO; // Limpio el Flag
matirodriguez 0:1a9bfeb27157 802 ticker_actual = ticker_actual - 10; // Y aumento la velocidad
matirodriguez 0:1a9bfeb27157 803 }
matirodriguez 0:1a9bfeb27157 804 }
matirodriguez 0:1a9bfeb27157 805 if(ticker_actual < ticker_deseado) { // Si el motor esta yendo mas rapido de lo que debería:
matirodriguez 0:1a9bfeb27157 806 if(incremento_VSlide == HABILITADO) { // Y me encuentro habilitado para incrementar:
matirodriguez 0:1a9bfeb27157 807 incremento_VSlide = DESHABILITADO; // Limpio el Flag
matirodriguez 0:1a9bfeb27157 808 ticker_actual = ticker_actual + 10; // Y disminuyo la velocidad
matirodriguez 0:1a9bfeb27157 809 }
matirodriguez 0:1a9bfeb27157 810 }
matirodriguez 0:1a9bfeb27157 811 }
matirodriguez 0:1a9bfeb27157 812 VSlide.attach_us(&timeoutVSlide, ticker_actual); // Seteo el tiempo para con el que se realizarán los cambios de estado
matirodriguez 0:1a9bfeb27157 813 estado_VSlide = DELAY; // Cambio de estado
matirodriguez 0:1a9bfeb27157 814 }
matirodriguez 0:1a9bfeb27157 815 break;
matirodriguez 0:1a9bfeb27157 816
matirodriguez 0:1a9bfeb27157 817 case DELAY: // Caso: pongo la salida de step en 0
matirodriguez 0:1a9bfeb27157 818 Slide_step = 0; // Pongo la salida de step en 0
matirodriguez 0:1a9bfeb27157 819
matirodriguez 0:1a9bfeb27157 820 if(timeout_VSlide == HABILITADO) { // Transicion a otro estado: cuando pasó el tiempo establecido en el ticker
matirodriguez 0:1a9bfeb27157 821 timeout_VSlide = DESHABILITADO; // Limpio Flag
matirodriguez 0:1a9bfeb27157 822
matirodriguez 0:1a9bfeb27157 823 if(ticker_actual >= 2000) { // Si la velocidad del motor es mas lenta de lo que yo considero como parado:
matirodriguez 0:1a9bfeb27157 824
matirodriguez 0:1a9bfeb27157 825 estado_VSlide = ESPERO; // Vuelvo al estado de reset
matirodriguez 0:1a9bfeb27157 826 hab_maq_VSlide = DESHABILITADO; // Deshabilito la maquina
matirodriguez 0:1a9bfeb27157 827
matirodriguez 0:1a9bfeb27157 828 } else { // Si el motor "sigue moviendose":
matirodriguez 0:1a9bfeb27157 829 VSlide.attach_us(&timeoutVSlide, ticker_actual); // Vuelvo a establecer un tiempo para cambiar de estado
matirodriguez 0:1a9bfeb27157 830 if(Slide_dir == 1) {
matirodriguez 0:1a9bfeb27157 831 pasos_slide--; // Como hice un paso, lo sumo a la cuenta.
matirodriguez 0:1a9bfeb27157 832 } else {
matirodriguez 0:1a9bfeb27157 833 pasos_slide++; // Como hice un paso, lo sumo a la cuenta.
matirodriguez 0:1a9bfeb27157 834 }
matirodriguez 0:1a9bfeb27157 835
matirodriguez 0:1a9bfeb27157 836 estado_VSlide = PASO; // Cambio de estado
matirodriguez 0:1a9bfeb27157 837 }
matirodriguez 0:1a9bfeb27157 838 }
matirodriguez 0:1a9bfeb27157 839 break;
matirodriguez 0:1a9bfeb27157 840 }
matirodriguez 0:1a9bfeb27157 841 }
matirodriguez 0:1a9bfeb27157 842 void MAQ_VTilt(int velocidad_deseada, int direccion)
matirodriguez 0:1a9bfeb27157 843 {
matirodriguez 0:1a9bfeb27157 844 // Para que no existan cambios bruscos de velocidad, voy a ir incrementando el valor actual de la misma hasta llegar al punto que deseo.
matirodriguez 0:1a9bfeb27157 845 // De esta forma, seteo dos variables para poder lograr ese efecto.
matirodriguez 0:1a9bfeb27157 846 // Además, yo voy a querer que el motor no se detenga de golpe, asi que aprovecho este ultimo metodo para realizar esa operacion.
matirodriguez 0:1a9bfeb27157 847
matirodriguez 0:1a9bfeb27157 848 static int ticker_actual = 0; // Variable que me indicará el valor actual de tiempo de ticker (en micro-segundos)
matirodriguez 0:1a9bfeb27157 849 static int ticker_deseado = 0; // Variable que me indicará el valor deseado de tiempo de ticker (en micro-segundos), depèndiendo del joystick y de la pausa que se desee lograr
matirodriguez 0:1a9bfeb27157 850
matirodriguez 0:1a9bfeb27157 851 switch(estado_VTilt) {
matirodriguez 0:1a9bfeb27157 852
matirodriguez 0:1a9bfeb27157 853 case ESPERO: // Caso: Espero habilitacion de la maquina.
matirodriguez 0:1a9bfeb27157 854
matirodriguez 0:1a9bfeb27157 855 stop_VTilt = QUIETO; // Indico que la maquina no se activo todavia
matirodriguez 0:1a9bfeb27157 856
matirodriguez 0:1a9bfeb27157 857 if(hab_maq_VTilt == HABILITADO) {
matirodriguez 0:1a9bfeb27157 858
matirodriguez 0:1a9bfeb27157 859 Tilt_dir = direccion; // Establezco la salida fisica igual a la direccion que se indicó en la función
matirodriguez 0:1a9bfeb27157 860
matirodriguez 0:1a9bfeb27157 861 ticker_actual = 1999; // Seteo la velocidad de inicio como una lo suficientemente lenta como para considerar el motor "parado"
matirodriguez 0:1a9bfeb27157 862
matirodriguez 0:1a9bfeb27157 863 ticker_deseado = (1300 - velocidad_deseada); // Seteo el tiempo del ticker deseado, dependiendo del valor de velocidad que se haya ingresado en la funcion.
matirodriguez 0:1a9bfeb27157 864
matirodriguez 0:1a9bfeb27157 865 timeout_VTilt = DESHABILITADO; // Reseteo el Flag del timeout
matirodriguez 0:1a9bfeb27157 866
matirodriguez 0:1a9bfeb27157 867 VTilt.attach_us(&timeoutVTilt, ticker_actual); // Seteo el tiempo para con el que se realizarán los cambios de estado
matirodriguez 0:1a9bfeb27157 868
matirodriguez 0:1a9bfeb27157 869 estado_VTilt = PASO; // Cambio de estado
matirodriguez 0:1a9bfeb27157 870
matirodriguez 0:1a9bfeb27157 871 stop_VTilt = MOVIENDO; // Indico que el motor se esta moviendo
matirodriguez 0:1a9bfeb27157 872 }
matirodriguez 0:1a9bfeb27157 873 break;
matirodriguez 0:1a9bfeb27157 874
matirodriguez 0:1a9bfeb27157 875 case PASO: // Caso: pongo la salida de step en 1
matirodriguez 0:1a9bfeb27157 876
matirodriguez 0:1a9bfeb27157 877 Tilt_step = 1; // Pongo la salida de step en 1
matirodriguez 0:1a9bfeb27157 878
matirodriguez 0:1a9bfeb27157 879 if(timeout_VTilt == HABILITADO) { // Transicion a otro estado: cuando pasó el tiempo establecido en el ticker
matirodriguez 0:1a9bfeb27157 880
matirodriguez 0:1a9bfeb27157 881 timeout_VTilt = DESHABILITADO; // Reseteo el Flag del timeout
matirodriguez 0:1a9bfeb27157 882
matirodriguez 0:1a9bfeb27157 883 if(velocidad_deseada != 0) { // Siempre que la velocidad sea distinta de 0, es decir, que el joystick no esté en el estado de reposo
matirodriguez 0:1a9bfeb27157 884
matirodriguez 0:1a9bfeb27157 885 ticker_deseado = (1300 - velocidad_deseada); // Seteo el tiempo del ticker deseado, dependiendo del valor de velocidad que se haya ingresado en la funcion.
matirodriguez 0:1a9bfeb27157 886
matirodriguez 0:1a9bfeb27157 887 } else {
matirodriguez 0:1a9bfeb27157 888 ticker_deseado = 2000; // Si se desea el motor, establezco el ticker a un tiempo que sea tan lento como para considerar el motor parado
matirodriguez 0:1a9bfeb27157 889 }
matirodriguez 0:1a9bfeb27157 890
matirodriguez 0:1a9bfeb27157 891 if(Tilt_dir != direccion) { // Caso de que la direccion deseada no sea la direccion ACTUAL del motor
matirodriguez 0:1a9bfeb27157 892 // En este caso, primero debo detener el motor para poder así comenzar otra vez con el giro
matirodriguez 0:1a9bfeb27157 893
matirodriguez 0:1a9bfeb27157 894 if(incremento_VTilt == HABILITADO) { // Si pasó el tiempo suficiente como para poder incrementar o disminuir la velocidad:
matirodriguez 0:1a9bfeb27157 895 incremento_VTilt = DESHABILITADO; // Limpio el Flag
matirodriguez 0:1a9bfeb27157 896 ticker_actual = ticker_actual + 10; // Incremento el ticker. Esto hará que cada vez el motor gire mas lento
matirodriguez 0:1a9bfeb27157 897 }
matirodriguez 0:1a9bfeb27157 898 if(ticker_actual >= 2000) { // Cuando considero que el motor está casi detenido:
matirodriguez 0:1a9bfeb27157 899 Tilt_dir = direccion; // Cambio la direccion
matirodriguez 0:1a9bfeb27157 900 }
matirodriguez 0:1a9bfeb27157 901 } else if(Tilt_dir == direccion) { // Caso de que la direccion sea la misma que la deseada:
matirodriguez 0:1a9bfeb27157 902 // En este caso, voy a aumentar o disminuir la velocidad dependiendo de lo que se desee
matirodriguez 0:1a9bfeb27157 903
matirodriguez 0:1a9bfeb27157 904 if(ticker_actual > ticker_deseado) { // Si el motor esta yendo mas lento que lo que yo deseo:
matirodriguez 0:1a9bfeb27157 905 if(incremento_VTilt == HABILITADO) { // Y me encuentro habilitado para incrementar:
matirodriguez 0:1a9bfeb27157 906 incremento_VTilt = DESHABILITADO; // Limpio el Flag
matirodriguez 0:1a9bfeb27157 907 ticker_actual = ticker_actual - 10; // Y aumento la velocidad
matirodriguez 0:1a9bfeb27157 908 }
matirodriguez 0:1a9bfeb27157 909 }
matirodriguez 0:1a9bfeb27157 910 if(ticker_actual < ticker_deseado) { // Si el motor esta yendo mas rapido de lo que debería:
matirodriguez 0:1a9bfeb27157 911 if(incremento_VTilt == HABILITADO) { // Y me encuentro habilitado para incrementar:
matirodriguez 0:1a9bfeb27157 912 incremento_VTilt = DESHABILITADO; // Limpio el Flag
matirodriguez 0:1a9bfeb27157 913 ticker_actual = ticker_actual + 10; // Y disminuyo la velocidad
matirodriguez 0:1a9bfeb27157 914 }
matirodriguez 0:1a9bfeb27157 915 }
matirodriguez 0:1a9bfeb27157 916 }
matirodriguez 0:1a9bfeb27157 917 VTilt.attach_us(&timeoutVTilt, ticker_actual); // Seteo el tiempo para con el que se realizarán los cambios de estado
matirodriguez 0:1a9bfeb27157 918 estado_VTilt = DELAY; // Cambio de estado
matirodriguez 0:1a9bfeb27157 919 }
matirodriguez 0:1a9bfeb27157 920 break;
matirodriguez 0:1a9bfeb27157 921
matirodriguez 0:1a9bfeb27157 922 case DELAY: // Caso: pongo la salida de step en 0
matirodriguez 0:1a9bfeb27157 923 Tilt_step = 0; // Pongo la salida de step en 0
matirodriguez 0:1a9bfeb27157 924
matirodriguez 0:1a9bfeb27157 925 if(timeout_VTilt == HABILITADO) { // Transicion a otro estado: cuando pasó el tiempo establecido en el ticker
matirodriguez 0:1a9bfeb27157 926 timeout_VTilt = DESHABILITADO; // Limpio Flag
matirodriguez 0:1a9bfeb27157 927
matirodriguez 0:1a9bfeb27157 928 if(ticker_actual >= 2000) { // Si la velocidad del motor es mas lenta de lo que yo considero como parado:
matirodriguez 0:1a9bfeb27157 929
matirodriguez 0:1a9bfeb27157 930 estado_VTilt = ESPERO; // Vuelvo al estado de reset
matirodriguez 0:1a9bfeb27157 931 hab_maq_VTilt = DESHABILITADO; // Deshabilito la maquina
matirodriguez 0:1a9bfeb27157 932
matirodriguez 0:1a9bfeb27157 933 } else { // Si el motor "sigue moviendose":
matirodriguez 0:1a9bfeb27157 934 VTilt.attach_us(&timeoutVTilt, ticker_actual); // Vuelvo a establecer un tiempo para cambiar de estado
matirodriguez 0:1a9bfeb27157 935 if(Tilt_dir == 1) {
matirodriguez 0:1a9bfeb27157 936 pasos_tilt--; // Como hice un paso, lo sumo a la cuenta.
matirodriguez 0:1a9bfeb27157 937 } else {
matirodriguez 0:1a9bfeb27157 938 pasos_tilt++; // Como hice un paso, lo sumo a la cuenta.
matirodriguez 0:1a9bfeb27157 939 }
matirodriguez 0:1a9bfeb27157 940 estado_VTilt = PASO; // Cambio de estado
matirodriguez 0:1a9bfeb27157 941 }
matirodriguez 0:1a9bfeb27157 942 }
matirodriguez 0:1a9bfeb27157 943 break;
matirodriguez 0:1a9bfeb27157 944 }
matirodriguez 0:1a9bfeb27157 945 }
matirodriguez 0:1a9bfeb27157 946 void MAQ_VPan(int velocidad_deseada, int direccion)
matirodriguez 0:1a9bfeb27157 947 {
matirodriguez 0:1a9bfeb27157 948 // Para que no existan cambios bruscos de velocidad, voy a ir incrementando el valor actual de la misma hasta llegar al punto que deseo.
matirodriguez 0:1a9bfeb27157 949 // De esta forma, seteo dos variables para poder lograr ese efecto.
matirodriguez 0:1a9bfeb27157 950 // Además, yo voy a querer que el motor no se detenga de golpe, asi que aprovecho este ultimo metodo para realizar esa operacion.
matirodriguez 0:1a9bfeb27157 951
matirodriguez 0:1a9bfeb27157 952 static int ticker_actual = 0; // Variable que me indicará el valor actual de tiempo de ticker (en micro-segundos)
matirodriguez 0:1a9bfeb27157 953 static int ticker_deseado = 0; // Variable que me indicará el valor deseado de tiempo de ticker (en micro-segundos), depèndiendo del joystick y de la pausa que se desee lograr
matirodriguez 0:1a9bfeb27157 954
matirodriguez 0:1a9bfeb27157 955 switch(estado_VPan) {
matirodriguez 0:1a9bfeb27157 956
matirodriguez 0:1a9bfeb27157 957 case ESPERO: // Caso: Espero habilitacion de la maquina.
matirodriguez 0:1a9bfeb27157 958
matirodriguez 0:1a9bfeb27157 959 stop_VPan = QUIETO; // Indico que la maquina no se activo todavia
matirodriguez 0:1a9bfeb27157 960
matirodriguez 0:1a9bfeb27157 961 if(hab_maq_VPan == HABILITADO) {
matirodriguez 0:1a9bfeb27157 962
matirodriguez 0:1a9bfeb27157 963 Pan_dir = direccion; // Establezco la salida fisica igual a la direccion que se indicó en la función
matirodriguez 0:1a9bfeb27157 964
matirodriguez 0:1a9bfeb27157 965 ticker_actual = 1999; // Seteo la velocidad de inicio como una lo suficientemente lenta como para considerar el motor "parado"
matirodriguez 0:1a9bfeb27157 966
matirodriguez 0:1a9bfeb27157 967 ticker_deseado = (1300 - velocidad_deseada); // Seteo el tiempo del ticker deseado, dependiendo del valor de velocidad que se haya ingresado en la funcion.
matirodriguez 0:1a9bfeb27157 968
matirodriguez 0:1a9bfeb27157 969 timeout_VPan = DESHABILITADO; // Reseteo el Flag del timeout
matirodriguez 0:1a9bfeb27157 970
matirodriguez 0:1a9bfeb27157 971 VPan.attach_us(&timeoutVPan, ticker_actual); // Seteo el tiempo para con el que se realizarán los cambios de estado
matirodriguez 0:1a9bfeb27157 972
matirodriguez 0:1a9bfeb27157 973 estado_VPan = PASO; // Cambio de estado
matirodriguez 0:1a9bfeb27157 974
matirodriguez 0:1a9bfeb27157 975 stop_VPan = MOVIENDO; // Indico que el motor se esta moviendo
matirodriguez 0:1a9bfeb27157 976 }
matirodriguez 0:1a9bfeb27157 977 break;
matirodriguez 0:1a9bfeb27157 978
matirodriguez 0:1a9bfeb27157 979 case PASO: // Caso: pongo la salida de step en 1
matirodriguez 0:1a9bfeb27157 980
matirodriguez 0:1a9bfeb27157 981 Pan_step = 1; // Pongo la salida de step en 1
matirodriguez 0:1a9bfeb27157 982
matirodriguez 0:1a9bfeb27157 983 if(timeout_VPan == HABILITADO) { // Transicion a otro estado: cuando pasó el tiempo establecido en el ticker
matirodriguez 0:1a9bfeb27157 984
matirodriguez 0:1a9bfeb27157 985 timeout_VPan = DESHABILITADO; // Reseteo el Flag del timeout
matirodriguez 0:1a9bfeb27157 986
matirodriguez 0:1a9bfeb27157 987 if(velocidad_deseada != 0) { // Siempre que la velocidad sea distinta de 0, es decir, que el joystick no esté en el estado de reposo
matirodriguez 0:1a9bfeb27157 988
matirodriguez 0:1a9bfeb27157 989 ticker_deseado = (1300 - velocidad_deseada); // Seteo el tiempo del ticker deseado, dependiendo del valor de velocidad que se haya ingresado en la funcion.
matirodriguez 0:1a9bfeb27157 990
matirodriguez 0:1a9bfeb27157 991 } else {
matirodriguez 0:1a9bfeb27157 992 ticker_deseado = 2000; // Si se desea el motor, establezco el ticker a un tiempo que sea tan lento como para considerar el motor parado
matirodriguez 0:1a9bfeb27157 993 }
matirodriguez 0:1a9bfeb27157 994
matirodriguez 0:1a9bfeb27157 995 if(Pan_dir != direccion) { // Caso de que la direccion deseada no sea la direccion ACTUAL del motor
matirodriguez 0:1a9bfeb27157 996 // En este caso, primero debo detener el motor para poder así comenzar otra vez con el giro
matirodriguez 0:1a9bfeb27157 997
matirodriguez 0:1a9bfeb27157 998 if(incremento_VPan == HABILITADO) { // Si pasó el tiempo suficiente como para poder incrementar o disminuir la velocidad:
matirodriguez 0:1a9bfeb27157 999 incremento_VPan = DESHABILITADO; // Limpio el Flag
matirodriguez 0:1a9bfeb27157 1000 ticker_actual = ticker_actual + 10; // Incremento el ticker. Esto hará que cada vez el motor gire mas lento
matirodriguez 0:1a9bfeb27157 1001 }
matirodriguez 0:1a9bfeb27157 1002 if(ticker_actual >= 2000) { // Cuando considero que el motor está casi detenido:
matirodriguez 0:1a9bfeb27157 1003 Pan_dir = direccion; // Cambio la direccion
matirodriguez 0:1a9bfeb27157 1004 }
matirodriguez 0:1a9bfeb27157 1005 } else if(Pan_dir == direccion) { // Caso de que la direccion sea la misma que la deseada:
matirodriguez 0:1a9bfeb27157 1006 // En este caso, voy a aumentar o disminuir la velocidad dependiendo de lo que se desee
matirodriguez 0:1a9bfeb27157 1007
matirodriguez 0:1a9bfeb27157 1008 if(ticker_actual > ticker_deseado) { // Si el motor esta yendo mas lento que lo que yo deseo:
matirodriguez 0:1a9bfeb27157 1009 if(incremento_VPan == HABILITADO) { // Y me encuentro habilitado para incrementar:
matirodriguez 0:1a9bfeb27157 1010 incremento_VPan = DESHABILITADO; // Limpio el Flag
matirodriguez 0:1a9bfeb27157 1011 ticker_actual = ticker_actual - 10; // Y aumento la velocidad
matirodriguez 0:1a9bfeb27157 1012 }
matirodriguez 0:1a9bfeb27157 1013 }
matirodriguez 0:1a9bfeb27157 1014 if(ticker_actual < ticker_deseado) { // Si el motor esta yendo mas rapido de lo que debería:
matirodriguez 0:1a9bfeb27157 1015 if(incremento_VPan == HABILITADO) { // Y me encuentro habilitado para incrementar:
matirodriguez 0:1a9bfeb27157 1016 incremento_VPan = DESHABILITADO; // Limpio el Flag
matirodriguez 0:1a9bfeb27157 1017 ticker_actual = ticker_actual + 10; // Y disminuyo la velocidad
matirodriguez 0:1a9bfeb27157 1018 }
matirodriguez 0:1a9bfeb27157 1019 }
matirodriguez 0:1a9bfeb27157 1020 }
matirodriguez 0:1a9bfeb27157 1021 VPan.attach_us(&timeoutVPan, ticker_actual); // Seteo el tiempo para con el que se realizarán los cambios de estado
matirodriguez 0:1a9bfeb27157 1022 estado_VPan = DELAY; // Cambio de estado
matirodriguez 0:1a9bfeb27157 1023 }
matirodriguez 0:1a9bfeb27157 1024 break;
matirodriguez 0:1a9bfeb27157 1025
matirodriguez 0:1a9bfeb27157 1026 case DELAY: // Caso: pongo la salida de step en 0
matirodriguez 0:1a9bfeb27157 1027 Pan_step = 0; // Pongo la salida de step en 0
matirodriguez 0:1a9bfeb27157 1028
matirodriguez 0:1a9bfeb27157 1029 if(timeout_VPan == HABILITADO) { // Transicion a otro estado: cuando pasó el tiempo establecido en el ticker
matirodriguez 0:1a9bfeb27157 1030 timeout_VPan = DESHABILITADO; // Limpio Flag
matirodriguez 0:1a9bfeb27157 1031
matirodriguez 0:1a9bfeb27157 1032 if(ticker_actual >= 2000) { // Si la velocidad del motor es mas lenta de lo que yo considero como parado:
matirodriguez 0:1a9bfeb27157 1033
matirodriguez 0:1a9bfeb27157 1034 estado_VPan = ESPERO; // Vuelvo al estado de reset
matirodriguez 0:1a9bfeb27157 1035 hab_maq_VPan = DESHABILITADO; // Deshabilito la maquina
matirodriguez 0:1a9bfeb27157 1036
matirodriguez 0:1a9bfeb27157 1037 } else { // Si el motor "sigue moviendose":
matirodriguez 0:1a9bfeb27157 1038 VPan.attach_us(&timeoutVPan, ticker_actual); // Vuelvo a establecer un tiempo para cambiar de estado
matirodriguez 0:1a9bfeb27157 1039 if(Pan_dir == 1) {
matirodriguez 0:1a9bfeb27157 1040 pasos_pan--; // Como hice un paso, lo sumo a la cuenta.
matirodriguez 0:1a9bfeb27157 1041 } else {
matirodriguez 0:1a9bfeb27157 1042 pasos_pan++; // Como hice un paso, lo sumo a la cuenta.
matirodriguez 0:1a9bfeb27157 1043 }
matirodriguez 0:1a9bfeb27157 1044 estado_VPan = PASO; // Cambio de estado
matirodriguez 0:1a9bfeb27157 1045 }
matirodriguez 0:1a9bfeb27157 1046 }
matirodriguez 0:1a9bfeb27157 1047 break;
matirodriguez 0:1a9bfeb27157 1048 }
matirodriguez 0:1a9bfeb27157 1049 }
matirodriguez 0:1a9bfeb27157 1050 void MAQ_recepcion_app()
matirodriguez 0:1a9bfeb27157 1051 {
matirodriguez 0:1a9bfeb27157 1052 static int aux_slide[3];
matirodriguez 0:1a9bfeb27157 1053 static int aux_tilt[3];
matirodriguez 0:1a9bfeb27157 1054 static int aux_pan[3];
matirodriguez 0:1a9bfeb27157 1055 static int aux_botones[2];
matirodriguez 0:1a9bfeb27157 1056 static int crc;
matirodriguez 0:1a9bfeb27157 1057 static int aux_vel[2];
matirodriguez 0:1a9bfeb27157 1058 static int trama_recibida = 0;
matirodriguez 0:1a9bfeb27157 1059 static int aux_modo = 0;
matirodriguez 0:1a9bfeb27157 1060 static int aux_loop = DESHABILITADO;
matirodriguez 0:1a9bfeb27157 1061 static int t_delay[4];
matirodriguez 0:1a9bfeb27157 1062 static int t_out[4];
matirodriguez 0:1a9bfeb27157 1063 static int aux_pe;
matirodriguez 0:1a9bfeb27157 1064 static int aux_accuracy[2];
matirodriguez 0:1a9bfeb27157 1065 static int aux_timelapse;
matirodriguez 0:1a9bfeb27157 1066 static int timelapse_t[4];
matirodriguez 0:1a9bfeb27157 1067 static int ladoTimelapse = 0;
matirodriguez 0:1a9bfeb27157 1068 static int modoTimelapse = 0;
matirodriguez 0:1a9bfeb27157 1069
matirodriguez 0:1a9bfeb27157 1070 switch(estado_recepcion_app) {
matirodriguez 0:1a9bfeb27157 1071 case START:
matirodriguez 0:1a9bfeb27157 1072
matirodriguez 0:1a9bfeb27157 1073 // Reseteo todas las variables
matirodriguez 0:1a9bfeb27157 1074 aux_slide[0] = 0;
matirodriguez 0:1a9bfeb27157 1075 aux_slide[1] = 0;
matirodriguez 0:1a9bfeb27157 1076 aux_slide[2] = 0;
matirodriguez 0:1a9bfeb27157 1077 aux_tilt[0] = 0;
matirodriguez 0:1a9bfeb27157 1078 aux_tilt[1] = 0;
matirodriguez 0:1a9bfeb27157 1079 aux_tilt[2] = 0;
matirodriguez 0:1a9bfeb27157 1080 aux_pan[0] = 0;
matirodriguez 0:1a9bfeb27157 1081 aux_pan[1] = 0;
matirodriguez 0:1a9bfeb27157 1082 aux_pan[2] = 0;
matirodriguez 0:1a9bfeb27157 1083 aux_vel[0] = 0;
matirodriguez 0:1a9bfeb27157 1084 aux_vel[1] = 0;
matirodriguez 0:1a9bfeb27157 1085 crc = 0;
matirodriguez 0:1a9bfeb27157 1086 trama_recibida = 0;
matirodriguez 0:1a9bfeb27157 1087 aux_modo = 0;
matirodriguez 0:1a9bfeb27157 1088 aux_loop = DESHABILITADO;
matirodriguez 0:1a9bfeb27157 1089 t_delay[1]=0;
matirodriguez 0:1a9bfeb27157 1090 t_delay[2]=0;
matirodriguez 0:1a9bfeb27157 1091 t_delay[3]=0;
matirodriguez 0:1a9bfeb27157 1092 t_out[1]=0;
matirodriguez 0:1a9bfeb27157 1093 t_out[2]=0;
matirodriguez 0:1a9bfeb27157 1094 t_out[3]=0;
matirodriguez 0:1a9bfeb27157 1095 aux_accuracy[0] = 0;
matirodriguez 0:1a9bfeb27157 1096 aux_accuracy[1] = 0;
matirodriguez 0:1a9bfeb27157 1097 aux_pe = 0;
matirodriguez 0:1a9bfeb27157 1098 aux_timelapse;
matirodriguez 0:1a9bfeb27157 1099 timelapse_t[1]=0;
matirodriguez 0:1a9bfeb27157 1100 timelapse_t[2]=0;
matirodriguez 0:1a9bfeb27157 1101 timelapse_t[3]=0;
matirodriguez 0:1a9bfeb27157 1102 ladoTimelapse = 0;
matirodriguez 0:1a9bfeb27157 1103 modoTimelapse = 0;
matirodriguez 0:1a9bfeb27157 1104
matirodriguez 0:1a9bfeb27157 1105
matirodriguez 0:1a9bfeb27157 1106 if(ingreso_app == '$') {
matirodriguez 0:1a9bfeb27157 1107 estado_recepcion_app = INICIO;
matirodriguez 0:1a9bfeb27157 1108 }
matirodriguez 0:1a9bfeb27157 1109 break;
matirodriguez 0:1a9bfeb27157 1110
matirodriguez 0:1a9bfeb27157 1111 case INICIO:
matirodriguez 0:1a9bfeb27157 1112
matirodriguez 0:1a9bfeb27157 1113 // Reseteo todas las variables
matirodriguez 0:1a9bfeb27157 1114 aux_slide[0] = 0;
matirodriguez 0:1a9bfeb27157 1115 aux_slide[1] = 0;
matirodriguez 0:1a9bfeb27157 1116 aux_slide[2] = 0;
matirodriguez 0:1a9bfeb27157 1117 aux_tilt[0] = 0;
matirodriguez 0:1a9bfeb27157 1118 aux_tilt[1] = 0;
matirodriguez 0:1a9bfeb27157 1119 aux_tilt[2] = 0;
matirodriguez 0:1a9bfeb27157 1120 aux_pan[0] = 0;
matirodriguez 0:1a9bfeb27157 1121 aux_pan[1] = 0;
matirodriguez 0:1a9bfeb27157 1122 aux_pan[2] = 0;
matirodriguez 0:1a9bfeb27157 1123 aux_vel[0] = 0;
matirodriguez 0:1a9bfeb27157 1124 aux_vel[1] = 0;
matirodriguez 0:1a9bfeb27157 1125 crc = 0;
matirodriguez 0:1a9bfeb27157 1126 trama_recibida = 0;
matirodriguez 0:1a9bfeb27157 1127 aux_modo = 0;
matirodriguez 0:1a9bfeb27157 1128 aux_loop = DESHABILITADO;
matirodriguez 0:1a9bfeb27157 1129 t_delay[1]=0;
matirodriguez 0:1a9bfeb27157 1130 t_delay[2]=0;
matirodriguez 0:1a9bfeb27157 1131 t_delay[3]=0;
matirodriguez 0:1a9bfeb27157 1132 t_out[1]=0;
matirodriguez 0:1a9bfeb27157 1133 t_out[2]=0;
matirodriguez 0:1a9bfeb27157 1134 t_out[3]=0;
matirodriguez 0:1a9bfeb27157 1135 aux_accuracy[0] = 0;
matirodriguez 0:1a9bfeb27157 1136 aux_accuracy[1] = 0;
matirodriguez 0:1a9bfeb27157 1137 aux_pe = 0;
matirodriguez 0:1a9bfeb27157 1138 aux_timelapse;
matirodriguez 0:1a9bfeb27157 1139 timelapse_t[1]=0;
matirodriguez 0:1a9bfeb27157 1140 timelapse_t[2]=0;
matirodriguez 0:1a9bfeb27157 1141 timelapse_t[3]=0;
matirodriguez 0:1a9bfeb27157 1142 ladoTimelapse = 0;
matirodriguez 0:1a9bfeb27157 1143 modoTimelapse = 0;
matirodriguez 0:1a9bfeb27157 1144
matirodriguez 0:1a9bfeb27157 1145 if((ingreso_app == '$')||(ingreso_app == 'S')||(ingreso_app == 'V')||(ingreso_app == 'J')||(ingreso_app == 'L')||(ingreso_app == 'P')||(ingreso_app == 'T')) {
matirodriguez 0:1a9bfeb27157 1146 if(ingreso_app == 'S') {
matirodriguez 0:1a9bfeb27157 1147 estado_recepcion_app = S1;
matirodriguez 0:1a9bfeb27157 1148 }
matirodriguez 0:1a9bfeb27157 1149 if(ingreso_app == 'V') {
matirodriguez 0:1a9bfeb27157 1150 estado_recepcion_app = V1;
matirodriguez 0:1a9bfeb27157 1151 }
matirodriguez 0:1a9bfeb27157 1152 if(ingreso_app == 'J') {
matirodriguez 0:1a9bfeb27157 1153 estado_recepcion_app = HAB_JOYSTICK;
matirodriguez 0:1a9bfeb27157 1154 }
matirodriguez 0:1a9bfeb27157 1155 if(ingreso_app == 'L') {
matirodriguez 0:1a9bfeb27157 1156 estado_recepcion_app = LOOP_HAB;
matirodriguez 0:1a9bfeb27157 1157 }
matirodriguez 0:1a9bfeb27157 1158 if(ingreso_app == 'T') {
matirodriguez 0:1a9bfeb27157 1159 estado_recepcion_app = TIMELAPSE;
matirodriguez 0:1a9bfeb27157 1160 }
matirodriguez 0:1a9bfeb27157 1161 if(ingreso_app == 'P') {
matirodriguez 0:1a9bfeb27157 1162 estado_recepcion_app = PUNTOE;
matirodriguez 0:1a9bfeb27157 1163 aux_pe = 1;
matirodriguez 0:1a9bfeb27157 1164 }
matirodriguez 0:1a9bfeb27157 1165 if(ingreso_app == '$') {
matirodriguez 0:1a9bfeb27157 1166 estado_recepcion_app = INICIO;
matirodriguez 0:1a9bfeb27157 1167 }
matirodriguez 0:1a9bfeb27157 1168 } else {
matirodriguez 0:1a9bfeb27157 1169 estado_recepcion_app = START;
matirodriguez 0:1a9bfeb27157 1170 }
matirodriguez 0:1a9bfeb27157 1171 break;
matirodriguez 0:1a9bfeb27157 1172
matirodriguez 0:1a9bfeb27157 1173 case S1:
matirodriguez 0:1a9bfeb27157 1174
matirodriguez 0:1a9bfeb27157 1175 if((ingreso_app == '$')||((ingreso_app>='0')&&(ingreso_app<='9'))) {
matirodriguez 0:1a9bfeb27157 1176 if((ingreso_app>='0')&&(ingreso_app<='9')) {
matirodriguez 0:1a9bfeb27157 1177 estado_recepcion_app = S2;
matirodriguez 0:1a9bfeb27157 1178 //RECIBO PRIMER DIGITO
matirodriguez 0:1a9bfeb27157 1179 aux_slide[0] = ingreso_app;
matirodriguez 0:1a9bfeb27157 1180 }
matirodriguez 0:1a9bfeb27157 1181 if(ingreso_app == '$') {
matirodriguez 0:1a9bfeb27157 1182 estado_recepcion_app = INICIO;
matirodriguez 0:1a9bfeb27157 1183 }
matirodriguez 0:1a9bfeb27157 1184 } else {
matirodriguez 0:1a9bfeb27157 1185 estado_recepcion_app = START;
matirodriguez 0:1a9bfeb27157 1186 }
matirodriguez 0:1a9bfeb27157 1187 break;
matirodriguez 0:1a9bfeb27157 1188
matirodriguez 0:1a9bfeb27157 1189 case S2:
matirodriguez 0:1a9bfeb27157 1190
matirodriguez 0:1a9bfeb27157 1191 if((ingreso_app == '$')||((ingreso_app>='0')&&(ingreso_app<='9'))) {
matirodriguez 0:1a9bfeb27157 1192 if((ingreso_app>='0')&&(ingreso_app<='9')) {
matirodriguez 0:1a9bfeb27157 1193 estado_recepcion_app = S3;
matirodriguez 0:1a9bfeb27157 1194 //RECIBO SEGUNDO DIGITO
matirodriguez 0:1a9bfeb27157 1195 aux_slide[1] = ingreso_app;
matirodriguez 0:1a9bfeb27157 1196 }
matirodriguez 0:1a9bfeb27157 1197 if(ingreso_app == '$') {
matirodriguez 0:1a9bfeb27157 1198 estado_recepcion_app = INICIO;
matirodriguez 0:1a9bfeb27157 1199 }
matirodriguez 0:1a9bfeb27157 1200 } else {
matirodriguez 0:1a9bfeb27157 1201 estado_recepcion_app = START;
matirodriguez 0:1a9bfeb27157 1202 }
matirodriguez 0:1a9bfeb27157 1203 break;
matirodriguez 0:1a9bfeb27157 1204
matirodriguez 0:1a9bfeb27157 1205 case S3:
matirodriguez 0:1a9bfeb27157 1206
matirodriguez 0:1a9bfeb27157 1207 if((ingreso_app == '$')||((ingreso_app>='0')&&(ingreso_app<='9'))) {
matirodriguez 0:1a9bfeb27157 1208 if((ingreso_app>='0')&&(ingreso_app<='9')) {
matirodriguez 0:1a9bfeb27157 1209 estado_recepcion_app = TILT;
matirodriguez 0:1a9bfeb27157 1210 //RECIBO TERCER DIGITO
matirodriguez 0:1a9bfeb27157 1211 aux_slide[2] = ingreso_app;
matirodriguez 0:1a9bfeb27157 1212 }
matirodriguez 0:1a9bfeb27157 1213 if(ingreso_app == '$') {
matirodriguez 0:1a9bfeb27157 1214 estado_recepcion_app = INICIO;
matirodriguez 0:1a9bfeb27157 1215 }
matirodriguez 0:1a9bfeb27157 1216 } else {
matirodriguez 0:1a9bfeb27157 1217 estado_recepcion_app = START;
matirodriguez 0:1a9bfeb27157 1218 }
matirodriguez 0:1a9bfeb27157 1219 break;
matirodriguez 0:1a9bfeb27157 1220 case TILT:
matirodriguez 0:1a9bfeb27157 1221
matirodriguez 0:1a9bfeb27157 1222 if((ingreso_app == '$')||(ingreso_app == 'T')) {
matirodriguez 0:1a9bfeb27157 1223 if(ingreso_app == 'T') {
matirodriguez 0:1a9bfeb27157 1224 estado_recepcion_app = T1;
matirodriguez 0:1a9bfeb27157 1225 }
matirodriguez 0:1a9bfeb27157 1226 if(ingreso_app == '$') {
matirodriguez 0:1a9bfeb27157 1227 estado_recepcion_app = INICIO;
matirodriguez 0:1a9bfeb27157 1228 }
matirodriguez 0:1a9bfeb27157 1229 } else {
matirodriguez 0:1a9bfeb27157 1230 estado_recepcion_app = START;
matirodriguez 0:1a9bfeb27157 1231 }
matirodriguez 0:1a9bfeb27157 1232 break;
matirodriguez 0:1a9bfeb27157 1233
matirodriguez 0:1a9bfeb27157 1234 case T1:
matirodriguez 0:1a9bfeb27157 1235
matirodriguez 0:1a9bfeb27157 1236 if((ingreso_app == '$')||((ingreso_app>='0')&&(ingreso_app<='9'))) {
matirodriguez 0:1a9bfeb27157 1237 if((ingreso_app>='0')&&(ingreso_app<='9')) {
matirodriguez 0:1a9bfeb27157 1238 estado_recepcion_app = T2;
matirodriguez 0:1a9bfeb27157 1239 //RECIBO PRIMER DIGITO
matirodriguez 0:1a9bfeb27157 1240 aux_tilt[0] = ingreso_app;
matirodriguez 0:1a9bfeb27157 1241 }
matirodriguez 0:1a9bfeb27157 1242 if(ingreso_app == '$') {
matirodriguez 0:1a9bfeb27157 1243 estado_recepcion_app = INICIO;
matirodriguez 0:1a9bfeb27157 1244 }
matirodriguez 0:1a9bfeb27157 1245 } else {
matirodriguez 0:1a9bfeb27157 1246 estado_recepcion_app = START;
matirodriguez 0:1a9bfeb27157 1247 }
matirodriguez 0:1a9bfeb27157 1248 break;
matirodriguez 0:1a9bfeb27157 1249
matirodriguez 0:1a9bfeb27157 1250 case T2:
matirodriguez 0:1a9bfeb27157 1251
matirodriguez 0:1a9bfeb27157 1252 if((ingreso_app == '$')||((ingreso_app>='0')&&(ingreso_app<='9'))) {
matirodriguez 0:1a9bfeb27157 1253 if((ingreso_app>='0')&&(ingreso_app<='9')) {
matirodriguez 0:1a9bfeb27157 1254 estado_recepcion_app = T3;
matirodriguez 0:1a9bfeb27157 1255 //RECIBO SEGUNDO DIGITO
matirodriguez 0:1a9bfeb27157 1256 aux_tilt[1] = ingreso_app;
matirodriguez 0:1a9bfeb27157 1257 }
matirodriguez 0:1a9bfeb27157 1258 if(ingreso_app == '$') {
matirodriguez 0:1a9bfeb27157 1259 estado_recepcion_app = INICIO;
matirodriguez 0:1a9bfeb27157 1260 }
matirodriguez 0:1a9bfeb27157 1261 } else {
matirodriguez 0:1a9bfeb27157 1262 estado_recepcion_app = START;
matirodriguez 0:1a9bfeb27157 1263 }
matirodriguez 0:1a9bfeb27157 1264 break;
matirodriguez 0:1a9bfeb27157 1265
matirodriguez 0:1a9bfeb27157 1266 case T3:
matirodriguez 0:1a9bfeb27157 1267
matirodriguez 0:1a9bfeb27157 1268 if((ingreso_app == '$')||((ingreso_app>='0')&&(ingreso_app<='9'))) {
matirodriguez 0:1a9bfeb27157 1269 if((ingreso_app>='0')&&(ingreso_app<='9')) {
matirodriguez 0:1a9bfeb27157 1270 estado_recepcion_app = PAN;
matirodriguez 0:1a9bfeb27157 1271 //RECIBO TERCER DIGITO
matirodriguez 0:1a9bfeb27157 1272 aux_tilt[2] = ingreso_app;
matirodriguez 0:1a9bfeb27157 1273 }
matirodriguez 0:1a9bfeb27157 1274 if(ingreso_app == '$') {
matirodriguez 0:1a9bfeb27157 1275 estado_recepcion_app = INICIO;
matirodriguez 0:1a9bfeb27157 1276 }
matirodriguez 0:1a9bfeb27157 1277 } else {
matirodriguez 0:1a9bfeb27157 1278 estado_recepcion_app = START;
matirodriguez 0:1a9bfeb27157 1279 }
matirodriguez 0:1a9bfeb27157 1280 break;
matirodriguez 0:1a9bfeb27157 1281
matirodriguez 0:1a9bfeb27157 1282 case PAN:
matirodriguez 0:1a9bfeb27157 1283
matirodriguez 0:1a9bfeb27157 1284 if((ingreso_app == '$')||(ingreso_app == 'P')) {
matirodriguez 0:1a9bfeb27157 1285 if(ingreso_app == 'P') {
matirodriguez 0:1a9bfeb27157 1286 estado_recepcion_app = P1;
matirodriguez 0:1a9bfeb27157 1287 }
matirodriguez 0:1a9bfeb27157 1288 if(ingreso_app == '$') {
matirodriguez 0:1a9bfeb27157 1289 estado_recepcion_app = INICIO;
matirodriguez 0:1a9bfeb27157 1290 }
matirodriguez 0:1a9bfeb27157 1291 } else {
matirodriguez 0:1a9bfeb27157 1292 estado_recepcion_app = START;
matirodriguez 0:1a9bfeb27157 1293 }
matirodriguez 0:1a9bfeb27157 1294 break;
matirodriguez 0:1a9bfeb27157 1295
matirodriguez 0:1a9bfeb27157 1296 case P1:
matirodriguez 0:1a9bfeb27157 1297
matirodriguez 0:1a9bfeb27157 1298 if((ingreso_app == '$')||((ingreso_app>='0')&&(ingreso_app<='9'))) {
matirodriguez 0:1a9bfeb27157 1299 if((ingreso_app>='0')&&(ingreso_app<='9')) {
matirodriguez 0:1a9bfeb27157 1300 estado_recepcion_app = P2;
matirodriguez 0:1a9bfeb27157 1301 //RECIBO PRIMER DIGITO
matirodriguez 0:1a9bfeb27157 1302 aux_pan[0] = ingreso_app;
matirodriguez 0:1a9bfeb27157 1303 }
matirodriguez 0:1a9bfeb27157 1304 if(ingreso_app == '$') {
matirodriguez 0:1a9bfeb27157 1305 estado_recepcion_app = INICIO;
matirodriguez 0:1a9bfeb27157 1306 }
matirodriguez 0:1a9bfeb27157 1307 } else {
matirodriguez 0:1a9bfeb27157 1308 estado_recepcion_app = START;
matirodriguez 0:1a9bfeb27157 1309 }
matirodriguez 0:1a9bfeb27157 1310 break;
matirodriguez 0:1a9bfeb27157 1311
matirodriguez 0:1a9bfeb27157 1312 case P2:
matirodriguez 0:1a9bfeb27157 1313
matirodriguez 0:1a9bfeb27157 1314 if((ingreso_app == '$')||((ingreso_app>='0')&&(ingreso_app<='9'))) {
matirodriguez 0:1a9bfeb27157 1315 if((ingreso_app>='0')&&(ingreso_app<='9')) {
matirodriguez 0:1a9bfeb27157 1316 estado_recepcion_app = P3;
matirodriguez 0:1a9bfeb27157 1317 //RECIBO SEGUNDO DIGITO
matirodriguez 0:1a9bfeb27157 1318 aux_pan[1] = ingreso_app;
matirodriguez 0:1a9bfeb27157 1319 }
matirodriguez 0:1a9bfeb27157 1320 if(ingreso_app == '$') {
matirodriguez 0:1a9bfeb27157 1321 estado_recepcion_app = INICIO;
matirodriguez 0:1a9bfeb27157 1322 }
matirodriguez 0:1a9bfeb27157 1323 } else {
matirodriguez 0:1a9bfeb27157 1324 estado_recepcion_app = START;
matirodriguez 0:1a9bfeb27157 1325 }
matirodriguez 0:1a9bfeb27157 1326 break;
matirodriguez 0:1a9bfeb27157 1327
matirodriguez 0:1a9bfeb27157 1328 case P3:
matirodriguez 0:1a9bfeb27157 1329
matirodriguez 0:1a9bfeb27157 1330 if((ingreso_app == '$')||((ingreso_app>='0')&&(ingreso_app<='9'))) {
matirodriguez 0:1a9bfeb27157 1331 if((ingreso_app>='0')&&(ingreso_app<='9')) {
matirodriguez 0:1a9bfeb27157 1332 estado_recepcion_app = CRC;
matirodriguez 0:1a9bfeb27157 1333 //RECIBO TERCER DIGITO
matirodriguez 0:1a9bfeb27157 1334 aux_pan[2] = ingreso_app;
matirodriguez 0:1a9bfeb27157 1335 trama_recibida = VALORES_MOTOR;
matirodriguez 0:1a9bfeb27157 1336
matirodriguez 0:1a9bfeb27157 1337 }
matirodriguez 0:1a9bfeb27157 1338 if(ingreso_app == '$') {
matirodriguez 0:1a9bfeb27157 1339 estado_recepcion_app = INICIO;
matirodriguez 0:1a9bfeb27157 1340 }
matirodriguez 0:1a9bfeb27157 1341 } else {
matirodriguez 0:1a9bfeb27157 1342 estado_recepcion_app = START;
matirodriguez 0:1a9bfeb27157 1343 }
matirodriguez 0:1a9bfeb27157 1344 break;
matirodriguez 0:1a9bfeb27157 1345 case V1:
matirodriguez 0:1a9bfeb27157 1346 if((ingreso_app == '$')||((ingreso_app>='0')&&(ingreso_app<='1'))) {
matirodriguez 0:1a9bfeb27157 1347 if((ingreso_app>='0')&&(ingreso_app<='1')) {
matirodriguez 0:1a9bfeb27157 1348 estado_recepcion_app = V2;
matirodriguez 0:1a9bfeb27157 1349 //RECIBO PRIMER DIGITO
matirodriguez 0:1a9bfeb27157 1350 aux_vel[0] = ingreso_app;
matirodriguez 0:1a9bfeb27157 1351 }
matirodriguez 0:1a9bfeb27157 1352 if(ingreso_app == '$') {
matirodriguez 0:1a9bfeb27157 1353 estado_recepcion_app = INICIO;
matirodriguez 0:1a9bfeb27157 1354 }
matirodriguez 0:1a9bfeb27157 1355 } else {
matirodriguez 0:1a9bfeb27157 1356 estado_recepcion_app = START;
matirodriguez 0:1a9bfeb27157 1357 }
matirodriguez 0:1a9bfeb27157 1358 break;
matirodriguez 0:1a9bfeb27157 1359 case V2:
matirodriguez 0:1a9bfeb27157 1360
matirodriguez 0:1a9bfeb27157 1361 if((ingreso_app == '$')||((ingreso_app>='0')&&(ingreso_app<='9'))) {
matirodriguez 0:1a9bfeb27157 1362 if((ingreso_app>='0')&&(ingreso_app<='9')) {
matirodriguez 0:1a9bfeb27157 1363 estado_recepcion_app = CRC;
matirodriguez 0:1a9bfeb27157 1364 //RECIBO SEGUNDO DIGITO
matirodriguez 0:1a9bfeb27157 1365 aux_vel[1] = ingreso_app;
matirodriguez 0:1a9bfeb27157 1366 trama_recibida = VELOCIDAD_MOTOR;
matirodriguez 0:1a9bfeb27157 1367 }
matirodriguez 0:1a9bfeb27157 1368 if(ingreso_app == '$') {
matirodriguez 0:1a9bfeb27157 1369 estado_recepcion_app = INICIO;
matirodriguez 0:1a9bfeb27157 1370 }
matirodriguez 0:1a9bfeb27157 1371 } else {
matirodriguez 0:1a9bfeb27157 1372 estado_recepcion_app = START;
matirodriguez 0:1a9bfeb27157 1373 }
matirodriguez 0:1a9bfeb27157 1374 break;
matirodriguez 0:1a9bfeb27157 1375 case HAB_JOYSTICK:
matirodriguez 0:1a9bfeb27157 1376
matirodriguez 0:1a9bfeb27157 1377 if((ingreso_app == '$')||(ingreso_app=='A')||(ingreso_app=='R')) {
matirodriguez 0:1a9bfeb27157 1378 if(ingreso_app == 'A') {
matirodriguez 0:1a9bfeb27157 1379 estado_recepcion_app = CRC;
matirodriguez 0:1a9bfeb27157 1380 trama_recibida = MODO_DE_CONTROL;
matirodriguez 0:1a9bfeb27157 1381 //RECIBO VALOR
matirodriguez 0:1a9bfeb27157 1382 aux_modo = APP;
matirodriguez 0:1a9bfeb27157 1383
matirodriguez 0:1a9bfeb27157 1384 }
matirodriguez 0:1a9bfeb27157 1385 if(ingreso_app == 'R') {
matirodriguez 0:1a9bfeb27157 1386 estado_recepcion_app = CRC;
matirodriguez 0:1a9bfeb27157 1387 trama_recibida = MODO_DE_CONTROL;
matirodriguez 0:1a9bfeb27157 1388 //RECIBO VALOR
matirodriguez 0:1a9bfeb27157 1389 aux_modo = CONTROL;
matirodriguez 0:1a9bfeb27157 1390
matirodriguez 0:1a9bfeb27157 1391 }
matirodriguez 0:1a9bfeb27157 1392 if(ingreso_app == '$') {
matirodriguez 0:1a9bfeb27157 1393 estado_recepcion_app = INICIO;
matirodriguez 0:1a9bfeb27157 1394 }
matirodriguez 0:1a9bfeb27157 1395 } else {
matirodriguez 0:1a9bfeb27157 1396 estado_recepcion_app = START;
matirodriguez 0:1a9bfeb27157 1397 }
matirodriguez 0:1a9bfeb27157 1398 break;
matirodriguez 0:1a9bfeb27157 1399 case LOOP_HAB:
matirodriguez 0:1a9bfeb27157 1400 if((ingreso_app == '$')||((ingreso_app>='0')&&(ingreso_app<='1'))) {
matirodriguez 0:1a9bfeb27157 1401 if(ingreso_app=='0') {
matirodriguez 0:1a9bfeb27157 1402 aux_loop = DESHABILITADO;
matirodriguez 0:1a9bfeb27157 1403 estado_recepcion_app = CRC;
matirodriguez 0:1a9bfeb27157 1404 trama_recibida = CONF_LOOP;
matirodriguez 0:1a9bfeb27157 1405 //RECIBO PRIMER DIGITO
matirodriguez 0:1a9bfeb27157 1406 }
matirodriguez 0:1a9bfeb27157 1407 if(ingreso_app=='1') {
matirodriguez 0:1a9bfeb27157 1408 aux_loop = HABILITADO;
matirodriguez 0:1a9bfeb27157 1409 estado_recepcion_app = L_DELAY1;
matirodriguez 0:1a9bfeb27157 1410 //RECIBO PRIMER DIGITO
matirodriguez 0:1a9bfeb27157 1411 }
matirodriguez 0:1a9bfeb27157 1412 if(ingreso_app == '$') {
matirodriguez 0:1a9bfeb27157 1413 estado_recepcion_app = INICIO;
matirodriguez 0:1a9bfeb27157 1414 }
matirodriguez 0:1a9bfeb27157 1415 } else {
matirodriguez 0:1a9bfeb27157 1416 estado_recepcion_app = START;
matirodriguez 0:1a9bfeb27157 1417 }
matirodriguez 0:1a9bfeb27157 1418 break;
matirodriguez 0:1a9bfeb27157 1419 case L_DELAY1:
matirodriguez 0:1a9bfeb27157 1420 if((ingreso_app == '$')||((ingreso_app>='0')&&(ingreso_app<='9'))) {
matirodriguez 0:1a9bfeb27157 1421 if((ingreso_app>='0')&&(ingreso_app<='9')) {
matirodriguez 0:1a9bfeb27157 1422 t_delay[1] = ingreso_app;
matirodriguez 0:1a9bfeb27157 1423 estado_recepcion_app = L_DELAY2;
matirodriguez 0:1a9bfeb27157 1424 //RECIBO PRIMER DIGITO
matirodriguez 0:1a9bfeb27157 1425 }
matirodriguez 0:1a9bfeb27157 1426 if(ingreso_app == '$') {
matirodriguez 0:1a9bfeb27157 1427 estado_recepcion_app = INICIO;
matirodriguez 0:1a9bfeb27157 1428 }
matirodriguez 0:1a9bfeb27157 1429 } else {
matirodriguez 0:1a9bfeb27157 1430 estado_recepcion_app = START;
matirodriguez 0:1a9bfeb27157 1431 }
matirodriguez 0:1a9bfeb27157 1432 break;
matirodriguez 0:1a9bfeb27157 1433 case L_DELAY2:
matirodriguez 0:1a9bfeb27157 1434 if((ingreso_app == '$')||((ingreso_app>='0')&&(ingreso_app<='9'))) {
matirodriguez 0:1a9bfeb27157 1435 if((ingreso_app>='0')&&(ingreso_app<='9')) {
matirodriguez 0:1a9bfeb27157 1436 t_delay[2] = ingreso_app;
matirodriguez 0:1a9bfeb27157 1437 estado_recepcion_app = LD_UNIDAD;
matirodriguez 0:1a9bfeb27157 1438 //RECIBO PRIMER DIGITO
matirodriguez 0:1a9bfeb27157 1439 }
matirodriguez 0:1a9bfeb27157 1440 if(ingreso_app == '$') {
matirodriguez 0:1a9bfeb27157 1441 estado_recepcion_app = INICIO;
matirodriguez 0:1a9bfeb27157 1442 }
matirodriguez 0:1a9bfeb27157 1443 } else {
matirodriguez 0:1a9bfeb27157 1444 estado_recepcion_app = START;
matirodriguez 0:1a9bfeb27157 1445 }
matirodriguez 0:1a9bfeb27157 1446 break;
matirodriguez 0:1a9bfeb27157 1447 case LD_UNIDAD:
matirodriguez 0:1a9bfeb27157 1448 if((ingreso_app == '$')||(ingreso_app>='S')||(ingreso_app<='M')||(ingreso_app<='H')) {
matirodriguez 0:1a9bfeb27157 1449 if(ingreso_app=='S') {
matirodriguez 0:1a9bfeb27157 1450 t_delay[3] = SEGUNDOS;
matirodriguez 0:1a9bfeb27157 1451 estado_recepcion_app = L_TIMEOUT1;
matirodriguez 0:1a9bfeb27157 1452 //RECIBO PRIMER DIGITO
matirodriguez 0:1a9bfeb27157 1453 }
matirodriguez 0:1a9bfeb27157 1454 if(ingreso_app=='M') {
matirodriguez 0:1a9bfeb27157 1455 t_delay[3] = MINUTOS;
matirodriguez 0:1a9bfeb27157 1456 estado_recepcion_app = L_TIMEOUT1;
matirodriguez 0:1a9bfeb27157 1457 //RECIBO PRIMER DIGITO
matirodriguez 0:1a9bfeb27157 1458 }
matirodriguez 0:1a9bfeb27157 1459 if(ingreso_app=='H') {
matirodriguez 0:1a9bfeb27157 1460 t_delay[3] = HORAS;
matirodriguez 0:1a9bfeb27157 1461 estado_recepcion_app = L_TIMEOUT1;
matirodriguez 0:1a9bfeb27157 1462 //RECIBO PRIMER DIGITO
matirodriguez 0:1a9bfeb27157 1463 }
matirodriguez 0:1a9bfeb27157 1464 if(ingreso_app == '$') {
matirodriguez 0:1a9bfeb27157 1465 estado_recepcion_app = INICIO;
matirodriguez 0:1a9bfeb27157 1466 }
matirodriguez 0:1a9bfeb27157 1467 } else {
matirodriguez 0:1a9bfeb27157 1468 estado_recepcion_app = START;
matirodriguez 0:1a9bfeb27157 1469 }
matirodriguez 0:1a9bfeb27157 1470 break;
matirodriguez 0:1a9bfeb27157 1471 case L_TIMEOUT1:
matirodriguez 0:1a9bfeb27157 1472 if((ingreso_app == '$')||(ingreso_app == 'N')||((ingreso_app>='0')&&(ingreso_app<='9'))) {
matirodriguez 0:1a9bfeb27157 1473 if((ingreso_app>='0')&&(ingreso_app<='9')) {
matirodriguez 0:1a9bfeb27157 1474 t_out[1] = ingreso_app;
matirodriguez 0:1a9bfeb27157 1475 estado_recepcion_app = L_TIMEOUT2;
matirodriguez 0:1a9bfeb27157 1476 //RECIBO PRIMER DIGITO
matirodriguez 0:1a9bfeb27157 1477 }
matirodriguez 0:1a9bfeb27157 1478 if(ingreso_app == '$') {
matirodriguez 0:1a9bfeb27157 1479 estado_recepcion_app = INICIO;
matirodriguez 0:1a9bfeb27157 1480 }
matirodriguez 0:1a9bfeb27157 1481 if(ingreso_app == 'N') {
matirodriguez 0:1a9bfeb27157 1482 t_out[1] = '0';
matirodriguez 0:1a9bfeb27157 1483 estado_recepcion_app = L_TIMEOUT2;
matirodriguez 0:1a9bfeb27157 1484 }
matirodriguez 0:1a9bfeb27157 1485 } else {
matirodriguez 0:1a9bfeb27157 1486 estado_recepcion_app = START;
matirodriguez 0:1a9bfeb27157 1487 }
matirodriguez 0:1a9bfeb27157 1488 break;
matirodriguez 0:1a9bfeb27157 1489 case L_TIMEOUT2:
matirodriguez 0:1a9bfeb27157 1490 if((ingreso_app == '$')||(ingreso_app == 'C')||((ingreso_app>='0')&&(ingreso_app<='9'))) {
matirodriguez 0:1a9bfeb27157 1491 if((ingreso_app>='0')&&(ingreso_app<='9')) {
matirodriguez 0:1a9bfeb27157 1492 t_out[2] = ingreso_app;
matirodriguez 0:1a9bfeb27157 1493 estado_recepcion_app = LT_UNIDAD;
matirodriguez 0:1a9bfeb27157 1494 //RECIBO PRIMER DIGITO
matirodriguez 0:1a9bfeb27157 1495 }
matirodriguez 0:1a9bfeb27157 1496 if(ingreso_app == '$') {
matirodriguez 0:1a9bfeb27157 1497 estado_recepcion_app = INICIO;
matirodriguez 0:1a9bfeb27157 1498 }
matirodriguez 0:1a9bfeb27157 1499 if(ingreso_app == 'C') {
matirodriguez 0:1a9bfeb27157 1500 t_out[2] = '0';
matirodriguez 0:1a9bfeb27157 1501 estado_recepcion_app = LT_UNIDAD;
matirodriguez 0:1a9bfeb27157 1502 }
matirodriguez 0:1a9bfeb27157 1503 } else {
matirodriguez 0:1a9bfeb27157 1504 estado_recepcion_app = START;
matirodriguez 0:1a9bfeb27157 1505 }
matirodriguez 0:1a9bfeb27157 1506 break;
matirodriguez 0:1a9bfeb27157 1507 case LT_UNIDAD:
matirodriguez 0:1a9bfeb27157 1508 if((ingreso_app == '$')||(ingreso_app>='S')||(ingreso_app<='M')||(ingreso_app<='H')) {
matirodriguez 0:1a9bfeb27157 1509 if(ingreso_app=='S') {
matirodriguez 0:1a9bfeb27157 1510 t_out[3] = SEGUNDOS;
matirodriguez 0:1a9bfeb27157 1511 estado_recepcion_app = CRC;
matirodriguez 0:1a9bfeb27157 1512 //RECIBO PRIMER DIGITO
matirodriguez 0:1a9bfeb27157 1513 trama_recibida = CONF_LOOP;
matirodriguez 0:1a9bfeb27157 1514 }
matirodriguez 0:1a9bfeb27157 1515 if(ingreso_app=='M') {
matirodriguez 0:1a9bfeb27157 1516 t_out[3] = MINUTOS;
matirodriguez 0:1a9bfeb27157 1517 estado_recepcion_app = CRC;
matirodriguez 0:1a9bfeb27157 1518 //RECIBO PRIMER DIGITO
matirodriguez 0:1a9bfeb27157 1519 trama_recibida = CONF_LOOP;
matirodriguez 0:1a9bfeb27157 1520 }
matirodriguez 0:1a9bfeb27157 1521 if(ingreso_app=='H') {
matirodriguez 0:1a9bfeb27157 1522 t_out[3] = HORAS;
matirodriguez 0:1a9bfeb27157 1523 estado_recepcion_app = CRC;
matirodriguez 0:1a9bfeb27157 1524 //RECIBO PRIMER DIGITO
matirodriguez 0:1a9bfeb27157 1525 trama_recibida = CONF_LOOP;
matirodriguez 0:1a9bfeb27157 1526 }
matirodriguez 0:1a9bfeb27157 1527 if(ingreso_app == '$') {
matirodriguez 0:1a9bfeb27157 1528 estado_recepcion_app = INICIO;
matirodriguez 0:1a9bfeb27157 1529 }
matirodriguez 0:1a9bfeb27157 1530 } else {
matirodriguez 0:1a9bfeb27157 1531 estado_recepcion_app = START;
matirodriguez 0:1a9bfeb27157 1532 }
matirodriguez 0:1a9bfeb27157 1533 break;
matirodriguez 0:1a9bfeb27157 1534 case PUNTOE:
matirodriguez 0:1a9bfeb27157 1535 if((ingreso_app == '$')||(ingreso_app>='R')||((ingreso_app>='0')&&(ingreso_app<='9'))) {
matirodriguez 0:1a9bfeb27157 1536 if((ingreso_app>='0')&&(ingreso_app<='9')) {
matirodriguez 0:1a9bfeb27157 1537 aux_accuracy[0] = ingreso_app;
matirodriguez 0:1a9bfeb27157 1538 estado_recepcion_app = PRECISION;
matirodriguez 0:1a9bfeb27157 1539
matirodriguez 0:1a9bfeb27157 1540 }
matirodriguez 0:1a9bfeb27157 1541 if(ingreso_app>='R') {
matirodriguez 0:1a9bfeb27157 1542 aux_pe = DESHABILITADO;
matirodriguez 0:1a9bfeb27157 1543 estado_recepcion_app = CRC;
matirodriguez 0:1a9bfeb27157 1544 trama_recibida = PUNTO_E;
matirodriguez 0:1a9bfeb27157 1545 }
matirodriguez 0:1a9bfeb27157 1546 if(ingreso_app == '$') {
matirodriguez 0:1a9bfeb27157 1547 estado_recepcion_app = INICIO;
matirodriguez 0:1a9bfeb27157 1548 }
matirodriguez 0:1a9bfeb27157 1549 } else {
matirodriguez 0:1a9bfeb27157 1550 estado_recepcion_app = START;
matirodriguez 0:1a9bfeb27157 1551 }
matirodriguez 0:1a9bfeb27157 1552 break;
matirodriguez 0:1a9bfeb27157 1553 case PRECISION:
matirodriguez 0:1a9bfeb27157 1554 if((ingreso_app == '$')||((ingreso_app>='0')&&(ingreso_app<='9'))) {
matirodriguez 0:1a9bfeb27157 1555 if((ingreso_app>='0')&&(ingreso_app<='9')) {
matirodriguez 0:1a9bfeb27157 1556 aux_accuracy[1] = ingreso_app;
matirodriguez 0:1a9bfeb27157 1557 estado_recepcion_app = CRC;
matirodriguez 0:1a9bfeb27157 1558 aux_pe = HABILITADO;
matirodriguez 0:1a9bfeb27157 1559 trama_recibida = PUNTO_E;
matirodriguez 0:1a9bfeb27157 1560 }
matirodriguez 0:1a9bfeb27157 1561 if(ingreso_app == '$') {
matirodriguez 0:1a9bfeb27157 1562 estado_recepcion_app = INICIO;
matirodriguez 0:1a9bfeb27157 1563 }
matirodriguez 0:1a9bfeb27157 1564 } else {
matirodriguez 0:1a9bfeb27157 1565 estado_recepcion_app = START;
matirodriguez 0:1a9bfeb27157 1566 }
matirodriguez 0:1a9bfeb27157 1567 break;
matirodriguez 0:1a9bfeb27157 1568
matirodriguez 0:1a9bfeb27157 1569 case TIMELAPSE:
matirodriguez 0:1a9bfeb27157 1570 if((ingreso_app == '$')||((ingreso_app>='0')&&(ingreso_app<='1'))) {
matirodriguez 0:1a9bfeb27157 1571 if(ingreso_app=='0') {
matirodriguez 0:1a9bfeb27157 1572 //aux_accuracy[1] = ingreso_app;
matirodriguez 0:1a9bfeb27157 1573 estado_recepcion_app = CRC;
matirodriguez 0:1a9bfeb27157 1574 aux_timelapse = DESHABILITADO;
matirodriguez 0:1a9bfeb27157 1575 trama_recibida = TIME_LAPSE;
matirodriguez 0:1a9bfeb27157 1576 }
matirodriguez 0:1a9bfeb27157 1577 if(ingreso_app=='1') {
matirodriguez 0:1a9bfeb27157 1578 estado_recepcion_app = T_DURACION;
matirodriguez 0:1a9bfeb27157 1579 aux_timelapse = HABILITADO;
matirodriguez 0:1a9bfeb27157 1580 trama_recibida = TIME_LAPSE;
matirodriguez 0:1a9bfeb27157 1581 }
matirodriguez 0:1a9bfeb27157 1582 if(ingreso_app == '$') {
matirodriguez 0:1a9bfeb27157 1583 estado_recepcion_app = INICIO;
matirodriguez 0:1a9bfeb27157 1584 }
matirodriguez 0:1a9bfeb27157 1585 } else {
matirodriguez 0:1a9bfeb27157 1586 estado_recepcion_app = START;
matirodriguez 0:1a9bfeb27157 1587 }
matirodriguez 0:1a9bfeb27157 1588 break;
matirodriguez 0:1a9bfeb27157 1589
matirodriguez 0:1a9bfeb27157 1590 case T_DURACION:
matirodriguez 0:1a9bfeb27157 1591 if((ingreso_app == '$')||((ingreso_app>='0')&&(ingreso_app<='9'))) {
matirodriguez 0:1a9bfeb27157 1592 if((ingreso_app>='0')&&(ingreso_app<='9')) {
matirodriguez 0:1a9bfeb27157 1593 //aux_accuracy[1] = ingreso_app;
matirodriguez 0:1a9bfeb27157 1594 estado_recepcion_app = T_DURACION2;
matirodriguez 0:1a9bfeb27157 1595 timelapse_t[1] = ingreso_app;
matirodriguez 0:1a9bfeb27157 1596 }
matirodriguez 0:1a9bfeb27157 1597 if(ingreso_app == '$') {
matirodriguez 0:1a9bfeb27157 1598 estado_recepcion_app = INICIO;
matirodriguez 0:1a9bfeb27157 1599 }
matirodriguez 0:1a9bfeb27157 1600 } else {
matirodriguez 0:1a9bfeb27157 1601 estado_recepcion_app = START;
matirodriguez 0:1a9bfeb27157 1602 }
matirodriguez 0:1a9bfeb27157 1603 break;
matirodriguez 0:1a9bfeb27157 1604 case T_DURACION2:
matirodriguez 0:1a9bfeb27157 1605 if((ingreso_app == '$')||((ingreso_app>='0')&&(ingreso_app<='9'))) {
matirodriguez 0:1a9bfeb27157 1606 if((ingreso_app>='0')&&(ingreso_app<='9')) {
matirodriguez 0:1a9bfeb27157 1607 //aux_accuracy[1] = ingreso_app;
matirodriguez 0:1a9bfeb27157 1608 estado_recepcion_app = T_UNIDAD;
matirodriguez 0:1a9bfeb27157 1609 timelapse_t[2] = ingreso_app;
matirodriguez 0:1a9bfeb27157 1610 }
matirodriguez 0:1a9bfeb27157 1611 if(ingreso_app == '$') {
matirodriguez 0:1a9bfeb27157 1612 estado_recepcion_app = INICIO;
matirodriguez 0:1a9bfeb27157 1613 }
matirodriguez 0:1a9bfeb27157 1614 } else {
matirodriguez 0:1a9bfeb27157 1615 estado_recepcion_app = START;
matirodriguez 0:1a9bfeb27157 1616 }
matirodriguez 0:1a9bfeb27157 1617 break;
matirodriguez 0:1a9bfeb27157 1618 case T_UNIDAD:
matirodriguez 0:1a9bfeb27157 1619 if((ingreso_app == '$')||(ingreso_app == 'S')||(ingreso_app == 'M')||(ingreso_app == 'H')) {
matirodriguez 0:1a9bfeb27157 1620 if(ingreso_app == 'S') {
matirodriguez 0:1a9bfeb27157 1621 //aux_accuracy[1] = ingreso_app;
matirodriguez 0:1a9bfeb27157 1622 estado_recepcion_app = T_LADO;
matirodriguez 0:1a9bfeb27157 1623 timelapse_t[3] = SEGUNDOS;
matirodriguez 0:1a9bfeb27157 1624 }
matirodriguez 0:1a9bfeb27157 1625 if(ingreso_app == 'M') {
matirodriguez 0:1a9bfeb27157 1626 //aux_accuracy[1] = ingreso_app;
matirodriguez 0:1a9bfeb27157 1627 estado_recepcion_app = T_LADO;
matirodriguez 0:1a9bfeb27157 1628 timelapse_t[3] = MINUTOS;
matirodriguez 0:1a9bfeb27157 1629 }
matirodriguez 0:1a9bfeb27157 1630 if(ingreso_app == 'H') {
matirodriguez 0:1a9bfeb27157 1631 //aux_accuracy[1] = ingreso_app;
matirodriguez 0:1a9bfeb27157 1632 estado_recepcion_app = T_LADO;
matirodriguez 0:1a9bfeb27157 1633 timelapse_t[3] = HORAS;
matirodriguez 0:1a9bfeb27157 1634 }
matirodriguez 0:1a9bfeb27157 1635 if(ingreso_app == '$') {
matirodriguez 0:1a9bfeb27157 1636 estado_recepcion_app = INICIO;
matirodriguez 0:1a9bfeb27157 1637 }
matirodriguez 0:1a9bfeb27157 1638 } else {
matirodriguez 0:1a9bfeb27157 1639 estado_recepcion_app = START;
matirodriguez 0:1a9bfeb27157 1640 }
matirodriguez 0:1a9bfeb27157 1641 break;
matirodriguez 0:1a9bfeb27157 1642 case T_LADO:
matirodriguez 0:1a9bfeb27157 1643 if((ingreso_app == '$')||(ingreso_app == 'I')||(ingreso_app == 'D')) {
matirodriguez 0:1a9bfeb27157 1644 if(ingreso_app == 'D') {
matirodriguez 0:1a9bfeb27157 1645 //aux_accuracy[1] = ingreso_app;
matirodriguez 0:1a9bfeb27157 1646 estado_recepcion_app = T_MODO;
matirodriguez 0:1a9bfeb27157 1647 ladoTimelapse = DERECHA;
matirodriguez 0:1a9bfeb27157 1648 }
matirodriguez 0:1a9bfeb27157 1649 if(ingreso_app == 'I') {
matirodriguez 0:1a9bfeb27157 1650 //aux_accuracy[1] = ingreso_app;
matirodriguez 0:1a9bfeb27157 1651 estado_recepcion_app = T_MODO;
matirodriguez 0:1a9bfeb27157 1652 ladoTimelapse = IZQUIERDA;
matirodriguez 0:1a9bfeb27157 1653 }
matirodriguez 0:1a9bfeb27157 1654 if(ingreso_app == '$') {
matirodriguez 0:1a9bfeb27157 1655 estado_recepcion_app = INICIO;
matirodriguez 0:1a9bfeb27157 1656 }
matirodriguez 0:1a9bfeb27157 1657 } else {
matirodriguez 0:1a9bfeb27157 1658 estado_recepcion_app = START;
matirodriguez 0:1a9bfeb27157 1659 }
matirodriguez 0:1a9bfeb27157 1660 break;
matirodriguez 0:1a9bfeb27157 1661 case T_MODO:
matirodriguez 0:1a9bfeb27157 1662 if((ingreso_app == '$')||(ingreso_app == 'P')||(ingreso_app == 'E')||(ingreso_app == 'M')) {
matirodriguez 0:1a9bfeb27157 1663 if(ingreso_app == 'P') {
matirodriguez 0:1a9bfeb27157 1664 //aux_accuracy[1] = ingreso_app;
matirodriguez 0:1a9bfeb27157 1665 estado_recepcion_app = CRC;
matirodriguez 0:1a9bfeb27157 1666 modoTimelapse = 1;
matirodriguez 0:1a9bfeb27157 1667 }
matirodriguez 0:1a9bfeb27157 1668 if(ingreso_app == 'M') {
matirodriguez 0:1a9bfeb27157 1669 //aux_accuracy[1] = ingreso_app;
matirodriguez 0:1a9bfeb27157 1670 estado_recepcion_app = CRC;
matirodriguez 0:1a9bfeb27157 1671 modoTimelapse = 2;
matirodriguez 0:1a9bfeb27157 1672 }
matirodriguez 0:1a9bfeb27157 1673 if(ingreso_app == 'H') {
matirodriguez 0:1a9bfeb27157 1674 //aux_accuracy[1] = ingreso_app;
matirodriguez 0:1a9bfeb27157 1675 estado_recepcion_app = CRC;
matirodriguez 0:1a9bfeb27157 1676 modoTimelapse = 3;
matirodriguez 0:1a9bfeb27157 1677 }
matirodriguez 0:1a9bfeb27157 1678 if(ingreso_app == '$') {
matirodriguez 0:1a9bfeb27157 1679 estado_recepcion_app = INICIO;
matirodriguez 0:1a9bfeb27157 1680 }
matirodriguez 0:1a9bfeb27157 1681 } else {
matirodriguez 0:1a9bfeb27157 1682 estado_recepcion_app = START;
matirodriguez 0:1a9bfeb27157 1683 }
matirodriguez 0:1a9bfeb27157 1684 break;
matirodriguez 0:1a9bfeb27157 1685 case CRC:
matirodriguez 0:1a9bfeb27157 1686 //Guardo valor CRC
matirodriguez 0:1a9bfeb27157 1687 crc = ingreso_app;
matirodriguez 0:1a9bfeb27157 1688 estado_recepcion_app = FIN;
matirodriguez 0:1a9bfeb27157 1689 break;
matirodriguez 0:1a9bfeb27157 1690 case FIN:
matirodriguez 0:1a9bfeb27157 1691
matirodriguez 0:1a9bfeb27157 1692 if((ingreso_app == '$')||(ingreso_app == '!')) {
matirodriguez 0:1a9bfeb27157 1693 if(ingreso_app == '$') {
matirodriguez 0:1a9bfeb27157 1694 estado_recepcion_app = INICIO;
matirodriguez 0:1a9bfeb27157 1695 }
matirodriguez 0:1a9bfeb27157 1696 if(ingreso_app == '!') {
matirodriguez 0:1a9bfeb27157 1697 if(crc == 'e') {
matirodriguez 0:1a9bfeb27157 1698 if(trama_recibida == CONF_LOOP) {
matirodriguez 0:1a9bfeb27157 1699 loop = aux_loop;
matirodriguez 0:1a9bfeb27157 1700 estado_maq_loop = ESPERO;
matirodriguez 0:1a9bfeb27157 1701 loopRetraso = ((t_delay[1]-0x30)*10+(t_delay[2]-0x30));
matirodriguez 0:1a9bfeb27157 1702 loopRetrasoUnidadDeTiempo = t_delay[3];
matirodriguez 0:1a9bfeb27157 1703 loopDetenerseUnidadDeTiempo = t_out[3];
matirodriguez 0:1a9bfeb27157 1704 loopDetenerse = ((t_out[1]-0x30)*10+(t_out[2]-0x30));
matirodriguez 0:1a9bfeb27157 1705 if(loopDetenerse != 0) {
matirodriguez 0:1a9bfeb27157 1706 switch(loopDetenerseUnidadDeTiempo) {
matirodriguez 0:1a9bfeb27157 1707 case SEGUNDOS:
matirodriguez 0:1a9bfeb27157 1708 desactivar_loop.attach(&off_loop,loopDetenerse);
matirodriguez 0:1a9bfeb27157 1709 break;
matirodriguez 0:1a9bfeb27157 1710 case MINUTOS:
matirodriguez 0:1a9bfeb27157 1711 desactivar_loop.attach(&off_loop,loopDetenerse*60);
matirodriguez 0:1a9bfeb27157 1712 break;
matirodriguez 0:1a9bfeb27157 1713 case HORAS:
matirodriguez 0:1a9bfeb27157 1714 desactivar_loop.attach(&off_loop,loopDetenerse * 60); // Falta multiplicar por 60 mas
matirodriguez 0:1a9bfeb27157 1715 break;
matirodriguez 0:1a9bfeb27157 1716 }
matirodriguez 0:1a9bfeb27157 1717 }
matirodriguez 0:1a9bfeb27157 1718 }
matirodriguez 0:1a9bfeb27157 1719 estado_recepcion_app = START;
matirodriguez 0:1a9bfeb27157 1720 if(trama_recibida == TIME_LAPSE) {
matirodriguez 0:1a9bfeb27157 1721 if(aux_timelapse==HABILITADO) {
matirodriguez 0:1a9bfeb27157 1722 stateTimelapse = HABILITADO;
matirodriguez 0:1a9bfeb27157 1723 tiempoTimelapse = ((timelapse_t[1]-0x30)*10+(timelapse_t[2]-0x30));;
matirodriguez 0:1a9bfeb27157 1724 unidadtiempoTimelapse = timelapse_t[3];
matirodriguez 0:1a9bfeb27157 1725 lado_Timelapse = ladoTimelapse;
matirodriguez 0:1a9bfeb27157 1726 modo_Timelapse = modoTimelapse;
matirodriguez 0:1a9bfeb27157 1727 loop = DESHABILITADO;
matirodriguez 0:1a9bfeb27157 1728 off_loop();
matirodriguez 0:1a9bfeb27157 1729 } else if(aux_timelapse==DESHABILITADO) {
matirodriguez 0:1a9bfeb27157 1730 stateTimelapse = DESHABILITADO;
matirodriguez 0:1a9bfeb27157 1731 }
matirodriguez 0:1a9bfeb27157 1732
matirodriguez 0:1a9bfeb27157 1733
matirodriguez 0:1a9bfeb27157 1734 }
matirodriguez 0:1a9bfeb27157 1735 if(trama_recibida == VALORES_MOTOR) {
matirodriguez 0:1a9bfeb27157 1736 app_VSlide = ((aux_slide[0]-0x30)*100+(aux_slide[1]-0x30)*10+(aux_slide[2]-0x30));
matirodriguez 0:1a9bfeb27157 1737 app_VTilt = ((aux_tilt[0]-0x30)*100+(aux_tilt[1]-0x30)*10+(aux_tilt[2]-0x30));
matirodriguez 0:1a9bfeb27157 1738 app_VPan = ((aux_pan[0]-0x30)*100+(aux_pan[1]-0x30)*10+(aux_pan[2]-0x30));
matirodriguez 0:1a9bfeb27157 1739 }
matirodriguez 0:1a9bfeb27157 1740 if(trama_recibida == PUNTO_E) {
matirodriguez 0:1a9bfeb27157 1741 punto_especifico = aux_pe;
matirodriguez 0:1a9bfeb27157 1742 posicion_slide = pasos_slide;
matirodriguez 0:1a9bfeb27157 1743 posicion_pan = pasos_pan;
matirodriguez 0:1a9bfeb27157 1744
matirodriguez 0:1a9bfeb27157 1745 }
matirodriguez 0:1a9bfeb27157 1746 if(trama_recibida == VELOCIDAD_MOTOR) {
matirodriguez 0:1a9bfeb27157 1747 intensidad_VSlide = ((aux_vel[0]-0x30)*10+(aux_vel[1]-0x30));
matirodriguez 0:1a9bfeb27157 1748 }
matirodriguez 0:1a9bfeb27157 1749 if(trama_recibida == MODO_DE_CONTROL) {
matirodriguez 0:1a9bfeb27157 1750 modo_de_funcionamiento = aux_modo;
matirodriguez 0:1a9bfeb27157 1751 }
matirodriguez 0:1a9bfeb27157 1752
matirodriguez 0:1a9bfeb27157 1753 }
matirodriguez 0:1a9bfeb27157 1754 } else {
matirodriguez 0:1a9bfeb27157 1755 estado_recepcion_app = START;
matirodriguez 0:1a9bfeb27157 1756 }
matirodriguez 0:1a9bfeb27157 1757 }
matirodriguez 0:1a9bfeb27157 1758 break;
matirodriguez 0:1a9bfeb27157 1759 }
matirodriguez 0:1a9bfeb27157 1760 }
matirodriguez 0:1a9bfeb27157 1761 void MAQ_recepcion_control()
matirodriguez 0:1a9bfeb27157 1762 {
matirodriguez 0:1a9bfeb27157 1763 static int aux_slide[3];
matirodriguez 0:1a9bfeb27157 1764 static int aux_tilt[3];
matirodriguez 0:1a9bfeb27157 1765 static int aux_pan[3];
matirodriguez 0:1a9bfeb27157 1766 static int aux_botones[2];
matirodriguez 0:1a9bfeb27157 1767 static int crc;
matirodriguez 0:1a9bfeb27157 1768
matirodriguez 0:1a9bfeb27157 1769 switch(estado_recepcion_control) {
matirodriguez 0:1a9bfeb27157 1770 case START:
matirodriguez 0:1a9bfeb27157 1771
matirodriguez 0:1a9bfeb27157 1772 // Reseteo todas las variables
matirodriguez 0:1a9bfeb27157 1773 aux_slide[0] = 0;
matirodriguez 0:1a9bfeb27157 1774 aux_slide[1] = 0;
matirodriguez 0:1a9bfeb27157 1775 aux_slide[2] = 0;
matirodriguez 0:1a9bfeb27157 1776 aux_tilt[0] = 0;
matirodriguez 0:1a9bfeb27157 1777 aux_tilt[1] = 0;
matirodriguez 0:1a9bfeb27157 1778 aux_tilt[2] = 0;
matirodriguez 0:1a9bfeb27157 1779 aux_pan[0] = 0;
matirodriguez 0:1a9bfeb27157 1780 aux_pan[1] = 0;
matirodriguez 0:1a9bfeb27157 1781 aux_pan[2] = 0;
matirodriguez 0:1a9bfeb27157 1782 aux_botones[0] = 0;
matirodriguez 0:1a9bfeb27157 1783 aux_botones[1] = 0;
matirodriguez 0:1a9bfeb27157 1784 crc = 0;
matirodriguez 0:1a9bfeb27157 1785
matirodriguez 0:1a9bfeb27157 1786 if(ingreso_control == '$') {
matirodriguez 0:1a9bfeb27157 1787 estado_recepcion_control = SLIDE;
matirodriguez 0:1a9bfeb27157 1788 }
matirodriguez 0:1a9bfeb27157 1789 break;
matirodriguez 0:1a9bfeb27157 1790
matirodriguez 0:1a9bfeb27157 1791 case SLIDE:
matirodriguez 0:1a9bfeb27157 1792
matirodriguez 0:1a9bfeb27157 1793 if((ingreso_control == '$')||(ingreso_control == 'S')) {
matirodriguez 0:1a9bfeb27157 1794 if(ingreso_control == 'S') {
matirodriguez 0:1a9bfeb27157 1795 estado_recepcion_control = S1;
matirodriguez 0:1a9bfeb27157 1796 }
matirodriguez 0:1a9bfeb27157 1797 if(ingreso_control == '$') {
matirodriguez 0:1a9bfeb27157 1798 estado_recepcion_control = SLIDE;
matirodriguez 0:1a9bfeb27157 1799 }
matirodriguez 0:1a9bfeb27157 1800 } else {
matirodriguez 0:1a9bfeb27157 1801 estado_recepcion_control = START;
matirodriguez 0:1a9bfeb27157 1802 }
matirodriguez 0:1a9bfeb27157 1803 break;
matirodriguez 0:1a9bfeb27157 1804
matirodriguez 0:1a9bfeb27157 1805 case S1:
matirodriguez 0:1a9bfeb27157 1806
matirodriguez 0:1a9bfeb27157 1807 if((ingreso_control == '$')||((ingreso_control>='0')&&(ingreso_control<='9'))) {
matirodriguez 0:1a9bfeb27157 1808 if((ingreso_control>='0')&&(ingreso_control<='9')) {
matirodriguez 0:1a9bfeb27157 1809 estado_recepcion_control = S2;
matirodriguez 0:1a9bfeb27157 1810 //RECIBO PRIMER DIGITO
matirodriguez 0:1a9bfeb27157 1811 aux_slide[0] = ingreso_control;
matirodriguez 0:1a9bfeb27157 1812 }
matirodriguez 0:1a9bfeb27157 1813 if(ingreso_control == '$') {
matirodriguez 0:1a9bfeb27157 1814 estado_recepcion_control = SLIDE;
matirodriguez 0:1a9bfeb27157 1815 }
matirodriguez 0:1a9bfeb27157 1816 } else {
matirodriguez 0:1a9bfeb27157 1817 estado_recepcion_control = START;
matirodriguez 0:1a9bfeb27157 1818 }
matirodriguez 0:1a9bfeb27157 1819 break;
matirodriguez 0:1a9bfeb27157 1820
matirodriguez 0:1a9bfeb27157 1821 case S2:
matirodriguez 0:1a9bfeb27157 1822
matirodriguez 0:1a9bfeb27157 1823 if((ingreso_control == '$')||((ingreso_control>='0')&&(ingreso_control<='9'))) {
matirodriguez 0:1a9bfeb27157 1824 if((ingreso_control>='0')&&(ingreso_control<='9')) {
matirodriguez 0:1a9bfeb27157 1825 estado_recepcion_control = S3;
matirodriguez 0:1a9bfeb27157 1826 //RECIBO SEGUNDO DIGITO
matirodriguez 0:1a9bfeb27157 1827 aux_slide[1] = ingreso_control;
matirodriguez 0:1a9bfeb27157 1828 }
matirodriguez 0:1a9bfeb27157 1829 if(ingreso_control == '$') {
matirodriguez 0:1a9bfeb27157 1830 estado_recepcion_control = SLIDE;
matirodriguez 0:1a9bfeb27157 1831 }
matirodriguez 0:1a9bfeb27157 1832 } else {
matirodriguez 0:1a9bfeb27157 1833 estado_recepcion_control = START;
matirodriguez 0:1a9bfeb27157 1834 }
matirodriguez 0:1a9bfeb27157 1835 break;
matirodriguez 0:1a9bfeb27157 1836
matirodriguez 0:1a9bfeb27157 1837 case S3:
matirodriguez 0:1a9bfeb27157 1838
matirodriguez 0:1a9bfeb27157 1839 if((ingreso_control == '$')||((ingreso_control>='0')&&(ingreso_control<='9'))) {
matirodriguez 0:1a9bfeb27157 1840 if((ingreso_control>='0')&&(ingreso_control<='9')) {
matirodriguez 0:1a9bfeb27157 1841 estado_recepcion_control = TILT;
matirodriguez 0:1a9bfeb27157 1842 //RECIBO TERCER DIGITO
matirodriguez 0:1a9bfeb27157 1843 aux_slide[2] = ingreso_control;
matirodriguez 0:1a9bfeb27157 1844 }
matirodriguez 0:1a9bfeb27157 1845 if(ingreso_control == '$') {
matirodriguez 0:1a9bfeb27157 1846 estado_recepcion_control = SLIDE;
matirodriguez 0:1a9bfeb27157 1847 }
matirodriguez 0:1a9bfeb27157 1848 } else {
matirodriguez 0:1a9bfeb27157 1849 estado_recepcion_control = START;
matirodriguez 0:1a9bfeb27157 1850 }
matirodriguez 0:1a9bfeb27157 1851 break;
matirodriguez 0:1a9bfeb27157 1852 case TILT:
matirodriguez 0:1a9bfeb27157 1853 if((ingreso_control == '$')||(ingreso_control == 'T')) {
matirodriguez 0:1a9bfeb27157 1854 if(ingreso_control == 'T') {
matirodriguez 0:1a9bfeb27157 1855 estado_recepcion_control = T1;
matirodriguez 0:1a9bfeb27157 1856 }
matirodriguez 0:1a9bfeb27157 1857 if(ingreso_control == '$') {
matirodriguez 0:1a9bfeb27157 1858 estado_recepcion_control = SLIDE;
matirodriguez 0:1a9bfeb27157 1859 }
matirodriguez 0:1a9bfeb27157 1860 } else {
matirodriguez 0:1a9bfeb27157 1861 estado_recepcion_control = START;
matirodriguez 0:1a9bfeb27157 1862 }
matirodriguez 0:1a9bfeb27157 1863 break;
matirodriguez 0:1a9bfeb27157 1864
matirodriguez 0:1a9bfeb27157 1865 case T1:
matirodriguez 0:1a9bfeb27157 1866
matirodriguez 0:1a9bfeb27157 1867 if((ingreso_control == '$')||((ingreso_control>='0')&&(ingreso_control<='9'))) {
matirodriguez 0:1a9bfeb27157 1868 if((ingreso_control>='0')&&(ingreso_control<='9')) {
matirodriguez 0:1a9bfeb27157 1869 estado_recepcion_control = T2;
matirodriguez 0:1a9bfeb27157 1870 //RECIBO PRIMER DIGITO
matirodriguez 0:1a9bfeb27157 1871 aux_tilt[0] = ingreso_control;
matirodriguez 0:1a9bfeb27157 1872 }
matirodriguez 0:1a9bfeb27157 1873 if(ingreso_control == '$') {
matirodriguez 0:1a9bfeb27157 1874 estado_recepcion_control = SLIDE;
matirodriguez 0:1a9bfeb27157 1875 }
matirodriguez 0:1a9bfeb27157 1876 } else {
matirodriguez 0:1a9bfeb27157 1877 estado_recepcion_control = START;
matirodriguez 0:1a9bfeb27157 1878 }
matirodriguez 0:1a9bfeb27157 1879 break;
matirodriguez 0:1a9bfeb27157 1880
matirodriguez 0:1a9bfeb27157 1881 case T2:
matirodriguez 0:1a9bfeb27157 1882
matirodriguez 0:1a9bfeb27157 1883 if((ingreso_control == '$')||((ingreso_control>='0')&&(ingreso_control<='9'))) {
matirodriguez 0:1a9bfeb27157 1884 if((ingreso_control>='0')&&(ingreso_control<='9')) {
matirodriguez 0:1a9bfeb27157 1885 estado_recepcion_control = T3;
matirodriguez 0:1a9bfeb27157 1886 //RECIBO SEGUNDO DIGITO
matirodriguez 0:1a9bfeb27157 1887 aux_tilt[1] = ingreso_control;
matirodriguez 0:1a9bfeb27157 1888 }
matirodriguez 0:1a9bfeb27157 1889 if(ingreso_control == '$') {
matirodriguez 0:1a9bfeb27157 1890 estado_recepcion_control = SLIDE;
matirodriguez 0:1a9bfeb27157 1891 }
matirodriguez 0:1a9bfeb27157 1892 } else {
matirodriguez 0:1a9bfeb27157 1893 estado_recepcion_control = START;
matirodriguez 0:1a9bfeb27157 1894 }
matirodriguez 0:1a9bfeb27157 1895 break;
matirodriguez 0:1a9bfeb27157 1896
matirodriguez 0:1a9bfeb27157 1897 case T3:
matirodriguez 0:1a9bfeb27157 1898
matirodriguez 0:1a9bfeb27157 1899 if((ingreso_control == '$')||((ingreso_control>='0')&&(ingreso_control<='9'))) {
matirodriguez 0:1a9bfeb27157 1900 if((ingreso_control>='0')&&(ingreso_control<='9')) {
matirodriguez 0:1a9bfeb27157 1901 estado_recepcion_control = PAN;
matirodriguez 0:1a9bfeb27157 1902 //RECIBO TERCER DIGITO
matirodriguez 0:1a9bfeb27157 1903 aux_tilt[2] = ingreso_control;
matirodriguez 0:1a9bfeb27157 1904 }
matirodriguez 0:1a9bfeb27157 1905 if(ingreso_control == '$') {
matirodriguez 0:1a9bfeb27157 1906 estado_recepcion_control = SLIDE;
matirodriguez 0:1a9bfeb27157 1907 }
matirodriguez 0:1a9bfeb27157 1908 } else {
matirodriguez 0:1a9bfeb27157 1909 estado_recepcion_control = START;
matirodriguez 0:1a9bfeb27157 1910 }
matirodriguez 0:1a9bfeb27157 1911 break;
matirodriguez 0:1a9bfeb27157 1912 case PAN:
matirodriguez 0:1a9bfeb27157 1913
matirodriguez 0:1a9bfeb27157 1914 if((ingreso_control == '$')||(ingreso_control == 'P')) {
matirodriguez 0:1a9bfeb27157 1915 if(ingreso_control == 'P') {
matirodriguez 0:1a9bfeb27157 1916 estado_recepcion_control = P1;
matirodriguez 0:1a9bfeb27157 1917 }
matirodriguez 0:1a9bfeb27157 1918 if(ingreso_control == '$') {
matirodriguez 0:1a9bfeb27157 1919 estado_recepcion_control = SLIDE;
matirodriguez 0:1a9bfeb27157 1920 }
matirodriguez 0:1a9bfeb27157 1921 } else {
matirodriguez 0:1a9bfeb27157 1922 estado_recepcion_control = START;
matirodriguez 0:1a9bfeb27157 1923 }
matirodriguez 0:1a9bfeb27157 1924 break;
matirodriguez 0:1a9bfeb27157 1925
matirodriguez 0:1a9bfeb27157 1926 case P1:
matirodriguez 0:1a9bfeb27157 1927
matirodriguez 0:1a9bfeb27157 1928 if((ingreso_control == '$')||((ingreso_control>='0')&&(ingreso_control<='9'))) {
matirodriguez 0:1a9bfeb27157 1929 if((ingreso_control>='0')&&(ingreso_control<='9')) {
matirodriguez 0:1a9bfeb27157 1930 estado_recepcion_control = P2;
matirodriguez 0:1a9bfeb27157 1931 //RECIBO PRIMER DIGITO
matirodriguez 0:1a9bfeb27157 1932 aux_pan[0] = ingreso_control;
matirodriguez 0:1a9bfeb27157 1933 }
matirodriguez 0:1a9bfeb27157 1934 if(ingreso_control == '$') {
matirodriguez 0:1a9bfeb27157 1935 estado_recepcion_control = SLIDE;
matirodriguez 0:1a9bfeb27157 1936 }
matirodriguez 0:1a9bfeb27157 1937 } else {
matirodriguez 0:1a9bfeb27157 1938 estado_recepcion_control = START;
matirodriguez 0:1a9bfeb27157 1939 }
matirodriguez 0:1a9bfeb27157 1940 break;
matirodriguez 0:1a9bfeb27157 1941
matirodriguez 0:1a9bfeb27157 1942 case P2:
matirodriguez 0:1a9bfeb27157 1943
matirodriguez 0:1a9bfeb27157 1944 if((ingreso_control == '$')||((ingreso_control>='0')&&(ingreso_control<='9'))) {
matirodriguez 0:1a9bfeb27157 1945 if((ingreso_control>='0')&&(ingreso_control<='9')) {
matirodriguez 0:1a9bfeb27157 1946 estado_recepcion_control = P3;
matirodriguez 0:1a9bfeb27157 1947 //RECIBO SEGUNDO DIGITO
matirodriguez 0:1a9bfeb27157 1948 aux_pan[1] = ingreso_control;
matirodriguez 0:1a9bfeb27157 1949 }
matirodriguez 0:1a9bfeb27157 1950 if(ingreso_control == '$') {
matirodriguez 0:1a9bfeb27157 1951 estado_recepcion_control = SLIDE;
matirodriguez 0:1a9bfeb27157 1952 }
matirodriguez 0:1a9bfeb27157 1953 } else {
matirodriguez 0:1a9bfeb27157 1954 estado_recepcion_control = START;
matirodriguez 0:1a9bfeb27157 1955 }
matirodriguez 0:1a9bfeb27157 1956 break;
matirodriguez 0:1a9bfeb27157 1957
matirodriguez 0:1a9bfeb27157 1958 case P3:
matirodriguez 0:1a9bfeb27157 1959
matirodriguez 0:1a9bfeb27157 1960 if((ingreso_control == '$')||((ingreso_control>='0')&&(ingreso_control<='9'))) {
matirodriguez 0:1a9bfeb27157 1961 if((ingreso_control>='0')&&(ingreso_control<='9')) {
matirodriguez 0:1a9bfeb27157 1962 estado_recepcion_control = BOTONES;
matirodriguez 0:1a9bfeb27157 1963 //RECIBO TERCER DIGITO
matirodriguez 0:1a9bfeb27157 1964 aux_pan[2] = ingreso_control;
matirodriguez 0:1a9bfeb27157 1965 }
matirodriguez 0:1a9bfeb27157 1966 if(ingreso_control == '$') {
matirodriguez 0:1a9bfeb27157 1967 estado_recepcion_control = SLIDE;
matirodriguez 0:1a9bfeb27157 1968 }
matirodriguez 0:1a9bfeb27157 1969 } else {
matirodriguez 0:1a9bfeb27157 1970 estado_recepcion_control = START;
matirodriguez 0:1a9bfeb27157 1971 }
matirodriguez 0:1a9bfeb27157 1972 break;
matirodriguez 0:1a9bfeb27157 1973 case BOTONES:
matirodriguez 0:1a9bfeb27157 1974
matirodriguez 0:1a9bfeb27157 1975 if((ingreso_control == '$')||(ingreso_control == 'B')) {
matirodriguez 0:1a9bfeb27157 1976 if(ingreso_control == 'B') {
matirodriguez 0:1a9bfeb27157 1977 estado_recepcion_control = B1;
matirodriguez 0:1a9bfeb27157 1978 }
matirodriguez 0:1a9bfeb27157 1979 if(ingreso_control == '$') {
matirodriguez 0:1a9bfeb27157 1980 estado_recepcion_control = SLIDE;
matirodriguez 0:1a9bfeb27157 1981 }
matirodriguez 0:1a9bfeb27157 1982 } else {
matirodriguez 0:1a9bfeb27157 1983 estado_recepcion_control = START;
matirodriguez 0:1a9bfeb27157 1984 }
matirodriguez 0:1a9bfeb27157 1985 break;
matirodriguez 0:1a9bfeb27157 1986
matirodriguez 0:1a9bfeb27157 1987 case B1:
matirodriguez 0:1a9bfeb27157 1988 if((ingreso_control == '$')||((ingreso_control>='0')&&(ingreso_control<='9'))) {
matirodriguez 0:1a9bfeb27157 1989 //if((ingreso_control == '$')||((ingreso_control>=(0b1100+0x30))&&(ingreso_control<=(0b1111+0x30)))) {
matirodriguez 0:1a9bfeb27157 1990 if((ingreso_control>='0')&&(ingreso_control<='9')) {
matirodriguez 0:1a9bfeb27157 1991 estado_recepcion_control = B2;
matirodriguez 0:1a9bfeb27157 1992 //RECIBO PRIMER DIGITO
matirodriguez 0:1a9bfeb27157 1993 aux_botones[0] = ingreso_control;
matirodriguez 0:1a9bfeb27157 1994 }
matirodriguez 0:1a9bfeb27157 1995 if(ingreso_control == '$') {
matirodriguez 0:1a9bfeb27157 1996 estado_recepcion_control = SLIDE;
matirodriguez 0:1a9bfeb27157 1997 }
matirodriguez 0:1a9bfeb27157 1998 } else {
matirodriguez 0:1a9bfeb27157 1999 estado_recepcion_control = START;
matirodriguez 0:1a9bfeb27157 2000 }
matirodriguez 0:1a9bfeb27157 2001 break;
matirodriguez 0:1a9bfeb27157 2002
matirodriguez 0:1a9bfeb27157 2003 case B2:
matirodriguez 0:1a9bfeb27157 2004 if((ingreso_control == '$')||((ingreso_control>='0')&&(ingreso_control<='9'))) {
matirodriguez 0:1a9bfeb27157 2005 //if((ingreso_control == '$')||((ingreso_control>=(0b1100+0x30))&&(ingreso_control<=(0b1111+0x30)))) {
matirodriguez 0:1a9bfeb27157 2006 if((ingreso_control>='0')&&(ingreso_control<='9')) {
matirodriguez 0:1a9bfeb27157 2007 estado_recepcion_control = CRC;
matirodriguez 0:1a9bfeb27157 2008 //RECIBO SEGUNDO DIGITO
matirodriguez 0:1a9bfeb27157 2009 aux_botones[1] = ingreso_control;
matirodriguez 0:1a9bfeb27157 2010 }
matirodriguez 0:1a9bfeb27157 2011 if(ingreso_control == '$') {
matirodriguez 0:1a9bfeb27157 2012 estado_recepcion_control = SLIDE;
matirodriguez 0:1a9bfeb27157 2013 }
matirodriguez 0:1a9bfeb27157 2014 } else {
matirodriguez 0:1a9bfeb27157 2015 estado_recepcion_control = START;
matirodriguez 0:1a9bfeb27157 2016 }
matirodriguez 0:1a9bfeb27157 2017 break;
matirodriguez 0:1a9bfeb27157 2018
matirodriguez 0:1a9bfeb27157 2019 case CRC:
matirodriguez 0:1a9bfeb27157 2020
matirodriguez 0:1a9bfeb27157 2021 //Guardo valor CRC
matirodriguez 0:1a9bfeb27157 2022 crc = ingreso_control;
matirodriguez 0:1a9bfeb27157 2023 estado_recepcion_control = FIN;
matirodriguez 0:1a9bfeb27157 2024
matirodriguez 0:1a9bfeb27157 2025 break;
matirodriguez 0:1a9bfeb27157 2026
matirodriguez 0:1a9bfeb27157 2027 case FIN:
matirodriguez 0:1a9bfeb27157 2028 if((ingreso_control == '$')||(ingreso_control == '!')) {
matirodriguez 0:1a9bfeb27157 2029 if(ingreso_control == '$') {
matirodriguez 0:1a9bfeb27157 2030 estado_recepcion_control = SLIDE;
matirodriguez 0:1a9bfeb27157 2031 }
matirodriguez 0:1a9bfeb27157 2032 if(ingreso_control == '!') {
matirodriguez 0:1a9bfeb27157 2033 if(crc == 'e') {
matirodriguez 0:1a9bfeb27157 2034 estado_recepcion_control = START;
matirodriguez 0:1a9bfeb27157 2035 joystick_VSlide = ((aux_slide[0]-0x30)*100+(aux_slide[1]-0x30)*10+(aux_slide[2]-0x30));
matirodriguez 0:1a9bfeb27157 2036 joystick_VTilt = ((aux_tilt[0]-0x30)*100+(aux_tilt[1]-0x30)*10+(aux_tilt[2]-0x30));
matirodriguez 0:1a9bfeb27157 2037 joystick_VPan = ((aux_pan[0]-0x30)*100+(aux_pan[1]-0x30)*10+(aux_pan[2]-0x30));
matirodriguez 0:1a9bfeb27157 2038 }
matirodriguez 0:1a9bfeb27157 2039 } else {
matirodriguez 0:1a9bfeb27157 2040 estado_recepcion_control = START;
matirodriguez 0:1a9bfeb27157 2041 }
matirodriguez 0:1a9bfeb27157 2042 }
matirodriguez 0:1a9bfeb27157 2043 }
matirodriguez 0:1a9bfeb27157 2044 }