Pedro Campos / Mbed OS SERVOS_V0_3
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers pulsadores.cpp Source File

pulsadores.cpp

00001 /*
00002 // Proceso de actuación sobre pulsadores, recibido desde el mando
00003 */
00004 #include "declaraciones.h"
00005 
00006 
00007 extern st_datos_servo datos_servo;              // ESTRUCTURA DE VARIABLES DE ESTADO DEL SERVO DE DIRECCION
00008 extern st_datos_servo datos_otro_servo;         // ESTRUCTURA DE VARIABLES DE ESTADO DEL OTRO SERVO DE DIRECCION
00009 extern long desviacion_servo;
00010 extern volatile int pos_actual_servo;
00011 extern volatile int pos_objetivo_servo;
00012 
00013 
00014 // ******************************************************
00015 // Procesa segun estado de los pulsadores del mando
00016 // ******************************************************
00017 void procesa_pulsadores(uint8_t pulsadores){     // Procesa segun estado de los pulsadores del mando
00018 static unsigned long tiempo_pulsado_rumbo = 0;               // tiempo que se ha mantenido pulsado RUMBO
00019 
00020     
00021     if(pulsadores & MASK_PULS_RUMBO != 0){      // BOTON PULSADO
00022         if(tiempo_pulsado_rumbo == 0){
00023             tiempo_pulsado_rumbo = millis();     // devuelve cuenta de tiempo en ms
00024         }
00025         if(datos_servo.estado == DIR_PILOTO || datos_otro_servo.estado == DIR_PILOTO || datos_servo.estado == DIR_RUMBO || datos_otro_servo.estado == DIR_RUMBO) { // Si algun servo esta en RUMBO o PILOTO
00026             datos_servo.estado = DIR_END_PILOT;     // Finaliza PILOTO        
00027             printf("Finaliza RUMBO o PILOTO estado otro:%d estado:%d\r\n", datos_otro_servo.estado, datos_servo.estado);
00028         }
00029     }
00030     else {  // Se ha soltado el boton
00031         unsigned long pulsado_ms = millis()-tiempo_pulsado_rumbo;
00032 
00033         if(tiempo_pulsado_rumbo != 0 && pulsado_ms >= 2000){
00034             // Activa RUMBO o PILOTO
00035             if(datos_servo.estado == DIR_REPOSO && datos_otro_servo.estado == DIR_REPOSO) { // Si los dos servos estan en reposo
00036                 if(pulsado_ms >= 4000){
00037                     datos_servo.estado = DIR_PILOTO;     // Pone en PILOTO AUT  
00038                     printf("En PILOTO estado otro:%d estado:%d\r\n", datos_otro_servo.estado, datos_servo.estado);
00039                 }              
00040                 else if(pulsado_ms < 10000){            
00041                     datos_servo.estado = DIR_RUMBO;     // Pone en RUMBO
00042                     printf("En RUMBO estado otro:%d estado:%d\r\n", datos_otro_servo.estado, datos_servo.estado);
00043                 }
00044             }
00045         }
00046         tiempo_pulsado_rumbo = 0;
00047     }
00048 }
00049