Last active
January 27, 2019 08:10
-
-
Save HiromuKato/6b5513324408eb3032f15d42cf9e1488 to your computer and use it in GitHub Desktop.
Photoshop(のジェネレータ)からTELLOを操作するスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
解説サイト:http://www.hiromukato.com/entry/2019/01/27/170555