Skip to content

Commit

Permalink
final commits
Browse files Browse the repository at this point in the history
  • Loading branch information
brunostjohn committed Feb 13, 2023
1 parent e0c3db2 commit 3d031d5
Show file tree
Hide file tree
Showing 16 changed files with 400 additions and 57 deletions.
2 changes: 1 addition & 1 deletion app.config.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"defaultThemePath":"C:\\Users\\bruno\\Documents\\GitHub\\capellix-lcd\\themes\\clock\\theme.js","fps":25,"renderAtStartup":false,"startMinimised":false,"startAtLogin":false,"showWarningAlert":true}
{"defaultThemePath":"C:\\Users\\bruno\\Documents\\GitHub\\capellix-lcd\\themes\\notzxt\\theme.js","fps":25,"renderAtStartup":false,"startMinimised":false,"startAtLogin":false,"showWarningAlert":true}
133 changes: 125 additions & 8 deletions assets/scripts/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ window.addEventListener("load", (event) => {
'rgb(0,119,182)'
],
});
window.electronAPI.requestSensorInfo();
window.electronAPI.renderStatus();
window.electronAPI.getThemeList();
})
Expand All @@ -32,6 +33,13 @@ function makeId(length) {
}
return result;
}

let sensorinfo;

window.electronAPI.receiveSensorInfo((_event, value) => {
sensorinfo = value;
// console.log(value);
});

window.electronAPI.updateRenderStatus((_event, value) => {
if (value == 1){
Expand Down Expand Up @@ -91,9 +99,11 @@ const reset = document.getElementById("reset");

reset.addEventListener("click", () => {
parameters.forEach(controllableParameter => {
const controllingElement = document.getElementById(controllableParameter.id);
controllableParameter.value = controllableParameter.defaultValue;
controllingElement.value = controllableParameter.defaultValue;
if(controllableParameter.type != "sensor"){
const controllingElement = document.getElementById(controllableParameter.id);
controllableParameter.value = controllableParameter.defaultValue;
controllingElement.value = controllableParameter.defaultValue;
}
});
window.electronAPI.parametersSendback(parameters);

Expand All @@ -112,7 +122,7 @@ function createControllableParameter(controllableParameter) {
colour.addEventListener("input", () => {
colourBadge.style.backgroundColor = colour.value;
});
htmlToAppend = "";
htmlToAppend = "<br /><br />";
} else if (controllableParameter.type == "file") {
htmlToAppend += "<h4>" + controllableParameter.title + "</h4><button type='button' class='btn btn-outline-info' id='" + controllableParameter.id + "'>Open File</button>";
form.insertAdjacentHTML("beforeend", htmlToAppend);
Expand All @@ -121,7 +131,7 @@ function createControllableParameter(controllableParameter) {
const filePath = await window.electronAPI.openFile();
button.value = filePath;
});
htmlToAppend = "";
htmlToAppend = "<br /><br />";
} else if (controllableParameter.type == "range") {
htmlToAppend += "<h4>" + controllableParameter.title + "</h4><input type='range' class='form-range' min='" + controllableParameter.min + "' max='" + controllableParameter.max + "' step='" + controllableParameter.step + "' id='" + controllableParameter.id + "' value='" + controllableParameter.value + "' /><label for='" + controllableParameter.id + "' class='form-label' id='" + controllableParameter.id + "label'>Current value: " + controllableParameter.value +"</label>";
form.insertAdjacentHTML("beforeend", htmlToAppend);
Expand All @@ -130,15 +140,122 @@ function createControllableParameter(controllableParameter) {
range.addEventListener("input", () => {
rangeLabel.textContent = "Current value: " + range.value;
});
htmlToAppend = "";
htmlToAppend = "<br /><br />";
} else if (controllableParameter.type == "sensor") {
appendSensors(controllableParameter);
} else if (controllableParameter.type == "text") {
htmlToAppend = `
<h4>${controllableParameter.title}</h4><input type="text" class="form-control" id="${controllableParameter.id}" placeholder="${controllableParameter.defaultValue}" value="${controllableParameter.value}" />
`;
form.insertAdjacentHTML("beforeend", htmlToAppend);
htmlToAppend = "<br />"
}
htmlToAppend += "<br /><br />";
parameters.push(controllableParameter);
form.insertAdjacentHTML("beforeend", htmlToAppend);
}

function appendSensors(controllableParameter) {
window.electronAPI.requestSensorInfoForPath([controllableParameter.value, controllableParameter.id]);
const form = document.getElementById("parameterContainer");
let sensorObject = [undefined, undefined];
let parentObject = [undefined, undefined];
let superObject = [undefined, undefined];
sensorinfo.forEach((object) =>{
object.sensorTree.forEach((object2) => {
object2.sensors.forEach((object3) => {
if(object3.path === controllableParameter.value) {
sensorObject[0] = object3;
}
});
if (sensorObject[0] != undefined) {
parentObject[0] = object2;
sensorObject[1] = sensorObject[0];
sensorObject[0] = undefined
}
});
if(parentObject[0] != undefined) {
superObject[1] = object;
parentObject[1] = parentObject[0];
parentObject[0] = undefined;
}
});
sensorObject = sensorObject[1];
parentObject = parentObject[1];
superObject = superObject[1];
let htmlToAppend = `
<div class="sensorPicker" id="${controllableParameter.id}container">
<h4>${controllableParameter.title}</h4>
<label for="${controllableParameter.id}stage1">Pick device</label>
<select class="form-select" id="${controllableParameter.id}stage1" onchange="updateStage1('${controllableParameter.id}')">
</select>
<label for="${controllableParameter.id}stage2">Pick sensor type</label>
<select class="form-select" id="${controllableParameter.id}stage2" onchange="updateStage2('${controllableParameter.id}')">
</select>
<label for="${controllableParameter.id}">Pick sensor</label>
<select class="form-select" id="${controllableParameter.id}">
</select>
</div>
`;
form.insertAdjacentHTML("beforeend", htmlToAppend);
const superPicker = document.getElementById(controllableParameter.id + "stage1");
const parentPicker = document.getElementById(controllableParameter.id + "stage2");
const sensorPicker = document.getElementById(controllableParameter.id);
sensorinfo.forEach((element) => {
const newHTML = element == superObject ? `<option value="${element.path}" selected>${element.name}</option>` : `<option value="${element.path}">${element.name}</option>`;
superPicker.insertAdjacentHTML("beforeend", newHTML);
});
updateStage1(controllableParameter.id);
updateStage2(controllableParameter.id);
parentPicker.value = parentObject.category;
sensorPicker.value = sensorObject.path;
}

function updateStage1(domID){
const superPicker = document.getElementById(domID + "stage1");
const parentPicker = document.getElementById(domID + "stage2");
const sensorPicker = document.getElementById(domID);
while(parentPicker.firstChild) {
parentPicker.removeChild(parentPicker.lastChild);
}
while(sensorPicker.firstChild) {
sensorPicker.removeChild(sensorPicker.lastChild);
}
sensorPicker.disabled = true;
const pathToLookFor = superPicker.value;
const newHTML = [];
sensorinfo.forEach((element) => {
if(element.path == pathToLookFor) {
element.sensorTree.forEach((tree) => {
newHTML.push(`<option value="${tree.category}">${tree.category}</option>`);
});
}
});
newHTML.forEach((elementDef) => {
parentPicker.insertAdjacentHTML("beforeend", elementDef);
});
updateStage2(domID);
}

function updateStage2(domID){
const superPicker = document.getElementById(domID + "stage1");
const parentPicker = document.getElementById(domID + "stage2");
const sensorPicker = document.getElementById(domID);
while(sensorPicker.firstChild) {
sensorPicker.removeChild(sensorPicker.lastChild);
}
sensorPicker.disabled = false;
const newHTML = [];
sensorinfo.forEach((element) => {
if(element.path == superPicker.value) {
element.sensorTree.forEach((tree) => {
if(tree.category == parentPicker.value) {
tree.sensors.forEach((sensor) => {
newHTML.push(`<option value="${sensor.path}">${sensor.name}</option>`);
});
}
});
}
});
newHTML.forEach((elementDef) => {
sensorPicker.insertAdjacentHTML("beforeend", elementDef);
});
}
38 changes: 34 additions & 4 deletions assets/styles/renderer.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
/* TODO: Make the UI not look like shit */

html {
overflow: hidden;
}

.btn{
margin: 4px;
}

#scrollContainer {
overflow-y: auto;
max-height: 100vh;
padding: 15px;
padding-bottom: 4.5rem;
}

#scrollContainer::-webkit-scrollbar {
width: 0.5em;
}

#scrollContainer::-webkit-scrollbar-track {
box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
}

#scrollContainer::-webkit-scrollbar-thumb {
background-color: rgba(107, 107, 107, 0.719);
border-radius: 20px;
}

#maindiv{
height:100%;
min-height: 100%;
Expand All @@ -20,13 +44,21 @@
left:0;
right:0;
}

.col {
display: table-cell;
min-height: 100%;
height: 100%;
}

.sensorPicker {
padding: 2rem;
padding-top: 1rem;
border-radius: 10px;
border: 1px solid var(--bs-secondary-bg);
margin-bottom: 1rem;
}

#smaller {
max-width: 30%;
width: 30%;
Expand All @@ -40,10 +72,8 @@
#larger {
max-width: 70%;
width:70%;
padding: 15px;
}


.card {
margin: 10px;
}
Expand All @@ -66,4 +96,4 @@ h2 {
width: 100%;
height: 100%;
border-radius: 5px;
}
}
1 change: 0 additions & 1 deletion assets/styles/settings.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
}

.actualSettings {
/* overflow-y: scroll; */
margin-left: 4rem;
margin-right: 4rem;
margin-top: 1rem;
Expand Down
26 changes: 14 additions & 12 deletions assets/ui/renderer.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@
<body>
<div class="col-container">
<div class="col" id="larger">
<h1>About the theme</h1>
<hr />
<h2 id="themeName">Theme name</h2>
<p id="themeDescription">Theme description</p>
<div id="parameters">
<hr id="separator"/>
<h2>Controllable parameters</h2>
<form id="parameterContainer">
</form>
<div class="btn-group">
<button type="button" class="btn btn-primary" id="apply">Apply</button>
<button type="button" class="btn btn-secondary" id="reset">Reset parameters to default values</button>
<div id="scrollContainer">
<h1>About the theme</h1>
<hr />
<h2 id="themeName">Theme name</h2>
<p id="themeDescription">Theme description</p>
<div id="parameters">
<hr id="separator"/>
<h2>Controllable parameters</h2>
<form id="parameterContainer">
</form>
<div class="btn-group">
<button type="button" class="btn btn-primary" id="apply">Apply</button>
<button type="button" class="btn btn-secondary" id="reset">Reset parameters to default values</button>
</div>
</div>
</div>
</div>
Expand Down
5 changes: 3 additions & 2 deletions libraries/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ contextBridge.exposeInMainWorld("electronAPI", {
themeSelected: (themeId) => ipcRenderer.send("themes:themeSelected", themeId),
parametersSendback: (parameters) => ipcRenderer.send("renderer:parameterTransfer", parameters),
openFile: () => ipcRenderer.invoke("global:openFile"),
requestSensorInfoForPath: (callback) => ipcRenderer.send("renderer:sensorInfoForPath", callback),
requestSensorInfo: () => ipcRenderer.invoke("renderer:sensorInfo"),
requestConfig: () => ipcRenderer.invoke("settings:requestConfig"),
requestVersion: () => ipcRenderer.invoke("settings:requestVersion"),
requestHealth: () => ipcRenderer.invoke("settings:requestHealth"),
Expand All @@ -21,5 +21,6 @@ contextBridge.exposeInMainWorld("electronAPI", {
configSendback: (config) => ipcRenderer.send("settings:configSendback", config),
requestThemeFolder: () => ipcRenderer.invoke("settings:requestThemeFolder"),
receiveThemeFolder: (themeFolder) => ipcRenderer.on("settings:receiveThemeFolder", themeFolder),
openThemeFolder: () => ipcRenderer.invoke("settings:openThemeFolder")
openThemeFolder: () => ipcRenderer.invoke("settings:openThemeFolder"),
receiveSensorInfo: (callback) => ipcRenderer.on("renderer:receiveSensorInfo", callback)
})
12 changes: 9 additions & 3 deletions libraries/renderer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const {workerData, parentPort} = require("worker_threads");
const lcd = require("./capellix.js");
// const usbDetect = require("usb-detection");
let themeScript = require(workerData.renderPath);

LCD = new lcd.LCD();
Expand All @@ -25,18 +24,24 @@ class Renderer{
render(){
LCD.sendFrame(themeScript.renderFrame());
}

setFramerate(framerate){
this.frametime=1000/framerate;
}

changeTheme(path) {
themeScript = require(path);
}

wrapUp(){
if(typeof themeScript.wrapUp === "function"){
themeScript.wrapUp();
}
}
}

renderer = new Renderer(workerData, LCD)

// usbDetect.on('add:6940:3129', LCD.reconstructUSB );

parentPort.on("message", message => {
if(message=="stop"){
renderer.stopRendering(false);
Expand All @@ -46,6 +51,7 @@ parentPort.on("message", message => {
// usbDetect.startMonitoring();
} else if(message=="exit"){
renderer.stopRendering(true);
renderer.wrapUp();
parentPort.close();
} else if(Number.isInteger(message)) {
renderer.stopRendering(false);
Expand Down
Loading

0 comments on commit 3d031d5

Please sign in to comment.