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.

This commit is contained in:
mmcwilliams 2024-04-14 14:48:13 -06:00
parent ba3ddf82de
commit 3addc7464f
3 changed files with 50 additions and 14 deletions

View File

@ -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<milliseconds>(currentTime - startTime).count();
@ -41,9 +46,11 @@ void displayQuad() {
quadCondVar.wait(lock, [&] { return shouldDisplayQuad; });
localShouldDisplayQuad = shouldDisplayQuad;
}
if (localShouldDisplayQuad && elapsedTime < DISPLAY_DURATION) {
glColor3f(1.0f, 0.0f, 0.0f);
} else {
glColor3f(0.0f, 0.0f, 0.0f);
}
glBegin(GL_QUADS);
glVertex2f(-0.5f, -0.5f);
@ -51,10 +58,6 @@ void displayQuad() {
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);
}
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<mutex> lock(quadMutex);
shouldDisplayQuad = true;
@ -115,6 +123,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) {
cerr << "Error creating socket" << endl;

27
send.js Normal file
View File

@ -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);
});

View File

@ -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)