-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
local pipeName = "\\\\.\\pipe\\AutoDepth" | ||
|
||
-- Oscillation logic | ||
local value = 0.5 | ||
local decreasing = true | ||
|
||
local function updateValue() | ||
if decreasing then | ||
value = value - 0.1 | ||
if value <= 0.1 then | ||
decreasing = false | ||
end | ||
else | ||
value = value + 0.1 | ||
if value >= 0.5 then | ||
decreasing = true | ||
end | ||
end | ||
return string.format("%.2f", value) -- Format as a string with 2 decimal places | ||
end | ||
|
||
while true do | ||
-- Try to open the named pipe for writing | ||
local pipe = io.open(pipeName, "w") | ||
|
||
if not pipe then | ||
print("Waiting for C++ server to start...") | ||
os.execute("timeout 1 > nul") -- Wait 1 second before retrying (Windows-compatible) | ||
else | ||
print("Connected to named pipe! Sending values...") | ||
|
||
-- Continuously write oscillating values | ||
while true do | ||
local oscillatingValue = updateValue() | ||
|
||
-- Write value to the named pipe | ||
pipe:write(oscillatingValue .. "\n") | ||
pipe:flush() | ||
|
||
print("Sent:", oscillatingValue) | ||
|
||
-- Sleep for 100ms before next update | ||
os.execute("timeout 1 > nul") -- Windows-compatible sleep | ||
end | ||
|
||
-- Close the pipe | ||
pipe:close() | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters