From de7a8c800bad46d9553099e4faa119e98d829f69 Mon Sep 17 00:00:00 2001 From: "gruvin@gmail.com" Date: Mon, 20 Aug 2012 05:06:31 +0000 Subject: [PATCH] DSM2 Bind Mode Fix -- Issue 98 Some DSM2 modules take longer than others to power up. Thus, sending a single BIND packet is not sufficient in some cases. I have implemented here an approimately 4 second period (after power-up) during which time the trainer swtich can activate BIND mode. This is in fact not strictly needed, since the DSM module will by itself reject bind packets after a short time. (I have confirmed this again with my DSM2 module today.) However, we like to be sure, so the limited time window for BIND activation remains. The word "BIND" also now appears as confirmation in upper-right of the main view, whenever bind packets are being sent to the DSM module. (I did not consider it important to add this "BIND" word to the language files. Please feel free to do so though, if warranted.) Gruvin. --- src/main_views.cpp | 4 ++++ src/pulses_avr.cpp | 19 +++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main_views.cpp b/src/main_views.cpp index 6244bba61..a9c70a1e7 100644 --- a/src/main_views.cpp +++ b/src/main_views.cpp @@ -380,4 +380,8 @@ void menuMainView(uint8_t event) DISPLAY_PROGRESS_BAR(20*FW+1); #endif +#ifdef DSM2 + if (s_bind_mode) + lcd_putsAtt(15*FW, 0, PSTR("BIND"), 0); +#endif } diff --git a/src/pulses_avr.cpp b/src/pulses_avr.cpp index 53cfd94c4..e76386581 100644 --- a/src/pulses_avr.cpp +++ b/src/pulses_avr.cpp @@ -418,20 +418,27 @@ normal: */ -bool s_bind_allowed = true; +bool s_bind_mode = false; // For confirmation display of "BIND" in upper-right of main view screen +uint8_t s_bind_allowed = 255; // Counter allows trainer switch bind mode during 1st ~4 seconds, after power-on. + // This is needed to give time for DSM module to repliably complete power up. FORCEINLINE void setupPulsesDsm2() { uint16_t *ptr = (uint16_t *)pulses2MHz; - if (s_bind_allowed) { - *ptr++ = (keyState(SW_Trainer) ? BIND_BIT : 0x00); - s_bind_allowed = false; + if (s_bind_allowed) s_bind_allowed--; + if (s_bind_allowed && keyState(SW_Trainer)) + { + s_bind_mode = true; + *ptr++ = BIND_BIT; } - else { + else + { + s_bind_mode = false; *ptr++ = 0x00; } *ptr++ = g_model.modelId; - for (uint8_t i=0; i>5)+512,1023); *ptr++ = (i<<2) | ((pulse>>8)&0x03); *ptr++ = pulse & 0xff;