diff --git a/package-lock.json b/package-lock.json index 07ce6c6..52c6189 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10889,7 +10889,7 @@ }, "node_modules/protobuf-ts": { "version": "1.0.0", - "resolved": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#bb403eef199a68f470fc025ae97fed2185682504", + "resolved": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#091928b04970731f9b543fcecc313b6f4ea7d4e2", "dependencies": { "protobufjs": "^6.8.8" } diff --git a/package.json b/package.json index a1fa968..ed3648f 100644 --- a/package.json +++ b/package.json @@ -12,10 +12,10 @@ "build": "tsc -b && vite build", "lint": "eslint .", "preview": "vite preview", - "build:staging": "VITE_AUTH0_CLIENT_DOMAIN=adaptivestaging.us.auth0.com VITE_AUTH0_AUDIENCE=stagingapi.brandxtech.ca VITE_AUTH0_CLIENT_ID=3ib460VvLwdeyse5iUSQfxkVdQaUmphP VITE_APP_API_URL=https://stagingapi.brandxtech.ca/v1 VITE_APP_WS_URL=wss://stagingapi.brandxtech.ca/v1/live NODE_OPTIONS=--max_old_space_size=4096 VITE_APP_GOOGLE_API_KEY=${GOOGLE_API_KEY} VITE_APP_STRIPE_PUBLIC_KEY=${STRIPE_PUBLIC_KEY_STAGING} VITE_MAPBOX_ACCESS_TOKEN=${MAPBOX_ACCESS_TOKEN} VITE_CNHI_CLIENT_ID=${CNHI_CLIENT_ID} VITE_CNHI_AUTHORIZE_URL=${CNHI_AUTHORIZE_URL} VITE_CNHI_REDIRECT_URI=${CNHI_REDIRECT_URI} VITE_CNHI_SCOPES=${CNHI_SCOPES} VITE_CNHI_CONNECTION=${CNHI_CONNECTION} VITE_CNHI_AUDIENCE=${CNHI_AUDIENCE} VITE_APP_IMAGE4IO_USERNAME=${IMAGE4IO_USERNAME} VITE_APP_IMAGE4IO_PASSWORD=${IMAGE4IO_PASSWORD} VITE_JD_CLIENT_ID=${JD_CLIENT_ID} VITE_JD_AUTHORIZE_URL=${JD_AUTHORIZE_URL} VITE_JD_REDIRECT_URI=${JD_REDIRECT_URI} VITE_JD_SCOPES=${JD_SCOPES} VITE_JD_STATE=${JD_STATE} VITE_OPEN_WEATHERMAP={OPEN_WEATHERMAP} vite build", - "build:development": "VITE_AUTH0_CLIENT_ID=dzJTpqIeMA4Rwk4xujtwPbAO3TY32bM1 VITE_AUTH0_AUDIENCE=bxt-dev.api.adaptiveagriculture.ca VITE_APP_API_URL=https://bxt-dev.api.adaptiveagriculture.ca/v1 NODE_OPTIONS=--max_old_space_size=4096 VITE_APP_GOOGLE_API_KEY=${GOOGLE_API_KEY} VITE_APP_STRIPE_PUBLIC_KEY=${STRIPE_PUBLIC_KEY_DEVELOPMENT} VITE_MAPBOX_ACCESS_TOKEN=${MAPBOX_ACCESS_TOKEN} VITE_CNHI_CLIENT_ID=${CNHI_CLIENT_ID} VITE_CNHI_AUTHORIZE_URL=${CNHI_AUTHORIZE_URL} VITE_CNHI_REDIRECT_URI=${CNHI_REDIRECT_URI} VITE_CNHI_SCOPES=${CNHI_SCOPES} VITE_CNHI_CONNECTION=${CNHI_CONNECTION} VITE_CNHI_AUDIENCE=${CNHI_AUDIENCE} VITE_APP_IMAGE4IO_USERNAME=${IMAGE4IO_USERNAME} VITE_APP_IMAGE4IO_PASSWORD=${IMAGE4IO_PASSWORD} VITE_JD_CLIENT_ID=${JD_CLIENT_ID} VITE_JD_AUTHORIZE_URL=${JD_AUTHORIZE_URL} VITE_JD_REDIRECT_URI=${JD_REDIRECT_URI} VITE_JD_SCOPES=${JD_SCOPES} VITE_JD_STATE=${JD_STATE} VITE_OPEN_WEATHERMAP={OPEN_WEATHERMAP} vite build", - "build:production": "VITE_AUTH0_CLIENT_ID=5pUCkl2SfogkWmM244UDcLEUOp8EFdHd VITE_AUTH0_CLIENT_DOMAIN=brandxtech.auth0.com VITE_AUTH0_AUDIENCE=api.brandxtech.ca VITE_APP_API_URL=https://api.brandxtech.ca/v1 NODE_OPTIONS=--max_old_space_size=4096 VITE_APP_GOOGLE_API_KEY=${GOOGLE_API_KEY} VITE_APP_STRIPE_PUBLIC_KEY=${STRIPE_PUBLIC_KEY_PRODUCTION} VITE_MAPBOX_ACCESS_TOKEN=${MAPBOX_ACCESS_TOKEN} VITE_CNHI_CLIENT_ID=${CNHI_CLIENT_ID} VITE_CNHI_AUTHORIZE_URL=${CNHI_AUTHORIZE_URL} VITE_CNHI_REDIRECT_URI=${CNHI_REDIRECT_URI} VITE_CNHI_SCOPES=${CNHI_SCOPES} VITE_CNHI_CONNECTION=${CNHI_CONNECTION} VITE_CNHI_AUDIENCE=${CNHI_AUDIENCE} VITE_APP_IMAGE4IO_USERNAME=${IMAGE4IO_USERNAME} VITE_APP_IMAGE4IO_PASSWORD=${IMAGE4IO_PASSWORD} VITE_JD_CLIENT_ID=${JD_CLIENT_ID} VITE_JD_AUTHORIZE_URL=${JD_AUTHORIZE_URL} VITE_JD_REDIRECT_URI=${JD_REDIRECT_URI} VITE_JD_SCOPES=${JD_SCOPES} VITE_JD_STATE=${JD_STATE} VITE_OPEN_WEATHERMAP={OPEN_WEATHERMAP} vite build", - "build:streamline": "VITE_AUTH0_CLIENT_ID=HwUV0hHNdVvU96zuMBTAU8i7nFdwwgIX VITE_AUTH0_CLIENT_DOMAIN=brandxtech.auth0.com VITE_AUTH0_AUDIENCE=streamline.api.adaptiveagriculture.ca VITE_APP_API_URL=https://streamline.api.adaptiveagriculture.ca/v1 NODE_OPTIONS=--max_old_space_size=4096 VITE_APP_GOOGLE_API_KEY=${GOOGLE_API_KEY} VITE_APP_STRIPE_PUBLIC_KEY=${STRIPE_PUBLIC_KEY_PRODUCTION} VITE_MAPBOX_ACCESS_TOKEN=${MAPBOX_ACCESS_TOKEN} VITE_CNHI_CLIENT_ID=${CNHI_CLIENT_ID} VITE_CNHI_AUTHORIZE_URL=${CNHI_AUTHORIZE_URL} VITE_CNHI_REDIRECT_URI=${CNHI_REDIRECT_URI} VITE_CNHI_SCOPES=${CNHI_SCOPES} VITE_CNHI_CONNECTION=${CNHI_CONNECTION} VITE_CNHI_AUDIENCE=${CNHI_AUDIENCE} VITE_APP_IMAGE4IO_USERNAME=${IMAGE4IO_USERNAME} VITE_APP_IMAGE4IO_PASSWORD=${IMAGE4IO_PASSWORD} VITE_JD_CLIENT_ID=${JD_CLIENT_ID} VITE_JD_AUTHORIZE_URL=${JD_AUTHORIZE_URL} VITE_JD_REDIRECT_URI=${JD_REDIRECT_URI} VITE_JD_SCOPES=${JD_SCOPES} VITE_JD_STATE=${JD_STATE} VITE_OPEN_WEATHERMAP={OPEN_WEATHERMAP} vite build", + "build:staging": "VITE_AUTH0_CLIENT_DOMAIN=adaptivestaging.us.auth0.com VITE_AUTH0_AUDIENCE=stagingapi.brandxtech.ca VITE_AUTH0_CLIENT_ID=3ib460VvLwdeyse5iUSQfxkVdQaUmphP VITE_APP_API_URL=https://stagingapi.brandxtech.ca/v1 VITE_APP_WS_URL=wss://stagingapi.brandxtech.ca/v1/live NODE_OPTIONS=--max_old_space_size=4096 VITE_APP_GOOGLE_API_KEY=${GOOGLE_API_KEY} VITE_APP_STRIPE_PUBLIC_KEY=${STRIPE_PUBLIC_KEY_STAGING} VITE_MAPBOX_ACCESS_TOKEN=${MAPBOX_ACCESS_TOKEN} VITE_CNHI_CLIENT_ID=${CNHI_CLIENT_ID} VITE_CNHI_AUTHORIZE_URL=${CNHI_AUTHORIZE_URL} VITE_CNHI_REDIRECT_URI=${CNHI_REDIRECT_URI} VITE_CNHI_SCOPES=${CNHI_SCOPES} VITE_CNHI_CONNECTION=${CNHI_CONNECTION} VITE_CNHI_AUDIENCE=${CNHI_AUDIENCE} VITE_APP_IMAGE4IO_USERNAME=${IMAGE4IO_USERNAME} VITE_APP_IMAGE4IO_PASSWORD=${IMAGE4IO_PASSWORD} VITE_JD_CLIENT_ID=${JD_CLIENT_ID} VITE_JD_AUTHORIZE_URL=${JD_AUTHORIZE_URL} VITE_JD_REDIRECT_URI=${JD_REDIRECT_URI} VITE_JD_SCOPES=${JD_SCOPES} VITE_JD_STATE=${JD_STATE} VITE_OPEN_WEATHERMAP=${OPEN_WEATHERMAP} vite build", + "build:development": "VITE_AUTH0_CLIENT_ID=dzJTpqIeMA4Rwk4xujtwPbAO3TY32bM1 VITE_AUTH0_AUDIENCE=bxt-dev.api.adaptiveagriculture.ca VITE_APP_API_URL=https://bxt-dev.api.adaptiveagriculture.ca/v1 NODE_OPTIONS=--max_old_space_size=4096 VITE_APP_GOOGLE_API_KEY=${GOOGLE_API_KEY} VITE_APP_STRIPE_PUBLIC_KEY=${STRIPE_PUBLIC_KEY_DEVELOPMENT} VITE_MAPBOX_ACCESS_TOKEN=${MAPBOX_ACCESS_TOKEN} VITE_CNHI_CLIENT_ID=${CNHI_CLIENT_ID} VITE_CNHI_AUTHORIZE_URL=${CNHI_AUTHORIZE_URL} VITE_CNHI_REDIRECT_URI=${CNHI_REDIRECT_URI} VITE_CNHI_SCOPES=${CNHI_SCOPES} VITE_CNHI_CONNECTION=${CNHI_CONNECTION} VITE_CNHI_AUDIENCE=${CNHI_AUDIENCE} VITE_APP_IMAGE4IO_USERNAME=${IMAGE4IO_USERNAME} VITE_APP_IMAGE4IO_PASSWORD=${IMAGE4IO_PASSWORD} VITE_JD_CLIENT_ID=${JD_CLIENT_ID} VITE_JD_AUTHORIZE_URL=${JD_AUTHORIZE_URL} VITE_JD_REDIRECT_URI=${JD_REDIRECT_URI} VITE_JD_SCOPES=${JD_SCOPES} VITE_JD_STATE=${JD_STATE} VITE_OPEN_WEATHERMAP=${OPEN_WEATHERMAP} vite build", + "build:production": "VITE_AUTH0_CLIENT_ID=5pUCkl2SfogkWmM244UDcLEUOp8EFdHd VITE_AUTH0_CLIENT_DOMAIN=brandxtech.auth0.com VITE_AUTH0_AUDIENCE=api.brandxtech.ca VITE_APP_API_URL=https://api.brandxtech.ca/v1 NODE_OPTIONS=--max_old_space_size=4096 VITE_APP_GOOGLE_API_KEY=${GOOGLE_API_KEY} VITE_APP_STRIPE_PUBLIC_KEY=${STRIPE_PUBLIC_KEY_PRODUCTION} VITE_MAPBOX_ACCESS_TOKEN=${MAPBOX_ACCESS_TOKEN} VITE_CNHI_CLIENT_ID=${CNHI_CLIENT_ID} VITE_CNHI_AUTHORIZE_URL=${CNHI_AUTHORIZE_URL} VITE_CNHI_REDIRECT_URI=${CNHI_REDIRECT_URI} VITE_CNHI_SCOPES=${CNHI_SCOPES} VITE_CNHI_CONNECTION=${CNHI_CONNECTION} VITE_CNHI_AUDIENCE=${CNHI_AUDIENCE} VITE_APP_IMAGE4IO_USERNAME=${IMAGE4IO_USERNAME} VITE_APP_IMAGE4IO_PASSWORD=${IMAGE4IO_PASSWORD} VITE_JD_CLIENT_ID=${JD_CLIENT_ID} VITE_JD_AUTHORIZE_URL=${JD_AUTHORIZE_URL} VITE_JD_REDIRECT_URI=${JD_REDIRECT_URI} VITE_JD_SCOPES=${JD_SCOPES} VITE_JD_STATE=${JD_STATE} VITE_OPEN_WEATHERMAP=${OPEN_WEATHERMAP} vite build", + "build:streamline": "VITE_AUTH0_CLIENT_ID=HwUV0hHNdVvU96zuMBTAU8i7nFdwwgIX VITE_AUTH0_CLIENT_DOMAIN=brandxtech.auth0.com VITE_AUTH0_AUDIENCE=streamline.api.adaptiveagriculture.ca VITE_APP_API_URL=https://streamline.api.adaptiveagriculture.ca/v1 NODE_OPTIONS=--max_old_space_size=4096 VITE_APP_GOOGLE_API_KEY=${GOOGLE_API_KEY} VITE_APP_STRIPE_PUBLIC_KEY=${STRIPE_PUBLIC_KEY_PRODUCTION} VITE_MAPBOX_ACCESS_TOKEN=${MAPBOX_ACCESS_TOKEN} VITE_CNHI_CLIENT_ID=${CNHI_CLIENT_ID} VITE_CNHI_AUTHORIZE_URL=${CNHI_AUTHORIZE_URL} VITE_CNHI_REDIRECT_URI=${CNHI_REDIRECT_URI} VITE_CNHI_SCOPES=${CNHI_SCOPES} VITE_CNHI_CONNECTION=${CNHI_CONNECTION} VITE_CNHI_AUDIENCE=${CNHI_AUDIENCE} VITE_APP_IMAGE4IO_USERNAME=${IMAGE4IO_USERNAME} VITE_APP_IMAGE4IO_PASSWORD=${IMAGE4IO_PASSWORD} VITE_JD_CLIENT_ID=${JD_CLIENT_ID} VITE_JD_AUTHORIZE_URL=${JD_AUTHORIZE_URL} VITE_JD_REDIRECT_URI=${JD_REDIRECT_URI} VITE_JD_SCOPES=${JD_SCOPES} VITE_JD_STATE=${JD_STATE} VITE_OPEN_WEATHERMAP=${OPEN_WEATHERMAP} vite build", "build:offline": "npx env-cmd offline,whitelabel npm run build", "test": "vitest" }, diff --git a/src/apiDocs/enumerators/generalEnums.tsx b/src/apiDocs/enumerators/generalEnums.tsx index 873cd95..c52974b 100644 --- a/src/apiDocs/enumerators/generalEnums.tsx +++ b/src/apiDocs/enumerators/generalEnums.tsx @@ -555,10 +555,10 @@ const componentType: data = { key: "COMPONENT_TYPE_CAPACITANCE", val: 24 }, - { - key: "COMPONENT_TYPE_VAPOUR_PRESSURE_DEFICIT", - val: 25 - }, + // { + // key: "COMPONENT_TYPE_VAPOUR_PRESSURE_DEFICIT", //this component type is deprecated? + // val: 25 + // }, { key: "COMPONENT_TYPE_WEIGHT", val: 26 diff --git a/src/bin/BinComponents.tsx b/src/bin/BinComponents.tsx index 33a912a..7864c46 100644 --- a/src/bin/BinComponents.tsx +++ b/src/bin/BinComponents.tsx @@ -414,7 +414,7 @@ export default function BinComponents(props: Props) { )} - {comp.name()} + {comp.name() + " - " + comp.addressDescription(devMap.get(device)?.settings.product)} {components?.get(comp.key()) !== undefined ? ( diff --git a/src/component/ComponentSettings.tsx b/src/component/ComponentSettings.tsx index d762ee3..54653a2 100644 --- a/src/component/ComponentSettings.tsx +++ b/src/component/ComponentSettings.tsx @@ -238,6 +238,7 @@ export default function ComponentSettings(props: Props) { componentType: quack.ComponentType ): number[] => { let positions = availablePositions.get(addressType); + console.log(positions) if (!positions) return []; switch (addressType) { case quack.AddressType.ADDRESS_TYPE_I2C: @@ -412,6 +413,7 @@ export default function ComponentSettings(props: Props) { for (let i = 0; i < addressTypes.length; i++) { let addressType = addressTypes[i]; let availablePositions = getAvailablePositions(addressType, type); + console.log(availablePositions) availableMenuItemPositions.push( diff --git a/src/device/DeviceWizard.tsx b/src/device/DeviceWizard.tsx index d426c21..4de3cc2 100644 --- a/src/device/DeviceWizard.tsx +++ b/src/device/DeviceWizard.tsx @@ -26,7 +26,8 @@ import { import { GetDeviceProductIcon, GetDeviceProductLabel } from "products/DeviceProduct"; import { pond } from "protobuf-ts/pond"; import { quack } from "protobuf-ts/quack"; -import { useComponentAPI, useGlobalState, useSnackbar } from "providers"; +import { useComponentAPI, useDeviceAPI, useGlobalState, useSnackbar } from "providers"; + import React, { useState } from "react"; import DeviceSVG, { PortInformation } from "./deviceSVG"; import { makeStyles } from "@mui/styles"; @@ -83,6 +84,8 @@ export default function DeviceWizard(props: Props) { ); const classes = useStyles(); const [selectedPort, setSelectedPort] = useState(); + const deviceAPI = useDeviceAPI() + const { openSnack } = useSnackbar() //const [addressType, setAddressType] = useState(quack.AddressType.ADDRESS_TYPE_CONFIGURABLE_PIN_ARRAY); const wizardMenu = () => { @@ -118,6 +121,22 @@ export default function DeviceWizard(props: Props) { )} + {selectedPort && selectedPort.addressType === quack.AddressType.ADDRESS_TYPE_I2C && device.featureSupported("detectI2C") && ( + + { + deviceAPI.detectI2C(device.id()) + .then(resp => { + openSnack("Device will scan port on next check-in") + }).catch(err => { + openSnack("Command failed to send to device") + }) + }}> + Scan Port + + + )} {portComponents.length > 0 && ( Current Components diff --git a/src/device/autoDetect/DeviceScannedComponents.tsx b/src/device/autoDetect/DeviceScannedComponents.tsx new file mode 100644 index 0000000..52a66e4 --- /dev/null +++ b/src/device/autoDetect/DeviceScannedComponents.tsx @@ -0,0 +1,219 @@ +import { Box, Button, Card, DialogActions, DialogContent, DialogTitle, FormControlLabel, Grid2, Radio, RadioGroup, Step, StepLabel, Stepper, Typography } from "@mui/material"; +import { cloneDeep } from "lodash"; +import { getSubtypes, Subtype } from "pbHelpers/ComponentType"; +import { pond, quack } from "protobuf-ts/pond"; +import React from "react"; +import { useEffect, useState } from "react"; +import ScannedI2C from "./ScannedI2C"; +import ComponentForm from "component/ComponentForm"; +import { Component, Device } from "models"; +import { DeviceAvailabilityMap, OffsetAvailabilityMap } from "pbHelpers/DeviceAvailability"; +import ResponsiveDialog from "common/ResponsiveDialog"; +import { useComponentAPI, useSnackbar } from "hooks"; + +interface Props { + scannedComponents: pond.ComponentAddressMap + device: Device + availablePositions: DeviceAvailabilityMap + availableOffsets: OffsetAvailabilityMap + refreshCallback: () => void +} + +interface CompStep { + label: string; + completed?: boolean; +} + +export default function DeviceScannedComponents(props: Props){ + const {scannedComponents, device, availablePositions, availableOffsets, refreshCallback} = props + const compAPI = useComponentAPI(); + const [scannedI2C, setScannedI2C] = useState() + const [components, setComponents] = useState([]) + const [steps, setSteps] = useState([]); + const { error, success } = useSnackbar(); + const [currentStep, setCurrentStep] = useState(0) + const [settingsValid, setSettingsValid] = useState(false); + const [openDialog, setOpenDialog] = useState(false); + + useEffect(()=>{ + if (scannedComponents.i2c) setScannedI2C(scannedComponents.i2c) + //makes the array empty for testing + // if (scannedComponents.i2c) { + // let clone = cloneDeep(scannedComponents.i2c) + // if (clone.settings){ + // clone.settings.foundAddresses = [] + // } + // setScannedI2C(clone) + // } + },[scannedComponents]) + + useEffect(() => { + let steps: CompStep[] = [] + components.forEach(comp => { + steps.push({ + label: comp.name(), + completed: false + }) + }) + setSteps(steps) + },[components]) + + const stepper = () => { + return ( + + {steps.map(compStep => { + const labelProps: { + optional?: React.ReactNode; + } = {}; + return ( + + {compStep.label} + + ); + })} + + ); + }; + + const addComponents = () => { + let c: pond.MultiComponentSettings = pond.MultiComponentSettings.create(); + components.forEach(component => { + c.components.push(component.settings); + }); + compAPI + .addMultiComponents(device.id(), c) + .then(resp => { + success("Components added to Device"); + }) + .catch(err => { + error("One or more component failed to add"); + }) + .finally(() => { + refreshCallback(); + }); + }; + + const addComponentDialog = () => { + return ( + {setOpenDialog(false)}}> + Adding Components + + {stepper()} + { + components[currentStep].settings = component.settings; + setSettingsValid(isValid); + }} + /> + + + + + + + + {currentStep !== 0 && ( + + )} + {currentStep !== steps.length - 1 && ( + + + + )} + + + + + + ); + }; + + const componentSelection = (newComponent: Component, checked: boolean) => { + let cloneList = cloneDeep(components) + if(checked){ + //add the component to the list + cloneList.push(newComponent) + }else{ + //remove any components that match the component location: (type)-(addressType)-(address) + components.forEach((comp, i) => { + //check the components location against the one in the list + if(comp.locationString() === newComponent.locationString()){ + cloneList.splice(i, 1) + } + }) + } + setComponents(cloneList) + } + + + + return ( + + + {scannedI2C !== undefined && + + + + I2C Sensors + + + {scannedI2C.settings?.foundAddresses && scannedI2C.settings.foundAddresses.length > 0 ? scannedI2C?.settings?.foundAddresses.map((addr, index) => { + return ( + + ) + }) : + + + No Sensors Found + + + } + + } + + + + + {addComponentDialog()} + + ) +} \ No newline at end of file diff --git a/src/device/autoDetect/ScannedI2C.tsx b/src/device/autoDetect/ScannedI2C.tsx new file mode 100644 index 0000000..db5954a --- /dev/null +++ b/src/device/autoDetect/ScannedI2C.tsx @@ -0,0 +1,150 @@ +import { Box, Button, Checkbox, FormControlLabel, Grid2, MenuItem, Radio, RadioGroup, TextField, Tooltip, Typography } from "@mui/material"; +import { Component } from "models"; +import { getAddressTypes, getFriendlyName, getSubtypes, Subtype } from "pbHelpers/ComponentType"; +import { ComponentAvailabilityMap, DevicePositions } from "pbHelpers/DeviceAvailability"; +import { GetProductAvailability } from "products/DeviceProduct"; +import { pond } from "protobuf-ts/pond"; +import { quack } from "protobuf-ts/quack"; +import { useEffect, useState } from "react"; + +interface Props { + decimalAddress: number + deviceProduct: pond.DeviceProduct + componentSelectionCallback: (component: Component, checked: boolean) => void + availablePositions: DevicePositions + sensorNum?: number +} + +export default function ScannedI2C(props: Props){ + const {decimalAddress, deviceProduct, componentSelectionCallback, availablePositions, sensorNum} = props + const [types, setTypes] = useState([]) + const [subtypeOptions, setSubtypeOptions] = useState>([]) + const [selectedType, setSelectedType] = useState(quack.ComponentType.COMPONENT_TYPE_INVALID) + const [selectedSubtype, setSelectedSubtype] = useState(0) + const [addressInUse, setAddressInUse] = useState(false) + + useEffect(()=>{ + let types: quack.ComponentType[] = [] + //find what component types use that address, this is different than the available positions passed in + //this is meant to get all possibilities according to product type and the given address, availablePositions is the restriction of what is available + let productAvailability = GetProductAvailability(deviceProduct) + if(productAvailability){ + let i2cMap = productAvailability.get(quack.AddressType.ADDRESS_TYPE_I2C) + if(i2cMap){ + i2cMap.forEach((val, key) => { + let addresses = val as number[] ?? [] + if(addresses.length > 0 && addresses.includes(decimalAddress)){ + types.push(key) + } + }) + } + } + //this if can be taken out if we dont want to select the first component type by default + if(types.length > 0) { + setSelectedType(types[0]) + buildSubtypeOptions(types[0]) + checkAddressAvailable(types[0]) + } + setTypes(types) + },[decimalAddress, deviceProduct]) + + const buildSubtypeOptions = (compType: quack.ComponentType) => { + let subtypes = getSubtypes(compType) + let validSub: Subtype[] = [] + //have to exclude subtypes that are not I2C + subtypes.forEach((sub,i) => { + let addrTypes = getAddressTypes(compType, sub.key) + if (addrTypes.includes(quack.AddressType.ADDRESS_TYPE_I2C)){ + validSub.push(sub) + } + }) + //set the selected on to be the first in the valid selection + if(validSub.length > 0){ + setSelectedSubtype(validSub[0].key) + } + setSubtypeOptions(validSub) + } + + const checkAddressAvailable = (compType: quack.ComponentType) => { + let i2cMap = availablePositions as ComponentAvailabilityMap + let compAddresses = i2cMap.get(compType) ?? [] + if (!compAddresses.includes(decimalAddress)){ + setAddressInUse(true) + }else{ + setAddressInUse(false) + } + } + + + + const componentSelected = (event: React.ChangeEvent, checked: boolean) => { + //build a component with given information and defaults for the rest + let component = Component.create() + component.settings.type = selectedType + component.settings.subtype = selectedSubtype + component.settings.addressType = quack.AddressType.ADDRESS_TYPE_I2C + component.settings.address = decimalAddress + component.settings.name = getFriendlyName(selectedType, selectedSubtype) + //return the component and the checked status to the parent + componentSelectionCallback(component, checked) + } + + + return ( + + {sensorNum && Sensor {sensorNum}} + + + { + let v = parseInt(value) + if (!isNaN(v)){ + buildSubtypeOptions(v) + checkAddressAvailable(v) + } + }}> + {types.map((type, i) => { + return ( + } + label={getFriendlyName(type)} + /> + ) + })} + + + + {subtypeOptions.length > 0 && + { + let val = +event.target.value + setSelectedSubtype(val) + }} + select> + {subtypeOptions.map(s => ( + {s.friendlyName} + ))} + + } + + + + } + /> + + + + + ) +} \ No newline at end of file diff --git a/src/models/Component.ts b/src/models/Component.ts index c9bbc2c..84f5574 100644 --- a/src/models/Component.ts +++ b/src/models/Component.ts @@ -3,6 +3,7 @@ import { quack } from "protobuf-ts/pond"; import { or } from "utils/types"; import { cloneDeep } from "lodash"; import { getSubtypes } from "pbHelpers/ComponentType"; +import { getFriendlyAddressTypeName, getHumanReadableAddress } from "pbHelpers/AddressType"; // import { getSubtypes } from "pbHelpers/ComponentType"; export class Component { @@ -105,4 +106,33 @@ export class Component { } return 0; } + + public addressDescription = (deviceProduct?: pond.DeviceProduct) => { + if ( + this.settings.addressType === quack.AddressType.ADDRESS_TYPE_CONFIGURABLE_PIN_ARRAY || + (this.settings.addressType >= quack.AddressType.ADDRESS_TYPE_PIN_OFFSET1 && + this.settings.addressType <= quack.AddressType.ADDRESS_TYPE_PIN_OFFSET100) + ) { + let addressDescription = getHumanReadableAddress( + this.settings.addressType, + this.settings.type, + this.settings.address, + deviceProduct + ); + if (addressDescription === "") { + addressDescription = "Internal"; + } + let port = "Port: " + addressDescription; + let cableID = ""; + if ( + this.settings.addressType >= quack.AddressType.ADDRESS_TYPE_PIN_OFFSET1 && + this.settings.addressType <= quack.AddressType.ADDRESS_TYPE_PIN_OFFSET100 + ) { + cableID = "Cable: " + (this.settings.addressType - 8); + } + return port + " " + cableID; + } else { + return getFriendlyAddressTypeName(this.settings.addressType); + } + }; } diff --git a/src/models/Device.ts b/src/models/Device.ts index b201407..6311981 100644 --- a/src/models/Device.ts +++ b/src/models/Device.ts @@ -33,6 +33,21 @@ const featureVersions: Map = new Map([ v2CellBlue: "2.0.44", v2EthBlue: "2.0.44" } + ],[ + "detectI2C", + { + photon: "NA", + electron: "NA", + v2Wifi: "2.1.6", + v2Cell: "2.1.6", + v2WifiS3: "2.1.6", + v2CellS3: "2.1.6", + v2CellBlack: "2.1.6", + v2CellGreen: "2.1.6", + v2WifiBlue: "2.1.6", + v2CellBlue: "2.1.6", + v2EthBlue: "2.1.6" + } ] ]); export class Device { diff --git a/src/pages/Device.tsx b/src/pages/Device.tsx index c6598fa..6a769c0 100644 --- a/src/pages/Device.tsx +++ b/src/pages/Device.tsx @@ -1,4 +1,4 @@ -import { Button, Divider, List, ListItem, Typography } from "@mui/material"; +import { Button, Card, Divider, List, ListItem, Typography } from "@mui/material"; import Grid from '@mui/material/Grid2'; import { Component, Device, Interaction, User } from "models"; import { getContextKeys, getContextTypes } from "pbHelpers/Context"; @@ -20,6 +20,7 @@ import { isController } from "pbHelpers/ComponentType"; import { or } from "utils"; import ComponentDiagnostics from "component/ComponentDiagnostics"; import DeviceWizard from "device/DeviceWizard"; +import DeviceScannedComponents from "device/autoDetect/DeviceScannedComponents"; export interface DevicePageData { device: Device; @@ -56,6 +57,7 @@ export default function DevicePage() { const [components, setComponents] = useState>(new Map()); const [diagnosticComponents, setDiagnosticComponents] = useState([]); + const [scannedAddresses, setScannedAddresses] = useState(undefined) // const [components, setComponents] = useState([]); const [addComponentManualDialogOpen, setAddComponentManualDialogOpen] = useState(false) @@ -162,8 +164,21 @@ export default function DevicePage() { .finally(() => setLoading(false)); } + const loadPortScan = () => { + deviceAPI.listFoundComponents(device.id()) + .then(resp => { + if (resp.data.foundComponents?.i2c){ + setScannedAddresses(resp.data.foundComponents ?? undefined) + } + }) + .catch(err => { + console.log(err) + }) + } + useEffect(() => { loadDevice() + loadPortScan() }, [deviceID, as]) const toggleNotificationPreference = () => { @@ -390,6 +405,8 @@ export default function DevicePage() { refreshCallback={loadDevice} /> + {/* add grid card here for I2C detected components */} + {diagnosticComponents.map(comp => ( ) : ( <> - + - - + {scannedAddresses && + + + + } + {diagnosticComponents.length > 0 && + + {diagnosticComponents.map(comp => ( - + + } )} @@ -443,7 +472,8 @@ export default function DevicePage() { { - deviceAPI.detectI2C(device.id()).then(resp => {console.log("No errors")}).catch(err => {console.log("error")}) + //deviceAPI.detectI2C(device.id()).then(resp => {console.log("No errors")}).catch(err => {console.log("error")}) + deviceAPI.listFoundComponents(device.id()).then(resp => console.log(resp)).catch(err => {console.log("errors")}) }} isPaused={false} isLoading={loading} diff --git a/src/pbHelpers/AddressTypes/I2C.ts b/src/pbHelpers/AddressTypes/I2C.ts index 7012eee..c17c743 100644 --- a/src/pbHelpers/AddressTypes/I2C.ts +++ b/src/pbHelpers/AddressTypes/I2C.ts @@ -12,7 +12,7 @@ export const I2C: AddressTypeExtension = { [quack.ComponentType.COMPONENT_TYPE_STEPPER_MOTOR, 0x13], [quack.ComponentType.COMPONENT_TYPE_PH, 0x3f], [quack.ComponentType.COMPONENT_TYPE_DHT, 0x3f], - [quack.ComponentType.COMPONENT_TYPE_VAPOUR_PRESSURE_DEFICIT, 0x3f], + // [quack.ComponentType.COMPONENT_TYPE_VAPOUR_PRESSURE_DEFICIT, 0x3f], //component type deprecated? [quack.ComponentType.COMPONENT_TYPE_CAPACITANCE, 0x4f], [quack.ComponentType.COMPONENT_TYPE_CAPACITOR_CABLE, 0x4f], [quack.ComponentType.COMPONENT_TYPE_SEN5X, 0x68], diff --git a/src/pbHelpers/DeviceAvailability.ts b/src/pbHelpers/DeviceAvailability.ts index 84cfa7e..c50a2a4 100644 --- a/src/pbHelpers/DeviceAvailability.ts +++ b/src/pbHelpers/DeviceAvailability.ts @@ -54,7 +54,7 @@ const DefaultAvailability: DeviceAvailabilityMap = new Map([ [quack.ComponentType.COMPONENT_TYPE_PRESSURE, [0x18]], [quack.ComponentType.COMPONENT_TYPE_DHT, [0x40]], - [quack.ComponentType.COMPONENT_TYPE_VAPOUR_PRESSURE_DEFICIT, [0x40]], + // [quack.ComponentType.COMPONENT_TYPE_VAPOUR_PRESSURE_DEFICIT, [0x40]], //component type deprecated? [quack.ComponentType.COMPONENT_TYPE_LIDAR, [0x62]], [quack.ComponentType.COMPONENT_TYPE_CO2, [0x61]], [quack.ComponentType.COMPONENT_TYPE_SEN5X, [0x69]] @@ -48,7 +48,7 @@ export const BindaptPlusModAvailability: DeviceAvailabilityMap = new Map< new Map([ //[quack.ComponentType.COMPONENT_TYPE_PRESSURE, [0x18]], [quack.ComponentType.COMPONENT_TYPE_DHT, [0x40]], - [quack.ComponentType.COMPONENT_TYPE_VAPOUR_PRESSURE_DEFICIT, [0x40]], + // [quack.ComponentType.COMPONENT_TYPE_VAPOUR_PRESSURE_DEFICIT, [0x40]], //component type deprecated? [quack.ComponentType.COMPONENT_TYPE_LIDAR, [0x62]], [quack.ComponentType.COMPONENT_TYPE_CO2, [0x61]], [quack.ComponentType.COMPONENT_TYPE_SEN5X, [0x69]] @@ -78,7 +78,7 @@ export const BindaptPlusProAvailability: DeviceAvailabilityMap = new Map< new Map([ [quack.ComponentType.COMPONENT_TYPE_PRESSURE, [0x18]], [quack.ComponentType.COMPONENT_TYPE_DHT, [0x40]], - [quack.ComponentType.COMPONENT_TYPE_VAPOUR_PRESSURE_DEFICIT, [0x40]], + // [quack.ComponentType.COMPONENT_TYPE_VAPOUR_PRESSURE_DEFICIT, [0x40]], [quack.ComponentType.COMPONENT_TYPE_LIDAR, [0x62]], [quack.ComponentType.COMPONENT_TYPE_CO2, [0x61]], [quack.ComponentType.COMPONENT_TYPE_SEN5X, [0x69]] @@ -109,7 +109,7 @@ export const BindaptPlusProModAvailability: DeviceAvailabilityMap = new Map< new Map([ //[quack.ComponentType.COMPONENT_TYPE_PRESSURE, [0x18]], [quack.ComponentType.COMPONENT_TYPE_DHT, [0x40]], - [quack.ComponentType.COMPONENT_TYPE_VAPOUR_PRESSURE_DEFICIT, [0x40]], + // [quack.ComponentType.COMPONENT_TYPE_VAPOUR_PRESSURE_DEFICIT, [0x40]], //component type deprecated? [quack.ComponentType.COMPONENT_TYPE_LIDAR, [0x62]], [quack.ComponentType.COMPONENT_TYPE_CO2, [0x61]], [quack.ComponentType.COMPONENT_TYPE_SEN5X, [0x69]] @@ -136,7 +136,7 @@ export const BindaptPlusLiteAvailability: DeviceAvailabilityMap = new Map< new Map([ [quack.ComponentType.COMPONENT_TYPE_PRESSURE, [0x18]], [quack.ComponentType.COMPONENT_TYPE_DHT, [0x40]], - [quack.ComponentType.COMPONENT_TYPE_VAPOUR_PRESSURE_DEFICIT, [0x40]], + // [quack.ComponentType.COMPONENT_TYPE_VAPOUR_PRESSURE_DEFICIT, [0x40]], //component type deprecated? [quack.ComponentType.COMPONENT_TYPE_LIDAR, [0x62]], [quack.ComponentType.COMPONENT_TYPE_CO2, [0x61]], [quack.ComponentType.COMPONENT_TYPE_SEN5X, [0x69]] @@ -192,7 +192,7 @@ export const BindaptUltimateAvailability: DeviceAvailabilityMap = new Map< new Map([ [quack.ComponentType.COMPONENT_TYPE_PRESSURE, [0x18]], [quack.ComponentType.COMPONENT_TYPE_DHT, [0x40]], - [quack.ComponentType.COMPONENT_TYPE_VAPOUR_PRESSURE_DEFICIT, [0x40]], + // [quack.ComponentType.COMPONENT_TYPE_VAPOUR_PRESSURE_DEFICIT, [0x40]], //component type deprecated? [quack.ComponentType.COMPONENT_TYPE_LIDAR, [0x62]], [quack.ComponentType.COMPONENT_TYPE_CO2, [0x61]], [quack.ComponentType.COMPONENT_TYPE_SEN5X, [0x69]] @@ -219,7 +219,7 @@ export const BinMonitorAvailability: DeviceAvailabilityMap = new Map< new Map([ [quack.ComponentType.COMPONENT_TYPE_PRESSURE, [0x18]], [quack.ComponentType.COMPONENT_TYPE_DHT, [0x40]], - [quack.ComponentType.COMPONENT_TYPE_VAPOUR_PRESSURE_DEFICIT, [0x40]], + // [quack.ComponentType.COMPONENT_TYPE_VAPOUR_PRESSURE_DEFICIT, [0x40]], //component type deprecated? [quack.ComponentType.COMPONENT_TYPE_LIDAR, [0x62]], [quack.ComponentType.COMPONENT_TYPE_CO2, [0x61]] ]) @@ -248,7 +248,7 @@ export const BindaptV2MonitorAvailability: DeviceAvailabilityMap = new Map< new Map([ //[quack.ComponentType.COMPONENT_TYPE_PRESSURE, [0x18]], [quack.ComponentType.COMPONENT_TYPE_DHT, [0x40]], - [quack.ComponentType.COMPONENT_TYPE_VAPOUR_PRESSURE_DEFICIT, [0x40]], + // [quack.ComponentType.COMPONENT_TYPE_VAPOUR_PRESSURE_DEFICIT, [0x40]], //component type deprecated? [quack.ComponentType.COMPONENT_TYPE_LIDAR, [0x62]], [quack.ComponentType.COMPONENT_TYPE_CO2, [0x61]], [quack.ComponentType.COMPONENT_TYPE_SEN5X, [0x69]] @@ -280,7 +280,7 @@ export const BindaptV2AutomateAvailability: DeviceAvailabilityMap = new Map< new Map([ //[quack.ComponentType.COMPONENT_TYPE_PRESSURE, [0x18]], [quack.ComponentType.COMPONENT_TYPE_DHT, [0x40]], - [quack.ComponentType.COMPONENT_TYPE_VAPOUR_PRESSURE_DEFICIT, [0x40]], + // [quack.ComponentType.COMPONENT_TYPE_VAPOUR_PRESSURE_DEFICIT, [0x40]], //component type deprecated? [quack.ComponentType.COMPONENT_TYPE_LIDAR, [0x62]], [quack.ComponentType.COMPONENT_TYPE_CO2, [0x61]], [quack.ComponentType.COMPONENT_TYPE_SEN5X, [0x69]] diff --git a/src/products/DeviceProduct.ts b/src/products/DeviceProduct.ts index 792be79..844e0be 100644 --- a/src/products/DeviceProduct.ts +++ b/src/products/DeviceProduct.ts @@ -64,7 +64,7 @@ const Weather: DeviceProductDescriber = { new Map([ [quack.ComponentType.COMPONENT_TYPE_PRESSURE, [0x18]], [quack.ComponentType.COMPONENT_TYPE_DHT, [0x40]], - [quack.ComponentType.COMPONENT_TYPE_VAPOUR_PRESSURE_DEFICIT, [0x40]], + // [quack.ComponentType.COMPONENT_TYPE_VAPOUR_PRESSURE_DEFICIT, [0x40]], //deprecated? [quack.ComponentType.COMPONENT_TYPE_LIDAR, [0x62]] ]) ], diff --git a/src/products/Nexus/NexusAvailability.ts b/src/products/Nexus/NexusAvailability.ts index 9f9fc57..2a1cf51 100644 --- a/src/products/Nexus/NexusAvailability.ts +++ b/src/products/Nexus/NexusAvailability.ts @@ -20,7 +20,7 @@ export const NexusSTAvailability: DeviceAvailabilityMap = new Map< new Map([ [quack.ComponentType.COMPONENT_TYPE_PRESSURE, [0x18]], [quack.ComponentType.COMPONENT_TYPE_DHT, [0x40]], - [quack.ComponentType.COMPONENT_TYPE_VAPOUR_PRESSURE_DEFICIT, [0x40]], + // [quack.ComponentType.COMPONENT_TYPE_VAPOUR_PRESSURE_DEFICIT, [0x40]], //component type deprecated? [quack.ComponentType.COMPONENT_TYPE_LIDAR, [0x62]], [quack.ComponentType.COMPONENT_TYPE_SEN5X, [0x69]] ]) diff --git a/src/providers/pond/deviceAPI.tsx b/src/providers/pond/deviceAPI.tsx index 512fad2..f42133f 100644 --- a/src/providers/pond/deviceAPI.tsx +++ b/src/providers/pond/deviceAPI.tsx @@ -23,6 +23,7 @@ export interface IDeviceAPIContext { ) => Promise>; getMulti: (ids: number[] | string[], otherTeam?: string) => Promise>; detectI2C: (id: number, otherTeam?: string) => Promise>; + listFoundComponents: (id: number, otherTeam?: string) => Promise> getGeoJson: (id: number | string, demo?: boolean, otherTeam?: string) => Promise; getMultiGeoJson: (ids: number[] | string[], otherTeam?: string) => Promise; list: ( @@ -960,6 +961,19 @@ export default function DeviceProvider(props: PropsWithChildren) { }) } + const listFoundComponents = (id: number, otherTeam?: string) => { + let url = "/devices/" + id + "/listScannedComponents"; + const view = otherTeam ? otherTeam : as + if(view) url = url + "?as=" + view + return new Promise>((resolve, reject) => { + get(pondURL(url)).then(resp => { + return resolve(resp) + }).catch(err => { + return reject(err) + }) + }) + } + return ( ) { buyData, updateComponentPreferences, listDeviceComponentPreferences, - detectI2C + detectI2C, + listFoundComponents }}> {children}