mirror of
https://github.com/pascallanger/DIY-Multiprotocol-TX-Module.git
synced 2025-02-04 16:38:12 +00:00
Core: blinking pattern for PPM signal detection
This commit is contained in:
parent
6fe3f90a26
commit
4f9f10ddf2
@ -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
|
||||
|
@ -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;
|
||||
@ -452,9 +452,9 @@ void loop()
|
||||
void Update_All()
|
||||
{
|
||||
#ifdef ENABLE_SERIAL
|
||||
if(mode_select==MODE_SERIAL && IS_RX_FLAG_on) // Serial mode and something has been received
|
||||
if(mode_select==MODE_SERIAL && IS_RX_FLAG_on) // Serial mode and something has been received
|
||||
{
|
||||
update_serial_data(); // Update protocol and data
|
||||
update_serial_data(); // Update protocol and data
|
||||
update_aux_flags();
|
||||
if(IS_CHANGE_PROTOCOL_FLAG_on)
|
||||
{ // Protocol needs to be changed
|
||||
@ -462,30 +462,35 @@ 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
|
||||
if(mode_select!=MODE_SERIAL && IS_PPM_FLAG_on) // PPM mode and a full frame has been received
|
||||
if(mode_select!=MODE_SERIAL && IS_PPM_FLAG_on) // PPM mode and a full frame has been received
|
||||
{
|
||||
for(uint8_t i=0;i<NUM_CHN;i++)
|
||||
{ // update servo data without interrupts to prevent bad read in protocols
|
||||
uint16_t temp_ppm ;
|
||||
cli(); // disable global int
|
||||
cli(); // disable global int
|
||||
temp_ppm = PPM_data[i] ;
|
||||
sei(); // enable global int
|
||||
sei(); // enable global int
|
||||
if(temp_ppm<PPM_MIN_125) temp_ppm=PPM_MIN_125;
|
||||
else if(temp_ppm>PPM_MAX_125) temp_ppm=PPM_MAX_125;
|
||||
Servo_data[i]= temp_ppm ;
|
||||
}
|
||||
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
|
||||
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
|
||||
blink+=BLINK_BIND_TIME; //blink fastly during binding
|
||||
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;
|
||||
}
|
||||
|
@ -211,25 +211,25 @@
|
||||
#define BIND_pin PA0
|
||||
#define LED_pin PA1
|
||||
//
|
||||
#define PPM_pin PA8 //PPM 5V tolerant
|
||||
#define PPM_pin PA8 //PPM 5V tolerant
|
||||
//
|
||||
#define S1_pin PA4 //Dial switch pins
|
||||
#define S1_pin PA4 //Dial switch pins
|
||||
#define S2_pin PA5
|
||||
#define S3_pin PA6
|
||||
#define S4_pin PA7
|
||||
//
|
||||
#define PE1_pin PB4 //PE1
|
||||
#define PE2_pin PB5 //PE2
|
||||
#define PE1_pin PB4 //PE1
|
||||
#define PE2_pin PB5 //PE2
|
||||
//CS pins
|
||||
#define CC25_CSN_pin PB6 //CC2500
|
||||
#define NRF_CSN_pin PB7 //NRF24L01
|
||||
#define CYRF_RST_pin PB8 //CYRF RESET
|
||||
#define A7105_CSN_pin PB9 //A7105
|
||||
#define CYRF_CSN_pin PB12 //CYRF CSN
|
||||
#define CC25_CSN_pin PB6 //CC2500
|
||||
#define NRF_CSN_pin PB7 //NRF24L01
|
||||
#define CYRF_RST_pin PB8 //CYRF RESET
|
||||
#define A7105_CSN_pin PB9 //A7105
|
||||
#define CYRF_CSN_pin PB12 //CYRF CSN
|
||||
//SPI pins
|
||||
#define SCK_pin PB13 //SCK
|
||||
#define SDO_pin PB14 //MISO
|
||||
#define SDI_pin PB15 //MOSI
|
||||
#define SCK_pin PB13 //SCK
|
||||
#define SDO_pin PB14 //MISO
|
||||
#define SDI_pin PB15 //MOSI
|
||||
//
|
||||
#define TX_INV_pin PB3
|
||||
#define RX_INV_pin PB1
|
||||
|
@ -724,7 +724,7 @@ void Serial_write( uint8_t byte )
|
||||
else
|
||||
{
|
||||
byteLo |= 0xFE ; // Stop bit
|
||||
}
|
||||
}
|
||||
byte <<= 1 ;
|
||||
#ifdef INVERT_SERIAL
|
||||
byte |= 1 ; // Start bit
|
||||
|
Loading…
x
Reference in New Issue
Block a user