-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
620 additions
and
325 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,5 @@ target | |
|
||
*.sublime-* | ||
*.swp | ||
|
||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
language: clojure | ||
lein: lein2 | ||
script: lein2 test | ||
script: lein2 cleantest | ||
jdk: | ||
- openjdk7 | ||
- oraclejdk7 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,22 @@ | ||
(defproject clj-gpio "0.1.0" | ||
:description "A lightweight Clojure library for Raspberry PI GPIO" | ||
:url "https://github.com/peterschwarz/clj-gpio" | ||
:license {:name "Eclipse Public License" | ||
:url "http://www.eclipse.org/legal/epl-v10.html"} | ||
:min-lein-version "2.0.0" | ||
:source-paths ["src/main/clojure"] | ||
:test-paths ["src/test/clojure"] | ||
:java-source-paths ["src/main/java"] | ||
:javac-options ["-target" "1.6" "-source" "1.6"] | ||
(defproject clj-gpio "0.2.0" | ||
:description "A lightweight Clojure library for Raspberry PI GPIO" | ||
:url "http://peterschwarz.github.io/clj-gpio" | ||
:license {:name "Eclipse Public License" | ||
:url "http://www.eclipse.org/legal/epl-v10.html"} | ||
:min-lein-version "2.0.0" | ||
:source-paths ["src/main/clojure"] | ||
:test-paths ["src/test/clojure"] | ||
:java-source-paths ["src/main/java"] | ||
:javac-options ["-target" "1.6" "-source" "1.6"] | ||
|
||
:dependencies [[org.clojure/clojure "1.6.0"] | ||
[org.clojure/core.async "0.1.346.0-17112a-alpha"] | ||
[net.java.dev.jna/jna "4.1.0"]]) | ||
:dependencies [[org.clojure/clojure "1.7.0"] | ||
[org.clojure/clojurescript "1.7.170"] | ||
[org.clojure/core.async "0.2.374"] | ||
[net.java.dev.jna/jna "4.2.1"]] | ||
|
||
:aliases {"cljs:test" ["trampoline" "run" "-m" "clojure.main" "./scripts/test.clj"] | ||
"cljs:repl" ["trampoline" "run" "-m" "clojure.main" "./scripts/repl.clj"] | ||
"cljs:dev" ["trampoline" "run" "-m" "clojure.main" "./scripts/build.clj"] | ||
"cljs:dev:watch" ["trampoline" "run" "-m" "clojure.main" "./scripts/watch.clj"] | ||
"cleantest" ["do" ["clean"] ["test"] ["cljs:test"]]}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
(require 'cljs.build.api) | ||
|
||
(cljs.build.api/build | ||
(cljs.build.api/inputs "src/main/clojure" "src/dev/clojure") | ||
{:main 'gpio.dev | ||
:output-to "target/out/dev.js" | ||
:output-dir "target/out" | ||
:target :nodejs }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
(require 'cljs.repl) | ||
(require 'cljs.build.api) | ||
(require 'cljs.repl.node) | ||
|
||
(cljs.build.api/build "src/main/clojure" | ||
{:output-to "target/out/main.js" | ||
:output-dir "target/out" | ||
:verbose true}) | ||
|
||
(cljs.repl/repl (cljs.repl.node/repl-env) | ||
:watch "src/main/clojure" | ||
:output-dir "target/out") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
(require 'cljs.build.api) | ||
|
||
(def test-inputs (cljs.build.api/inputs "src/main/clojure" "src/test/clojure")) | ||
|
||
(def test-opts | ||
{:main 'gpio.test-runner | ||
:output-to "target/out/test.js" | ||
:output-dir "target/out" | ||
:target :nodejs }) | ||
|
||
(require 'clojure.java.shell) | ||
|
||
(defn run-tests [] | ||
(let [result (clojure.java.shell/sh "node" (:output-to test-opts))] | ||
(println (:out result)) | ||
(.println *err* (:err result)))) | ||
|
||
(cljs.build.api/build test-inputs test-opts) | ||
|
||
(run-tests) | ||
|
||
(System/exit 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
(require 'cljs.build.api) | ||
|
||
(cljs.build.api/watch | ||
(cljs.build.api/inputs "src/main/clojure" "src/dev/clojure") | ||
{:main 'gpio.dev | ||
:output-to "target/out/dev.js" | ||
:output-dir "target/out" | ||
:target :nodejs }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
(ns gpio.dev | ||
(:require [cljs.nodejs :as nodejs] | ||
[gpio.core :as gpio] | ||
[cljs.core.async :as a :refer [<!]]) | ||
(:require-macros [cljs.core.async.macros :refer [go]])) | ||
|
||
|
||
(nodejs/enable-util-print!) | ||
|
||
|
||
(defn- configure-ports [led btn] | ||
(println "Configuring ports") | ||
(gpio/set-direction! led :out) | ||
|
||
(gpio/set-direction! btn :in) | ||
(gpio/set-active-low! btn true) | ||
(gpio/set-edge! btn :both)) | ||
|
||
(defn- forward-value [ch led] | ||
(go | ||
(println "Looping on btn changes...") | ||
(loop [] | ||
(when-let [value (<! ch)] | ||
(gpio/write-value! led value) | ||
(recur))))) | ||
|
||
(defn- on-sigint [led btn] | ||
(println "\nCleaning up ports") | ||
(gpio/close! led) | ||
(gpio/close! btn)) | ||
|
||
(defn setup-led-and-button [led-pin button-pin] | ||
(let [led (gpio/open-port led-pin) | ||
btn (gpio/open-channel-port button-pin) | ||
ch (gpio/create-edge-channel btn)] | ||
|
||
(.on js/process "SIGINT" #(on-sigint led btn)) | ||
|
||
(println "Waiting to settle") | ||
(js/setTimeout (fn [] | ||
(configure-ports led btn) | ||
(forward-value ch led)) | ||
100))) | ||
|
||
(defn -main [& args] | ||
(let [args (into [] args) | ||
led (get args 0 18) | ||
button (get args 1 19)] | ||
(println "Running against an LED on pin" led "and a button on pin" button) | ||
(setup-led-and-button led button))) | ||
|
||
(set! *main-cli-fn* -main) |
Oops, something went wrong.