From 6656bb7f66ccc57c10ec9b1e09a190e817e4b2bd Mon Sep 17 00:00:00 2001
From: wixette <wixette@gmail.com>
Date: Sun, 8 Mar 2020 11:14:12 +0800
Subject: [PATCH] play sound for poweron and toggle switches. TODO: refactor
 code to play sound for stateless switches

---
 index.html  |  4 ++++
 js/panel.js | 31 +++++++++++++++++++++++++++----
 2 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/index.html b/index.html
index 656f97b..d19763d 100644
--- a/index.html
+++ b/index.html
@@ -570,6 +570,10 @@
       <div id="mem-dump"></div>
     </footer>
 
+    <audio id="sound-beepbeep" src="media/beepbeep.mp3"></audio>
+    <audio id="sound-switch" src="media/switch.mp3"></audio>
+    <audio id="sound-toggle" src="media/toggle.mp3"></audio>
+
     <script src="js/l10n.js"></script>
     <script src="js/8080.js"></script>
     <script src="js/sim8800.js"></script>
diff --git a/js/panel.js b/js/panel.js
index 12911d9..5b4690f 100644
--- a/js/panel.js
+++ b/js/panel.js
@@ -508,6 +508,24 @@ panel.debugLoadData = function() {
     panel.sim.loadDataAsHexString(0, data);
 };
 
+panel.playSound = function(id) {
+    var sound = document.getElementById(id);
+    sound.currentTime = 0;
+    sound.play();
+};
+
+panel.playBeepbeep = function() {
+    panel.playSound('sound-beepbeep');
+};
+
+panel.playToggle = function() {
+    panel.playSound('sound-toggle');
+};
+
+panel.playSwitch = function() {
+    panel.playSound('sound-switch');
+};
+
 /**
  * Creates a new LED inside the panel svg.
  * @param {string} id The LED ID. This ID will be used as the prefix
@@ -600,14 +618,16 @@ panel.createSwitch = function(id, type, x, y) {
         var sourceId = id;
         upElem.addEventListener('click',
                                 function() {
+                                    panel.playToggle();
                                     panel.onToggle(sourceId, 1);
                                 },
                                 false);
         downElem.addEventListener('click',
-                                function() {
-                                    panel.onToggle(sourceId, 0);
-                                },
-                                false);
+                                  function() {
+                                      panel.playToggle();
+                                      panel.onToggle(sourceId, 0);
+                                  },
+                                  false);
     }
 
     panelElem.appendChild(midElem);
@@ -766,6 +786,9 @@ panel.onReset = function() {
  */
 panel.onPowerOn = function() {
     panel.sim.powerOn();
+    window.setTimeout(function() {
+        panel.playBeepbeep();
+    }, 500);
 };
 
 /**