also beep roomba at the same time

This commit is contained in:
legop3
2026-09-12 17:44:12 -04:00
parent 3b7b2ac21e
commit 3ec45de4b4
2 changed files with 100 additions and 43 deletions
@@ -6,6 +6,9 @@ const {
HELP_HORN_DURATION_MS,
HELP_HORN_FREQUENCY_HZ,
HELP_HORN_INTERVAL_MS,
HELP_ROOMBA_NOTE,
HELP_ROOMBA_NOTE_DURATION,
HELP_ROOMBA_SONG_SLOT,
createHelpHornNotifier,
} = require('./hornNotifier');
@@ -35,17 +38,29 @@ function createHarness({ enabled = true } = {}) {
return { clearedIntervals, clearedTimeouts, commands, intervals, notifier, timeouts };
}
test('starts an immediate 2000 Hz saw chirp and schedules the agreed cadence', () => {
test('starts matching external and Roomba chirps and schedules the agreed cadence', () => {
const harness = createHarness();
harness.notifier.start('red');
assert.deepEqual(harness.commands, [{
roverId: 'red',
payload: {
type: 'horn',
horn: { action: 'start', waveform: 'saw', freqs: [HELP_HORN_FREQUENCY_HZ] },
assert.deepEqual(harness.commands, [
{
roverId: 'red',
payload: {
type: 'horn',
horn: { action: 'start', waveform: 'saw', freqs: [HELP_HORN_FREQUENCY_HZ] },
},
},
}]);
{
roverId: 'red',
payload: {
type: 'song',
song: {
slot: HELP_ROOMBA_SONG_SLOT,
notes: [{ note: HELP_ROOMBA_NOTE, duration: HELP_ROOMBA_NOTE_DURATION }],
},
},
},
]);
assert.equal(Array.from(harness.intervals.values())[0].ms, HELP_HORN_INTERVAL_MS);
assert.equal(Array.from(harness.timeouts.values())[0].ms, HELP_HORN_DURATION_MS);
@@ -65,10 +80,19 @@ test('stop cancels cadence and pending pulse before issuing a final horn stop',
assert.equal(harness.commands.at(-1).payload.horn.action, 'stop');
});
test('does not schedule chirps for a rover without an enabled horn', () => {
test('still schedules the Roomba song when the external horn is disabled', () => {
const harness = createHarness({ enabled: false });
harness.notifier.start('green');
assert.equal(harness.commands.length, 0);
assert.equal(harness.intervals.size, 0);
assert.deepEqual(harness.commands, [{
roverId: 'green',
payload: {
type: 'song',
song: {
slot: HELP_ROOMBA_SONG_SLOT,
notes: [{ note: HELP_ROOMBA_NOTE, duration: HELP_ROOMBA_NOTE_DURATION }],
},
},
}]);
assert.equal(harness.intervals.size, 1);
assert.equal(harness.timeouts.size, 0);
});