Added display print API
This commit is contained in:
parent
55d5eb0c6e
commit
daa199b6bb
3 changed files with 3785 additions and 3778 deletions
|
@ -236,7 +236,7 @@ static void test2() {
|
||||||
int main() {
|
int main() {
|
||||||
init();
|
init();
|
||||||
while (1) {
|
while (1) {
|
||||||
|
test();
|
||||||
loop();
|
loop();
|
||||||
//test();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -11,6 +11,8 @@ import (
|
||||||
const (
|
const (
|
||||||
// highest slot number (range: 0..maxSlot)
|
// highest slot number (range: 0..maxSlot)
|
||||||
maxSlot = 4
|
maxSlot = 4
|
||||||
|
// highest display line number (range: 0..maxLine)
|
||||||
|
maxLine = 1
|
||||||
)
|
)
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
|
@ -106,6 +108,33 @@ func (s *Server) registerHandlers() {
|
||||||
http.Error(rw, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
http.Error(rw, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
s.HandleFunc("/display/", func(rw http.ResponseWriter, r *http.Request) {
|
||||||
|
if matched, _ := path.Match("/display/[0-9]*", r.URL.Path); matched {
|
||||||
|
line, err := strconv.ParseUint(path.Base(r.URL.Path), 10, 32)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error decoding line number: %v", err)
|
||||||
|
http.Error(rw, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
||||||
|
} else if line < 0 || line > maxLine {
|
||||||
|
log.Printf("Invalid line number: %d", line)
|
||||||
|
http.Error(rw, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
||||||
|
} else {
|
||||||
|
query := r.URL.Query()
|
||||||
|
if _, ok := query["text"]; ok {
|
||||||
|
text := query.Get("text")
|
||||||
|
s.can.DisplayPrint(int(line), text)
|
||||||
|
rw.Header().Set("Content-Type", "text/plain")
|
||||||
|
rw.WriteHeader(http.StatusOK)
|
||||||
|
fmt.Fprintf(rw, "Printed on line %d: '%s'", int(line), text)
|
||||||
|
} else {
|
||||||
|
log.Printf("Invalid query, missing text")
|
||||||
|
http.Error(rw, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.Printf("Mismatched path: %s", r.URL.Path)
|
||||||
|
http.Error(rw, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) Start() error {
|
func (s *Server) Start() error {
|
||||||
|
|
Loading…
Reference in a new issue