added a little test script

master
vitrinekast 10 months ago
parent 8704238d02
commit 5ea91baa0b

@ -1,8 +1,10 @@
const { SerialPort } = require('serialport')
const express = require('express')
const app = express()
const { init, translate, circle, rectangle, to, label } = require("./hpgl.js");
const tmi = require('tmi.js');
const { init, translate, circle, rectangle, to, label } = require("./hpgl.js");
const distance = 3;
const app = express()
const client = new tmi.Client({
channels: ['twitchplaysplotter']
@ -57,14 +59,14 @@ app.listen(3000, () => {
console.log(`Example app listening on port`)
})
client.on('message', (channel, tags, message, self) => {
const distance = 3;
console.log(`${tags['display-name']}: ${message}`);
const parseMessage = (message) => {
if (message.toLowerCase().startsWith("lb")) {
var words = message.toLowerCase().replace("lb", "");
toPlotter(label(words));
} else if (message.toLowerCase().startsWith("distance")) {
} else {
switch (message.toLowerCase()) {
case 'init':
@ -102,4 +104,25 @@ client.on('message', (channel, tags, message, self) => {
break;
}
}
}
client.on('message', (channel, tags, message, self) => {
console.log(`${tags['display-name']}: ${message}`);
parseMessage(message)
});
var testMessages = ['init','pu','pd','up','down','left','right','right','rectangle','circle','LBhaihai'];
var testIndex = 0;
var interval = setInterval(function () {
console.log("----- about to send a test message: ", testMessages[testIndex]);
parseMessage(testMessages[testIndex]);
if(testIndex < (testMessages.length - 1)) {
testIndex++;
} else {
console.log("completed the test")
clearInterval(interval);
}
}, 1000);

@ -32,19 +32,20 @@ function circle(radius, resolution = 10) {
}
function clampPosition() {
console.log(`clampPosition: ${state.position.x} ${state.position.y}`)
if (state.position.x > 100) {
console.log("in the borderland");
console.log("in the borderland up");
state.position.x = 100;
} else if (state.position.x < 0) {
console.log("in the borderland");
console.log("in the borderland down");
state.position.x = 0;
}
if (state.position.y > 100) {
console.log("in the borderland");
console.log("in the borderland up");
state.position.y = 100;
} else if (state.position.y < 0) {
console.log("in the borderland");
console.log("in the borderland down");
state.position.y = 0;
}
}

@ -13,5 +13,6 @@ the commands are right now
- left (move left by {distance})
- rectangle (draw a rectangle with the size of {distance})
- circle (draw a rectangle with the size of {distance})
- set the value for distance
Also, there is the start of some state tracking and clamping to prevent the plotter from getting stuck. But again, untested.
Loading…
Cancel
Save