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 IS_TX_RX_PAUSE_on ( ( protocol_flags2 & _BV(4) ) !=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 ***
//********************
#define BLINK_BIND_TIME 100
#define BLINK_SERIAL_TIME 500
#define BLINK_PPM_TIME 1000
#define BLINK_BAD_PROTO_TIME_LOW 1000
#define BLINK_BAD_PROTO_TIME_HIGH 50
@ -406,6 +412,7 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p --
DSM2_11 1
DSMX_22 2
DSMX_11 3
DSM_AUTO 4
sub_protocol==YD717
YD717 0
SKYWLKR 1

View File

@ -51,7 +51,7 @@
//Global constants/variables
uint32_t MProtocol_id;//tx id,
uint32_t MProtocol_id_master;
uint32_t blink=0;
uint32_t blink=0,last_signal=0;
//
uint16_t counter;
uint8_t channel;
@ -462,6 +462,9 @@ void Update_All()
modules_reset(); //reset all modules
protocol_init(); //init new protocol
}
INPUT_SIGNAL_on; //valid signal received
last_signal=millis();
}
#endif //ENABLE_SERIAL
#ifdef ENABLE_PPM
@ -479,13 +482,15 @@ void Update_All()
}
update_aux_flags();
PPM_FLAG_off; // wait for next frame before update
INPUT_SIGNAL_on; //valid signal received
last_signal=millis();
}
#endif //ENABLE_PPM
update_led_status();
#if defined(TELEMETRY)
if((protocol==MODE_FRSKYD) || (protocol==MODE_HUBSAN) || (protocol==MODE_AFHDS2A) || (protocol==MODE_FRSKYX) || (protocol==MODE_DSM) )
TelemetryUpdate();
#endif
update_led_status();
}
// 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
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(cur_protocol[1]==0) //No valid serial received at least once
blink+=BLINK_SERIAL_TIME; //blink slowly while waiting a valid serial input
if(IS_INPUT_SIGNAL_off)
{
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
if(remote_callback == 0)
{ // Invalid protocol
@ -513,10 +526,11 @@ static void update_led_status(void)
blink+=BLINK_BAD_PROTO_TIME_HIGH;
}
else
{
if(IS_BIND_DONE_on)
LED_off; //bind completed -> led on
else
LED_off; //bind completed force led on
blink+=BLINK_BIND_TIME; //blink fastly during binding
}
LED_toggle;
}
}
@ -1051,25 +1065,27 @@ static uint32_t random_id(uint16_t adress, uint8_t create_new)
#endif
#endif
{ // Interrupt on PPM pin
static int8_t chan=-1;
static int8_t chan=0,bad_frame=1;
static uint16_t Prev_TCNT1=0;
uint16_t Cur_TCNT1;
Cur_TCNT1 = TCNT1 - Prev_TCNT1 ; // Capture current Timer1 value
if(Cur_TCNT1<1000)
chan=-1; // bad frame
bad_frame=1; // bad frame
else
if(Cur_TCNT1>4840)
{
chan=0; // start of frame
PPM_FLAG_on; // full frame present (even at startup since PPM_data has been initialized)
{ //start of frame
if(chan>3)
PPM_FLAG_on; // good frame received if at least 4 channels have been seen
chan=0; // reset channel counter
bad_frame=0;
}
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
PPM_data[chan]= Cur_TCNT1>>1;;
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;
}