mirror of
https://github.com/eddyem/zeiss_utils.git
synced 2025-12-06 10:45:17 +03:00
fixed web-interface
This commit is contained in:
parent
8ce37f4151
commit
9081ca21a0
@ -1,6 +1,8 @@
|
|||||||
Foc = function(){
|
Foc = function(){
|
||||||
// const REQ_PATH=window.location.hostname+":4444/";
|
// const REQ_PATH=window.location.hostname+":4444/";
|
||||||
const REQ_PATH="http://dasha.sao.ru:4444/";
|
const REQ_PATH="http://ztcs.sao.ru:4444/";
|
||||||
|
const DEBUG = false; // set to true for debug
|
||||||
|
var targspeeds = [ 220, 500, 800, 1200 ]; // four target speeds
|
||||||
var minVal=0.01, maxVal=76.5, curVal = 3.0, curSpeed = 1;
|
var minVal=0.01, maxVal=76.5, curVal = 3.0, curSpeed = 1;
|
||||||
var timeout_upd, timeout_msg;
|
var timeout_upd, timeout_msg;
|
||||||
// ID
|
// ID
|
||||||
@ -24,25 +26,41 @@ function sendrequest(req_STR, _onOK){
|
|||||||
request.send(req_STR);
|
request.send(req_STR);
|
||||||
timeout_id = setTimeout(function(){blockMsg("Request timeout");}, 3000);
|
timeout_id = setTimeout(function(){blockMsg("Request timeout");}, 3000);
|
||||||
}
|
}
|
||||||
|
function Log(x){
|
||||||
|
if(DEBUG) console.log(x);
|
||||||
|
}
|
||||||
// show message blocking all
|
// show message blocking all
|
||||||
function blockMsg(txt, bgcolor){
|
function blockMsg(txt, bgcolor){
|
||||||
$("shadow").style.display = "block";
|
$("shadow").style.display = "block";
|
||||||
if(!bgcolor) bgcolor = "red";
|
if(!bgcolor) bgcolor = "gray";
|
||||||
|
$("shadow").style.backgroundColor = bgcolor;
|
||||||
$("shadow").innerHTML = txt.replace("\n", "<br>");
|
$("shadow").innerHTML = txt.replace("\n", "<br>");
|
||||||
}
|
}
|
||||||
|
function btnsStat(moving){
|
||||||
|
var color = moving ? "red" : "green";
|
||||||
|
$("Fstop").disabled = !moving;
|
||||||
|
$("Fstop").style.backgroundColor = moving ? "green" : "red";
|
||||||
|
$("Fset").disabled = moving;
|
||||||
|
$("Fset").style.backgroundColor = color;
|
||||||
|
$("F-").disabled = moving;
|
||||||
|
$("F-").style.backgroundColor = color;
|
||||||
|
$("F+").disabled = moving;
|
||||||
|
$("F+").style.backgroundColor = color;
|
||||||
|
}
|
||||||
// parse answer for status request
|
// parse answer for status request
|
||||||
function chkStatus(req){
|
function chkStatus(req){
|
||||||
var msg = req.responseText;
|
var msg = req.responseText;
|
||||||
console.log("Get status message: " + msg);
|
Log("Get status message: " + msg);
|
||||||
if(msg == "OK"){
|
if(msg == "OK" || msg == "moving"){
|
||||||
$("shadow").innerHTML = "";
|
$("shadow").innerHTML = "";
|
||||||
$("shadow").style.display = "none";
|
$("shadow").style.display = "none";
|
||||||
|
btnsStat(msg == "moving");
|
||||||
}else blockMsg(msg);
|
}else blockMsg(msg);
|
||||||
};
|
};
|
||||||
// parse answer for command requests
|
// parse answer for command requests
|
||||||
function chkCmd(req){
|
function chkCmd(req){
|
||||||
var msg = req.responseText;
|
var msg = req.responseText;
|
||||||
console.log("Get cmd answer: " + msg);
|
Log("Get cmd answer: " + msg);
|
||||||
if(msg != "OK") alert(msg);
|
if(msg != "OK") alert(msg);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@ -63,13 +81,13 @@ function ch_status(txt, bgcolor){
|
|||||||
}*/
|
}*/
|
||||||
var first = true;
|
var first = true;
|
||||||
function chF(req){
|
function chF(req){
|
||||||
console.log(req.responseText);
|
Log(req.responseText);
|
||||||
curVal = Number(req.responseText);
|
curVal = Number(req.responseText);
|
||||||
if(first){
|
if(first){
|
||||||
$('focSet').value = curVal;
|
$('focSet').value = curVal;
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
$('curFval').innerHTML = curVal;
|
$('curFval').innerHTML = Number(Math.round(curVal*100.)/100.).toFixed(2);
|
||||||
//$('focSlider').value = curVal;
|
//$('focSlider').value = curVal;
|
||||||
}
|
}
|
||||||
function getdata(){
|
function getdata(){
|
||||||
@ -78,7 +96,31 @@ function getdata(){
|
|||||||
sendrequest("status", chkStatus);
|
sendrequest("status", chkStatus);
|
||||||
timeout_upd = setTimeout(getdata, 1000);
|
timeout_upd = setTimeout(getdata, 1000);
|
||||||
}
|
}
|
||||||
|
// set limits
|
||||||
|
function getLimits(req){
|
||||||
|
var lims = {};
|
||||||
|
req.responseText.split('\n').forEach(function(value){
|
||||||
|
var keypair = value.split('=');
|
||||||
|
lims[keypair[0]] = keypair[1];
|
||||||
|
});
|
||||||
|
if(lims["focmin"]){ // focmin=2.75
|
||||||
|
$('focSet').min = minVal = Number(lims["focmin"]);
|
||||||
|
Log("focmin: " + minVal);
|
||||||
|
}
|
||||||
|
if(lims["focmax"]){ // focmax=76
|
||||||
|
$('focSet').max = maxVal = Number(lims["focmax"]);
|
||||||
|
Log("focmax: " + maxVal);
|
||||||
|
}
|
||||||
|
if(lims["maxspeed"] && lims["minspeed"]){
|
||||||
|
var minspd = Number(lims["minspeed"]); // minspeed=350
|
||||||
|
var maxspd = Number(lims["maxspeed"]); // maxspeed=1200
|
||||||
|
var w = (maxspd - minspd)/3;
|
||||||
|
for(i = 0; i < 4; ++i){
|
||||||
|
targspeeds[i] = Math.round(minspd + w*i);
|
||||||
|
Log("targspeeds["+i+"]="+targspeeds[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// init all things
|
// init all things
|
||||||
function FirstRun(){
|
function FirstRun(){
|
||||||
blockMsg("init", "black");
|
blockMsg("init", "black");
|
||||||
@ -88,6 +130,7 @@ function FirstRun(){
|
|||||||
F.value = curVal;
|
F.value = curVal;
|
||||||
F.min = minVal;
|
F.min = minVal;
|
||||||
F.max = maxVal;
|
F.max = maxVal;
|
||||||
|
sendrequest("limits", getLimits);
|
||||||
getdata();
|
getdata();
|
||||||
}
|
}
|
||||||
// send new focus value
|
// send new focus value
|
||||||
@ -97,19 +140,19 @@ function SetFocus(){
|
|||||||
alert("Wrong focus value");
|
alert("Wrong focus value");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log("Set focus: " + set);
|
Log("Set focus: " + set);
|
||||||
sendrequest("goto="+set, chkCmd);
|
sendrequest("goto="+set, chkCmd);
|
||||||
}
|
}
|
||||||
function Move(dir){
|
function Move(dir){
|
||||||
console.log("Move to " + ((dir > 0) ? "+" : "-") + " with speed " + curSpeed);
|
Log("Move to " + ((dir > 0) ? "+" : "-") + " with speed " + curSpeed);
|
||||||
var targspeeds = [ 130, 400, 800, 1200 ];
|
|
||||||
var cmd = "targspeed=" + ((dir > 0) ? "" : "-") + targspeeds[curSpeed-1];
|
var cmd = "targspeed=" + ((dir > 0) ? "" : "-") + targspeeds[curSpeed-1];
|
||||||
sendrequest(cmd, chkCmd);
|
sendrequest(cmd, chkCmd);
|
||||||
console.log("send request " + cmd);
|
Log("send request " + cmd);
|
||||||
}
|
}
|
||||||
function Stop(){
|
function Stop(){
|
||||||
sendrequest("stop", chkCmd);
|
sendrequest("stop", chkCmd);
|
||||||
console.log("Stop");
|
Log("Stop");
|
||||||
}
|
}
|
||||||
// slider or input field changed
|
// slider or input field changed
|
||||||
function change(val){
|
function change(val){
|
||||||
@ -117,14 +160,14 @@ function change(val){
|
|||||||
else if(val > maxVal) val = maxVal;
|
else if(val > maxVal) val = maxVal;
|
||||||
//$('focSlider').value = val;
|
//$('focSlider').value = val;
|
||||||
$('focSet').value = val;
|
$('focSet').value = val;
|
||||||
console.log("Chfocval: " + val);
|
Log("Chfocval: " + val);
|
||||||
}
|
}
|
||||||
function chSpd(val){
|
function chSpd(val){
|
||||||
if(val < 1) val = 1;
|
if(val < 1) val = 1;
|
||||||
else if(val > 4) val = 4;
|
else if(val > 4) val = 4;
|
||||||
$('speed').value = val;
|
$('speed').value = val;
|
||||||
curSpeed = val;
|
curSpeed = val;
|
||||||
console.log("Chspd: " + val);
|
Log("Chspd: " + val);
|
||||||
}
|
}
|
||||||
// update value in input field by current
|
// update value in input field by current
|
||||||
function update(){
|
function update(){
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=ASCII"/>
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
body{text-align:center;}
|
body{text-align:center;}
|
||||||
.shadow{
|
.shadow{
|
||||||
@ -19,8 +20,8 @@ body{text-align:center;}
|
|||||||
.big{font-size: 200%;}
|
.big{font-size: 200%;}
|
||||||
.M{margin-bottom: 5px;}
|
.M{margin-bottom: 5px;}
|
||||||
.C{text-align:center; padding: 10px;}
|
.C{text-align:center; padding: 10px;}
|
||||||
.btm{margin-top: 15px; color: red; position: fixed; bottom: 10px;
|
/*.btm{margin-top: 15px; color: red; position: fixed; bottom: 10px;
|
||||||
width: 50%; left: 25%; font-size: 200%;}
|
width: 50%; left: 25%; font-size: 200%;}*/
|
||||||
</style>
|
</style>
|
||||||
<script src="focus.js" type="text/javascript" language="javascript"></script>
|
<script src="focus.js" type="text/javascript" language="javascript"></script>
|
||||||
<title>Zeiss-1000 focusing</title>
|
<title>Zeiss-1000 focusing</title>
|
||||||
@ -39,9 +40,9 @@ body{text-align:center;}
|
|||||||
<button class="B" id="F+" onmousedown="Foc.Move(1);" onmouseup="Foc.Stop();">+</button>
|
<button class="B" id="F+" onmousedown="Foc.Move(1);" onmouseup="Foc.Stop();">+</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="C big">
|
<div class="C big">
|
||||||
<button class="B" id="Fstop" onclick="Foc.Stop();">Stop</button>
|
<button class="B" id="Fstop" onclick="Foc.Stop();" disabled>Stop</button>
|
||||||
<input style="width: 130px" id="focSet" type="number" lang="en-150" value="2" min="0.1" max="65" step="0.01"> <!-- onchange="Foc.Ch(this.value);"-->
|
<input style="width: 130px" id="focSet" type="number" lang="en-150" value="2" min="0.1" max="65" step="0.01"> <!-- onchange="Foc.Ch(this.value);"-->
|
||||||
<button class="B" id="Fset" onclick="Foc.SetFocus();">Set</button>
|
<button class="B" id="Fset" onclick="Foc.SetFocus();" disabled>Set</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="shadow" id="shadow">
|
<div class="shadow" id="shadow">
|
||||||
@ -127,6 +127,7 @@ static char* stringscan(char *str, char *needle){
|
|||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint8_t ismoving = 0; // ==1 when moving thread is active
|
||||||
/**
|
/**
|
||||||
* @brief move_focus - separate thread moving focus to given position
|
* @brief move_focus - separate thread moving focus to given position
|
||||||
* @param targpos - target position
|
* @param targpos - target position
|
||||||
@ -135,8 +136,10 @@ static void *move_focus(void *targpos){
|
|||||||
double pos = *((double*)targpos);
|
double pos = *((double*)targpos);
|
||||||
DBG("MOVE FOCUS: %g", pos);
|
DBG("MOVE FOCUS: %g", pos);
|
||||||
pthread_mutex_lock(&canbus_mutex);
|
pthread_mutex_lock(&canbus_mutex);
|
||||||
|
ismoving = 1;
|
||||||
// in any error case we should check end-switches and move out of them!
|
// in any error case we should check end-switches and move out of them!
|
||||||
if(move2pos(pos)) go_out_from_ESW();
|
if(move2pos(pos)) go_out_from_ESW();
|
||||||
|
ismoving = 0;
|
||||||
putlog("Focus value: %.03f", curPos());
|
putlog("Focus value: %.03f", curPos());
|
||||||
pthread_mutex_unlock(&moving_mutex);
|
pthread_mutex_unlock(&moving_mutex);
|
||||||
pthread_mutex_unlock(&canbus_mutex);
|
pthread_mutex_unlock(&canbus_mutex);
|
||||||
@ -271,7 +274,8 @@ static void *handle_socket(void *asock){
|
|||||||
const char *msg = S_STATUS_ERROR;
|
const char *msg = S_STATUS_ERROR;
|
||||||
switch(get_status()){
|
switch(get_status()){
|
||||||
case STAT_OK:
|
case STAT_OK:
|
||||||
msg = S_STATUS_OK;
|
if(ismoving) msg = S_STATUS_MOVING;
|
||||||
|
else msg = S_STATUS_OK;
|
||||||
break;
|
break;
|
||||||
case STAT_DAMAGE:
|
case STAT_DAMAGE:
|
||||||
msg = S_STATUS_DAMAGE;
|
msg = S_STATUS_DAMAGE;
|
||||||
@ -289,7 +293,7 @@ static void *handle_socket(void *asock){
|
|||||||
msg = S_STATUS_FORBIDDEN;
|
msg = S_STATUS_FORBIDDEN;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
msg = "Unknown status";
|
"Unknown status";
|
||||||
}
|
}
|
||||||
sprintf(buff, "%s", msg);
|
sprintf(buff, "%s", msg);
|
||||||
}else sprintf(buff, S_ANS_ERR);
|
}else sprintf(buff, S_ANS_ERR);
|
||||||
|
|||||||
@ -46,11 +46,12 @@
|
|||||||
|
|
||||||
// statuses
|
// statuses
|
||||||
#define S_STATUS_OK "OK"
|
#define S_STATUS_OK "OK"
|
||||||
#define S_STATUS_ESW "End-switch active"
|
#define S_STATUS_MOVING "moving"
|
||||||
#define S_STATUS_ERROR "SEW power if off (or other error)"
|
#define S_STATUS_ESW "Wait: end-switch active"
|
||||||
#define S_STATUS_GOFROMESW "Moving from end-switch"
|
#define S_STATUS_ERROR "Error: SEW power is off"
|
||||||
#define S_STATUS_FORBIDDEN "Motion in forbidden position"
|
#define S_STATUS_GOFROMESW "Wait: moving from end-switch"
|
||||||
#define S_STATUS_DAMAGE "Damaged state, call engineer"
|
#define S_STATUS_FORBIDDEN "Error: motion in forbidden position"
|
||||||
|
#define S_STATUS_DAMAGE "Error: damaged state, call engineer"
|
||||||
|
|
||||||
bool emerg_stop;
|
bool emerg_stop;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user