From 5ea91baa0b28cc4307818d8b3d7e4dacf54d8b08 Mon Sep 17 00:00:00 2001 From: vitrinekast Date: Mon, 12 Feb 2024 09:20:11 +0100 Subject: [PATCH] added a little test script --- app.js | 33 ++++++++++++++++++++++++++++----- hpgl.js | 9 +++++---- readme.md | 1 + 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/app.js b/app.js index aee43c5..0a14a2d 100644 --- a/app.js +++ b/app.js @@ -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); \ No newline at end of file diff --git a/hpgl.js b/hpgl.js index 74ed840..4d2b377 100644 --- a/hpgl.js +++ b/hpgl.js @@ -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; } } diff --git a/readme.md b/readme.md index bbd5324..6578507 100644 --- a/readme.md +++ b/readme.md @@ -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. \ No newline at end of file