add module ambient lighting (#142)
This commit is contained in:
@@ -0,0 +1,64 @@
|
|||||||
|
import { useDevice } from "@app/core/stores/deviceStore.js";
|
||||||
|
import type { AmbientLightingValidation } from "@app/validation/moduleConfig/ambientLighting.js";
|
||||||
|
import { DynamicForm } from "@components/Form/DynamicForm.js";
|
||||||
|
import { Protobuf } from "@meshtastic/meshtasticjs";
|
||||||
|
|
||||||
|
export const AmbientLighting = (): JSX.Element => {
|
||||||
|
const { moduleConfig, setWorkingModuleConfig } = useDevice();
|
||||||
|
|
||||||
|
const onSubmit = (data: AmbientLightingValidation) => {
|
||||||
|
setWorkingModuleConfig(
|
||||||
|
new Protobuf.ModuleConfig({
|
||||||
|
payloadVariant: {
|
||||||
|
case: "ambientLighting",
|
||||||
|
value: data,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DynamicForm<AmbientLightingValidation>
|
||||||
|
onSubmit={onSubmit}
|
||||||
|
defaultValues={moduleConfig.ambientLighting}
|
||||||
|
fieldGroups={[
|
||||||
|
{
|
||||||
|
label: "Ambient Lighting Settings",
|
||||||
|
description: "Settings for the Ambient Lighting module",
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
type: "toggle",
|
||||||
|
name: "ledState",
|
||||||
|
label: "LED State",
|
||||||
|
description: "Sets LED to on or off",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "number",
|
||||||
|
name: "current",
|
||||||
|
label: "Current",
|
||||||
|
description: "Sets the current for the LED output. Default is 10",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "number",
|
||||||
|
name: "red",
|
||||||
|
label: "Red",
|
||||||
|
description: "Sets the red LED level. Values are 0-255",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "number",
|
||||||
|
name: "green",
|
||||||
|
label: "Green",
|
||||||
|
description: "Sets the green LED level. Values are 0-255",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "number",
|
||||||
|
name: "blue",
|
||||||
|
label: "Blue",
|
||||||
|
description: "Sets the blue LED level. Values are 0-255",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -214,11 +214,14 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
|
|||||||
case "audio":
|
case "audio":
|
||||||
device.moduleConfig.audio = config.payloadVariant.value;
|
device.moduleConfig.audio = config.payloadVariant.value;
|
||||||
break;
|
break;
|
||||||
|
case "neighborInfo":
|
||||||
|
device.moduleConfig.neighborInfo = config.payloadVariant.value;
|
||||||
|
break;
|
||||||
|
case "ambientLighting":
|
||||||
|
device.moduleConfig.ambientLighting = config.payloadVariant.value;
|
||||||
|
break;
|
||||||
case "detectionSensor":
|
case "detectionSensor":
|
||||||
device.moduleConfig.detectionSensor = config.payloadVariant.value;
|
device.moduleConfig.detectionSensor = config.payloadVariant.value;
|
||||||
break;
|
|
||||||
case "neighborInfo":
|
|
||||||
device.moduleConfig.neighborInfo = config.payloadVariant.value;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { NeighborInfo } from "@app/components/PageComponents/ModuleConfig/NeighborInfo.js";
|
import { NeighborInfo } from "@app/components/PageComponents/ModuleConfig/NeighborInfo.js";
|
||||||
|
import { AmbientLighting } from "@app/components/PageComponents/ModuleConfig/AmbientLighting.js";
|
||||||
import { DetectionSensor } from "@app/components/PageComponents/ModuleConfig/DetectionSensor.js";
|
import { DetectionSensor } from "@app/components/PageComponents/ModuleConfig/DetectionSensor.js";
|
||||||
import { Audio } from "@components/PageComponents/ModuleConfig/Audio.js";
|
import { Audio } from "@components/PageComponents/ModuleConfig/Audio.js";
|
||||||
import { CannedMessage } from "@components/PageComponents/ModuleConfig/CannedMessage.js";
|
import { CannedMessage } from "@components/PageComponents/ModuleConfig/CannedMessage.js";
|
||||||
@@ -53,6 +54,10 @@ export const ModuleConfig = (): JSX.Element => {
|
|||||||
label: "Neighbor Info",
|
label: "Neighbor Info",
|
||||||
element: NeighborInfo,
|
element: NeighborInfo,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: "Ambient Lighting",
|
||||||
|
element: AmbientLighting,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: "Detection Sensor",
|
label: "Detection Sensor",
|
||||||
element: DetectionSensor,
|
element: DetectionSensor,
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import { IsBoolean, IsInt } from "class-validator";
|
||||||
|
|
||||||
|
import type { Protobuf } from "@meshtastic/meshtasticjs";
|
||||||
|
|
||||||
|
export class AmbientLightingValidation
|
||||||
|
implements
|
||||||
|
Omit<
|
||||||
|
Protobuf.ModuleConfig_AmbientLightingConfig,
|
||||||
|
keyof Protobuf.native.Message
|
||||||
|
>
|
||||||
|
{
|
||||||
|
@IsBoolean()
|
||||||
|
ledState: boolean;
|
||||||
|
|
||||||
|
@IsInt()
|
||||||
|
current: number;
|
||||||
|
|
||||||
|
@IsInt()
|
||||||
|
red: number;
|
||||||
|
|
||||||
|
@IsInt()
|
||||||
|
green: number;
|
||||||
|
|
||||||
|
@IsInt()
|
||||||
|
blue: number;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user