diff --git a/src/Containers/App/index.jsx b/src/Containers/App/index.jsx index 93d5e77da..968be88ab 100644 --- a/src/Containers/App/index.jsx +++ b/src/Containers/App/index.jsx @@ -967,8 +967,14 @@ class App extends Component { const { escs } = this.state; const individual = [ ...escs.individual ]; const converted = melodies.map((melody) => Rtttl.toBluejayStartupMelody(melody)); + + // Set wait time after melody to synchronize playback on all ESCs + const melodyDurations = melodies.map((melody) => Rtttl.parse(melody).melody.reduce((a, b) => a + b.duration, 0)); + const maxMelodyDuration = Math.max(...melodyDurations); + for(let i = 0; i < converted.length; i += 1) { individual[i].individualSettings.STARTUP_MELODY = converted[i].data; + individual[i].individualSettings.STARTUP_MELODY_WAIT_MS = maxMelodyDuration - melodyDurations[i]; } // Update individual settings, then write them. diff --git a/src/sources/Bluejay/eeprom.js b/src/sources/Bluejay/eeprom.js index 6581bbd81..169cd4e85 100644 --- a/src/sources/Bluejay/eeprom.js +++ b/src/sources/Bluejay/eeprom.js @@ -1,6 +1,6 @@ const EEPROM_OFFSET = 0x1A00; const PAGE_SIZE = 0x0200; -const LAYOUT_SIZE = 0xF0; +const LAYOUT_SIZE = 0xFF; const NAMES = [ 'Bluejay', @@ -188,6 +188,10 @@ const LAYOUT = { offset: 0x70, size: 128, }, + STARTUP_MELODY_WAIT_MS: { + offset: 0xF0, + size: 2, + }, }; const EEPROM = { diff --git a/src/sources/Bluejay/settings.js b/src/sources/Bluejay/settings.js index b110301fc..e8eb8494b 100644 --- a/src/sources/Bluejay/settings.js +++ b/src/sources/Bluejay/settings.js @@ -302,6 +302,27 @@ SETTINGS_DESCRIPTIONS['204'] = { ], }; +SETTINGS_DESCRIPTIONS['205'] = { + base: [ + ...SETTINGS_DESCRIPTIONS['204'].base, + { + name: 'STARTUP_BEEP', + type: 'enum', + label: 'escStartupBeep', + options: [{ + value: '0', + label: 'Off', + }, { + value: '1', + label: 'Normal', + }, { + value: '2', + label: 'Custom', + }], + }, + ], +}; + const INDIVIDUAL_SETTINGS = [{ name: 'MOTOR_DIRECTION', type: 'enum', @@ -341,12 +362,10 @@ const INDIVIDUAL_SETTINGS_203 = [{ }, { name: 'STARTUP_MELODY', type: 'melody', - label: 'startupMelody', - value: [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], - melodyLength: 128, }]; const INDIVIDUAL_SETTINGS_DESCRIPTIONS = { + '205': { base: INDIVIDUAL_SETTINGS_203 }, '204': { base: INDIVIDUAL_SETTINGS_203 }, '203': { base: INDIVIDUAL_SETTINGS_203 }, '202': { base: INDIVIDUAL_SETTINGS }, @@ -387,7 +406,7 @@ DEFAULTS['202'] = { // unreleased DEFAULTS['203'] = { // v0.12 ...DEFAULTS['201'], - 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: [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], }; delete DEFAULTS['203'].STARTUP_BEEP; @@ -396,6 +415,12 @@ DEFAULTS['204'] = { // v0.15 BRAKING_STRENGTH: 255, }; +DEFAULTS['205'] = { + ...DEFAULTS['204'], + STARTUP_BEEP: 1, + STARTUP_MELODY_WAIT_MS: 0, +}; + const settings = { DEFAULTS, INDIVIDUAL_SETTINGS_DESCRIPTIONS, diff --git a/src/utils/helpers/__tests__/Convert.test.js b/src/utils/helpers/__tests__/Convert.test.js index 24f1a8eff..d1ec15cfc 100644 --- a/src/utils/helpers/__tests__/Convert.test.js +++ b/src/utils/helpers/__tests__/Convert.test.js @@ -12,7 +12,7 @@ test('settingsUint8Array', () => { const settingsObject = Convert.arrayToSettingsObject(settingsArray, layout); const keys = Object.keys(settingsObject); - expect(keys.length).toEqual(44); + expect(keys.length).toEqual(45); layout.MAIN_REVISION.size = 0; expect(() => Convert.arrayToSettingsObject(settingsArray, layout)).toThrow(); @@ -24,7 +24,7 @@ test('settingsArray', () => { const shortArray = settingsArray.subarray(0, settingsArray.length - 2); const settingsObject = Convert.arrayToSettingsObject(shortArray, layout); const settingsArrayResult = Convert.objectToSettingsArray(settingsObject, layout, EEPROM.LAYOUT_SIZE); - expect(settingsArrayResult.length).toEqual(240); + expect(settingsArrayResult.length).toEqual(255); layout.MAIN_REVISION.size = 0; expect(() => Convert.objectToSettingsArray(settingsObject, layout, EEPROM.LAYOUT_SIZE)).toThrow();