Pulled over working features from regression branch. Found that macOS behavior is the issue.

This commit is contained in:
Matt McWilliams 2024-05-14 19:06:43 -04:00
parent fa6c998da2
commit 09ca10947a
4 changed files with 89 additions and 36 deletions

View File

@ -45,6 +45,7 @@ class State {
void setImage(json& msgData); void setImage(json& msgData);
void setMode(json& msgData); void setMode(json& msgData);
void setExposure(json& msgData); void setExposure(json& msgData);
void setNoExposure();
void setPosition(json& msgData); void setPosition(json& msgData);
void setActive () { active = true; } void setActive () { active = true; }

View File

@ -152,14 +152,20 @@ void display () {
actionStop(); actionStop();
} }
state.setInactive(); state.setInactive();
postAction();
} }
if (completed) {
postAction();
completed = false;
}
if (displaying && timing) { if (displaying && timing) {
auto currentTime = steady_clock::now(); auto currentTime = steady_clock::now();
auto elapsedTime = duration_cast<milliseconds>(currentTime - startTime).count(); auto elapsedTime = duration_cast<milliseconds>(currentTime - startTime).count();
if (elapsedTime > exposureTime) { if (elapsedTime > exposureTime) {
cout << "Exposed = " << elapsedTime << " ms" << endl; cout << "Exposed = " << elapsedTime << " ms" << endl;
displaying = false; displaying = false;
timing = false;
completed = true; completed = true;
} }
} }

View File

@ -56,7 +56,9 @@ void State::setPosition (json& msgData) {
} }
void State::setExposure (json& msgData) { void State::setExposure (json& msgData) {
if (msgData["exposure"].size() == 1) { if (msgData["exposure"].size() == 0) {
setNoExposure();
} else if (msgData["exposure"].size() == 1) {
exposure = { msgData["exposure"][0] }; exposure = { msgData["exposure"][0] };
cout << "Exposure = " << msgData["exposure"][0] << " ms" << endl; cout << "Exposure = " << msgData["exposure"][0] << " ms" << endl;
} /*else if (msgData["exposure"].size() == 3) { } /*else if (msgData["exposure"].size() == 3) {
@ -69,6 +71,11 @@ void State::setExposure (json& msgData) {
} }
} }
void State::setNoExposure () {
exposure = {};
cout << "No exposure, display indefinitely" << endl;
}
void State::receiveMessage (string msgString) { void State::receiveMessage (string msgString) {
ERROR = false; ERROR = false;
json msgData = json::parse(msgString); json msgData = json::parse(msgString);
@ -95,6 +102,8 @@ void State::receiveMessage (string msgString) {
if (action == DISPLAY && msgData.contains("exposure")) { if (action == DISPLAY && msgData.contains("exposure")) {
setExposure(msgData); setExposure(msgData);
} else if (action == DISPLAY && !msgData.contains("exposure")) {
setNoExposure();
} }
setActive(); setActive();

View File

@ -1,10 +1,22 @@
const net = require('net'); const net = require('net');
const { resolve } = require('path'); const { resolve } = require('path');
/**
Actions
0 = NONE,
1 = LOAD,
2 = DISPLAY,
3 = STOP
**/
const serverAddress = 'localhost'; const serverAddress = 'localhost';
const serverPort = 8081; const serverPort = 8081;
const client = new net.Socket(); const client = new net.Socket();
let sent = 0;
console.log(`Connecting to ${serverAddress}:${serverPort}...`); console.log(`Connecting to ${serverAddress}:${serverPort}...`);
@ -14,49 +26,74 @@ async function delay (ms) {
}); });
} }
client.connect(serverPort, serverAddress, async () => { function send (data) {
const data = { const str = JSON.stringify(data);
action : 1, sent = +new Date();
image: resolve('./img/4kSnake.png'), console.log(`[${sent}] SENDING ` + str);
client.write(str);
}
function actionLoad (img, x, y, w, h) {
const obj = {
action : 1, //LOAD
image : resolve(img),
position : { position : {
x: 100, x,
y : 100, y,
w : 320, w,
h : 320 h
} }
}; };
console.log('SENDING'); send(obj);
console.log(data); }
client.write(JSON.stringify(data));
function actionExpose (img, exposure) {
const obj = {
action : 2, //DISPLAY
image : resolve(img),
exposure : [ exposure ]
};
send(obj);
}
function actionStart (img) {
const obj = {
action : 2, //DISPLAY
image : resolve(img)
};
send(obj);
}
function actionStop (img) {
const obj = {
action : 3, //STOP
image : resolve(img)
}
}
client.connect(serverPort, serverAddress, async () => {
const img = './img/4kSnake.png';
actionLoad(img, 0, 0, 320, 320);
//
await delay(2000); await delay(2000);
data.action = 2; actionExpose(img, 4000);
delete data.position //actionStart(img);
data.exposure = [ 4000 ]; //
console.log('SENDING'); await delay(8000);
console.log(data); actionLoad(img, 100, 100, 640, 640);
client.write(JSON.stringify(data)); //
await delay(6000);
data.action = 1;
data.position = { x: 50, y : 50, w : 320, h : 320 };
console.log('SENDING');
console.log(data);
client.write(JSON.stringify(data));
await delay(1000); await delay(1000);
data.action = 2; actionExpose(img, 4000);
delete data.position; //actionStart(img);
console.log('SENDING'); //
console.log(data);
client.write(JSON.stringify(data));
await delay(2000); await delay(2000);
data.action = 3; //actionStop(img);
console.log('SENDING');
console.log(data);
client.write(JSON.stringify(data));
}); });
client.on('data', (data) => { client.on('data', (data) => {
console.log('RECEIVED'); const received = +new Date();
console.log(data.toString()); console.log(`[${received}] RECEIVED ` + data.toString());
console.log(`DIFF ${received - sent}`);
}); });
client.on('close', () => { client.on('close', () => {