Skip to content

Commit

Permalink
Merge pull request #11 from razerbann/refaktor
Browse files Browse the repository at this point in the history
Dactyl Lightcycle: Fixed problem related to plates being incomplete / Issue #10 / External holder position depending on tenting angle
  • Loading branch information
ibnuda authored Apr 20, 2020
2 parents f064a3a + 5b300fb commit 4654f50
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 186 deletions.
2 changes: 2 additions & 0 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
:plugins [[lein-exec "0.3.7"]
[lein-auto "0.1.3"]
[lein-ring "0.12.5"]]
:aliases {"generate-lightcycle" ["exec" "-p" "src/dactyl_keyboard/lightcycle.clj"]
"generate-manuform" ["exec" "-p" "src/dactyl_keyboard/manuform.clj"]}
:ring {:handler dactyl-keyboard.handler/app
:port 3030
:auto-reload? true}
Expand Down
18 changes: 9 additions & 9 deletions resources/lightcycle.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ <h1>Dactyl Lightcycle Generator</h1>
<h3>Keys</h3>
</label>
<fieldset name="keys" id="keys">
<label for="ncols">Number of columns</label>
<input type="number" name="ncols" id="ncols" value=6>
<label for="ncols">Number of columns (4 - 7)</label>
<input type="number" name="ncols" id="ncols" value=6 min="4" max="7">
<label for="thumb-count">Thumb key count?</label>
<select id="thumb-count" name="thumb-count">
<option value="5">5</option>
<option value="6">6</option>
<option value="3">3</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="5" selected>5</option>
<option value="6">6</option>
</select>
<label for="last-row">Use bottom row?</label>
<select id="last-row" name="last-row">
Expand All @@ -52,7 +52,7 @@ <h3>Curvature & Tenting</h3>
<label for="alpha">Column's Curvature</label>
<select id="alpha" name="alpha">
{% for cc in column-curvature %}
<option value={{cc}}>pi/{{cc}}</option>
<option value={{cc}}>pi/{{cc}}</option>
{% endfor %}
</select>
<label for="beta">Row's Curvature</label>
Expand All @@ -63,13 +63,13 @@ <h3>Curvature & Tenting</h3>
<label for="tenting-angle">Tenting Angle</label>
<select id="tenting-angle" name="tenting-angle" value="pi/12">
{% for ta in tenting-angle %}
<option value={{ta}}>pi/{{ta}}</option>
<option value={{ta}}>pi/{{ta}}</option>
{% endfor %}
</select>
<label for="thumb-tenting-angle">Thumb Tenting Angle</label>
<select id="thumb-tenting-angle" name="thumb-tenting-angle">
{% for tta in thumb-tenting-angle %}
<option value={{tta}}>pi/{{tta}}</option>
<option value={{tta}}>pi/{{tta}}</option>
{% endfor %}
</select>
</fieldset>
Expand Down Expand Up @@ -113,7 +113,7 @@ <h3>Form of the Case</h3>
<label for="z-offset">Height Offset</label>
<select id="z-offset" name="z-offset">
{% for ho in height-offset %}
<option value={{ho}}>{{ho}}mm</option>
<option value={{ho}}>{{ho}}mm</option>
{% endfor %}
</select>
</fieldset>
Expand Down
23 changes: 13 additions & 10 deletions resources/manuform.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
document.getElementById("last-row").value = lastrow;
document.getElementById("wide-pinky").value = widepinky;
}

function setminidox() {
setkeyboard(5, 4, "true", "false", "zero", "false");
}

function setcorne() {
setkeyboard(6, 4, "true", "false", "zero", "false");
}

function setergodox() {
setkeyboard(6, 5, "false", "true", "full", "true");
}
Expand All @@ -47,7 +50,7 @@
if (use_wrist_rest === "false") {
document.querySelector("label[for='integrated-wrist-rest']").style.display = 'none'; // Hide the label
document.querySelector("select[id='integrated-wrist-rest']").style.display = 'none'; // Hide the select
document.querySelector("input[name='generate-wrist-rest']").style.display = 'none'; // Hide the input
document.querySelector("input[name='generate-wrist-rest']").style.display = 'none'; // Hide the input
} else {
document.querySelector("label[for='integrated-wrist-rest']").style.display = 'block'; // Show the label
document.querySelector("select[id='integrated-wrist-rest']").style.display = 'block'; // Show the select
Expand All @@ -58,9 +61,9 @@
function toggle_generate_wrist_rest_button() {
const integrated_wrist_rest = document.getElementById("integrated-wrist-rest").value;
if (integrated_wrist_rest === "true") {
document.querySelector("input[name='generate-wrist-rest']").style.display = 'none'; // Hide the button
document.querySelector("input[name='generate-wrist-rest']").style.display = 'none'; // Hide the button
} else {
document.querySelector("input[name='generate-wrist-rest']").style.display = 'block'; // Show the button
document.querySelector("input[name='generate-wrist-rest']").style.display = 'block'; // Show the button
}
}
</script>
Expand Down Expand Up @@ -88,10 +91,10 @@ <h2>Defaults:</h2>
<h3>Keys</h3>
</label>
<fieldset name="keys" id="keys">
<label for="ncols">Number of columns</label>
<input type="number" name="ncols" id="ncols" value=5>
<label for="nrows">Number of rows</label>
<input type="number" name="nrows" id="nrows" value=4>
<label for="ncols">Number of columns (4 - 7)</label>
<input type="number" name="ncols" id="ncols" value=5 min="4" max="7">
<label for="nrows">Number of rows (3 - 6)</label>
<input type="number" name="nrows" id="nrows" value=4 min="3" max="6">
<label for="minidox">Thumb Key Count</label>
<select id="minidox" name="minidox">
<option value="false">6</option>
Expand Down Expand Up @@ -122,7 +125,7 @@ <h3>Curvature & Tenting</h3>
<label for="alpha">Column's Curvature</label>
<select id="alpha" name="alpha">
{% for cc in column-curvature %}
<option value={{cc}}>pi/{{cc}}</option>
<option value={{cc}}>pi/{{cc}}</option>
{% endfor %}
</select>
<label for="beta">Row's Curvature</label>
Expand All @@ -140,7 +143,7 @@ <h3>Curvature & Tenting</h3>
<label for="tenting-angle">Tenting Angle</label>
<select id="tenting-angle" name="tenting-angle">
{% for ta in tenting-angle %}
<option value={{ta}}>pi/{{ta}}</option>
<option value={{ta}}>pi/{{ta}}</option>
{% endfor %}
</select>
</fieldset>
Expand Down Expand Up @@ -187,7 +190,7 @@ <h3>Form of the Case</h3>
<label for="keyboard-z-offset">Height Offset</label>
<select id="keyboard-z-offset" name="keyboard-z-offset">
{% for ho in height-offset %}
<option value={{ho}}>{{ho}}mm</option>
<option value={{ho}}>{{ho}}mm</option>
{% endfor %}
</select>
<label for="wire-post">Wire Posts?</label>
Expand Down
2 changes: 1 addition & 1 deletion src/dactyl_keyboard/common.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns dactyl-keyboard.common
(:refer-clojure :exclude [use import])
(:require [clojure.core.matrix :refer [array matrix mmul]]
(:require [clojure.core.matrix :refer [mmul]]
[scad-clj.scad :refer :all]
[scad-clj.model :refer :all]))

Expand Down
6 changes: 3 additions & 3 deletions src/dactyl_keyboard/handler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@
param-wrist-rest (parse-bool (get p "wrist-rest"))
param-integrated-wrist-rest (parse-bool (get p "integrated-wrist-rest"))
is-right? (parse-bool (get p "right-side"))

param-generate-plate (get p "generate-plate")
param-generate-wrist-rest (get p "generate-wrist-rest")

generate-plate? (some? param-generate-plate)
generate-wrist-rest? (some? param-generate-wrist-rest)

Expand Down Expand Up @@ -175,7 +175,7 @@
:configuration-thumb-offset-y (- 0 param-thumb-offset-y)
:configuration-thumb-offset-z param-thumb-offset-z
:configuration-use-external-holder? param-use-external-holder

:configuration-use-screw-inserts? param-screw-inserts}
generated-scad (if generate-plate?
(generate-plate-dl c is-right?)
Expand Down
127 changes: 53 additions & 74 deletions src/dactyl_keyboard/lightcycle.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(ns dactyl-keyboard.lightcycle
(:refer-clojure :exclude [use import])
(:require [clojure.core.matrix :refer [array matrix mmul]]
[scad-clj.scad :refer :all]
(:require [scad-clj.scad :refer :all]
[scad-clj.model :refer :all]
[dactyl-keyboard.util :refer :all]
[dactyl-keyboard.common :refer :all]))
Expand Down Expand Up @@ -474,7 +473,7 @@
(top-cover 1.59 2.41 (* cornerrow 0.85) cornerrow) ;; was 3.32
(top-cover 2.39 3.41 (* cornerrow 0.9) cornerrow)
(apply union
(for [x (range 2 lastrow)]
(for [x (range 2 (- lastrow 1))]
(union
(hull (place (- x 1/2) cornerrow (translate [0 1 1] wall-sphere-bottom-front))
(place (+ x 1/2) cornerrow (translate [0 1 1] wall-sphere-bottom-front))
Expand Down Expand Up @@ -524,12 +523,12 @@
(for [x (range-inclusive left-wall-column (- (right-wall-column c) step) step)]
(bottom-hull (place x (back-y c) wall-sphere-bottom-back)
(place (+ x step) (back-y c) wall-sphere-bottom-back))))
;; (front-top-cover left-wall-column 1.56 back-y (+ back-y 0.06))
#_(front-top-cover left-wall-column right-wall-column back-y (+ back-y 0.06))
;; (front-top-cover 1.56 2.44 back-y (+ back-y 0.06))
(front-top-cover 3.56 4.44 (back-y c) (+ (back-y c) 0.2))
(front-top-cover 4.3 (right-wall-column c) (back-y c) (+ (back-y c) 0.2))

(if (> ncols 4)
(do
(front-top-cover 3.56 4.44 (back-y c) (+ (back-y c) 0.2))
(front-top-cover 4.3 (right-wall-column c) (back-y c) (+ (back-y c) 0.2)))
())

(hull (place left-wall-column (back-y c) (translate [1 -1 1] wall-sphere-bottom-back))
(place (+ left-wall-column 1) (back-y c) (translate [0 -1 1] wall-sphere-bottom-back))
Expand Down Expand Up @@ -655,15 +654,6 @@
(defn thumb-back-wall [c]
(let [thumb-count (get c :configuration-thumb-count)
step wall-step
top-step 0.05
front-top-cover (fn [x-start x-end y-start y-end]
(apply union
(for [x (range-inclusive x-start (- x-end top-step) top-step)
y (range-inclusive y-start (- y-end top-step) top-step)]
(hull (thumb-place c x y wall-sphere-top-back)
(thumb-place c (+ x top-step) y wall-sphere-top-back)
(thumb-place c x (+ y top-step) wall-sphere-top-back)
(thumb-place c (+ x top-step) (+ y top-step) wall-sphere-top-back)))))
local-back-y (thumb-back-y c)
thumb-range (case thumb-count :five 5/2 :six 5/2 3/2)
back-thumb-position (case thumb-count :two 0 1)
Expand Down Expand Up @@ -748,15 +738,10 @@
use-lastrow? (get c :configuration-use-lastrow?)
cornerrow (fcornerrow-lightcycle use-lastrow?)
step wall-step ;;0.1
wall-sphere-top-fronttep 0.05 ;;0.05
place (partial thumb-place c)
plate-height (/ (- sa-double-length mount-height) 2)
thumb-tl (->> web-post-tl
(translate [0 plate-height 0]))
thumb-bl (->> web-post-bl
(translate [0 (- plate-height) 0]))
thumb-tr (->> web-post-tr
(translate [-0 plate-height 0]))
thumb-br (->> web-post-br
(translate [-0 (- plate-height) 0]))
thumb-range (case thumb-count :five 5/2 :six 5/2 3/2)]
Expand Down Expand Up @@ -816,26 +801,35 @@
(let [use-numrow? (get c :configuration-use-numrow?)]
[-10 (if use-numrow? 55 35) 0]))

; Offsets for the controller/trrs external holder cutout
; Offsets for the controller/trrs external holder cutout
(defn external-holder-offset [c]
(let [use-external-holder? (get c :configuration-use-external-holder?)]
(if use-external-holder? 0 -3.5)))

; Cutout for controller/trrs jack holder
(def external-holder-ref [-40 45 0])
(defn external-holder-ref [c]
(let [tenting-angle (get c :configuration-tenting-angle)]
(case tenting-angle
0.4487989505128276 [-27 45] ;; pi/7
0.39269908169872414 [-30 45] ;; pi/8
0.3490658503988659 [-30 45] ;; pi/9
0.3141592653589793 [-33 45] ;; pi/10
0.28559933214452665 [-36 45] ;; pi/11
0.2617993877991494 [-36 45]))) ;; pi/12

(def external-holder-cube (cube 28.666 80 12.6))
(defn external-holder-position [c]
(map + [(+ 18.8 (external-holder-offset c)) 18.7 1.3] [(first external-holder-ref) (second external-holder-ref) 2]))
(map + [(+ 18.8 (external-holder-offset c)) 18.7 1.3] [(first (external-holder-ref c)) (second (external-holder-ref c)) 2]))
(defn external-holder-space [c]
(translate (map + (external-holder-position c) [-1.5 -2 3]) external-holder-cube))

#_(defn screw-insert
"Places screw insert to its place.
"Places screw insert to its place.
TODO: write me."
[c column row bottom-radius top-radius height]
(let [position (key-position c column row (map + (wall-locate2 0 0) [0 (/ mount-height 2) 0]))]
(->> (screw-insert-shape bottom-radius top-radius height)
(translate [(first position) (second position) (/ height 2)]))))
[c column row bottom-radius top-radius height]
(let [position (key-position c column row (map + (wall-locate2 0 0) [0 (/ mount-height 2) 0]))]
(->> (screw-insert-shape bottom-radius top-radius height)
(translate [(first position) (second position) (/ height 2)]))))

(defn screw-placement [c bottom-radius top-radius height]
(let [lastrow (if (get c :configuration-use-lastrow?) 4 3.55)
Expand All @@ -861,19 +855,13 @@
(screw-insert c lastcol middlecol bottom-radius top-radius height))))

(defn new-case [c]
(let [use-external-holder? (get c :configuration-use-external-holder?)]
(difference
(union (front-wall c)
(right-wall c)
(back-wall c)
(left-wall c)
(thumb-back-wall c)
(thumb-left-wall c)
(thumb-front-wall c)
(if-not use-external-holder?
(usb-holder fusb-holder-position c)
()))
(if-not use-external-holder? (rj9-space frj9-start c) ()))))
(union (front-wall c)
(right-wall c)
(back-wall c)
(left-wall c)
(thumb-back-wall c)
(thumb-left-wall c)
(thumb-front-wall c)))

;;;;;;;;;;;;;;;;
;;Final Export ;;
Expand All @@ -882,41 +870,32 @@
(defn dactyl-top-right [c]
(let [use-external-holder? (get c :configuration-use-external-holder?)
use-screw-inserts? (get c :configuration-use-screw-inserts?)]
(if-not use-external-holder?
(union
(difference
(union (key-holes c)
(connectors c)
(thumb c)
(new-case c)
(if use-screw-inserts? (screw-insert-outers screw-placement c) ())
#_(if (get c :configuration-show-caps?) (caps c) ())
#_(if (get c :configuration-show-caps?) (thumbcaps c) ()))
(if use-screw-inserts? (screw-insert-holes screw-placement c) ())
(translate [0 0 -60] (cube 350 350 120))
(usb-holder-hole fusb-holder-position c))
(rj9-holder frj9-start c))
(union (key-holes c)
(connectors c)
(thumb c)
(difference (union (new-case c)
(if use-screw-inserts? (screw-insert-outers screw-placement c) ()))
(if use-screw-inserts? (screw-insert-holes screw-placement c) ())
(external-holder-space c)
(translate [0 0 -60] (cube 350 350 120)))))))
(difference
(union (key-holes c)
(connectors c)
(thumb c)
(difference (union (new-case c)
(if use-screw-inserts? (screw-insert-outers screw-placement c) ())
(if-not use-external-holder? (usb-holder fusb-holder-position c) ()))
(if-not use-external-holder?
(union (rj9-space frj9-start c) (usb-holder-hole fusb-holder-position c))
(external-holder-space c))
(if use-screw-inserts? (screw-insert-holes screw-placement c) ()))
#_(if (get c :configuration-show-caps?) (caps c) ())
#_(if (get c :configuration-show-caps?) (thumbcaps c) ())
(if-not use-external-holder? (rj9-holder frj9-start c) ()))
(translate [0 0 -60] (cube 350 350 120)))))

(defn dactyl-top-left [c]
(mirror [-1 0 0] (dactyl-top-right c)))

(defn dactyl-plate-right [c]
(cut
(translate [0 0 -0.1]
(difference (union (new-case c)
(rj9-holder frj9-start c)
(usb-holder fusb-holder-position c)
#_(screw-insert-outers screw-placement c))
#_(translate [0 0 -10]
#_(screw-insert-screw-holes screw-placement c))))))
(let [use-screw-inserts? (get c :configuration-use-screw-inserts?)]
(cut
(translate [0 0 -0.1]
(difference (union (new-case c)
(if use-screw-inserts? (screw-insert-outers screw-placement c) ()))
(if use-screw-inserts? (translate [0 0 -10] (screw-insert-screw-holes screw-placement c)) ()))))))

(defn dactyl-plate-left [c]
(mirror [-1 0 0] (dactyl-plate-right c)))
Expand Down Expand Up @@ -945,4 +924,4 @@
(write-scad (dactyl-top-right c)))

#_(spit "things/light-cycle-plate-right.scad"
(write-scad (dactyl-plate-right c)))
(write-scad (dactyl-plate-right c)))
Loading

0 comments on commit 4654f50

Please sign in to comment.