-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy patheditsenseresistor.coffee
116 lines (88 loc) · 3.19 KB
/
editsenseresistor.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# (C) 2012 Nonolith Labs
# Author: Ian Daniher <[email protected]>
# Author: Kevin Mehall <[email protected]>
# Distributed under the terms of the GNU GPLv3
app = (window.app ?= {})
app.device = null
app.init = (server, params) ->
server.connect()
server.disconnected.listen ->
$("section").html("
<h1>Nonolith Connect not found</h1>
<div> <p>Make sure it is running or
<a href='http://www.nonolithlabs.com/connect/'>Install it</a></p> </div>
")
server.connected.listen app.update
server.devicesChanged.listen app.chooseDevice
app.chooseDevice = ->
app.device = null
for dev in server.devices
if dev.model == 'com.nonolithlabs.cee'
app.device = server.selectDevice(dev)
app.device.changed.listen app.update
return
app.update()
hex = (n) ->
t = n.toString(16)
if t.length == 1
t = '0'+t
return t
app.update = ->
e = $("section")
e.empty()
if app.device
$("<h1>").text("Edit Sense Resistor Values").appendTo(e)
$("<div>").append( \
$("<p>").text("hwVersion: #{app.device.hwVersion}")).append( \
$("<p>").text("fwVersion: #{app.device.fwVersion}")).append( \
$("<p>").text("serial: #{app.device.serial}")).appendTo(e)
$("""
<div>
<p>Channel A</p>
<p><span>Currently: <output id=now_a></span>Ω</p>
<p><label for=res_a>Resistor value:</label> <input type=text id=res_a value=.07 /></p>
</div>
<div>
<p>Channel B</p>
<p><span>Currently: <output id=now_b></span>Ω</p>
<p><label for=res_b>Resistor value:</label> <input type=text id=res_b value=.07 /></p>
</div>
<div>
<p>Power</p>
<p><input type=checkbox id=extpower /> <label for=extpower>Device has cleared solder jumper and external power</label></p>
</div>
<nav><button class="btn primary" id="savebtn">Save to device</button></nav>
""").appendTo(e)
read = ->
server.send 'readCalibration',
id: server.createCallback (e) ->
app.device.eeprom = e
$("#now_a").text(app.device.eeprom.current_gain_a/45/100000)
$("#now_b").text(app.device.eeprom.current_gain_b/45/100000)
$("#extpower").get(0).checked = !(app.device.eeprom.flags&1)
update = ->
console.log('update')
console.log(Math.round(parseFloat($('#res_a').val(),10)*45*100000,10))
console.log(Math.round(parseFloat($('#res_b').val(),10)*45*100000,10))
read()
update()
write = ->
app.device.eeprom.current_gain_a = Math.round(parseFloat($("#res_a").val())*45*100000, 10)
app.device.eeprom.current_gain_b = Math.round(parseFloat($("#res_b").val())*45*100000, 10)
usbpower = not $("#extpower").is(':checked')
app.device.eeprom.flags = app.device.eeprom.flags&(~1) | usbpower
app.device.eeprom.id = server.createCallback ->
alert("EEPROM written. Unplug and replug the CEE to make it take effect.")
read()
server.send 'writeCalibration', app.device.eeprom
app.device.eeprom = null
$("#savebtn").click(write)
else
$("<h1>").text("No Devices Found").appendTo(e)
$(document).ready ->
$("section").append("<p>Platform: #{window.navigator.userAgent}</p>");
if not window.WebSocket
$("section").append("<p>Your browser does not support webSocket</p>")
else
$("section").append("<p>Loading....</p>")
app.init(server)