summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Barksdale <amatus@amat.us>2017-04-23 12:50:41 -0500
committerDavid Barksdale <amatus@amat.us>2017-04-23 12:50:41 -0500
commitdf496b65b637fefd0a01ff90f9ff80cbdc7e9b7c (patch)
tree60ad6ca2b3a272aa2f1d77e4eee6e007b037a51b
parent2c83ecd5c8bc959150f113a62be66b63b605e851 (diff)
Portmaster control and temp display
-rw-r--r--src/app/api.clj12
-rw-r--r--src/app/portmaster.clj4
-rw-r--r--src/app/rpc.cljs9
-rw-r--r--src/index.cljs.hl34
4 files changed, 54 insertions, 5 deletions
diff --git a/src/app/api.clj b/src/app/api.clj
index f3a4324..277536c 100644
--- a/src/app/api.clj
+++ b/src/app/api.clj
@@ -1,4 +1,14 @@
(ns app.api
- (:require [castra.core :refer [defrpc]]))
+ (:require [app.portmaster :as pm]
+ [castra.core :refer [defrpc]]))
(defrpc get-state [])
+
+(defrpc turn-on [port]
+ (pm/turn-on port))
+
+(defrpc turn-off [port]
+ (pm/turn-off port))
+
+(defrpc set-name [port name]
+ (pm/set-name port name))
diff --git a/src/app/portmaster.clj b/src/app/portmaster.clj
index 1d34c88..3c25176 100644
--- a/src/app/portmaster.clj
+++ b/src/app/portmaster.clj
@@ -83,6 +83,10 @@
[port]
(do-command (str "off " port)))
+(defn set-name
+ [port name]
+ (do-command (str "name " port " " name)))
+
(defn init
[port-name username password]
(let [socat (.. (ProcessBuilder.
diff --git a/src/app/rpc.cljs b/src/app/rpc.cljs
index 1651f72..4d644fd 100644
--- a/src/app/rpc.cljs
+++ b/src/app/rpc.cljs
@@ -12,6 +12,15 @@
(def get-state
(mkremote 'app.api/get-state state error loading))
+(def turn-on
+ (mkremote 'app.api/turn-on state error loading))
+
+(def turn-off
+ (mkremote 'app.api/turn-off state error loading))
+
+(def set-name
+ (mkremote 'app.api/set-name state error loading))
+
(defn init []
(get-state)
(js/setInterval get-state 1000))
diff --git a/src/index.cljs.hl b/src/index.cljs.hl
index cc70325..be6ef8d 100644
--- a/src/index.cljs.hl
+++ b/src/index.cljs.hl
@@ -2,6 +2,7 @@
(:require [app.rpc :as rpc]
[cljs.pprint :refer [pprint]]
[cljsjs.semantic-ui :as ui]
+ [clojure.string :refer [trim]]
[Blockly]
[Blockly.Blocks.loops]
[Blockly.Blocks.lists]
@@ -43,9 +44,34 @@
:href "cljsjs/semantic-ui/common/semantic.min.css")
(title "Tankputer"))
(body
- (h1 "Tankputer")
- (textarea :text (cell= (with-out-str (pprint state))))
- (blockly-workspace :css {:height "480px" :width "600px"}
- :options {:media "media/" :toolbox toolbox})))
+ (h1 "Status")
+ (let [current (cell= (reduce + (map #(float (second %))
+ (:current (:pm state)))))]
+ (h2 (text "Power (~{current} A)")))
+ (table
+ (loop-tpl
+ :bindings [[port name state] (cell= (:status (:pm state)))]
+ (let [toggle (cell false)
+ name (cell= (trim name))
+ name-input (input :toggle toggle :value name)]
+ (tr
+ (td port)
+ (td :click #(reset! toggle true)
+ (span :toggle (cell= (not toggle))
+ :text (cell= (if (empty? name) "(unnamed)" name)))
+ (form :submit #(do (rpc/set-name @port (.-value name-input))
+ (reset! toggle false))
+ name-input
+ (input :toggle toggle :type "submit")))
+ (td state)
+ (td (button :click #(rpc/turn-on @port) "On")
+ (button :click #(rpc/turn-off @port) "Off"))))))
+ (h2 "Temperature")
+ (ul
+ (loop-tpl :bindings [[id temp] (cell= (:state (:temps state)))]
+ (let [millicelsius (cell= (int temp))
+ fahrenheit (cell= (+ 32 (* 0.0018 millicelsius)))]
+ (li (text "Sensor ~{id}: ~{fahrenheit} \u00b0F")))))
+ (textarea :text (cell= (with-out-str (pprint state))))))
;; vim: set expandtab ts=2 sw=2 filetype=clojure :