Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i have added tof_imager sensor in simulator #438

Merged
merged 2 commits into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,16 @@ Blockly.Generator.Simulator.forBlock["sensebox_esp32s2_light"] = function () {
return [code, Blockly.Generator.Simulator.ORDER_ATOMIC];
};

Blockly.Generator.Simulator.forBlock["sensebox_tof_imager"] = function () {
Blockly.Generator.Simulator.modules_["sensebox_tof_imager"] = "sensebox_tof_imager";

var dropdown_name = this.getFieldValue("dropdown");
var code = dropdown_name === "DistanzCM" ?
"readDistance()" :
"getDistanceBitmap()";
return [code, Blockly.Generator.Simulator.ORDER_ATOMIC];

}

Blockly.Generator.Simulator.forBlock["sensebox_sensor_bme680_bsec"] = function () {
Blockly.Generator.Simulator.modules_["sensebox_sensor_bme680_bsec"] = "sensebox_sensor_bme680_bsec";
Expand Down
3 changes: 2 additions & 1 deletion src/components/Simulator/flow.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import { useCallback, useEffect, memo } from "react";
import {
ReactFlow,
Expand All @@ -18,6 +17,7 @@ import WaterTemp from "./nodes/watertemp";
import SMT50 from "./nodes/smt50";
import store from "../../store";
import photodiode from "./nodes/photodiode";
import tofimager from "./nodes/tofimager";
import bme680 from "./nodes/bme680";
import scd30 from "./nodes/scd30";
import dps310 from "./nodes/dps310";
Expand All @@ -29,6 +29,7 @@ const nodeTypes = {
senseBox_display: Display,
senseBox_waterTemp: WaterTemp,
sensebox_esp32s2_light: photodiode,
sensebox_tof_imager: tofimager,
sensebox_sensor_bme680_bsec: bme680,
senseBox_smt50: SMT50,
sensebox_scd30: scd30,
Expand Down
2 changes: 2 additions & 0 deletions src/components/Simulator/init/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import initLightUv from "./sensors/lightUv";
import initPd from "./sensors/photodiode";
import initSCD30 from "./sensors/scd30";
import initTime from "./time";
import initTOFImager from "./sensors/tofimager";
import initSMT50 from "./sensors/smt50";

export default function initSimulator(interpreter, globalObject) {
Expand All @@ -20,6 +21,7 @@ export default function initSimulator(interpreter, globalObject) {
initLightUv(interpreter, globalObject);
initNeopixel(interpreter, globalObject);
initPd(interpreter, globalObject);
initTOFImager(interpreter, globalObject);
initBME680(interpreter, globalObject);
initSMT50(interpreter, globalObject);
initSCD30(interpreter, globalObject);
Expand Down
11 changes: 11 additions & 0 deletions src/components/Simulator/init/sensors/tofimager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default function initTOFImager(interpreter, globalObject) {
// Define distance reading function
var wrapper = function readDistance() {
return document.getElementById("distance-slider").value;
};
interpreter.setProperty(
globalObject,
"readDistance",
interpreter.createNativeFunction(wrapper)
);
}
29 changes: 29 additions & 0 deletions src/components/Simulator/nodes/tofimager/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React, { memo } from "react";
import { Handle, Position } from "@xyflow/react";
import SensorGraphic from "./tofimager.png";
import SensorNode from "../../uiComponents/SensorNode";

const tofimager = ({ data }) => {
const sensorConfigTOF = [
{
id: "distance",
emoji: "📏",
label: "Distance (mm)",
min: 0,
max: 4000,
step: 1,
initial: 1000
}
];

return (
<SensorNode
title="TOF Imager"
sensors={sensorConfigTOF}
imageSrc={SensorGraphic}
maxWidth="150px"
/>
);
};

export default memo(tofimager);
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.