git.haldean.org sousvide / c72dfc0
Add enable/disable status. Will Haldean Brown 8 years ago
6 changed file(s) with 29 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
7777 log.Printf("could not read temperature: %v", err)
7878 } else {
7979 co := s.ControllerResult()
80 s.Heating = co > 0
80 s.Heating = co > 0 && s.Enabled
8181 s.UpdateHardware()
8282 s.checkpoint()
8383 }
22 import (
33 "encoding/json"
44 "errors"
5 "flag"
56 "fmt"
67 "log"
78 "net/http"
89 "strconv"
910 )
11
12 var port = flag.Int("port", 80, "port for web interface")
1013
1114 func floatData(w http.ResponseWriter, req *http.Request, arg string) (float64, error) {
1215 valStr := req.FormValue(arg)
7780 http.Redirect(resp, req, "/", http.StatusSeeOther)
7881 })
7982
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
8089 http.HandleFunc("/csv", s.DumpCsv)
8190
8291 http.HandleFunc("/plot", s.GenerateChart)
8392
8493 http.Handle("/", http.FileServer(http.Dir("static/")))
8594
86 log.Fatal(http.ListenAndServe(":80", nil))
95 log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), nil))
8796 }
2222
2323 type SousVide struct {
2424 Heating bool
25 Enabled bool
2526 Temp Celsius
2627 Target Celsius
2728 History []HistorySample
3738
3839 type HistorySample struct {
3940 Time time.Time
41 Enabled bool
4042 Heating bool
4143 Temp float64
4244 Target float64
7375 func (s *SousVide) Snapshot() HistorySample {
7476 return HistorySample{
7577 Time: time.Now(),
78 Enabled: s.Enabled,
7679 Heating: s.Heating,
7780 Temp: float64(s.Temp),
7881 Target: float64(s.Target),
5656 margin-top: -2pt;
5757 color: #CCC;
5858 }
59
60 #enabled {
61 color: #666;
62 text-decoration: none;
63 }
5964 </style>
6065 <link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:400,700|Source+Code+Pro' rel='stylesheet' type='text/css'>
6166
6974 <table>
7075 <tr>
7176 <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>
7381 </tr>
7482 <tr>
7583 <td class="label temp_label">Current temperature:</td>
00 var tempElem, absErrElem, targetElem, heatingElem, plotElem, accErrElem
11 var targetDisplayElem, targetChangeElem, targetInputElem
22 var pInputElem, iInputElem, dInputElem
3 var enabledElem
34
45 function getApiData() {
56 $.ajax({
2425 $(targetElem).text(target.toFixed(2));
2526 $(absErrElem).text((err >= 0 ? '+' : '') + err.toFixed(2));
2627 $(accErrElem).text(data.AccError.toFixed(2))
28 $(enabledElem).text(data.Enabled ? "ENABLED" : "DISABLED")
2729
2830 pInputElem.setAttribute('value', data.Pid.P)
2931 iInputElem.setAttribute('value', data.Pid.I)
4749 heatingElem = document.getElementById('heating')
4850 plotElem = document.getElementById('plot')
4951 accErrElem = document.getElementById('acc_err')
52 enabledElem = document.getElementById('enabled')
5053
5154 targetChangeElem = document.getElementById('target_change')
5255 targetDisplayElem = document.getElementById('target_display')
6666 } else {
6767 s.Temp -= Celsius(10 * rand.Float64())
6868 }
69 if s.Temp < 0 {
70 s.Temp = 0
71 }
6972 return nil
7073 }
7174