Skip to content

Commit

Permalink
Add GM77 class and component
Browse files Browse the repository at this point in the history
Co-authored-by: TonProtofy <ton.miserachs@protofy.xyz>
  • Loading branch information
Ghofranezirouh and TonProtofy committed Dec 19, 2024
1 parent f6cf1ff commit 19315a5
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 2 deletions.
76 changes: 76 additions & 0 deletions packages/protodevice/src/device/GM77.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
class GM77 {
name;
type;
uartId;

constructor(name, type, uartId) {
this.name = name
this.type = type
this.uartId = uartId
}

attach(pin, deviceComponents) {
const componentObjects = [
{
name: "external_components",
config: {
//@ts-ignore
source: "github://Protofy-xyz/esphome-components",
refresh: "0s",
components: ["gm77"]
}
},

{
name: this.type,
config: {
id: this.name,
uart_id: this.uartId,
on_tag:
{
"mqtt.publish": {

topic: `devices/${deviceComponents.esphome.name}/${this.type}/${this.name}/state`,
payload: `@!lambda "return id(${this.name}).tag.c_str();"@`

},
}

},
subsystem: this.getSubsystem()
},
]

componentObjects.forEach((element, j) => {
if (!deviceComponents[element.name]) {
deviceComponents[element.name] = element.config
} else {
if (!Array.isArray(deviceComponents[element.name])) {
deviceComponents[element.name] = [deviceComponents[element.name]]
}
deviceComponents[element.name] = [...deviceComponents[element.name], element.config]
}
})
return deviceComponents
}

getSubsystem() {
return {
name: this.name,
type: this.type,
monitors: [
{
name: "barcodeReading",
label: "Barcode reading",
description: "Get barcode reading from qr sensor",
endpoint: "/" + this.type + "/" + this.name + "/state",
connectionType: "mqtt",
}
]
}
}
}

export function gm77(name, uartId) {
return new GM77(name, 'gm77', uartId)
}
3 changes: 2 additions & 1 deletion packages/protodevice/src/device/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ export * from './ODrive'
export * from './INA226'
export * from './SntpTime'
export * from './SdOfflineLogger'
export * from './ODriveCan'
export * from './ODriveCan'
export * from './GM77'
33 changes: 33 additions & 0 deletions packages/protodevice/src/nodes/GM77.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Field, Node, NodeParams } from 'protoflow';
import { getColor } from ".";

const GM77 = ({ node = {}, nodeData = {}, children, color }: any) => {
const nodeParams: Field[] = [
{
label: 'Name', static: true, field: 'param-1', type: 'input',
},
{
label: 'UART bus name', static: true, field: 'param-2', type: 'input'
},
] as Field[]
return (
<Node node={node} isPreview={!node.id} title='QR Sensor' color={color} id={node.id} skipCustom={true}>
<NodeParams id={node.id} params={nodeParams} />
</Node>
)
}
export default {
id: 'GM77',
type: 'CallExpression',
category: "sensors",
keywords: ["sensor", "qr", "barcode", "gm77", "gm73"],
check: (node, nodeData) => node.type == "CallExpression" && nodeData.to?.startsWith('gm77'), //TODO: Change output function name
getComponent: (node, nodeData, children) => <GM77 color={getColor('GM77')} node={node} nodeData={nodeData} children={children} />,
getInitialData: () => {
return {
to: 'gm77',
"param-1": { value: "", kind: "StringLiteral" },
"param-2": { value: "", kind: "StringLiteral" }
}
}
}
4 changes: 3 additions & 1 deletion packages/protodevice/src/nodes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import LEDCOutput from './LEDCOutput';
import SntpTime from './SntpTime';
import SdOfflineLogger from './SdOfflineLogger';
import OdriveCan from './ODriveCan'
import GM77 from './GM77'


const deviceMasks = [
Expand Down Expand Up @@ -84,7 +85,8 @@ const deviceMasks = [
LEDCOutput,
SntpTime,
SdOfflineLogger,
OdriveCan
OdriveCan,
GM77
]

const masksLength = deviceMasks.length
Expand Down

0 comments on commit 19315a5

Please sign in to comment.