Skip to content

Commit

Permalink
[2] use slim to buil the application
Browse files Browse the repository at this point in the history
  • Loading branch information
dpom committed Feb 15, 2025
1 parent e3a157a commit 2298285
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 55 deletions.
3 changes: 3 additions & 0 deletions .envrc.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export MIRROR_RM2_HOST="remarkable"
export MIRROR_RM2_SCALE_VALUE=20.0
export MIRROR_RM2_LOG_LEVEL="debug"
3 changes: 3 additions & 0 deletions .envrc.local.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export MIRROR_RM2_HOST="remarkable"
export MIRROR_RM2_SCALE_VALUE=20.0
export MIRROR_RM2_LOG_LEVEL="debug"
6 changes: 4 additions & 2 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ See ~doc~ folder:
**** One-time setup

On Linux, MacOS, and Windows (WSL2):
#+begin_src shell
1. Create an =.envrc.local= file (see =.envrc.local.example=)
2. Activate =direnv=:
#+begin_src shell
direnv allow
#+end_src
#+end_src

To make sure that no unformatted commits with lint errors end up in the
main branch run initially:
Expand Down
4 changes: 2 additions & 2 deletions bb.edn
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
(when-not (empty? tst-ns) (str " --focus " tst-ns)))))}
libupdate {:doc "Check for newer libraries"
:task (clojure "-X:outdated")}
deploy {:doc "Build and deploy jar"
:task (clojure "-T:build deploy")}
build {:doc "Build jar"
:task (clojure "-T:slim build")}
}}
5 changes: 3 additions & 2 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
:verbose false
:upgrade false
:force false}}
:neil {:project {:name mirror-rmk2
:version "0.1"}}
:slim {:deps {io.github.abogoyavlensky/slim {:mvn/version "LATEST"}}
:ns-default slim.app
:exec-args {:main-ns mirror.main}}
}
}
13 changes: 6 additions & 7 deletions resources/config.edn
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@
:renderer #ig/ref :mirror/renderer
:logger #ig/ref :duct/logger}

;; :mirror.tracer/event {:server "remarkable"
;; :logger #ig/ref :duct/logger}
:mirror.tracer/event {:server #or [#env MIRROR_RM2_HOST "remarkable"]
:logger #ig/ref :duct/logger}

:mirror.tracer/file {:logger #ig/ref :duct/logger}
;; :mirror.tracer/file {:logger #ig/ref :duct/logger}

:mirror.renderer/screen {:logger #ig/ref :duct/logger}
:mirror.renderer/screen {:scale-value #double #or [#env MIRROR_RM2_SCALE_VALUE 20.0]
:logger #ig/ref :duct/logger}

;; :mirror.renderer/file {:filename "test/resources/test.ev"
;; :logger #ig/ref :duct/logger}

[:duct/logger :duct.logger/timbre] {:level #profile {:prod :info
:dev :debug
:test :info}
[:duct/logger :duct.logger/timbre] {:level #keyword #or [#env MIRROR_RM2_LOG_LEVEL "info"]
:appenders {:println #ig/ref :duct.logger.timbre/println}}

:duct.logger.timbre/println {}}
84 changes: 42 additions & 42 deletions src/mirror/renderer/screen.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

(derive ig-key :mirror/renderer)

(def scale-value 20.0)
(def background 255)
(def color 0)
(def line-weight 3)
Expand All @@ -28,17 +27,12 @@


(defn scale
[x max-x]
[scale-value x max-x]
(if x
(Math/round (float (/ (abs (- max-x x)) scale-value)))
x))


(def screen
{:width (scale sch/max-y 0)
:height (scale sch/max-x 0)})


;; state

(defn init-state!
Expand All @@ -50,30 +44,32 @@


(defn process-event!
[{:keys [lines current-point current-line in-line?] :as state}
{:keys [pen x y rubber]}]
(if @in-line?
(if (or (= pen 0) (= rubber 0))
(do
(swap! lines conj @current-line)
(reset! current-line {:tool nil :points []})
(reset! in-line? false))
(do
(reset! current-point [(or (scale y 0) (first @current-point))
(or (scale x sch/max-x) (second @current-point))])
(swap! current-line assoc :points (dedupe (conj (:points @current-line) @current-point)))
(tap> @current-line)))
(cond
(= pen 1) (do
(reset! in-line? true)
(reset! current-point [(scale y 0) (scale x sch/max-x)])
(reset! current-line {:tool :pen :points [@current-point]}))
(= rubber 1) (do
(reset! in-line? true)
(reset! current-point [(scale y 0) (scale x sch/max-x)])
(reset! current-line {:tool :rubber :points [@current-point]}))
:else nil))
state)
[{:keys [scale-value lines current-point current-line in-line? logger] :as state}
{:keys [pen x y rubber] :as event}]
(log logger :debug ::event event)
(let [scf (partial scale scale-value)]
(if @in-line?
(if (or (= pen 0) (= rubber 0))
(do
(swap! lines conj @current-line)
(reset! current-line {:tool nil :points []})
(reset! in-line? false))
(do
(reset! current-point [(or (scf y 0) (first @current-point))
(or (scf x sch/max-x) (second @current-point))])
(swap! current-line assoc :points (dedupe (conj (:points @current-line) @current-point)))
(tap> @current-line)))
(cond
(= pen 1) (do
(reset! in-line? true)
(reset! current-point [(scf y 0) (scf x sch/max-x)])
(reset! current-line {:tool :pen :points [@current-point]}))
(= rubber 1) (do
(reset! in-line? true)
(reset! current-point [(scf y 0) (scf x sch/max-x)])
(reset! current-line {:tool :rubber :points [@current-point]}))
:else nil))
state))


;; UI
Expand All @@ -96,8 +92,8 @@
[state]
(let [raw-key (q/raw-key)
key-code (q/key-code)]
(tap> {:raw-key raw-key
:key-code key-code})
(log (:logger state) :debug ::key-pressed {:raw-key raw-key
:key-code key-code})
(case raw-key
\c (clean state)
nil)))
Expand All @@ -120,27 +116,31 @@

(defn create-sketch
[state]
(q/sketch
:title "mirror"
:size [(:width screen) (:height screen)]
:setup #'setup
:draw #(draw state)
:key-pressed #(ui-key-press state)
:middleware [qm/pause-on-error]))
(let [scf (partial scale (:scale-value state))]
(q/sketch
:title "mirror"
:size [(scf sch/max-y 0) (scf sch/max-x 0)]
:setup #'setup
:draw #(draw state)
:key-pressed #(ui-key-press state)
:middleware [qm/pause-on-error])))


;; integrant methods


(defmethod ig/init-key ig-key [_ config]
(let [{:keys [logger]} config
(let [{:keys [logger scale-value]} config
stream (stm/stream)
state {:lines (atom [])
state {:scale-value scale-value
:logger logger
:lines (atom [])
:current-point (atom [])
:current-line (atom {:tool nil :points []})
:in-line? (atom false)}]
(stm/consume #(process-event! state %) stream)
(log logger :info ::init)
(log logger :debug ::state state)
{:stream stream
:state state
:logger logger
Expand Down

0 comments on commit 2298285

Please sign in to comment.