From 3addc7464f90af9792e0eef5730df9d99aa6c752 Mon Sep 17 00:00:00 2001 From: mmcwilliams Date: Sun, 14 Apr 2024 14:48:13 -0600 Subject: [PATCH] Updates in attempt to get window to start on launch in macOS. Not happening but it's a quick hack to start it with a message. Add a send.js file for node. --- main.cpp | 32 +++++++++++++++++++++----------- send.js | 27 +++++++++++++++++++++++++++ send.py | 5 ++--- 3 files changed, 50 insertions(+), 14 deletions(-) create mode 100644 send.js diff --git a/main.cpp b/main.cpp index dd06226..8116367 100644 --- a/main.cpp +++ b/main.cpp @@ -21,7 +21,7 @@ using namespace std; using namespace std::chrono; using namespace nlohmann; -const int DISPLAY_DURATION = 2000; +volatile int DISPLAY_DURATION = 2000; const int PORT = 8081; steady_clock::time_point startTime; @@ -31,6 +31,11 @@ condition_variable quadCondVar; void displayQuad() { glClear(GL_COLOR_BUFFER_BIT); + glEnable(GL_TEXTURE_2D); + glViewport(0, 0, 500, 500); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); auto currentTime = steady_clock::now(); auto elapsedTime = duration_cast(currentTime - startTime).count(); @@ -41,21 +46,19 @@ void displayQuad() { quadCondVar.wait(lock, [&] { return shouldDisplayQuad; }); localShouldDisplayQuad = shouldDisplayQuad; } - if (localShouldDisplayQuad && elapsedTime < DISPLAY_DURATION) { glColor3f(1.0f, 0.0f, 0.0f); - - glBegin(GL_QUADS); - glVertex2f(-0.5f, -0.5f); - glVertex2f(-0.5f, 0.5f); - glVertex2f(0.5f, 0.5f); - glVertex2f(0.5f, -0.5f); - glEnd(); } else { - glClearColor(0.0f, 0.0f, 0.0f, 1.0f); - glClear(GL_COLOR_BUFFER_BIT); + glColor3f(0.0f, 0.0f, 0.0f); } + glBegin(GL_QUADS); + glVertex2f(-0.5f, -0.5f); + glVertex2f(-0.5f, 0.5f); + glVertex2f(0.5f, 0.5f); + glVertex2f(0.5f, -0.5f); + glEnd(); + glutSwapBuffers(); } @@ -87,6 +90,11 @@ void handleTCPConnection(int serverSocket) { json jsonData = json::parse(jsonString); cout << "Received JSON: " << jsonData << endl; + if (jsonData.contains("rgb")) { + DISPLAY_DURATION = jsonData["rgb"]; + cout << "Set exposure time to " << DISPLAY_DURATION << "ms" << endl; + } + { lock_guard lock(quadMutex); shouldDisplayQuad = true; @@ -114,6 +122,8 @@ int main(int argc, char** argv) { glutDisplayFunc(displayQuad); glutTimerFunc(0, timer, 0); + + startTime = steady_clock::now(); int serverSocket = socket(AF_INET, SOCK_STREAM, 0); if (serverSocket < 0) { diff --git a/send.js b/send.js new file mode 100644 index 0000000..7a534c5 --- /dev/null +++ b/send.js @@ -0,0 +1,27 @@ +const net = require('net'); + +const serverAddress = 'localhost'; +const serverPort = 8081; + +const client = new net.Socket(); + +console.log(`Connecting to ${serverAddress}:${serverPort}...`); + +client.connect(serverPort, serverAddress, () => { + const data = { + file: 'filename.tif', + rgb: 1000 + }; + const jsonData = JSON.stringify(data); + + console.log(`Sending: ${jsonData}`); + client.write(jsonData); +}); + +client.on('close', () => { + console.log('Closing connection'); +}); + +client.on('error', (err) => { + console.error('Error:', err); +}); \ No newline at end of file diff --git a/send.py b/send.py index d39d297..5c47bef 100644 --- a/send.py +++ b/send.py @@ -9,9 +9,8 @@ client_socket.connect(server_address) try: data = { - 'message': 'Hello from Python', - 'value': 42, - 'enabled': True + 'file': 'filename.tif', + 'rgb': 1000 } json_data = json.dumps(data)