Working build system

pull/14/head
Drew Bednar 8 months ago
parent 4e41910dc1
commit 38db1a86cf

@ -1,3 +1,3 @@
Dockerfile
Makefile
README.md
dist/
node_modules/

3
.gitignore vendored

@ -1,2 +1,3 @@
node_modules/
dist/
dist/
examples/

@ -1,2 +1,9 @@
FROM nginx
COPY ./src/index.html ./src/script.js ./src/main.css /usr/share/nginx/html/
FROM node:20.16.0 AS build-stage
WORKDIR /build
COPY package.json package-lock.json ./
RUN npm install
COPY . .
RUN make build
FROM nginx AS runtime-stage
COPY --from=build-stage /build/dist/* /usr/share/nginx/html/

@ -25,14 +25,14 @@ export function setupEventListeners() {
});
globals.connectButton.addEventListener('click', async () => {
console.log(globals.select)
const selectedPort = globals.serialPorts[globals.select.selectedIndex];
console.log("selected port: ", selectedPort)
const baudRate = Math.round(globals.baud.value);
console.log("Baud Rate: ", baudRate)
if (!globals.isPortConnected) {
console.log("selected port: ", selectedPort)
console.log("Baud Rate: ", baudRate)
await connectToSerialPort(selectedPort, baudRate);
} else {
console.log("Disconnecting from port...")
globals.setPortConnected(false);
onPortDisconnect();
}
@ -50,11 +50,11 @@ export function setupEventListeners() {
globals.transmitInput.innerHTML = ''
});
globals.transmitInput.addEventListener('keydown', (event) => {
globals.transmitInput.addEventListener('keydown', async (event) => {
if (event.key === 'c' && event.ctrlKey) {
event.preventDefault();
console.log("Sending interrupt ", uPyKeyboardInterrupt)
globals.writer.write(uPyKeyboardInterrupt);
await globals.writer.write(uPyKeyboardInterrupt);
}
});

@ -11,6 +11,7 @@ export const transmitInput = document.querySelector('div[contenteditable="true"]
export const transmitButton = document.getElementById('transmit-button');
export const uPyKeyboardInterrupt = new Uint8Array([13, 3, 3]);
export let controller;
export let isPortConnected = false;
export let autoscroll = true;
export let serialPorts = [];
@ -18,6 +19,10 @@ export let encoder;
export let reader;
export let writer;
export function setController(newController) {
controller = newController
}
export function setPortConnected(isConnected) {
isPortConnected = isConnected;
}

@ -14,8 +14,8 @@ export async function connectToSerialPort(port, baud) {
const readableStreamClosed = port.readable.pipeTo(textDecoder.writable);
globals.setReader(textDecoder.readable.getReader());
const controller = new AbortController();
const signal = controller.signal;
globals.setController(new AbortController());
const signal = globals.controller.signal;
try {
globals.setPortConnected(true);
while (globals.isPortConnected) {
@ -34,23 +34,22 @@ export async function connectToSerialPort(port, baud) {
addText(line);
}
}
console.log("Exiting serial print loop")
} catch (error) {
console.error('Error reading data from serial port:', error);
} finally {
// Port cleanup
controller.abort();
console.log("Cleaning up port.")
globals.controller.abort();
console.log("Releasing writer lock")
globals.writer.releaseLock();
globals.reader.releaseLock();
try {
globals.reader.cancel();
} catch (error) {
}
try {
await readableStreamClosed;
} catch (error) {
}
// Since we are using a readableSteam we should call cancel instead of globals.reader.releaseLock();
globals.reader.cancel().then(() => {
console.log('Stream canceled');
}).catch(error => {
console.error('Error canceling the stream:', error);
});
try {
await readableStreamClosed;
@ -62,12 +61,13 @@ export async function connectToSerialPort(port, baud) {
} catch (error) {
console.error("Error encountered closing port:", error);
}
console.log("Port closed.")
onPortDisconnect()
}
}
export function transmitContents(input) {
const encoded_string = globals.encoder.encode(input + '\r')
console.log("Binary Contents: ", encoded_string)
globals.writer.write(encoded_string)
console.log("Binary Contents: ", encoded_string);
globals.writer.write(encoded_string);
}

@ -50,7 +50,7 @@ export function scrollToBottom() {
export async function updateSerialSelect(ports) {
if (ports.length < 1) {
const option = document.createElement('option');
option.text = addDeviceMessage;
option.text = globals.addDeviceMessage;
globals.select.innerHTML = ''
globals.select.appendChild(option)
return;