Compare commits
3 commits
b84254d972
...
9e658bf3a1
Author | SHA1 | Date | |
---|---|---|---|
9e658bf3a1 | |||
248139ae1a | |||
616266e50e |
3 changed files with 196 additions and 6 deletions
33
main.py
33
main.py
|
@ -32,8 +32,8 @@ state = StateTree(
|
|||
)
|
||||
|
||||
rotary = RotaryIRQ(
|
||||
D4,
|
||||
D5,
|
||||
D2,
|
||||
D1,
|
||||
0,
|
||||
max_val=128,
|
||||
range_mode=RotaryIRQ.RANGE_UNBOUNDED,
|
||||
|
@ -41,9 +41,14 @@ rotary = RotaryIRQ(
|
|||
incr=5,
|
||||
)
|
||||
|
||||
rotary_button = Button(Pin(D1, Pin.IN, Pin.PULL_UP), inverted=True)
|
||||
rotary_button = Button(Pin(D3, Pin.IN, Pin.PULL_UP), inverted=True)
|
||||
rotary_value = rotary.value()
|
||||
|
||||
buttons = [
|
||||
Button(Pin(D5, Pin.IN, Pin.PULL_UP), inverted=True),
|
||||
Button(Pin(D6, Pin.IN, Pin.PULL_UP), inverted=True),
|
||||
Button(Pin(D7, Pin.IN, Pin.PULL_UP), inverted=True),
|
||||
]
|
||||
|
||||
with open("settings.json", "r") as f:
|
||||
settings = json.load(f)
|
||||
|
@ -97,6 +102,13 @@ class HomeAssistant:
|
|||
json={"entity_id": entity_id, "brightness_step": value},
|
||||
)
|
||||
|
||||
def activate_scene(self, entity_id: str) -> None:
|
||||
response = requests.post(
|
||||
f"{self._url}/api/services/scene/turn_on",
|
||||
headers={"Authorization": f"Bearer {self._api_token}"},
|
||||
json={"entity_id": entity_id},
|
||||
)
|
||||
|
||||
|
||||
hass = HomeAssistant(
|
||||
url=settings["home-assistant"]["url"],
|
||||
|
@ -109,6 +121,7 @@ def loop():
|
|||
global hass
|
||||
global mqtt, last_mqtt_attempt
|
||||
global rotary, rotary_button, rotary_value
|
||||
global buttons
|
||||
|
||||
rotary_button.update()
|
||||
if rotary_button.was_clicked():
|
||||
|
@ -123,6 +136,20 @@ def loop():
|
|||
hass.adjust_light("light.key_lights", change)
|
||||
|
||||
rotary_value = new_value
|
||||
|
||||
for i, button in enumerate(buttons):
|
||||
button.update()
|
||||
if button.was_clicked():
|
||||
print(f"Pressed button {i}")
|
||||
try:
|
||||
scene = settings["scenes"][i]
|
||||
print(f"Activating scene {scene}")
|
||||
hass.activate_scene(scene)
|
||||
except KeyError:
|
||||
print("No scenes defined")
|
||||
except IndexError:
|
||||
print(f"No scene defined for button {i}")
|
||||
|
||||
if not sta_if.active():
|
||||
print("Connecting to WiFi")
|
||||
sta_if.active(True)
|
||||
|
|
|
@ -1,11 +1,17 @@
|
|||
include <BOSL/constants.scad>
|
||||
use <BOSL/math.scad>
|
||||
use <BOSL/shapes.scad>
|
||||
use <BOSL/transforms.scad>
|
||||
include <wemos_d1_mini.scad>
|
||||
|
||||
$fn = $preview ? 30 : 50;
|
||||
|
||||
case_thickness = 3;
|
||||
wire_clearance = 10;
|
||||
plate_margin = 5;
|
||||
plate_thickness = 3;
|
||||
plate_depth = 3;
|
||||
plate_clearance = 0.3;
|
||||
|
||||
// Number of key switches
|
||||
keys = 3;
|
||||
|
@ -20,6 +26,7 @@ keyswitch_cutout_width = 14;
|
|||
dial_diameter = 20;
|
||||
dial_base_width = 12.85;
|
||||
dial_base_height = 16.75;
|
||||
dial_base_protrusion = 1.5;
|
||||
dial_pin_width = 6;
|
||||
dial_pin_length = 3;
|
||||
// Space between the dial and the keypad
|
||||
|
@ -27,14 +34,14 @@ dial_distance = 5;
|
|||
|
||||
keys_width = (key_width * keys) + (key_distance * (keys - 1));
|
||||
keys_height = key_width;
|
||||
plate_width = (plate_margin * 2) + dial_diameter + dial_distance + keys_width;
|
||||
plate_height = (plate_margin * 2) + max(dial_diameter, key_width);
|
||||
|
||||
module support_plate() {
|
||||
difference() {
|
||||
keyswitch_cutout_offset = (key_width - keyswitch_cutout_width) / 2;
|
||||
dial_cutout_offset_x = (dial_diameter - dial_base_width) / 2;
|
||||
dial_cutout_offset_y = (dial_diameter - dial_base_height) / 2;
|
||||
plate_width = (plate_margin * 2) + dial_diameter + dial_distance + keys_width;
|
||||
plate_height = (plate_margin * 2) + max(dial_diameter, key_width);
|
||||
cube([plate_width, plate_height, plate_thickness]);
|
||||
translate([plate_margin, plate_margin, -1]) {
|
||||
// Dial cutouts
|
||||
|
@ -61,4 +68,110 @@ module support_plate() {
|
|||
}
|
||||
}
|
||||
|
||||
support_plate();
|
||||
case = [(plate_margin * 2) + dial_diameter + dial_distance + keys_width + (plate_clearance * 2),
|
||||
(plate_margin * 2) + max(dial_diameter, key_width) + (plate_clearance * 2),
|
||||
wire_clearance + wemos_d1_mini.z + plate_depth];
|
||||
|
||||
module case() {
|
||||
difference() {
|
||||
cuboid([case.x + case_thickness * 2,
|
||||
case.y + case_thickness * 2,
|
||||
case.z + case_thickness],
|
||||
center=false,
|
||||
fillet=2,
|
||||
edges=EDGES_TOP + EDGES_Z_ALL);
|
||||
translate([case_thickness,case_thickness, case_thickness]) {
|
||||
cube([case.x, case.y, case.z + 1]);
|
||||
}
|
||||
translate([case.x + case_thickness * 1.5,
|
||||
case.y / 2 + case_thickness,
|
||||
case_thickness + (usb_thickness / 2)])
|
||||
rotate([90,0,90])
|
||||
slot(l=12, d=7, h=case_thickness * 2);
|
||||
}
|
||||
|
||||
// Wemos D1 Mini clip
|
||||
color("red", 0.1)
|
||||
translate([case_thickness + case.x - wemos_d1_mini.y,
|
||||
case_thickness + ((case.y - (wemos_d1_mini.x + 4)) / 2),
|
||||
case_thickness]) {
|
||||
difference() {
|
||||
cube([wemos_d1_mini.y, wemos_d1_mini.x + 4,
|
||||
wemos_d1_mini.z - esp_thickness + 2]);
|
||||
translate([0,1, usb_thickness])
|
||||
cuboid([wemos_d1_mini.y,
|
||||
wemos_d1_mini.x + 2,
|
||||
pcb_thickness + 2],
|
||||
center=false,
|
||||
chamfer=1,
|
||||
edges=EDGES_X_ALL);
|
||||
translate([0,2])
|
||||
cube([wemos_d1_mini.y, wemos_d1_mini.x,
|
||||
usb_thickness]);
|
||||
}
|
||||
translate([-3,wemos_d1_mini.x / 2 - 3])
|
||||
cube([2,9,wemos_d1_mini.z - esp_thickness]);
|
||||
}
|
||||
|
||||
// Supports
|
||||
color("purple") {
|
||||
// position within the bounds of the case
|
||||
translate([case_thickness, case_thickness]) {
|
||||
// position within the bounds of the support plate
|
||||
translate([plate_clearance, plate_clearance]) {
|
||||
// dial support pillar
|
||||
// position in the center of the dial
|
||||
translate([(plate_margin + dial_diameter / 2) - 2.5,
|
||||
(plate_margin + dial_diameter / 2) - 2.5])
|
||||
cube([5, 5, case.z - plate_depth - dial_base_protrusion]);
|
||||
|
||||
// screw pillar
|
||||
translate([plate_margin + dial_diameter + (dial_distance / 2),
|
||||
case.y / 2]) {
|
||||
difference() {
|
||||
cylinder(d=6,h=case.z - plate_depth);
|
||||
cylinder(d=3,h=case.z - plate_depth);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cube([3,3, case.z - plate_depth]);
|
||||
translate([0, case.y - 3])
|
||||
cube([3,3, case.z - plate_depth]);
|
||||
|
||||
translate([case.x / 2, 0])
|
||||
cube([3,3, case.z - plate_depth]);
|
||||
translate([case.x / 2, case.y - 3])
|
||||
cube([3,3, case.z - plate_depth]);
|
||||
|
||||
translate([case.x - 1.5, 0])
|
||||
cube([1.5,1.5,case.z - plate_depth]);
|
||||
translate([case.x - 1.5, case.y - 1.5])
|
||||
cube([1.5,1.5,case.z - plate_depth]);
|
||||
|
||||
translate([1.5, case_thickness, case.z - plate_depth]) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
translate([-4, -4, 0]) {
|
||||
case();
|
||||
translate([case_thickness, case_thickness, case_thickness]) {
|
||||
translate([plate_clearance,
|
||||
plate_clearance,
|
||||
case.z - plate_thickness - plate_depth]) {
|
||||
color("yellow", 0.3) {
|
||||
// support_plate();
|
||||
}
|
||||
}
|
||||
color("white", 0.05)
|
||||
translate([case.x - wemos_d1_mini.y,
|
||||
wemos_d1_mini.x + ((case.y - wemos_d1_mini.x) / 2),
|
||||
0])
|
||||
rotate([0,0,-90]) {
|
||||
// wemos_d1_mini();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
50
openscad/wemos_d1_mini.scad
Normal file
50
openscad/wemos_d1_mini.scad
Normal file
|
@ -0,0 +1,50 @@
|
|||
pcb_width = 25.3;
|
||||
pcb_height = 34.5;
|
||||
pcb_thickness = 1.25;
|
||||
|
||||
usb_height = 5.2;
|
||||
usb_width = 7.75;
|
||||
usb_thickness = 2.6;
|
||||
usb_offset = 10;
|
||||
|
||||
esp_height = 15;
|
||||
esp_width = 12;
|
||||
esp_thickness = 4.75;
|
||||
esp_offset_x = 7;
|
||||
esp_offset_y = 7.5;
|
||||
|
||||
esp_board_thickness = 1;
|
||||
esp_board_height = 24.25;
|
||||
esp_board_width = 16;
|
||||
esp_board_offset = 5.25;
|
||||
|
||||
wemos_d1_mini = [pcb_width,
|
||||
pcb_height,
|
||||
usb_thickness + pcb_thickness + esp_thickness];
|
||||
|
||||
module wemos_d1_mini(box=false, box_alpha=0.4) {
|
||||
|
||||
union() {
|
||||
color("blue")
|
||||
translate([0,0,usb_thickness])
|
||||
cube([pcb_width, pcb_height, pcb_thickness]);
|
||||
translate([usb_offset, pcb_height - usb_height, 0])
|
||||
color("silver")
|
||||
cube([usb_width, usb_height, usb_thickness]);
|
||||
translate([esp_board_offset,
|
||||
0,
|
||||
usb_thickness + pcb_thickness])
|
||||
color("black")
|
||||
cube([esp_board_width, esp_board_height, esp_board_thickness]);
|
||||
translate([esp_offset_x,
|
||||
esp_offset_y,
|
||||
pcb_thickness + usb_thickness])
|
||||
color("silver")
|
||||
cube([esp_width, esp_height, esp_thickness]);
|
||||
}
|
||||
|
||||
if (box) {
|
||||
color("gold", box_alpha)
|
||||
cube(wemos_d1_mini);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue