Skip to content

Commit

Permalink
Turn off LED when done
Browse files Browse the repository at this point in the history
  • Loading branch information
dtcooper committed Jul 28, 2024
1 parent 62f05d2 commit f6df4c5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
4 changes: 2 additions & 2 deletions client/src/main/Player.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import { singlePlayRotators, stop as stopSinglePlayRotator } from "../stores/single-play-rotators"
import { db } from "../stores/db"
import { Wait } from "../stores/player"
import { setLED } from "../stores/midi"
import { setLED, LED_OFF } from "../stores/midi"
// Object automatically updates on change
let items = []
Expand All @@ -39,7 +39,7 @@
$: overtime = items.length > 0 && items[0].type === "wait" && items[0].overtime
$: if (items.length === 0) {
setLED(0)
setLED(LED_OFF)
}
const doneWaiting = () => {
Expand Down
20 changes: 14 additions & 6 deletions client/src/main/player/Buttons.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@
import { userConfig } from "../../stores/config"
import { blockSpacebarPlay } from "../../stores/player"
import { setLED, registerButtonPressCallback } from "../../stores/midi"
import {
setLED,
registerButtonPressCallback,
LED_OFF,
LED_ON,
LED_FLASH,
LED_PULSATE_SLOW,
LED_PULSATE_FAST
} from "../../stores/midi"
import Icon from "../../components/Icon.svelte"
Expand All @@ -30,15 +38,15 @@
let ledState
$: if (playDisabled) {
ledState = 0 // LED_OFF
ledState = LED_OFF
} else if (isPaused) {
ledState = 2 // LED_FLASH
ledState = LED_FLASH
} else if (overdue) {
ledState = 4 // LED_PULSATE_FAST
ledState = LED_PULSATE_FAST
} else if (overtime) {
ledState = 3 // LED_PULSATE_SLOW
ledState = LED_PULSATE_SLOW
} else {
ledState = 1 // LED_ON
ledState = LED_ON
}
$: setLED(ledState)
Expand Down
12 changes: 11 additions & 1 deletion client/src/stores/midi.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@ let buttonPressCallback = noop

let lastLEDValue = 0

export const LED_OFF = 0
export const LED_ON = 1
export const LED_FLASH = 2
export const LED_PULSATE_SLOW = 3
export const LED_PULSATE_FAST = 4

const updateMidiDevices = (enabled = null) => {
if (enabled === null) {
enabled = get(userConfig).enableMIDIButtonBox
}

if (!enabled) {
setLED(0, true)
setLED(LED_OFF, true)
}

outputs = []
Expand Down Expand Up @@ -65,3 +71,7 @@ export let registerButtonPressCallback = (callback) => (buttonPressCallback = ca
updateMidiDevices()
midi.onstatechange = () => updateMidiDevices()
})()

window.addEventListener("beforeunload", () => {
setLED(LED_OFF, true)
})

0 comments on commit f6df4c5

Please sign in to comment.