diff --git a/client/index.html b/client/index.html index a1d8fc0..3939cc7 100644 --- a/client/index.html +++ b/client/index.html @@ -32,7 +32,7 @@ -
Amusez vous ! Pour contrôler le robot, utilisez les flèches @@ -77,6 +102,51 @@ assignCommands('left', 'right', event) ) + // Buttons handlers + for (const button of document + .querySelector('#touch-controls') + .querySelectorAll('button')) { + button.addEventListener('click', () => { + const { command, value } = button.dataset + + // Check datas are set for button + if (command === undefined || value === undefined) { + alert( + `Pas de command ou de valeur assigné au bouton "${button.title}"` + ) + throw new Error( + `no command or value assigned to ${button.title}` + ) + } + + // Check command is valid + if ( + !['forward', 'backward', 'left', 'right', 'stop'].includes( + command + ) + ) { + alert( + `La command "${command}" n'est pas valide en tant que ('forward', 'backward', 'left', 'right', 'stop')` + ) + throw new Error( + `specified command "${command}" is not in ['forward', 'backward', 'left', 'right', 'stop']` + ) + } + + // Check value is valid finite number + if (!Number.isFinite(Number(value))) { + alert( + `La valeur "${value}" n'est convertible en entier fini` + ) + throw new Error( + `value "${value}" cannot be casted to finite integer` + ) + } + + sendCommand(command, Number(value)) + }) + } + // Keyboard handler document.addEventListener('keydown', ({ code }) => { if (code === 'ArrowUp') { @@ -208,4 +278,10 @@ return sendCommand(positiveCommand, value) } +