Core: blinking pattern for PPM signal detection

This commit is contained in:
pascallanger 2016-11-17 12:08:44 +01:00
parent 6fe3f90a26
commit 4f9f10ddf2
4 changed files with 56 additions and 33 deletions

View File

@ -211,12 +211,18 @@ struct PPM_Parameters
#define TX_RX_PAUSE_on protocol_flags2 |= _BV(4) #define TX_RX_PAUSE_on protocol_flags2 |= _BV(4)
#define IS_TX_RX_PAUSE_on ( ( protocol_flags2 & _BV(4) ) !=0 ) #define IS_TX_RX_PAUSE_on ( ( protocol_flags2 & _BV(4) ) !=0 )
#define IS_TX_PAUSE_on ( ( protocol_flags2 & (_BV(4)|_BV(3)) ) !=0 ) #define IS_TX_PAUSE_on ( ( protocol_flags2 & (_BV(4)|_BV(3)) ) !=0 )
//Signal OK
#define INPUT_SIGNAL_off protocol_flags2 &= ~_BV(5)
#define INPUT_SIGNAL_on protocol_flags2 |= _BV(5)
#define IS_INPUT_SIGNAL_on ( ( protocol_flags2 & _BV(5) ) !=0 )
#define IS_INPUT_SIGNAL_off ( ( protocol_flags2 & _BV(5) ) ==0 )
//******************** //********************
//*** Blink timing *** //*** Blink timing ***
//******************** //********************
#define BLINK_BIND_TIME 100 #define BLINK_BIND_TIME 100
#define BLINK_SERIAL_TIME 500 #define BLINK_SERIAL_TIME 500
#define BLINK_PPM_TIME 1000
#define BLINK_BAD_PROTO_TIME_LOW 1000 #define BLINK_BAD_PROTO_TIME_LOW 1000
#define BLINK_BAD_PROTO_TIME_HIGH 50 #define BLINK_BAD_PROTO_TIME_HIGH 50
@ -406,6 +412,7 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p --
DSM2_11 1 DSM2_11 1
DSMX_22 2 DSMX_22 2
DSMX_11 3 DSMX_11 3
DSM_AUTO 4
sub_protocol==YD717 sub_protocol==YD717
YD717 0 YD717 0
SKYWLKR 1 SKYWLKR 1

View File

@ -51,7 +51,7 @@
//Global constants/variables //Global constants/variables
uint32_t MProtocol_id;//tx id, uint32_t MProtocol_id;//tx id,
uint32_t MProtocol_id_master; uint32_t MProtocol_id_master;
uint32_t blink=0; uint32_t blink=0,last_signal=0;
// //
uint16_t counter; uint16_t counter;
uint8_t channel; uint8_t channel;
@ -462,6 +462,9 @@ void Update_All()
modules_reset(); //reset all modules modules_reset(); //reset all modules
protocol_init(); //init new protocol protocol_init(); //init new protocol
} }
INPUT_SIGNAL_on; //valid signal received
last_signal=millis();
} }
#endif //ENABLE_SERIAL #endif //ENABLE_SERIAL
#ifdef ENABLE_PPM #ifdef ENABLE_PPM
@ -479,13 +482,15 @@ void Update_All()
} }
update_aux_flags(); update_aux_flags();
PPM_FLAG_off; // wait for next frame before update PPM_FLAG_off; // wait for next frame before update
INPUT_SIGNAL_on; //valid signal received
last_signal=millis();
} }
#endif //ENABLE_PPM #endif //ENABLE_PPM
update_led_status();
#if defined(TELEMETRY) #if defined(TELEMETRY)
if((protocol==MODE_FRSKYD) || (protocol==MODE_HUBSAN) || (protocol==MODE_AFHDS2A) || (protocol==MODE_FRSKYX) || (protocol==MODE_DSM) ) if((protocol==MODE_FRSKYD) || (protocol==MODE_HUBSAN) || (protocol==MODE_AFHDS2A) || (protocol==MODE_FRSKYX) || (protocol==MODE_DSM) )
TelemetryUpdate(); TelemetryUpdate();
#endif #endif
update_led_status();
} }
// Update Servo_AUX flags based on servo AUX positions // Update Servo_AUX flags based on servo AUX positions
@ -500,10 +505,18 @@ static void update_aux_flags(void)
// Update led status based on binding and serial // Update led status based on binding and serial
static void update_led_status(void) static void update_led_status(void)
{ {
if(IS_INPUT_SIGNAL_on)
if(millis()-last_signal>50)
INPUT_SIGNAL_off; //no valid signal (PPM or Serial) received for 50ms
if(blink<millis()) if(blink<millis())
{ {
if(cur_protocol[1]==0) //No valid serial received at least once if(IS_INPUT_SIGNAL_off)
blink+=BLINK_SERIAL_TIME; //blink slowly while waiting a valid serial input {
if(mode_select==MODE_SERIAL)
blink+=BLINK_SERIAL_TIME; //blink slowly if no valid serial input
else
blink+=BLINK_PPM_TIME; //blink more slowly if no valid PPM input
}
else else
if(remote_callback == 0) if(remote_callback == 0)
{ // Invalid protocol { // Invalid protocol
@ -513,10 +526,11 @@ static void update_led_status(void)
blink+=BLINK_BAD_PROTO_TIME_HIGH; blink+=BLINK_BAD_PROTO_TIME_HIGH;
} }
else else
{
if(IS_BIND_DONE_on) if(IS_BIND_DONE_on)
LED_off; //bind completed -> led on LED_off; //bind completed force led on
else
blink+=BLINK_BIND_TIME; //blink fastly during binding blink+=BLINK_BIND_TIME; //blink fastly during binding
}
LED_toggle; LED_toggle;
} }
} }
@ -1051,25 +1065,27 @@ static uint32_t random_id(uint16_t adress, uint8_t create_new)
#endif #endif
#endif #endif
{ // Interrupt on PPM pin { // Interrupt on PPM pin
static int8_t chan=-1; static int8_t chan=0,bad_frame=1;
static uint16_t Prev_TCNT1=0; static uint16_t Prev_TCNT1=0;
uint16_t Cur_TCNT1; uint16_t Cur_TCNT1;
Cur_TCNT1 = TCNT1 - Prev_TCNT1 ; // Capture current Timer1 value Cur_TCNT1 = TCNT1 - Prev_TCNT1 ; // Capture current Timer1 value
if(Cur_TCNT1<1000) if(Cur_TCNT1<1000)
chan=-1; // bad frame bad_frame=1; // bad frame
else else
if(Cur_TCNT1>4840) if(Cur_TCNT1>4840)
{ { //start of frame
chan=0; // start of frame if(chan>3)
PPM_FLAG_on; // full frame present (even at startup since PPM_data has been initialized) PPM_FLAG_on; // good frame received if at least 4 channels have been seen
chan=0; // reset channel counter
bad_frame=0;
} }
else else
if(chan!=-1) // need to wait for start of frame if(bad_frame==0) // need to wait for start of frame
{ //servo values between 500us and 2420us will end up here { //servo values between 500us and 2420us will end up here
PPM_data[chan]= Cur_TCNT1>>1;; PPM_data[chan]= Cur_TCNT1>>1;;
if(chan++>=NUM_CHN) if(chan++>=NUM_CHN)
chan=-1; // don't accept any new channels bad_frame=1; // don't accept any new channels
} }
Prev_TCNT1+=Cur_TCNT1; Prev_TCNT1+=Cur_TCNT1;
} }