From 880dff13aca947dfa9c699e4e6c8ebb44d6ed7fd Mon Sep 17 00:00:00 2001 From: wixette Date: Sun, 8 Mar 2020 20:31:56 +0800 Subject: [PATCH] handle all toggle switches on switch board helper --- index.html | 56 ++++++++++++++++++++++++++--------------------------- js/l10n.js | 4 ++-- js/panel.js | 50 +++++++++++++++++++++++++++++++---------------- 3 files changed, 63 insertions(+), 47 deletions(-) diff --git a/index.html b/index.html index cc27003..fb5eb76 100644 --- a/index.html +++ b/index.html @@ -566,38 +566,38 @@ -
-
Soft Switch Board
+
+
Switch Board Helper
-
+
-
A15
-
A14
-
A13
-
A12
-
A11
-
A10
-
A09
-
A08
-
A07
-
A06
-
A05
-
A04
-
A03
-
A02
-
A01
-
A00
+
A15
+
A14
+
A13
+
A12
+
A11
+
A10
+
A09
+
A08
+
A07
+
A06
+
A05
+
A04
+
A03
+
A02
+
A01
+
A00
-
ON/OFF
-
STOP
-
RUN
-
SINGLE STEP
-
EXAMINE
-
EXAMINE-NEXT
-
DEPOSIT
-
DEPOSIT-NEXT
-
RESET
+
OFF/ON
+
STOP
+
RUN
+
SINGLE STEP
+
EXAMINE
+
EXAMINE-NEXT
+
DEPOSIT
+
DEPOSIT-NEXT
+
RESET
diff --git a/js/l10n.js b/js/l10n.js index 54f30e8..6c88511 100644 --- a/js/l10n.js +++ b/js/l10n.js @@ -60,8 +60,8 @@ l10n.MESSAGES = { 'zh': '参考', }, - 'switchboard': { - 'en': 'Soft Switch Board', + 'switchboard-helper': { + 'en': 'Switch Board Helper', 'zh': '辅助开关面板', }, diff --git a/js/panel.js b/js/panel.js index c1f23e3..46fb072 100644 --- a/js/panel.js +++ b/js/panel.js @@ -546,6 +546,9 @@ panel.STATELESS_SWITCH = 1; /** The current state of all the address switches. */ panel.addressSwitchStates = new Array(16); +/** If the power is turned on. */ +panel.isPoweredOn = false; + /** The simulator object. */ panel.sim = null; @@ -592,6 +595,7 @@ panel.init = function() { } // Initializes internal states. + panel.isPoweredOn = false; panel.addressSwitchStates.fill(0); panel.switchUp('OFF-ON'); @@ -704,16 +708,24 @@ panel.createSwitch = function(id, type, x, y, upperCmd, lowerCmd) { var sourceId = id; upElem.addEventListener('click', function() { - panel.playToggle(); - panel.onToggle(sourceId, 1); + panel.onToggle(sourceId); }, false); downElem.addEventListener('click', function() { - panel.playToggle(); - panel.onToggle(sourceId, 0); + panel.onToggle(sourceId); }, false); + // Also installs soft switch handlers. + let softSwitchId = 'S-' + id; + let elem = document.getElementById(softSwitchId); + elem.addEventListener( + 'click', + function() { + panel.onToggle(sourceId); + }, + false + ); } else { if (upperCmd) { let cmdElem = document.getElementById(upperCmd.textId); @@ -831,25 +843,29 @@ panel.switchDownThenBack = function(id) { /** * Handles the click event for all TOGGLE_SWITCH controls. * @param {string} id The switch ID which has been clicked. - * @param {number} state The state of the switch before it's clicked. - * 0 for the down state. 1 for the up state. */ -panel.onToggle = function(id, state) { - if (state == 0) { - panel.switchUp(id); - } else { - panel.switchDown(id); - } - if (id == 'OFF-ON') { +panel.onToggle = function(id) { + panel.playToggle(); + if (id[0] == 'S') { + var bitIndex = parseInt(id.substr(1)); + var state = panel.addressSwitchStates[bitIndex]; if (state == 0) { + panel.switchUp(id); + } else { + panel.switchDown(id); + } + panel.addressSwitchStates[bitIndex] = state ? 0 : 1; + } else if (id == 'OFF-ON') { + console.log(panel.isPoweredOn); + if (panel.isPoweredOn) { panel.onPowerOff(); + panel.switchUp(id); + panel.isPoweredOn = false; } else { panel.onPowerOn(); + panel.switchDown(id); + panel.isPoweredOn = true; } - } else { - var bitIndex = parseInt(id.substr(1)); - panel.addressSwitchStates[bitIndex] = - panel.addressSwitchStates[bitIndex] ? 0 : 1; } };