From be60112de15945449293206ba8b9546c9e1ac28e Mon Sep 17 00:00:00 2001 From: Dinesh Manajipet Date: Thu, 15 Apr 2021 01:12:14 +0530 Subject: [PATCH] feat: Synchronize Individual after playing back startup tune Since we allow each ESC to set it's own startup tune, we can now automatically configure each of them to wait until all the others have finished playing their tune. The support for this is implemented using the new Eeprom variables in Bluejay: Eep_Pgm_Tune_Wait_MSB_ms - most significant byte Eep_Pgm_Tune_Wait_LSB_ms - least significant byte This should allow us to wait for 65536ms now. This should typically be enough for most usecases imo. If not, we can add another byte later on. --- js/bluejay_defaults.js | 20 ++++++++++++++++++++ js/bluejay_eeprom_layout.js | 6 ++++-- jsx/blheli_configurator.jsx | 7 +++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/js/bluejay_defaults.js b/js/bluejay_defaults.js index 6b23a8e..f68f2b5 100644 --- a/js/bluejay_defaults.js +++ b/js/bluejay_defaults.js @@ -1,6 +1,26 @@ 'use strict'; var BLUEJAY_DEFAULTS = { + '204': { // 201 with STARTUP_MELODY + RPM_POWER_SLOPE: 9, + MOTOR_DIRECTION: 1, + COMMUTATION_TIMING: 4, + BEEP_STRENGTH: 40, + BEACON_STRENGTH: 80, + BEACON_DELAY: 4, + DEMAG_COMPENSATION: 2, + TEMPERATURE_PROTECTION: 7, + BRAKE_ON_STOP: 0, + LED_CONTROL: 0, + + STARTUP_POWER_MIN: 51, + DITHERING: 1, + + STARTUP_POWER_MAX: 25, + STARTUP_MELODY: [2,58,4,32,52,66,13,0,69,45,13,0,52,66,13,0,78,39,211,0,69,45,208,25,52,25,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], + STARTUP_MELODY_WAIT_MS_MSB: 0, + STARTUP_MELODY_WAIT_MS_LSB: 0 + }, '203': { // 201 with STARTUP_MELODY RPM_POWER_SLOPE: 9, MOTOR_DIRECTION: 1, diff --git a/js/bluejay_eeprom_layout.js b/js/bluejay_eeprom_layout.js index 6fedf82..2381e66 100644 --- a/js/bluejay_eeprom_layout.js +++ b/js/bluejay_eeprom_layout.js @@ -23,7 +23,7 @@ var BLHELI_SILABS_BOOTLOADER_SIZE = 0x0200 var BLHELI_SILABS_FLASH_SIZE = 0x2000 var BLHELI_SILABS_ADDRESS_SPACE_SIZE = BLHELI_SILABS_BOOTLOADER_ADDRESS -var BLHELI_LAYOUT_SIZE = 0xF0 +var BLHELI_LAYOUT_SIZE = 0xF2 var BLHELI_MIN_SUPPORTED_LAYOUT_REVISION = 0x13 var BLHELI_S_MIN_LAYOUT_REVISION = 0x20 @@ -76,7 +76,9 @@ var BLHELI_LAYOUT = { MCU: { offset: 0x50, size: 16 }, NAME: { offset: 0x60, size: 16 }, - STARTUP_MELODY: { offset: 0x70, size: 128 } + STARTUP_MELODY: { offset: 0x70, size: 128 }, + STARTUP_MELODY_WAIT_MS_MSB: { offset: 0xF0, size: 1 }, + STARTUP_MELODY_WAIT_MS_LSB: { offset: 0xF1, size: 1 } }; function blheliModeToString(mode) { diff --git a/jsx/blheli_configurator.jsx b/jsx/blheli_configurator.jsx index 284c2cd..149de4c 100644 --- a/jsx/blheli_configurator.jsx +++ b/jsx/blheli_configurator.jsx @@ -215,7 +215,14 @@ var Configurator = React.createClass({ }, // @todo add validation of each setting via BLHELI_SETTINGS_DESCRIPTION writeSetupAll: async function() { + //Update escSettings' wait time after playing back their tune so they all start the dshot beacons at the same time + const melodyDurations = this.state.escSettings.map((s) => { Rtttl.parse(Rtttl.fromBluejayStartupMelody(s.STARTUP_MELODY)).melody.reduce((a, b)=> a + b.duration, 0) }); + const maxMelodyDuration = melodyDurations.reduce((a, b) => Math.max(a, b), 0); + for (var esc = 0; esc < this.state.escSettings.length; ++esc) { + const melodyWaitDifference = maxMelodyDuration - melodyDurations[esc]; + this.state.escSettings[esc].STARTUP_MELODY_WAIT_MS_MSB = (melodyWaitDifference >> 8) & (2**8 - 1); + this.state.escSettings[esc].STARTUP_MELODY_WAIT_MS_LSB = (melodyWaitDifference) & (2**8 - 1); await this.writeSetupImpl(esc); } },