Skip to content

Instantly share code, notes, and snippets.

@HiromuKato

HiromuKato/main.js

Last active Jan 27, 2019
Embed
What would you like to do?
Photoshop(のジェネレータ)からTELLOを操作するスクリプト
(function() {
"use strict";
var PLUGIN_ID = require("./package.json").name;
var MENU_ID = "fp";
var dgram = require('dgram');
var PORT = 8889;
var HOST = '192.168.10.1';
var client = dgram.createSocket('udp4');
var _generator;
function init(generator) {
_generator = generator;
console.log("TELLOプラグイン");
_generator.addMenuItem(MENU_ID, "TELLO", true, false);
_generator.onPhotoshopEvent("toolChanged", handleToolChanged);
}
function handleToolChanged(document){
console.log(stringify(document));
if(document == "moveTool") {
// UDP send
var message = new Buffer('command');
client.send(message, 0, message.length, PORT, HOST, function(err, bytes) {
if (err) throw err;
console.log('UDP message sent to ' + HOST +':'+ PORT);
});
}
else if(document == "marqueeRectTool") {
var message = new Buffer('takeoff');
client.send(message, 0, message.length, PORT, HOST, function(err, bytes) {
});
}
else if(document == "lassoTool") {
var message = new Buffer('flip r');
client.send(message, 0, message.length, PORT, HOST, function(err, bytes) {
});
}
else if(document == "quickSelectTool") {
var message = new Buffer('flip l');
client.send(message, 0, message.length, PORT, HOST, function(err, bytes) {
});
}
else if(document == "cropTool") {
var message = new Buffer('flip b');
client.send(message, 0, message.length, PORT, HOST, function(err, bytes) {
});
}
else if(document == "framedGroupTool") {
var message = new Buffer('flip f');
client.send(message, 0, message.length, PORT, HOST, function(err, bytes) {
});
}
else if(document == "eyedropperTool") {
var message = new Buffer('land');
client.send(message, 0, message.length, PORT, HOST, function(err, bytes) {
});
}
}
function stringify(object) {
try {
return JSON.stringify(object, null, " ");
} catch (e) {
console.error(e);
}
return String(object);
}
exports.init = init;
}());
@HiromuKato

This comment has been minimized.

Copy link
Owner Author

@HiromuKato HiromuKato commented Jan 27, 2019

package.json

{
"name": "TELLO",
"version": "1.0.0",
"description": "TELLOプラグイン",
"main": "main.js"
}

@HiromuKato

This comment has been minimized.

Copy link
Owner Author

@HiromuKato HiromuKato commented Jan 27, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.