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 setMode(json& msgData);
void setExposure(json& msgData);
void setNoExposure();
void setPosition(json& msgData);
void setActive () { active = true; }

View File

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

View File

@ -56,7 +56,9 @@ void State::setPosition (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] };
cout << "Exposure = " << msgData["exposure"][0] << " ms" << endl;
} /*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) {
ERROR = false;
json msgData = json::parse(msgString);
@ -95,6 +102,8 @@ void State::receiveMessage (string msgString) {
if (action == DISPLAY && msgData.contains("exposure")) {
setExposure(msgData);
} else if (action == DISPLAY && !msgData.contains("exposure")) {
setNoExposure();
}
setActive();

View File

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