Add enable/disable status.
Will Haldean Brown
9 years ago
77 | 77 |
log.Printf("could not read temperature: %v", err)
|
78 | 78 |
} else {
|
79 | 79 |
co := s.ControllerResult()
|
80 | |
s.Heating = co > 0
|
|
80 |
s.Heating = co > 0 && s.Enabled
|
81 | 81 |
s.UpdateHardware()
|
82 | 82 |
s.checkpoint()
|
83 | 83 |
}
|
2 | 2 |
import (
|
3 | 3 |
"encoding/json"
|
4 | 4 |
"errors"
|
|
5 |
"flag"
|
5 | 6 |
"fmt"
|
6 | 7 |
"log"
|
7 | 8 |
"net/http"
|
8 | 9 |
"strconv"
|
9 | 10 |
)
|
|
11 |
|
|
12 |
var port = flag.Int("port", 80, "port for web interface")
|
10 | 13 |
|
11 | 14 |
func floatData(w http.ResponseWriter, req *http.Request, arg string) (float64, error) {
|
12 | 15 |
valStr := req.FormValue(arg)
|
|
77 | 80 |
http.Redirect(resp, req, "/", http.StatusSeeOther)
|
78 | 81 |
})
|
79 | 82 |
|
|
83 |
http.HandleFunc("/enable", func(w http.ResponseWriter, r *http.Request) {
|
|
84 |
s.Enabled = !s.Enabled
|
|
85 |
log.Printf("set enabled to %v", s.Enabled)
|
|
86 |
http.Redirect(w, r, "/", http.StatusSeeOther)
|
|
87 |
})
|
|
88 |
|
80 | 89 |
http.HandleFunc("/csv", s.DumpCsv)
|
81 | 90 |
|
82 | 91 |
http.HandleFunc("/plot", s.GenerateChart)
|
83 | 92 |
|
84 | 93 |
http.Handle("/", http.FileServer(http.Dir("static/")))
|
85 | 94 |
|
86 | |
log.Fatal(http.ListenAndServe(":80", nil))
|
|
95 |
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), nil))
|
87 | 96 |
}
|
22 | 22 |
|
23 | 23 |
type SousVide struct {
|
24 | 24 |
Heating bool
|
|
25 |
Enabled bool
|
25 | 26 |
Temp Celsius
|
26 | 27 |
Target Celsius
|
27 | 28 |
History []HistorySample
|
|
37 | 38 |
|
38 | 39 |
type HistorySample struct {
|
39 | 40 |
Time time.Time
|
|
41 |
Enabled bool
|
40 | 42 |
Heating bool
|
41 | 43 |
Temp float64
|
42 | 44 |
Target float64
|
|
73 | 75 |
func (s *SousVide) Snapshot() HistorySample {
|
74 | 76 |
return HistorySample{
|
75 | 77 |
Time: time.Now(),
|
|
78 |
Enabled: s.Enabled,
|
76 | 79 |
Heating: s.Heating,
|
77 | 80 |
Temp: float64(s.Temp),
|
78 | 81 |
Target: float64(s.Target),
|
56 | 56 |
margin-top: -2pt;
|
57 | 57 |
color: #CCC;
|
58 | 58 |
}
|
|
59 |
|
|
60 |
#enabled {
|
|
61 |
color: #666;
|
|
62 |
text-decoration: none;
|
|
63 |
}
|
59 | 64 |
</style>
|
60 | 65 |
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:400,700|Source+Code+Pro' rel='stylesheet' type='text/css'>
|
61 | 66 |
|
|
69 | 74 |
<table>
|
70 | 75 |
<tr>
|
71 | 76 |
<td class="label heater_label">Heater is:</td>
|
72 | |
<td class="val"><span id="heating"></span></td>
|
|
77 |
<td class="val">
|
|
78 |
<a href="/enable" id="enabled"></a>,
|
|
79 |
<span id="heating"></span>
|
|
80 |
</td>
|
73 | 81 |
</tr>
|
74 | 82 |
<tr>
|
75 | 83 |
<td class="label temp_label">Current temperature:</td>
|
0 | 0 |
var tempElem, absErrElem, targetElem, heatingElem, plotElem, accErrElem
|
1 | 1 |
var targetDisplayElem, targetChangeElem, targetInputElem
|
2 | 2 |
var pInputElem, iInputElem, dInputElem
|
|
3 |
var enabledElem
|
3 | 4 |
|
4 | 5 |
function getApiData() {
|
5 | 6 |
$.ajax({
|
|
24 | 25 |
$(targetElem).text(target.toFixed(2));
|
25 | 26 |
$(absErrElem).text((err >= 0 ? '+' : '') + err.toFixed(2));
|
26 | 27 |
$(accErrElem).text(data.AccError.toFixed(2))
|
|
28 |
$(enabledElem).text(data.Enabled ? "ENABLED" : "DISABLED")
|
27 | 29 |
|
28 | 30 |
pInputElem.setAttribute('value', data.Pid.P)
|
29 | 31 |
iInputElem.setAttribute('value', data.Pid.I)
|
|
47 | 49 |
heatingElem = document.getElementById('heating')
|
48 | 50 |
plotElem = document.getElementById('plot')
|
49 | 51 |
accErrElem = document.getElementById('acc_err')
|
|
52 |
enabledElem = document.getElementById('enabled')
|
50 | 53 |
|
51 | 54 |
targetChangeElem = document.getElementById('target_change')
|
52 | 55 |
targetDisplayElem = document.getElementById('target_display')
|