Caused a reguression with these changes, will revert to main to see what is different
This commit is contained in:
parent
fa6c998da2
commit
c56a5fd9e7
|
@ -36,8 +36,8 @@ class State {
|
||||||
uint64_t y;
|
uint64_t y;
|
||||||
uint64_t w;
|
uint64_t w;
|
||||||
uint64_t h;
|
uint64_t h;
|
||||||
bool active = false;
|
|
||||||
bool ERROR = false;
|
bool ERROR = false;
|
||||||
|
bool ACTIVE = false;
|
||||||
|
|
||||||
void error();
|
void error();
|
||||||
bool imageExists(string& image);
|
bool imageExists(string& image);
|
||||||
|
@ -45,8 +45,9 @@ 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 setHasAction () { ACTIVE = true; }
|
||||||
|
|
||||||
public :
|
public :
|
||||||
State();
|
State();
|
||||||
|
@ -58,8 +59,8 @@ class State {
|
||||||
vector<uint64_t> getExposure() { return exposure; }
|
vector<uint64_t> getExposure() { return exposure; }
|
||||||
vector<uint64_t> getPosition() { return { x, y, w, h }; }
|
vector<uint64_t> getPosition() { return { x, y, w, h }; }
|
||||||
bool isError () { return ERROR; }
|
bool isError () { return ERROR; }
|
||||||
void setInactive () { active = false; }
|
void performedAction () { ACTIVE = false; }
|
||||||
bool isActive () { return active; }
|
bool hasAction () { return ACTIVE; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
28
src/main.cpp
28
src/main.cpp
|
@ -38,8 +38,10 @@ State state;
|
||||||
|
|
||||||
uint64_t exposureTime = 0;
|
uint64_t exposureTime = 0;
|
||||||
steady_clock::time_point startTime;
|
steady_clock::time_point startTime;
|
||||||
|
|
||||||
|
bool newAction = false;
|
||||||
|
bool actionComplete = false;
|
||||||
bool displaying = false;
|
bool displaying = false;
|
||||||
bool completed = true;
|
|
||||||
bool timing = false;
|
bool timing = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -58,20 +60,24 @@ void actionDisplay () {
|
||||||
vector<uint64_t> exposure = state.getExposure();
|
vector<uint64_t> exposure = state.getExposure();
|
||||||
if (exposure.size() == 0) {
|
if (exposure.size() == 0) {
|
||||||
displaying = true;
|
displaying = true;
|
||||||
completed = true;
|
|
||||||
timing = false;
|
timing = false;
|
||||||
|
cout << "Displaying indefinitely" << endl;
|
||||||
|
actionComplete = true;
|
||||||
} else if (exposure.size() == 1) {
|
} else if (exposure.size() == 1) {
|
||||||
exposureTime = exposure[0];
|
exposureTime = exposure[0];
|
||||||
displaying = true;
|
displaying = true;
|
||||||
completed = false;
|
|
||||||
timing = true;
|
timing = true;
|
||||||
startTime = steady_clock::now();
|
startTime = steady_clock::now();
|
||||||
|
cout << "Displaying timed" << endl;
|
||||||
|
actionComplete = false;
|
||||||
} // multi channel case
|
} // multi channel case
|
||||||
}
|
}
|
||||||
|
|
||||||
void actionStop () {
|
void actionStop () {
|
||||||
|
cout << "Stopping display" << endl;
|
||||||
displaying = false;
|
displaying = false;
|
||||||
completed = true;
|
timing = false;
|
||||||
|
actionComplete = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void postAction () {
|
void postAction () {
|
||||||
|
@ -87,6 +93,7 @@ void postAction () {
|
||||||
} else {
|
} else {
|
||||||
cout << "Sent = " << outgoingMessage << endl;
|
cout << "Sent = " << outgoingMessage << endl;
|
||||||
}
|
}
|
||||||
|
actionComplete = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void actionLoad () {
|
void actionLoad () {
|
||||||
|
@ -115,6 +122,7 @@ void actionLoad () {
|
||||||
auto localCurrentTime = steady_clock::now();
|
auto localCurrentTime = steady_clock::now();
|
||||||
auto localElapsedTime = duration_cast<milliseconds>(localCurrentTime - localStartTime).count();
|
auto localElapsedTime = duration_cast<milliseconds>(localCurrentTime - localStartTime).count();
|
||||||
cout << "actionLoad() [" << localElapsedTime << " ms]" << endl;
|
cout << "actionLoad() [" << localElapsedTime << " ms]" << endl;
|
||||||
|
actionComplete = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadBlank () {
|
void loadBlank () {
|
||||||
|
@ -143,7 +151,8 @@ void initImageTexture() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void display () {
|
void display () {
|
||||||
if (state.isActive()) {
|
if (state.hasAction()) {
|
||||||
|
actionComplete = false;
|
||||||
if (state.getAction() == LOAD) {
|
if (state.getAction() == LOAD) {
|
||||||
actionLoad();
|
actionLoad();
|
||||||
} else if (state.getAction() == DISPLAY) {
|
} else if (state.getAction() == DISPLAY) {
|
||||||
|
@ -151,7 +160,9 @@ void display () {
|
||||||
} else if (state.getAction() == STOP) {
|
} else if (state.getAction() == STOP) {
|
||||||
actionStop();
|
actionStop();
|
||||||
}
|
}
|
||||||
state.setInactive();
|
state.performedAction();
|
||||||
|
}
|
||||||
|
if (actionComplete) {
|
||||||
postAction();
|
postAction();
|
||||||
}
|
}
|
||||||
if (displaying && timing) {
|
if (displaying && timing) {
|
||||||
|
@ -160,7 +171,8 @@ void display () {
|
||||||
if (elapsedTime > exposureTime) {
|
if (elapsedTime > exposureTime) {
|
||||||
cout << "Exposed = " << elapsedTime << " ms" << endl;
|
cout << "Exposed = " << elapsedTime << " ms" << endl;
|
||||||
displaying = false;
|
displaying = false;
|
||||||
completed = true;
|
timing = false;
|
||||||
|
actionComplete = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,10 +185,10 @@ void display () {
|
||||||
|
|
||||||
if (displaying) {
|
if (displaying) {
|
||||||
glBindTexture(GL_TEXTURE_2D, imageTexture);
|
glBindTexture(GL_TEXTURE_2D, imageTexture);
|
||||||
|
cout << "Displaying image" << endl;
|
||||||
} else {
|
} else {
|
||||||
glBindTexture(GL_TEXTURE_2D, blankTexture);
|
glBindTexture(GL_TEXTURE_2D, blankTexture);
|
||||||
}
|
}
|
||||||
|
|
||||||
glBegin(GL_QUADS); // front face
|
glBegin(GL_QUADS); // front face
|
||||||
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 0.0f); //bottom right
|
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 0.0f); //bottom right
|
||||||
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 0.0f); //top right
|
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 0.0f); //top right
|
||||||
|
|
|
@ -56,19 +56,26 @@ 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) {
|
||||||
exposure = { msgData["exposure"][0], msgData["exposure"][1], msgData["exposure"][2] };
|
exposure = { msgData["exposure"][0], msgData["exposure"][1], msgData["exposure"][2] };
|
||||||
cout << "Exposure[0] = " << msgData["exposure"][0] << " ms, [1] = " << msgData["exposure"][1] << " ms, [2] = " << msgData["exposure"][2] << " ms" << endl;
|
cout << "Exposure[0] = " << msgData["exposure"][0] << " ms, [1] = " << msgData["exposure"][1] << " ms, [2] = " << msgData["exposure"][2] << " ms" << endl;
|
||||||
}*/ else {
|
} else {
|
||||||
error();
|
error();
|
||||||
cerr << "Exposure array is incorrect length, " << msgData["exposure"].size() << endl;
|
cerr << "Exposure array is incorrect length, " << msgData["exposure"].size() << endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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,9 +102,11 @@ 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();
|
setHasAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
string State::createMessage (bool success) {
|
string State::createMessage (bool success) {
|
||||||
|
|
|
@ -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,73 @@ 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, 0, 0, 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;
|
//actionStart(img);
|
||||||
delete data.position;
|
//
|
||||||
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', () => {
|
||||||
|
|
Loading…
Reference in New Issue