Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve action on manual Keypad when activated from the keyboard. #1072

Merged
merged 16 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions dashboard/build/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
<body id="body">
<div id='mainContent'>
</div>
<div class="speed_read_out">
100
</div>
<form>
<input type="file" id="hidden-file-input" style="position: fixed; top:-1000; display: none" />
</form>
Expand Down Expand Up @@ -247,9 +244,11 @@

<!-- The Dialog -->
<div class="modalDim"></div>
<div class="manual-drive-modal" oncontextmenu="return false;">
<div class="manual-drive-modal" id="keypad-modal" oncontextmenu="return false;">
<div class="manual-drive-exit"><i class="fa fa-times"></i></div>

<div class="speed_read_out">
100
</div>
<div class="manual-drive-message">This is where a message will go</div>
<div class="manual-drive-container">
<div>
Expand Down Expand Up @@ -314,7 +313,7 @@
<div id="keypad" class="fabmo-manual-control keypad " style="text-align: center;">
<div class="slidecontainer">
<input type="range" step="0.1" class="slider" id="manual-move-speed">
<label >XY Move Speed</label>
<label><u><</u>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;XY Move Speed&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<u>></u></label>
</div>
<div class="fixed-input-container ">
<div>
Expand Down Expand Up @@ -401,7 +400,7 @@
</div>
</div>
<div class="switch-container">
<span class="fixed-label">Fixed Distance </span>
<span class="fixed-label"><u>F</u>ixed Distance </span>
<label class="fixed-switch">
<input type="checkbox">
<span class="slider-toggle round"></span>
Expand Down
14 changes: 10 additions & 4 deletions dashboard/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -1339,10 +1339,11 @@ ul.off-canvas-list li a, ul.off-canvas-list li.no-link {
.manual-drive-message {
font-size: 1.2rem;
display: none;
color: #eee;
color: #313366;
width: 100%;
height: auto;
text-align: center;
margin-top: -8px;
margin-bottom: 10px;
}
.keypad-button {
Expand Down Expand Up @@ -1538,7 +1539,9 @@ ul.off-canvas-list li a, ul.off-canvas-list li.no-link {
} */

.speed_read_out {
position: absolute;
position: relative;
top: 0%;
left: 73%;
color: #422001;
display: none;
z-index: 10000;
Expand Down Expand Up @@ -1574,6 +1577,7 @@ input[type='range']::-webkit-slider-runnable-track {
background: linear-gradient(#e38928, #DB8635) no-repeat content-box, linear-gradient(#1c1c1c, #fd2) content-box;
background-size: 100% 100%;
}
/* #### Between marks these may need updating for new appearance ? Don't seem to be used in edge */
input[type='range']::-moz-range-track {
box-sizing: border-box;
padding: 0.75em;
Expand All @@ -1594,10 +1598,10 @@ input[type='range']::-ms-track {
background: linear-gradient(#1c1c1c, #fd2) content-box;
color: transparent;
}
/* #### and possibly below as well */




/* Also needed for new appearance ? */
input[type='range']::-moz-range-progress {
padding: 0.75em 1px 0.75em 0.75em;
height: 1em;
Expand Down Expand Up @@ -2185,6 +2189,8 @@ input[type='range']:focus {
}

.speed_read_out {
top: 40%;
left: 40%;
padding-top: 35px;
padding-left: 35px;
}
Expand Down
15 changes: 9 additions & 6 deletions dashboard/static/js/libs/fabmoui.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@
$("#manual-move-speed").on("input", function (e) {
$(".speed_read_out").show();
$(".speed_read_out").html($("#manual-move-speed").val());
$(".speed_read_out").css({
top: $("#manual-move-speed").offset().top - 35,
left: mouseX,
});
setTimeout(function () {
$(".speed_read_out").hide();
}, 750);
});

$("#manual-move-speed").on("mouseup touchend", function () {
Expand Down Expand Up @@ -215,8 +214,12 @@
}

var unit = status.unit || "??";

var digits = unit === "mm" ? 2 : 3;
var digits = 3;
$("#manual-move-speed").attr("step", 0.1);
if (unit === "mm") {
digits = 2;
$("#manual-move-speed").attr("step", 1);
}

if (unit !== currentUnits) {
currentUnits = unit;
Expand Down
23 changes: 21 additions & 2 deletions dashboard/static/js/libs/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
to the designed functionality was ever supposed to be handled for the keyboard case (vs the keypad case). I also went back
a bit in time and did not find evidence that this system ever worked to set a visual indicators that an axis button was
being pushed from the device keyboard arrows. There may be other "intended" features that also fail here. I have created a
system for handling the display for now. Don't know if it's as efficient as it could be.
system for handling the display for now. Don't know if it's as efficient as it could be. Note that both keyboard and
work through main.js motion calls.
*/

Keyboard.prototype.init = function () {
Expand Down Expand Up @@ -132,7 +133,7 @@
}
};

// Get keypad icons to light when keyboard arrow keys are used; see note above; see note above
// Get keypad icons to light when keyboard arrow keys are used; see note above
Keyboard.prototype.start = function (axis, direction) {
if (this.going) {
return;
Expand Down Expand Up @@ -218,6 +219,9 @@
};

Keyboard.prototype.onKeyUp = function (evt) {
if (evt.keyCode < 27) {
return;
} // prevents un-needed kills to shift and ctl release
if (this.nudgeTimer) {
clearTimeout(this.nudgeTimer);
this.nudgeTimer = null;
Expand Down Expand Up @@ -261,11 +265,26 @@

Keyboard.prototype.nudge = function (axis, direction) {
if (this.going) {
this.going = false;
return this.stop();
}
var nudge = { axis: axis, dir: direction };
if (this.enabled) {
this.emit("nudge", nudge);
let activeArrowStr =
"#keyboardArrow_" + axis + (direction === 1 ? "_pos" : "_neg");
$(activeArrowStr).addClass("drive-button-active-transient");
setTimeout(
function () {
if (!this.going) {
$(activeArrowStr).removeClass(
"drive-button-active-transient"
);
$(activeArrowStr).addClass("drive-button-inactive");
}
}.bind(this),
50
);
}
};

Expand Down
2 changes: 1 addition & 1 deletion dashboard/static/js/libs/keypad.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@
);
}
}.bind(this),
25
50
);
}
};
Expand Down
86 changes: 57 additions & 29 deletions dashboard/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,27 +577,6 @@ $(".manual-drive-enter").on("click", function () {
dashboard.engine.manualEnter();
});

function showConsent() {
$(".modalDim").show();
$("#beacon_consent_container").show();
}
function hideConsent() {
$(".modalDim").hide();
$("#beacon_consent_container").hide();
}

$("#beacon_consent_button").on("click", function (conf) {
conf = { consent_for_beacon: "true" };
dashboard.engine.setUpdaterConfig(conf, function (err) {
if (err) {
return;
}
});
consent = "true";
$(".modalDim").hide();
$("#beacon_consent_container").hide();
});

function showDaisy(callback) {
if (daisyIsShown) {
return;
Expand All @@ -623,18 +602,68 @@ function hideDaisy(callback) {
dashboard.hideModal();
}

// listen for escape key press to quit the engine ctrl and k enters manual
// Click outside the modal keypad to close it //th: don't know if I like this now that it is done?
const modalKeyPad = document.getElementById("keypad-modal");
function handleClickOutside(event) {
if (
modalKeyPad &&
!modalKeyPad.contains(event.target) &&
modalKeyPad.style.display === "block"
) {
if (last_state_seen === "manual") {
dashboard.engine.manualExit();
}
}
}
// Attach the event listener to the document
document.addEventListener("click", handleClickOutside);

// Access slider for using speed up/dn keys (could not make our jquery work for this, need ui version?)
const slider = document.getElementById("manual-move-speed");
function triggerSliderEvent(value) {
if (slider) {
slider.value = value;
const changeEvent = new Event("change");
slider.dispatchEvent(changeEvent);
const inputEvent = new Event("input");
slider.dispatchEvent(inputEvent);
}
}

// Key action in from keyboard in Modal Keypad
$(document).on("keydown", function (e) {
if (e.keyCode === 27) {
console.warn("ESC key pressed - quitting engine.");
dashboard.engine.manualExit();
// keyboard.setEnabled(true);
} else if (e.keyCode === 75 && e.ctrlKey) {
// escape key press to quit the engine
if (e.key === "Escape") {
console.warn("ESC key pressed - quitting manual mode.");
dashboard.engine.manualExit(); // not checking for modal active as useful to a button to send a "kill" to G2 for general clear
// alt + k enters manual (only if not in iframe)
} else if (e.key === "k" && e.altKey) {
// changed to alt but still not very useful only working outside iframe
dashboard.engine.manualEnter();
// toggle "Fixed" moves
} else if (e.key === "f") {
$(".fixed-switch").trigger("click");
// increase or decrease speed
} else if (e.key === ">" || e.key === "<") {
let newSpeed;
let adder = 0.1;
if (dashboard.engine.status.unit === "mm") {
adder = 1.0;
}
switch (e.key) {
case ">":
newSpeed = parseFloat($("#manual-move-speed").val()) + adder;
triggerSliderEvent(newSpeed);
break;
case "<":
newSpeed = parseFloat($("#manual-move-speed").val()) - adder;
triggerSliderEvent(newSpeed);
break;
}
}
});

//goto this location
// Goto this location
var axisValues = [];
var getAxis = function () {
$(".axi").each(function () {
Expand Down Expand Up @@ -797,7 +826,6 @@ engine.on("disconnect", function () {
if (!disconnected) {
disconnected = true;
setConnectionStrength(null);
hideConsent();
showDaisy();
}
});
Expand Down