Skip to content

Commit

Permalink
added sendDynInstructionLen
Browse files Browse the repository at this point in the history
added that on connection loss the gui tries to reconnect
  • Loading branch information
1Euro7Cent committed May 16, 2024
1 parent 69406f2 commit fc54b55
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ for (let file of cleanupFiles) {
}

// auto change log generation
//*
/*
try {
execSync("github_changelog_generator --help")
Expand Down
3 changes: 2 additions & 1 deletion classes/config/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ module.exports = class Config extends BaseConfig {
height: -1,
x: -1,
y: -1
}
},
sendDynInstructionLen: false, // if true it will send instruction data length to gui every 100 instructions. otherwise every new color

},
communication: {
Expand Down
17 changes: 16 additions & 1 deletion classes/instructions/InstructionWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,9 @@ module.exports = class InstructionWriter {
process.stdout.write(' ')
let logText = `writing color ${color} ${colorCounter}/${colorCount} ${this.settings.dualColorMode && nextColor ? 'and ' + nextColor : ''}`
console.timeLog("write", logText)
this.logger("Calculating...\n" + logText)
// this.logger("Calculating...\n" + logText)
this.logger("Calculating...\n" + logText + `(${instructions.length})`)

if (this.isAborting) return []
await sleep(5)
// console.log("next color", nextColor)
Expand Down Expand Up @@ -544,6 +546,7 @@ module.exports = class InstructionWriter {


for (let y = 0; y < recolored.bitmap.height; y++) {
if (this.config.gui.sendDynInstructionLen) await sleep(1) // sleep to not block the event loop
if (this.isAborting) return []
for (let x = 0; x < recolored.bitmap.width; x++) {
let numb = recolored.getPixelColor(x, y)
Expand Down Expand Up @@ -608,6 +611,8 @@ module.exports = class InstructionWriter {
delay: this.settings.delay,
moveDelay: this.settings.moveDelay
}, hex == nextColor ? "right" : "left", "DRAW_LINE"))
if (this.config.gui.sendDynInstructionLen && instructions.length % 100 == 0) this.logger("Calculating...\n" + logText + `(${instructions.length})`)

}
else {
let pos = relativeToAbsolute(x, y, position, this.settings.distancing, 0, 0)
Expand All @@ -617,6 +622,8 @@ module.exports = class InstructionWriter {
delay: this.settings.delay,
moveDelay: this.settings.moveDelay
}, hex == nextColor ? "right" : "left", "DRAW_PIXEL"))
if (this.config.gui.sendDynInstructionLen && instructions.length % 100 == 0) this.logger("Calculating...\n" + logText + `(${instructions.length})`)


}
x = fx
Expand Down Expand Up @@ -660,6 +667,8 @@ module.exports = class InstructionWriter {
delay: this.settings.delay,
moveDelay: this.settings.moveDelay
}, hex == nextColor ? "right" : "left", "DRAW_LINE"))
if (this.config.gui.sendDynInstructionLen && instructions.length % 100 == 0) this.logger("Calculating...\n" + logText + `(${instructions.length})`)


let pixString = `${x}-${x + (xPixels - 1)},${y}-${y}`
this.debug?.drawnPixels.push(pixString)
Expand All @@ -684,6 +693,8 @@ module.exports = class InstructionWriter {
delay: this.settings.delay,
moveDelay: this.settings.moveDelay
}, hex == nextColor ? "right" : "left", "DRAW_LINE"))
if (this.config.gui.sendDynInstructionLen && instructions.length % 100 == 0) this.logger("Calculating...\n" + logText + `(${instructions.length})`)


// addLTodrawn(instructions, drawnPixels)
let pixString = `${x}-${x},${y}-${y + (yPixels - 1)}`
Expand All @@ -701,6 +712,8 @@ module.exports = class InstructionWriter {
delay: this.settings.delay,
moveDelay: this.settings.moveDelay
}, hex == nextColor ? "right" : "left", "DRAW_PIXEL"))
if (this.config.gui.sendDynInstructionLen && instructions.length % 100 == 0) this.logger("Calculating...\n" + logText + `(${instructions.length})`)


this.debug?.customPixels.push(`${x},${y}`)
}
Expand All @@ -718,6 +731,8 @@ module.exports = class InstructionWriter {
}, hex == nextColor ? "right" : "left", "DRAW_PIXEL")
instructions.push(instruction)
this.debug?.customPixels.push(`${x},${y}`)
if (this.config.gui.sendDynInstructionLen && instructions.length % 100 == 0) this.logger("Calculating...\n" + logText + `(${instructions.length})`)

}
}
}
Expand Down
7 changes: 5 additions & 2 deletions gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,11 @@ def negativeColor(hex):
sys.exit()

if not communicationThread.is_alive():
print("websocket thread died... exiting")
sys.exit()
print("websocket thread died... restarting session...")
communicationThread = threading.Thread(target=communication, args=(config,))
communicationThread.daemon = True
communicationThread.start()
# sys.exit()

if not keyboardThread.is_alive():
print("keyboard thread died... exiting")
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "Drawbot",
"version": "3.17.1",
"version": "3.18.0",
"description": "This moves the mouse to draw stuff",
"main": "index.js",
"scripts": {
"dev": "nodemon",
"dev": "start cmd /C python gui.py && nodemon",
"build": "node build.js"
},
"repository": {
Expand Down Expand Up @@ -39,7 +39,7 @@
},
"nodemonConfig": {
"events": {
"start": "start cmd /C python gui.py"
"start_": "start cmd /C python gui.py"
},
"ignore": [
"/temp/*",
Expand Down

0 comments on commit fc54b55

Please sign in to comment.