Skip to content

Commit

Permalink
DMX bugfixes and QOL improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
newcat committed Mar 3, 2024
1 parent 579f278 commit 2ec8e6c
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 12 deletions.
14 changes: 9 additions & 5 deletions lms_bridge/src/controllers/dmx_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,16 @@ impl DmxController {
DmxControllerMessage::UpdateConfiguration(configuration) => {
println!("Updating configuration: {:?}", configuration);

let mut port = serialport::new(&configuration.port, 115200)
let port = serialport::new(&configuration.port, 115200)
.parity(serialport::Parity::None)
.data_bits(serialport::DataBits::Eight)
.stop_bits(serialport::StopBits::One)
.open();

match port {
Ok(ref mut p) => {
Ok(mut p) => {
let _ = p.as_mut().write(&[99]);
self.serialport = Some(p);
}
Err(ref err) => {
println!("Failed to open port {}: {}", configuration.port, err);
Expand Down Expand Up @@ -78,9 +79,12 @@ impl Controller for DmxController {
match self.rx.recv() {
Ok(msg) => match msg {
BridgeToControllerMessage::Message(str_message) => {
let parsed_message: DmxControllerMessage =
serde_json::from_str(&str_message).unwrap();
self.handle_message(parsed_message);
let parsed_message =
serde_json::from_str::<DmxControllerMessage>(&str_message);
match parsed_message {
Ok(m) => self.handle_message(m),
Err(err) => println!("Error parsing message: {}", err),
}
}
BridgeToControllerMessage::Dispose => {
break;
Expand Down
5 changes: 4 additions & 1 deletion src/graph/nodes/input/LfoNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ const functions: Record<string, (x: number) => number> = {
Sine: (x: number) => Math.sin(Math.PI * 2 * x),
Triangle: (x: number) => 4 * Math.abs(x - Math.floor(x + 0.5)) - 1,
Sawtooth: (x: number) => 2 * x - 1,
Square: (x: number) => Math.sign(Math.sin(Math.PI * 2 * x)),
Square: (x: number) => {
const v = Math.sign(Math.sin(Math.PI * 2 * x));
return v === 0 ? -1 : v;
},
};

export const LfoNode = defineNode({
Expand Down
2 changes: 1 addition & 1 deletion src/stage/controllers/dmx/DmxControllerSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<LabelledInputText v-model="port">Port</LabelledInputText>
<ChannelVisualization :fixtures="controller.controlledFixtures" />
<div>
<Button outlined label="Open DMX Panel" @click="panelVisible = true" />
<Button outlined label="Open DMX Control Panel" @click="panelVisible = true" />
</div>
<DmxPanel :controller="controller" v-model:visible="panelVisible" />
</template>
Expand Down
43 changes: 40 additions & 3 deletions src/stage/controllers/dmx/DmxPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,19 @@
<template v-if="selectedFixture">
<div v-for="(channel, i) in selectedFixture.channelNames" :key="channel" class="channel">
<div>{{ channel }}</div>
<Slider v-model="selectedFixture.value[i]" class="h-full" orientation="vertical" :min="0" :max="255" :step="1" />
<Slider
:model-value="selectedFixture.value[i]"
class="h-full"
orientation="vertical"
:min="0"
:max="255"
:step="1"
@update:model-value="setValue(i, $event)"
/>
<div class="flex gap-2">
<Button text icon="pi pi-minus" @click="setValue(i, selectedFixture.value[i] - 1)" />
<Button text icon="pi pi-plus" @click="setValue(i, selectedFixture.value[i] + 1)" />
</div>
<div>{{ selectedFixture.value[i] ?? 0 }}</div>
</div>
</template>
Expand All @@ -19,20 +31,45 @@
</template>

<script setup lang="ts">
import { ref } from "vue";
import { onMounted, ref } from "vue";
import Button from "primevue/button";
import Dropdown from "primevue/dropdown";
import Dialog from "primevue/dialog";
import Slider from "primevue/slider";
import { DmxController } from "./dmx.controller";
import { DmxFixture } from "../../fixtures";
import { useThrottleFn } from "@vueuse/core";
const visible = defineModel<boolean>("visible", { required: true });
defineProps<{
const props = defineProps<{
controller: DmxController;
}>();
const selectedFixture = ref<DmxFixture>();
onMounted(() => {
selectedFixture.value = props.controller.controlledFixtures[0];
});
const throttledSend = useThrottleFn(
() => {
props.controller.send();
},
300,
true
);
function setValue(index: number, value: number) {
if (!selectedFixture.value) {
return;
}
const clone = [...selectedFixture.value.value];
clone[index] = value;
selectedFixture.value.setValue(clone);
throttledSend();
}
</script>

<style scoped>
Expand Down
5 changes: 5 additions & 0 deletions src/stage/controllers/dmx/dmx.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ export class DmxController extends BaseController<DmxControllerConfiguration, Dm
this.sendConfiguration();
}

public override setConfig(c: DmxControllerConfiguration): void {
super.setConfig(c);
this.sendConfiguration();
}

public async send() {
if (this.controlledFixtures.length === 0) {
return;
Expand Down
4 changes: 2 additions & 2 deletions src/stage/fixtures/dmx/dmx.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ export class DmxFixture extends BaseFixture<number[], DmxFixtureConfiguration> {
}

public override setValue(v: number[]): void {
const normalizedValues = v.map((val) => Math.max(0, Math.min(255, Math.floor(val))));
const normalizedValues = v.map((val) => (isNaN(val) ? 0 : Math.max(0, Math.min(255, Math.floor(val)))));
super.setValue(normalizedValues);
}

public override resetValue(): void {
this.setValue([]);
this.setValue(new Array(this.channelNames.length).fill(0));
}
}

0 comments on commit 2ec8e6c

Please sign in to comment.