diff --git a/src/components/PageComponents/ModuleConfig/Paxcounter.tsx b/src/components/PageComponents/ModuleConfig/Paxcounter.tsx new file mode 100644 index 00000000..fd82d241 --- /dev/null +++ b/src/components/PageComponents/ModuleConfig/Paxcounter.tsx @@ -0,0 +1,51 @@ +import type { PaxcounterValidation } from "@app/validation/moduleConfig/paxcounter.js"; +import { DynamicForm } from "@components/Form/DynamicForm.js"; +import { useDevice } from "@core/stores/deviceStore.js"; +import { Protobuf } from "@meshtastic/js"; + +export const Paxcounter = (): JSX.Element => { + const { moduleConfig, setWorkingModuleConfig } = useDevice(); + + const onSubmit = (data: PaxcounterValidation) => { + setWorkingModuleConfig( + new Protobuf.ModuleConfig.ModuleConfig({ + payloadVariant: { + case: "paxcounter", + value: data, + }, + }), + ); + }; + + return ( + + onSubmit={onSubmit} + defaultValues={moduleConfig.paxcounter} + fieldGroups={[ + { + label: "Paxcounter Settings", + description: "Settings for the Paxcounter module", + fields: [ + { + type: "toggle", + name: "enabled", + label: "Module Enabled", + description: "Enable Paxcounter", + }, + { + type: "number", + name: "paxcounterUpdateInterval", + label: "Update Interval (seconds)", + description: "How long to wait between sending paxcounter packets", + disabledBy: [ + { + fieldName: "enabled", + }, + ], + }, + ], + }, + ]} + /> + ); +}; diff --git a/src/core/stores/deviceStore.ts b/src/core/stores/deviceStore.ts index d9851a1a..cd9e84a2 100644 --- a/src/core/stores/deviceStore.ts +++ b/src/core/stores/deviceStore.ts @@ -243,6 +243,11 @@ export const useDeviceStore = create((set, get) => ({ config.payloadVariant.value; break; } + case "paxcounter": { + device.moduleConfig.paxcounter = + config.payloadVariant.value; + break; + } } } }), diff --git a/src/pages/Config/ModuleConfig.tsx b/src/pages/Config/ModuleConfig.tsx index ee8d5553..cbec8030 100644 --- a/src/pages/Config/ModuleConfig.tsx +++ b/src/pages/Config/ModuleConfig.tsx @@ -9,6 +9,7 @@ import { RangeTest } from "@components/PageComponents/ModuleConfig/RangeTest.js" import { Serial } from "@components/PageComponents/ModuleConfig/Serial.js"; import { StoreForward } from "@components/PageComponents/ModuleConfig/StoreForward.js"; import { Telemetry } from "@components/PageComponents/ModuleConfig/Telemetry.js"; +import { Paxcounter } from "@components/PageComponents/ModuleConfig/Paxcounter.js"; import { Tabs, TabsContent, @@ -62,6 +63,10 @@ export const ModuleConfig = (): JSX.Element => { label: "Detection Sensor", element: DetectionSensor, }, + { + label: "Paxcounter", + element: Paxcounter, + }, ]; return ( diff --git a/src/validation/moduleConfig/paxcounter.ts b/src/validation/moduleConfig/paxcounter.ts new file mode 100644 index 00000000..67317c96 --- /dev/null +++ b/src/validation/moduleConfig/paxcounter.ts @@ -0,0 +1,14 @@ +import type { Message } from "@bufbuild/protobuf"; +import type { Protobuf } from "@meshtastic/js"; +import { IsBoolean, IsInt } from "class-validator"; + +export class PaxcounterValidation + implements + Omit +{ + @IsBoolean() + enabled: boolean; + + @IsInt() + paxcounterUpdateInterval: number; +}