handle all toggle switches on switch board helper

This commit is contained in:
wixette 2020-03-08 20:31:56 +08:00
parent 6dc0867bd4
commit 880dff13ac
3 changed files with 63 additions and 47 deletions

View File

@ -566,38 +566,38 @@
</svg> </svg>
<div class="subheader-bar"> <div class="subheader-bar mt-8">
<div id="switchboard" class="l10n">Soft Switch Board</div> <div id="switchboard-helper" class="l10n">Switch Board Helper</div>
</div> </div>
<div class="v-box"> <div class="v-box mt-8">
<div class="h-box justify-space-around"> <div class="h-box justify-space-around">
<div class="button m-8">A15</div> <div id="S-S15" class="button m-8">A15</div>
<div class="button m-8">A14</div> <div id="S-S14" class="button m-8">A14</div>
<div class="button m-8">A13</div> <div id="S-S13" class="button m-8">A13</div>
<div class="button m-8">A12</div> <div id="S-S12" class="button m-8">A12</div>
<div class="button m-8">A11</div> <div id="S-S11" class="button m-8">A11</div>
<div class="button m-8">A10</div> <div id="S-S10" class="button m-8">A10</div>
<div class="button m-8">A09</div> <div id="S-S9" class="button m-8">A09</div>
<div class="button m-8">A08</div> <div id="S-S8" class="button m-8">A08</div>
<div class="button m-8">A07</div> <div id="S-S7" class="button m-8">A07</div>
<div class="button m-8">A06</div> <div id="S-S6" class="button m-8">A06</div>
<div class="button m-8">A05</div> <div id="S-S5" class="button m-8">A05</div>
<div class="button m-8">A04</div> <div id="S-S4" class="button m-8">A04</div>
<div class="button m-8">A03</div> <div id="S-S3" class="button m-8">A03</div>
<div class="button m-8">A02</div> <div id="S-S2" class="button m-8">A02</div>
<div class="button m-8">A01</div> <div id="S-S1" class="button m-8">A01</div>
<div class="button m-8">A00</div> <div id="S-S0" class="button m-8">A00</div>
</div> </div>
<div class="h-box justify-space-start"> <div class="h-box justify-space-start">
<div class="button m-8 flex-grow-1">ON/OFF</div> <div id="S-OFF-ON" class="button m-8 flex-grow-1">OFF/ON</div>
<div class="button m-8 flex-grow-1">STOP</div> <div id="S-STOP" class="button m-8 flex-grow-1">STOP</div>
<div class="button m-8 flex-grow-1">RUN</div> <div id="S-RUN" class="button m-8 flex-grow-1">RUN</div>
<div class="button m-8 flex-grow-1">SINGLE STEP</div> <div id="S-SINGLE" class="button m-8 flex-grow-1">SINGLE STEP</div>
<div class="button m-8 flex-grow-1">EXAMINE</div> <div id="S-EXAMINE" class="button m-8 flex-grow-1">EXAMINE</div>
<div class="button m-8 flex-grow-1">EXAMINE-NEXT</div> <div id="S-EXAMINE-NEXT" class="button m-8 flex-grow-1">EXAMINE-NEXT</div>
<div class="button m-8 flex-grow-1">DEPOSIT</div> <div id="S-DEPOSIT" class="button m-8 flex-grow-1">DEPOSIT</div>
<div class="button m-8 flex-grow-1">DEPOSIT-NEXT</div> <div id="S-DEPOSIT-NEXT" class="button m-8 flex-grow-1">DEPOSIT-NEXT</div>
<div class="button m-8 flex-grow-1">RESET</div> <div id="S-RESET" class="button m-8 flex-grow-1">RESET</div>
</div> </div>
</div> </div>

View File

@ -60,8 +60,8 @@ l10n.MESSAGES = {
'zh': '参考', 'zh': '参考',
}, },
'switchboard': { 'switchboard-helper': {
'en': 'Soft Switch Board', 'en': 'Switch Board Helper',
'zh': '辅助开关面板', 'zh': '辅助开关面板',
}, },

View File

@ -546,6 +546,9 @@ panel.STATELESS_SWITCH = 1;
/** The current state of all the address switches. */ /** The current state of all the address switches. */
panel.addressSwitchStates = new Array(16); panel.addressSwitchStates = new Array(16);
/** If the power is turned on. */
panel.isPoweredOn = false;
/** The simulator object. */ /** The simulator object. */
panel.sim = null; panel.sim = null;
@ -592,6 +595,7 @@ panel.init = function() {
} }
// Initializes internal states. // Initializes internal states.
panel.isPoweredOn = false;
panel.addressSwitchStates.fill(0); panel.addressSwitchStates.fill(0);
panel.switchUp('OFF-ON'); panel.switchUp('OFF-ON');
@ -704,16 +708,24 @@ panel.createSwitch = function(id, type, x, y, upperCmd, lowerCmd) {
var sourceId = id; var sourceId = id;
upElem.addEventListener('click', upElem.addEventListener('click',
function() { function() {
panel.playToggle(); panel.onToggle(sourceId);
panel.onToggle(sourceId, 1);
}, },
false); false);
downElem.addEventListener('click', downElem.addEventListener('click',
function() { function() {
panel.playToggle(); panel.onToggle(sourceId);
panel.onToggle(sourceId, 0);
}, },
false); false);
// Also installs soft switch handlers.
let softSwitchId = 'S-' + id;
let elem = document.getElementById(softSwitchId);
elem.addEventListener(
'click',
function() {
panel.onToggle(sourceId);
},
false
);
} else { } else {
if (upperCmd) { if (upperCmd) {
let cmdElem = document.getElementById(upperCmd.textId); let cmdElem = document.getElementById(upperCmd.textId);
@ -831,25 +843,29 @@ panel.switchDownThenBack = function(id) {
/** /**
* Handles the click event for all TOGGLE_SWITCH controls. * Handles the click event for all TOGGLE_SWITCH controls.
* @param {string} id The switch ID which has been clicked. * @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) { panel.onToggle = function(id) {
panel.playToggle();
if (id[0] == 'S') {
var bitIndex = parseInt(id.substr(1));
var state = panel.addressSwitchStates[bitIndex];
if (state == 0) { if (state == 0) {
panel.switchUp(id); panel.switchUp(id);
} else { } else {
panel.switchDown(id); panel.switchDown(id);
} }
if (id == 'OFF-ON') { panel.addressSwitchStates[bitIndex] = state ? 0 : 1;
if (state == 0) { } else if (id == 'OFF-ON') {
console.log(panel.isPoweredOn);
if (panel.isPoweredOn) {
panel.onPowerOff(); panel.onPowerOff();
panel.switchUp(id);
panel.isPoweredOn = false;
} else { } else {
panel.onPowerOn(); panel.onPowerOn();
panel.switchDown(id);
panel.isPoweredOn = true;
} }
} else {
var bitIndex = parseInt(id.substr(1));
panel.addressSwitchStates[bitIndex] =
panel.addressSwitchStates[bitIndex] ? 0 : 1;
} }
}; };