git.haldean.org sousvide / 6895e58
Change /target and /pid to be handled by /params This simplifies the form stuff a lot. Will Haldean Brown 8 years ago
5 changed file(s) with 21 addition(s) and 60 deletion(s). Raw diff Collapse all Expand all
5959 resp.Write(b)
6060 })
6161
62 http.HandleFunc("/target", func(resp http.ResponseWriter, req *http.Request) {
62 http.HandleFunc("/params", func(resp http.ResponseWriter, req *http.Request) {
6363 s.DataLock.Lock()
6464 defer s.DataLock.Unlock()
6565
6767 if err != nil {
6868 return
6969 }
70 s.Target = Celsius(t)
71 s.checkpoint()
72 resp.Write([]byte("success"))
73 })
74
75 http.HandleFunc("/pid", func(resp http.ResponseWriter, req *http.Request) {
76 s.DataLock.Lock()
77 defer s.DataLock.Unlock()
78
7970 p, err := floatData(resp, req, "p")
8071 if err != nil {
8172 return
9182 s.Pid.P = p
9283 s.Pid.I = i
9384 s.Pid.D = d
85 s.Target = Celsius(t)
9486 s.checkpoint()
9587 s.SavePid()
9688 log.Printf("new pid parameters p=%f i=%f d=%f", p, i, d);
97 http.Redirect(resp, req, "/", http.StatusSeeOther)
89 resp.Write([]byte("success"));
9890 })
9991
10092 http.HandleFunc("/enable", func(w http.ResponseWriter, r *http.Request) {
7878 return;
7979 }
8080 for (var i = 0; i < n; i++) {
81 target[i] = newT
81 target[i] = newT;
8282 }
83 targetpath.attr("d", line)
83 targetpath.transition().duration(1000).attr("d", line);
8484 }
3535 editorVisible = !editorVisible;
3636 });
3737
38 formAjax(document.getElementById("target_form"), "/target", function(data) {
39 return !!data;
40 });
41
42 formAjax(document.getElementById("pid_form"), "/pid", function(data) {
38 formAjax(document.getElementById("param_form"), "/params", function(data) {
4339 return !!data;
4440 });
4541 }
4343 <div id="editor_container">
4444 <div id="editor" class="bg-secondary">
4545 <table>
46 <tr>
47 <td>target</td>
48 <td>
49 <form id="target_form" method="POST" action="/target">
50 <input type="text" id="target_input" name="target" class="bg-secondary">&deg;C
51 <input type="submit" style="display:none;">
52 </form>
53 </td>
54 </tr>
5546 </table>
56 <form id="pid_form" method="POST" action="/pid">
47 <form id="param_form" method="POST" action="/params">
5748 <table>
49 <tr>
50 <td>target</td>
51 <td>
52 <form id="target_form" method="POST" action="/target">
53 <input type="text"
54 id="target_input"
55 name="target"
56 class="bg-secondary">&deg;C
57 <input type="submit" style="display:none;">
58 </form>
59 </td>
60 </tr>
61 <tr><td></td></tr>
5862 <tr>
5963 <td>Prop</td>
6064 <td class="val">
128132 </tr>
129133 </table>
130134 </section>
131 <section style="display:none">
132 <h2>controller</h2>
133 <form method="POST" action="/pid">
134 <table>
135 <tr>
136 <td>Proportional</td>
137 <td class="val">
138 <input type="text" class="bg-secondary" name="p" id="pid_p">
139 </td>
140 </tr>
141 <tr>
142 <td>Integral</td>
143 <td class="val">
144 <input type="text" class="bg-secondary" name="i" id="pid_i">
145 </td>
146 </tr>
147 <tr>
148 <td>Derivative</td>
149 <td class="val">
150 <input type="text" class="bg-secondary" name="d" id="pid_d">
151 </td>
152 </tr>
153 <tr>
154 <td></td>
155 <td class="val">
156 <input value="update" type="submit">
157 </td>
158 </tr>
159 </table>
160 </form>
161 </section>
162135 </body>
163136 </html>
7676 }
7777
7878 function formAjax(formElem, path, blinkUntil) {
79 submit = (function(e) {
79 var submit = (function(e) {
8080 if (e) e.preventDefault();
8181 startLoader(blinkUntil);
8282 var data = {};