Keybindings on facelight for Brian "Danger" Hicks

This commit is contained in:
Neale Pickett 2021-05-11 19:23:43 -06:00
parent 39658b87cd
commit ccd32987f7
1 changed files with 22 additions and 2 deletions

View File

@ -1,3 +1,5 @@
const defaultTemp = 5500
function colorTemperatureToRGB(kelvin) { function colorTemperatureToRGB(kelvin) {
// https://gist.github.com/paulkaplan/5184275 // https://gist.github.com/paulkaplan/5184275
@ -42,7 +44,7 @@ function changeTemp(e) {
let tempOut = document.querySelector("#tempOut") let tempOut = document.querySelector("#tempOut")
let temp let temp
if (!e) { if (!e) {
temp = localStorage.temp || 5500 temp = localStorage.temp || defaultTemp
} else if (e.target) { } else if (e.target) {
temp = Number(e.target.value) temp = Number(e.target.value)
} else { } else {
@ -56,8 +58,26 @@ function changeTemp(e) {
localStorage.temp = temp localStorage.temp = temp
} }
function keydownEvent(event) {
let temp = Number(localStorage.temp || defaultTemp)
switch (event.key) {
case "ArrowLeft":
case "ArrowDown":
event.preventDefault()
changeTemp(temp - 100)
break
case "ArrowRight":
case "ArrowUp":
event.preventDefault()
changeTemp(temp + 100)
break
}
console.log("new temp is", temp)
}
function init() { function init() {
document.querySelector("#temp").addEventListener("input", changeTemp) document.querySelector("#temp").addEventListener("input", changeTemp)
document.addEventListener("keydown", keydownEvent)
changeTemp() changeTemp()
if (navigator.serviceWorker) { if (navigator.serviceWorker) {
navigator.serviceWorker.register("sw.js") navigator.serviceWorker.register("sw.js")