Skip to content

Commit

Permalink
Merge pull request #160 from pdxlocations/paxcounter
Browse files Browse the repository at this point in the history
Add Paxcounter Config
  • Loading branch information
sachaw authored Feb 19, 2024
2 parents 291fce5 + edc0be7 commit 7a39e07
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/components/PageComponents/ModuleConfig/Paxcounter.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<DynamicForm<PaxcounterValidation>
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",
},
],
},
],
},
]}
/>
);
};
5 changes: 5 additions & 0 deletions src/core/stores/deviceStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
config.payloadVariant.value;
break;
}
case "paxcounter": {
device.moduleConfig.paxcounter =
config.payloadVariant.value;
break;
}
}
}
}),
Expand Down
5 changes: 5 additions & 0 deletions src/pages/Config/ModuleConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -62,6 +63,10 @@ export const ModuleConfig = (): JSX.Element => {
label: "Detection Sensor",
element: DetectionSensor,
},
{
label: "Paxcounter",
element: Paxcounter,
},
];

return (
Expand Down
14 changes: 14 additions & 0 deletions src/validation/moduleConfig/paxcounter.ts
Original file line number Diff line number Diff line change
@@ -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<Protobuf.ModuleConfig.ModuleConfig_PaxcounterConfig, keyof Message>
{
@IsBoolean()
enabled: boolean;

@IsInt()
paxcounterUpdateInterval: number;
}

0 comments on commit 7a39e07

Please sign in to comment.