Library created by mixing https://github.com/stilesdev/stackmat and stackmatsignalprocessor from https://github.com/Kubiverse/StackmatSignalProcessor converted to typescript Thanks for this 2 great projects
Work with my QiYi timer.
Subscribe to events received from a Stackmat timer connected to the browser via the HTML5 Audio API.
Both a Typescript-based library and a UMD build are available.
Subscribe to events and start listening for packets:
import { Stackmat, Packet } from 'stackmat'
const stackmat = new Stackmat()
stackmat.on('started', (packet: Packet) => {
console.log('Timer started')
})
stackmat.start()
Import the UMD build:
Subscribe to events and start listening for packets:
<script type="text/javascript">
const stackmat = new Stackmat();
stackmat.on('started', packet => {
console.log('Timer started')
})
stackmat.start()
</script>
stackmat.stop()
may be called to stop listening for packets, without unsubscribing from any events.
stackmat.off(TimerEvent?)
may be called to unsubscribe from a specified event, or all events if no specific event is provided.
TimerEvent |
When Fired |
---|---|
packetRecieved | Every time a valid packet is recieved |
timerConnected | Valid packets start being received |
timerDisconnected | Valid packets stop being received |
started | A solve is started, and the timer starts counting up from zero |
stopped | A solve is completed, and the timer is stopped |
reset | The timer is reset to zero |
ready | Both hands are placed on the timer while the timer is in a reset state |
unready | One or both hands are removed before the green light turns on and the timer is in a ready state |
starting | The green light turns on while in a ready state, indicating the solve can be started |
leftHandDown | The left hand is placed on the timer while the timer is in any state |
leftHandUp | The left hand is removed from the timer while the timer is in any state |
rightHandDown | The right hand is placed on the timer while the timer is in any state |
rightHandUp | The right hand is removed from the timer while the timer is in any state |
Each event callback (with the exception of timerConnected
and timerDisconnected
) sends a Packet
with the following properties:
interface Packet {
isValid: boolean
status: PacketStatus
timeInMilliseconds: number
isLeftHandDown: boolean
isRightHandDown: boolean
areBothHandsDown: boolean
}
PacketStatus
is an enum representing the internal code sent with each Stackmat packet:
enum PacketStatus {
IDLE = 'I',
STARTING = 'A',
RUNNING = ' ',
STOPPED = 'S',
LEFT_HAND = 'L',
RIGHT_HAND = 'R',
BOTH_HANDS = 'C',
INVALID = 'X',
}