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 w;
|
||||
uint64_t h;
|
||||
bool active = false;
|
||||
bool ERROR = false;
|
||||
bool ACTIVE = false;
|
||||
|
||||
void error();
|
||||
bool imageExists(string& image);
|
||||
|
@ -45,8 +45,9 @@ class State {
|
|||
void setImage(json& msgData);
|
||||
void setMode(json& msgData);
|
||||
void setExposure(json& msgData);
|
||||
void setNoExposure();
|
||||
void setPosition(json& msgData);
|
||||
void setActive () { active = true; }
|
||||
void setHasAction () { ACTIVE = true; }
|
||||
|
||||
public :
|
||||
State();
|
||||
|
@ -58,8 +59,8 @@ class State {
|
|||
vector<uint64_t> getExposure() { return exposure; }
|
||||
vector<uint64_t> getPosition() { return { x, y, w, h }; }
|
||||
bool isError () { return ERROR; }
|
||||
void setInactive () { active = false; }
|
||||
bool isActive () { return active; }
|
||||
void performedAction () { ACTIVE = false; }
|
||||
bool hasAction () { return ACTIVE; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
28
src/main.cpp
28
src/main.cpp
|
@ -38,8 +38,10 @@ State state;
|
|||
|
||||
uint64_t exposureTime = 0;
|
||||
steady_clock::time_point startTime;
|
||||
|
||||
bool newAction = false;
|
||||
bool actionComplete = false;
|
||||
bool displaying = false;
|
||||
bool completed = true;
|
||||
bool timing = false;
|
||||
|
||||
/**
|
||||
|
@ -58,20 +60,24 @@ void actionDisplay () {
|
|||
vector<uint64_t> exposure = state.getExposure();
|
||||
if (exposure.size() == 0) {
|
||||
displaying = true;
|
||||
completed = true;
|
||||
timing = false;
|
||||
cout << "Displaying indefinitely" << endl;
|
||||
actionComplete = true;
|
||||
} else if (exposure.size() == 1) {
|
||||
exposureTime = exposure[0];
|
||||
displaying = true;
|
||||
completed = false;
|
||||
timing = true;
|
||||
startTime = steady_clock::now();
|
||||
cout << "Displaying timed" << endl;
|
||||
actionComplete = false;
|
||||
} // multi channel case
|
||||
}
|
||||
|
||||
void actionStop () {
|
||||
cout << "Stopping display" << endl;
|
||||
displaying = false;
|
||||
completed = true;
|
||||
timing = false;
|
||||
actionComplete = true;
|
||||
}
|
||||
|
||||
void postAction () {
|
||||
|
@ -87,6 +93,7 @@ void postAction () {
|
|||
} else {
|
||||
cout << "Sent = " << outgoingMessage << endl;
|
||||
}
|
||||
actionComplete = false;
|
||||
}
|
||||
|
||||
void actionLoad () {
|
||||
|
@ -115,6 +122,7 @@ void actionLoad () {
|
|||
auto localCurrentTime = steady_clock::now();
|
||||
auto localElapsedTime = duration_cast<milliseconds>(localCurrentTime - localStartTime).count();
|
||||
cout << "actionLoad() [" << localElapsedTime << " ms]" << endl;
|
||||
actionComplete = true;
|
||||
}
|
||||
|
||||
void loadBlank () {
|
||||
|
@ -143,7 +151,8 @@ void initImageTexture() {
|
|||
}
|
||||
|
||||
void display () {
|
||||
if (state.isActive()) {
|
||||
if (state.hasAction()) {
|
||||
actionComplete = false;
|
||||
if (state.getAction() == LOAD) {
|
||||
actionLoad();
|
||||
} else if (state.getAction() == DISPLAY) {
|
||||
|
@ -151,7 +160,9 @@ void display () {
|
|||
} else if (state.getAction() == STOP) {
|
||||
actionStop();
|
||||
}
|
||||
state.setInactive();
|
||||
state.performedAction();
|
||||
}
|
||||
if (actionComplete) {
|
||||
postAction();
|
||||
}
|
||||
if (displaying && timing) {
|
||||
|
@ -160,7 +171,8 @@ void display () {
|
|||
if (elapsedTime > exposureTime) {
|
||||
cout << "Exposed = " << elapsedTime << " ms" << endl;
|
||||
displaying = false;
|
||||
completed = true;
|
||||
timing = false;
|
||||
actionComplete = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -173,10 +185,10 @@ void display () {
|
|||
|
||||
if (displaying) {
|
||||
glBindTexture(GL_TEXTURE_2D, imageTexture);
|
||||
cout << "Displaying image" << endl;
|
||||
} else {
|
||||
glBindTexture(GL_TEXTURE_2D, blankTexture);
|
||||
}
|
||||
|
||||
glBegin(GL_QUADS); // front face
|
||||
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
|
||||
|
|
|
@ -56,19 +56,26 @@ 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) {
|
||||
} else if (msgData["exposure"].size() == 3) {
|
||||
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;
|
||||
}*/ else {
|
||||
} else {
|
||||
error();
|
||||
cerr << "Exposure array is incorrect length, " << msgData["exposure"].size() << endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void State::setNoExposure () {
|
||||
exposure = {};
|
||||
cout << "No exposure, display indefinitely" << endl;
|
||||
}
|
||||
|
||||
void State::receiveMessage (string msgString) {
|
||||
ERROR = false;
|
||||
json msgData = json::parse(msgString);
|
||||
|
@ -95,9 +102,11 @@ void State::receiveMessage (string msgString) {
|
|||
|
||||
if (action == DISPLAY && msgData.contains("exposure")) {
|
||||
setExposure(msgData);
|
||||
} else if (action == DISPLAY && !msgData.contains("exposure")) {
|
||||
setNoExposure();
|
||||
}
|
||||
|
||||
setActive();
|
||||
setHasAction();
|
||||
}
|
||||
|
||||
string State::createMessage (bool success) {
|
||||
|
|
|
@ -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,73 @@ 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, 0, 0, 640, 640);
|
||||
//
|
||||
await delay(1000);
|
||||
data.action = 2;
|
||||
delete data.position;
|
||||
console.log('SENDING');
|
||||
console.log(data);
|
||||
client.write(JSON.stringify(data));
|
||||
//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', () => {
|
||||
|
|
Loading…
Reference in New Issue