Skip to content

Commit

Permalink
Indicator (Kennlicht) added
Browse files Browse the repository at this point in the history
  • Loading branch information
iGEL committed Dec 22, 2023
1 parent d80ea2b commit ca4c403
Show file tree
Hide file tree
Showing 11 changed files with 836 additions and 165 deletions.
10 changes: 9 additions & 1 deletion src/signals/demo/aspect.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,12 @@
"Deaktiviere das Zs7"
"Stelle das Signal auf Halt und aktiviere das Zs7")
:active? zs7-active?
:type "danger"} "Zs7"))))))
:type "danger"} "Zs7")))
(when (and (:indicator? main-state)
(not= :hv-semaphore (:system state)))
($ :div
($ button {:on-click #(set-state! {:aspect :off})
:title "Betrieblich abschalten"
:active? (= :off current-aspect)
:type "light"}
"Aus"))))))
17 changes: 12 additions & 5 deletions src/signals/demo/features.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@
:type "info"
:active? zs7?} "Zs7")))))

(defui indicator-btn [{:keys [state set-state!]}]
(when-not (= :hv-semaphore (:system state))
(let [indicator? (-> state :main :indicator?)]
($ button {:on-click #(set-state! (update-in state [:main :indicator?] not))
:type "info"
:active? indicator?}
"Kennlicht"))))

(defui speed-limit-config-btns [{:keys [set-state! state]}]
(let [slow-speed-lights (-> state :main :slow-speed-lights seq)
active-40? (some #{40} slow-speed-lights)
Expand Down Expand Up @@ -108,8 +116,7 @@

(defui base [{:keys [main set-main! distant set-distant! set-both!]}]
($ :<>
($ feature-btns {:set-state! set-main! :state main})
($ :div
($ shortened-break-path-btn {:set-state! set-distant! :state distant}))
($ :div
($ speed-limit-config-btns {:set-state! set-both! :state main}))))
($ :div ($ feature-btns {:set-state! set-main! :state main}))
($ :div ($ indicator-btn {:set-state! set-main! :state main}))
($ :div ($ shortened-break-path-btn {:set-state! set-distant! :state distant}))
($ :div ($ speed-limit-config-btns {:set-state! set-both! :state main}))))
31 changes: 24 additions & 7 deletions src/signals/hl.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,47 @@

(s/def ::lights (s/keys :req-un [::top-yellow ::top-green ::top-white ::red ::bottom-white ::bottom-yellow ::replacement-red ::green-stripe ::yellow-stripe ::shortened-break-path?]))

(defn lights [{{main-aspect :aspect
(defn lights [{{main-aspect* :aspect
main-slow-speed-lights :slow-speed-lights
main-speed-limit :speed-limit
sh1? :sh1?
zs1? :zs1?} :main
{distant-aspect :aspect
zs1? :zs1?
main-indicator? :indicator?} :main
{distant-aspect* :aspect
distant-slow-speed-lights :slow-speed-lights
distant-speed-limit :speed-limit
distant-addition :distant-addition} :distant
distant-addition :distant-addition
distant-indicator? :indicator?} :distant
signal-type :type
:as signal}]
{:pre [(p/arg! ::spec/signal signal)]
:post [(p/ret! ::lights %)]}
(let [distant? (= :distant signal-type)
(let [main-aspect (if (and (= :off main-aspect*)
(not main-indicator?))
:stop
main-aspect*)
distant-aspect (if (and (= :off distant-aspect*)
(not distant-indicator?))
:stop
distant-aspect*)
distant? (= :distant signal-type)
main? (= :main signal-type)
distant-40-or-60-limit? (and (some #{40 60} distant-slow-speed-lights)
(#{40 60} distant-speed-limit))]
{:top-yellow (cond
main? nil
(= :off main-aspect) :off
(= :off distant-aspect) :off
(stop-aspect? main-aspect) :off
(stop-aspect? distant-aspect) :on
distant-40-or-60-limit? :blinking
:else :off)
:top-green (cond
(or (stop-aspect? main-aspect)
(stop-aspect? distant-aspect)
distant-40-or-60-limit?) :off
distant-40-or-60-limit?
(= :off main-aspect)
(= :off distant-aspect)) :off
(and (some #{100} distant-slow-speed-lights)
(= 100 distant-speed-limit)) :blinking
:else :on)
Expand All @@ -57,10 +71,13 @@
:else :off)
:red (cond
distant? nil
(= :off main-aspect) :off
(stop-aspect? main-aspect) :on
:else :off)
:bottom-white (cond
(not (or sh1? zs1?)) nil
(not (or sh1? zs1? main-indicator? distant-indicator?)) nil
(= :off main-aspect) :on
(= :off distant-aspect) :on
(and sh1? (= :stop+sh1 main-aspect)) :on
(and zs1? (= :stop+zs1 main-aspect)) :blinking
:else :off)
Expand Down
129 changes: 77 additions & 52 deletions src/signals/hv_light.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -27,70 +27,85 @@

(s/def ::lights (s/keys :req-un [::distant ::main]))

(defn lights [{{main-aspect :aspect
(defn lights [{{main-aspect* :aspect
main-slow-speed-lights :slow-speed-lights
main-speed-limit :speed-limit
main-indicator? :indicator?
sh1? :sh1?
zs1? :zs1?
zs7? :zs7?} :main
{distant-aspect :aspect
{distant-aspect* :aspect
distant-slow-speed-lights :slow-speed-lights
distant-speed-limit :speed-limit
distant-addition :distant-addition} :distant
distant-addition :distant-addition
distant-indicator? :indicator?} :distant
signal-type :type
:as signal}]
{:pre [(p/arg! ::spec/signal signal)]
:post [(p/ret! ::lights %)]}
{:main (when-not (= :distant signal-type)
{:green (if (stop-aspect? main-aspect) :off :on)
:red (if (stop-aspect? main-aspect) :on :off)
:yellow (let [has-light? (some #{40} main-slow-speed-lights)]
(cond
(not has-light?) nil
(and (not (stop-aspect? main-aspect))
main-speed-limit (>= 60 main-speed-limit)) :on
:else :off))
:secondary-red (cond
(not sh1?) nil
(= :stop+sh1 main-aspect) :off
(stop-aspect? main-aspect) :on
:else :off)
:sh1 (cond
(not sh1?) nil
(= :stop+sh1 main-aspect) :on
:else :off)
:zs1 (cond
(not zs1?) nil
(= :stop+zs1 main-aspect) :on
:else :off)
:zs7 (cond
(not zs7?) nil
(= :stop+zs7 main-aspect) :on
:else :off)})
:distant (when-not (= :main signal-type)
(let [slow-speed? (and (some #{40} distant-slow-speed-lights)
distant-speed-limit
(>= 60 distant-speed-limit))]
{:top-green (cond
(stop-aspect? main-aspect) :off
(stop-aspect? distant-aspect) :off
:else :on)
:top-yellow (cond
(stop-aspect? main-aspect) :off
(stop-aspect? distant-aspect) :on
(let [main-aspect (if (and (not main-indicator?)
(= :off main-aspect*)) :stop main-aspect*)
distant-aspect (if (and (not distant-indicator?)
(= :off distant-aspect*)) :stop distant-aspect*)]
{:main (when-not (= :distant signal-type)
{:green (if (or (stop-aspect? main-aspect)
(= :off main-aspect)) :off :on)
:red (if (stop-aspect? main-aspect) :on :off)
:yellow (let [has-light? (some #{40} main-slow-speed-lights)]
(cond
(not has-light?) nil
(and (not (stop-aspect? main-aspect))
(not (= :off main-aspect))
main-speed-limit (>= 60 main-speed-limit)) :on
:else :off))
:secondary-red (cond
(not sh1?) nil
(= :stop+sh1 main-aspect) :off
(stop-aspect? main-aspect) :on
:else :off)
:white (when distant-addition
(if (stop-aspect? main-aspect) :off :on))
:bottom-green (cond
:indicator (cond
(not main-indicator?) nil
(= :off main-aspect) :on
:else :off)
:sh1 (cond
(not sh1?) nil
(= :stop+sh1 main-aspect) :on
:else :off)
:zs1 (cond
(not zs1?) nil
(= :stop+zs1 main-aspect) :on
:else :off)
:zs7 (cond
(not zs7?) nil
(= :stop+zs7 main-aspect) :on
:else :off)})
:distant (when-not (= :main signal-type)
(let [slow-speed? (and (some #{40} distant-slow-speed-lights)
distant-speed-limit
(>= 60 distant-speed-limit))]
{:top-green (cond
(stop-aspect? main-aspect) :off
(stop-aspect? distant-aspect) :off
(= :off distant-aspect) :off
:else :on)
:top-yellow (cond
(stop-aspect? main-aspect) :off
(stop-aspect? distant-aspect) :off
slow-speed? :off
:else :on)
:bottom-yellow (cond
(stop-aspect? main-aspect) :off
(stop-aspect? distant-aspect) :on
slow-speed? :on
:else :off)}))})
(stop-aspect? distant-aspect) :on
:else :off)
:white (cond
distant-addition (if (stop-aspect? main-aspect) :off :on)
distant-indicator? (if (= :off distant-aspect) :on :off))
:bottom-green (cond
(stop-aspect? main-aspect) :off
(stop-aspect? distant-aspect) :off
(= :off distant-aspect) :off
slow-speed? :off
:else :on)
:bottom-yellow (cond
(stop-aspect? main-aspect) :off
(stop-aspect? distant-aspect) :on
slow-speed? :on
:else :off)}))}))

(defui zs1+zs7-view [{:keys [zs1 zs7]}]
(when (or zs1 zs7)
Expand Down Expand Up @@ -129,7 +144,7 @@

(defui view [{:keys [signal]}]
{:pre [(p/arg! ::spec/signal signal)]}
(let [{{:keys [green red yellow secondary-red sh1] :as main} :main
(let [{{:keys [green red yellow secondary-red sh1 indicator] :as main} :main
{:keys [top-green top-yellow white bottom-green bottom-yellow]} :distant} (lights signal)]
($ :<>
(when main
Expand All @@ -156,6 +171,11 @@
:size :big
:x 65
:y 44})
($ lamp/lamp {:color :white
:state indicator
:size :small
:x 38
:y 68})
($ lamp/lamp {:color :white
:state sh1
:size :small
Expand Down Expand Up @@ -185,6 +205,11 @@
:size :big
:x 43
:y 126})
($ lamp/lamp {:color :white
:state indicator
:size :small
:x 51.5
:y 68})
($ lamp/lamp {:color :green
:state green
:size :big
Expand Down
88 changes: 45 additions & 43 deletions src/signals/hv_semaphore.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -23,61 +23,63 @@

(s/def ::arms (s/keys :req-un [::distant ::main]))

(defn arms [{{main-aspect :aspect
(defn arms [{{main-aspect* :aspect
main-slow-speed-lights :slow-speed-lights
main-speed-limit :speed-limit
sh1? :sh1?
zs1? :zs1?
zs7? :zs7?} :main
{distant-aspect :aspect
{distant-aspect* :aspect
distant-slow-speed-lights :slow-speed-lights
distant-speed-limit :speed-limit
distant-addition :distant-addition} :distant
signal-type :type
:as signal}]
{:pre [(p/arg! ::spec/signal signal)]
:post [(p/ret! ::arms %)]}
{:main (when-not (= :distant signal-type)
{:top-arm (if (stop-aspect? main-aspect) :horizontal :inclined)
:lower-arm (cond
(not (some #{40} main-slow-speed-lights)) nil
(and (not (stop-aspect? main-aspect))
main-speed-limit
(>= 60 main-speed-limit)) :inclined
:else :vertical)
:sh1 (cond
(not sh1?) nil
(#{:proceed :stop+sh1} main-aspect) :inclined
:else :horizontal)
:zs1 (cond
(not zs1?) nil
(= :stop+zs1 main-aspect) :on
:else :off)
:zs7 (cond
(not zs7?) nil
(= :stop+zs7 main-aspect) :on
:else :off)})
:distant (when (and (not= :main signal-type)
(not= :repeater distant-addition))
(let [has-slow-speed? (some #{40} distant-slow-speed-lights)
slow-speed? (and has-slow-speed?
(not (stop-aspect? main-aspect))
(not (stop-aspect? distant-aspect))
distant-speed-limit
(>= 60 distant-speed-limit))]
{:disk (if (or (stop-aspect? main-aspect)
(stop-aspect? distant-aspect)
slow-speed?) :vertical
:horizontal)
:arm (cond
(not has-slow-speed?) nil
slow-speed? :inclined
:else :vertical)
:right-lights (if (and (not (stop-aspect? main-aspect))
(not (stop-aspect? distant-aspect)))
:inclined
:vertical)
:shortened-break-path? (= :shortened-break-path distant-addition)}))})
(let [main-aspect (if (= :off main-aspect*) :stop main-aspect*)
distant-aspect (if (= :off distant-aspect*) :stop distant-aspect*)]
{:main (when-not (= :distant signal-type)
{:top-arm (if (stop-aspect? main-aspect) :horizontal :inclined)
:lower-arm (cond
(not (some #{40} main-slow-speed-lights)) nil
(and (not (stop-aspect? main-aspect))
main-speed-limit
(>= 60 main-speed-limit)) :inclined
:else :vertical)
:sh1 (cond
(not sh1?) nil
(#{:proceed :stop+sh1} main-aspect) :inclined
:else :horizontal)
:zs1 (cond
(not zs1?) nil
(= :stop+zs1 main-aspect) :on
:else :off)
:zs7 (cond
(not zs7?) nil
(= :stop+zs7 main-aspect) :on
:else :off)})
:distant (when (and (not= :main signal-type)
(not= :repeater distant-addition))
(let [has-slow-speed? (some #{40} distant-slow-speed-lights)
slow-speed? (and has-slow-speed?
(not (stop-aspect? main-aspect))
(not (stop-aspect? distant-aspect))
distant-speed-limit
(>= 60 distant-speed-limit))]
{:disk (if (or (stop-aspect? main-aspect)
(stop-aspect? distant-aspect)
slow-speed?) :vertical
:horizontal)
:arm (cond
(not has-slow-speed?) nil
slow-speed? :inclined
:else :vertical)
:right-lights (if (and (not (stop-aspect? main-aspect))
(not (stop-aspect? distant-aspect)))
:inclined
:vertical)
:shortened-break-path? (= :shortened-break-path distant-addition)}))}))

(defui main-lights [{:keys [position top-color bottom-color]}]
(let [colors {:red "#e64e54"
Expand Down
Loading

0 comments on commit ca4c403

Please sign in to comment.