Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions pyindi/client.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ class INDIConn:
read_width : int
Amount to read from the stream per read
"""
def __init__(self):
def __init__(self,timeout=10):
self.writer = None
self.reader = None
self.timeout = 3
self.timeout = timeout
self.read_width = 30000

async def connect(self, host, port):
Expand Down Expand Up @@ -168,7 +168,7 @@ class INDIClient:
----------
None
"""
def start(self, host="localhost", port=7624):
def start(self, host="localhost", port=7624, timeout=10):
"""Initializes the client

Parameters
Expand All @@ -186,6 +186,7 @@ def start(self, host="localhost", port=7624):
self.host = host
self.lastblob = None
self.conn = None
self.timeout = timeout

async def connect(self):
"""Attempt to connect to the indiserver in a loop
Expand All @@ -208,9 +209,12 @@ async def connect(self):
await self.disconnect()

try:
self.conn = INDIConn()
self.conn = INDIConn(timeout=self.timeout)
logging.info(
f"Connecting to indiserver {self.host}:{self.port}"
)
await self.conn.connect(self.host, self.port)
logging.debug(
logging.info(
f"Connected to indiserver {self.host}:{self.port}"
)
self.task = asyncio.gather(
Expand Down
41 changes: 32 additions & 9 deletions pyindi/www/static/js/builder-indi.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,25 @@
if (!document.getElementById(vectorSelector)) {
console.debug(`Creating new ${indi.metainfo}=${generateId.vector(indi)}`);
var html = this.vector(indi);
html.addEventListener("setindi", (event) => {
let args = []
let inputs = html.getElementsByTagName("input")
if(event.detail.type == "Switch") {
// how else to get at the indistate? indi.state is stale by now
let isBusy = html.getElementsByClassName("pyindi-led")[0].style.backgroundColor === "var(--indistate-busy)"
indi.values.forEach((prop, idx) => {
let onOff = inputs[idx].checked && !isBusy ? "On" : "Off"
args.push(prop.name, onOff)
localStorage.setItem(inputs[idx].id, inputs[idx].value)
});
} else {
indi.values.forEach((prop, idx) => {
args.push(prop.name, inputs[idx].value)
localStorage.setItem(inputs[idx].id, inputs[idx].value)
});
}
setindi(event.detail.type, generateId.indiXml(indi), ...args);
});

switch (indi.metainfo) {
case "nvp":
Expand Down Expand Up @@ -352,15 +371,14 @@
var wo = document.createElement("input");
wo.classList.add("pyindi-property", "pyindi-wo", "col");
wo.id = `${id}__input`;
wo.value = localStorage.getItem(wo.id) || ""

// If "Enter" is pressed on writeonly area, send new text to indi
wo.addEventListener("keyup", (event) => {
if (event.key === "Enter") {

event.preventDefault() // TODO Test if needed

let value = event.target.value;
setindi("Text", generateId.indiXml(indi), property.name, value);
builder.dispatch(appendTo, "Text")
}
});

Expand Down Expand Up @@ -407,6 +425,7 @@
var wo = document.createElement("input");
wo.classList.add("pyindi-property", "pyindi-wo", "col")
wo.id = `${id}__input`;
wo.value = localStorage.getItem(wo.id) || 0
wo.defaultValue = 0;

// Add min and max data attributes
Expand Down Expand Up @@ -445,7 +464,8 @@
else {
wo.classList.remove("invalid");
tip.classList.add("hide")
setindi("Number", generateId.indiXml(indi), property.name, value);
event.preventDefault()
builder.dispatch(appendTo, "Number")
}
}
});
Expand Down Expand Up @@ -493,12 +513,10 @@
input.checked = property.value === "On" ? true : false;

// Create event listeners for input button
input.addEventListener("change", (event) => {
let name = event.target.value
let value = event.target.checked ? "On" : "Off"
setindi("Switch", generateId.indiXml(indi), name, value);
input.addEventListener("click", (event) => {
builder.dispatch(appendTo, "Switch")
})

// Append all
span.appendChild(input);
span.appendChild(label);
Expand Down Expand Up @@ -559,4 +577,9 @@

return appendTo;
},
dispatch(html, type) {
html.dispatchEvent(new CustomEvent('setindi', {
detail: { type: type}
}))
},
};