-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
browser.coffee
62 lines (47 loc) · 1.74 KB
/
browser.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
###
This file is to be ran on the browser.
###
LightwaveRF = require('./lightwaverf.coffee')
sampleData = require('./sample.coffee')
formEl = null
outputEl = null
dataEl = null
output = (results) ->
html = ""
lastData = null
repeatCount = 0
outputRepeats = ->
if repeatCount > 0
html += "Repeats: <span class='data'>#{repeatCount}</span><br />"
repeatCount = 0
html += "</div>" if lastData?
for result in results when result.valid
if lastData is result.data
repeatCount++
else
outputRepeats()
lastData = result.data
html += "<div class='entry'>"
html += "<tt>#{result.pretty}</tt> <span class='debug'>from #{result.startIndex}..#{result.stopIndex}</span><br />"
html += "Remote: <span class='data'>#{result.remoteId}</span>, subunit: <span class='data'>#{result.subunit}</span> <span class='debug'>(#{result.subunitName})</span>, command: <span class='data'>#{result.command}</span> <span class='debug'>(#{result.commandName})</span>, parameter: <span class='data'>#{result.parameter}</span> <span class='debug'>(#{result.level ? "-"})</span><br />"
outputRepeats()
outputEl.innerHTML = html
window.addEventListener 'DOMContentLoaded', ->
formEl = document.getElementById('input')
outputEl = document.getElementById('output')
dataEl = document.getElementById('data')
sampleEl = document.getElementById('sample')
sampleEl.onclick = (e) ->
e.preventDefault?()
dataEl.value = JSON.stringify(sampleData)
onsubmit()
return false
onsubmit = (e) ->
e?.preventDefault?()
data = dataEl.value.replace /[^0-9,]/,""
data = data.split(",")
results = LightwaveRF.decode data
console.log results
output(results)
return false
formEl.onsubmit = onsubmit