初始化提交
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* @file BlynkUpdater.java
|
||||
* @author Volodymyr Shymanskyy
|
||||
* @license This project is released under the MIT License (MIT)
|
||||
* @copyright Copyright (c) 2016 Volodymyr Shymanskyy
|
||||
* @date Dec 2016
|
||||
* @brief
|
||||
*
|
||||
* It is not permitted to use this source code for other purposes,
|
||||
* except running scripts of original Blynk library.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.github.blynk.arduino.tools;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.lang.Runnable;
|
||||
import java.lang.Thread;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import processing.app.Editor;
|
||||
import processing.app.PreferencesData;
|
||||
import processing.app.tools.Tool;
|
||||
|
||||
import processing.app.BaseNoGui;
|
||||
import processing.app.I18n;
|
||||
import processing.app.helpers.OSUtils;
|
||||
import processing.app.helpers.FileUtils;
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
import processing.app.Base;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.DefaultCaret;
|
||||
import java.nio.file.*;
|
||||
|
||||
import processing.app.Theme;
|
||||
|
||||
import static processing.app.I18n.tr;
|
||||
import processing.app.I18n;
|
||||
|
||||
public class BlynkExampleBuilder implements Tool {
|
||||
private Editor editor;
|
||||
|
||||
public void init(Editor editor) {
|
||||
this.editor = editor;
|
||||
}
|
||||
|
||||
public String getMenuTitle() {
|
||||
return "Blynk: Example Builder";
|
||||
}
|
||||
|
||||
public void run() {
|
||||
Runnable runnable = () -> {
|
||||
try {
|
||||
Base.openURL(tr("http://examples.blynk.cc/"));
|
||||
} catch (Exception e) {
|
||||
editor.statusError("Blynk cannot open Example Builder");
|
||||
System.err.println(e);
|
||||
//e.printStackTrace(System.err);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
Thread thread = new Thread(runnable);
|
||||
thread.start();
|
||||
}
|
||||
}
|
||||
Binary file not shown.
259
arduino-cli/libraries/Blynk/extras/ide-tools/BlynkUpdater.java
Normal file
259
arduino-cli/libraries/Blynk/extras/ide-tools/BlynkUpdater.java
Normal file
@@ -0,0 +1,259 @@
|
||||
/**
|
||||
* @file BlynkUpdater.java
|
||||
* @author Volodymyr Shymanskyy
|
||||
* @license This project is released under the MIT License (MIT)
|
||||
* @copyright Copyright (c) 2016 Volodymyr Shymanskyy
|
||||
* @date Dec 2016
|
||||
* @brief
|
||||
*
|
||||
* It is not permitted to use this source code for other purposes,
|
||||
* except original Blynk library installation.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.github.blynk.arduino.tools;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.net.URL;
|
||||
import java.lang.Runnable;
|
||||
import java.lang.Thread;
|
||||
import java.util.zip.ZipInputStream;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import processing.app.Editor;
|
||||
import processing.app.PreferencesData;
|
||||
import processing.app.tools.Tool;
|
||||
|
||||
import processing.app.BaseNoGui;
|
||||
import processing.app.I18n;
|
||||
import processing.app.helpers.FileUtils;
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
import processing.app.Base;
|
||||
import processing.app.tools.ZipDeflater;
|
||||
|
||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||
import cc.arduino.contributions.filters.InstalledPredicate;
|
||||
import cc.arduino.contributions.VersionComparator;
|
||||
|
||||
import static processing.app.I18n.tr;
|
||||
|
||||
public class BlynkUpdater implements Tool {
|
||||
private Editor editor;
|
||||
final String lib_url = "https://raw.githubusercontent.com/blynkkk/blynk-library/master/library.properties";
|
||||
|
||||
public void init(Editor editor) {
|
||||
this.editor = editor;
|
||||
}
|
||||
|
||||
public String getMenuTitle() {
|
||||
return "Blynk: Check for updates";
|
||||
}
|
||||
|
||||
private static ByteArrayOutputStream downloadFile(String url) throws IOException {
|
||||
System.out.println("Downloading '" + url + "'");
|
||||
System.out.print("...");
|
||||
|
||||
final int retries = 3;
|
||||
for (int i=0; i<retries; i++) {
|
||||
try {
|
||||
InputStream is = new URL(url).openStream();
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
|
||||
byte[] chunk = new byte[32 * 1024];
|
||||
int bytesRead;
|
||||
|
||||
while ((bytesRead = is.read(chunk)) > 0) {
|
||||
System.out.print(".");
|
||||
outputStream.write(chunk, 0, bytesRead);
|
||||
}
|
||||
System.out.println(" done.");
|
||||
return outputStream;
|
||||
} catch (Exception e) {
|
||||
if (i == retries-1) {
|
||||
throw(e);
|
||||
}
|
||||
try { Thread.sleep(1000); } catch (Exception _e) {}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean isSymlink(File file) throws IOException {
|
||||
if (file == null)
|
||||
throw new NullPointerException("File must not be null");
|
||||
File canon;
|
||||
if (file.getParent() == null) {
|
||||
canon = file;
|
||||
} else {
|
||||
File canonDir = file.getParentFile().getCanonicalFile();
|
||||
canon = new File(canonDir, file.getName());
|
||||
}
|
||||
return !canon.getCanonicalFile().equals(canon.getAbsoluteFile());
|
||||
}
|
||||
|
||||
private static void updateFolder(File[] components, File tgtFolder) throws IOException {
|
||||
for (File f: components) {
|
||||
File tgt = new File(tgtFolder, f.getName());
|
||||
if (isSymlink(tgt)) {
|
||||
System.out.println("Skipping " + f.getName() + " [symlink]");
|
||||
} else {
|
||||
System.out.println("Updating " + f.getName());
|
||||
|
||||
final int retries = 3;
|
||||
for (int i=0; i<retries; i++) {
|
||||
try {
|
||||
FileUtils.recursiveDelete(tgt);
|
||||
tgt.mkdir();
|
||||
FileUtils.copy(f, tgt);
|
||||
break;
|
||||
} catch (Exception e) {
|
||||
if (i == retries-1) {
|
||||
throw(e);
|
||||
}
|
||||
System.out.println("Retry.");
|
||||
try { Thread.sleep(1000); } catch (Exception _e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String getLatestVersion() throws IOException {
|
||||
ByteArrayOutputStream last_lib_os = downloadFile(lib_url);
|
||||
ByteArrayInputStream last_lib_is = new ByteArrayInputStream(last_lib_os.toByteArray());
|
||||
PreferencesMap properties = new PreferencesMap();
|
||||
properties.load(last_lib_is);
|
||||
return properties.get("version");
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
||||
Thread thread = new Thread(() -> {
|
||||
try {
|
||||
BaseNoGui.librariesIndexer.rescanLibraries();
|
||||
final File sketchbook_path = new File(PreferencesData.get("sketchbook.path"));
|
||||
final File ide_path = new File(PreferencesData.get("runtime.ide.path"));
|
||||
|
||||
final String last_version = getLatestVersion();
|
||||
System.out.println("Latest version: " + last_version);
|
||||
|
||||
List<ContributedLibrary> blynk_libs = BaseNoGui.librariesIndexer.getIndex().find("Blynk").stream().filter(new InstalledPredicate()).collect(Collectors.toList());
|
||||
if (blynk_libs.size() > 1) {
|
||||
JOptionPane.showMessageDialog(editor,
|
||||
tr("Multiple Blynk libraries found!\n\nPlease reinstall libraries manually."),
|
||||
tr("Error"),
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean needUpdate = true;
|
||||
if (blynk_libs.size() == 1) {
|
||||
ContributedLibrary installed = blynk_libs.get(0);
|
||||
|
||||
System.out.println("Installed version: " + installed.getVersion());
|
||||
final VersionComparator versionComparator = new VersionComparator();
|
||||
needUpdate = versionComparator.greaterThan(last_version, installed.getParsedVersion());
|
||||
}
|
||||
|
||||
if (!needUpdate) {
|
||||
Base.showMessage(tr("No update needed"), tr("Blynk is up to date!"));
|
||||
return;
|
||||
}
|
||||
|
||||
{ // Ask for update
|
||||
Object[] options = { tr("Yes"), tr("No") };
|
||||
int result = JOptionPane.showOptionDialog(editor,
|
||||
"Blynk v" + last_version + " is available.\n" +
|
||||
"Do you want to update?",
|
||||
tr("Update"),
|
||||
JOptionPane.YES_NO_OPTION,
|
||||
JOptionPane.QUESTION_MESSAGE,
|
||||
null,
|
||||
options,
|
||||
options[0]);
|
||||
if (result != JOptionPane.YES_OPTION) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
final String zip_fn = "Blynk_Release_v" + last_version;
|
||||
final String zip_url = "https://github.com/blynkkk/blynk-library/releases/download/v" + last_version + "/" + zip_fn + ".zip";
|
||||
|
||||
ByteArrayOutputStream zip_os = downloadFile(zip_url);
|
||||
File tmpFolder = null;
|
||||
try {
|
||||
tmpFolder = FileUtils.createTempFolder();
|
||||
|
||||
{
|
||||
File tmpFile = new File(tmpFolder, zip_fn + ".zip");
|
||||
try(OutputStream outputStream = new FileOutputStream(tmpFile)) {
|
||||
zip_os.writeTo(outputStream);
|
||||
}
|
||||
System.out.println("Unpacking to " + tmpFolder);
|
||||
ZipDeflater zipDeflater = new ZipDeflater(tmpFile, tmpFolder);
|
||||
zipDeflater.deflate();
|
||||
|
||||
zip_os = null;
|
||||
zipDeflater = null;
|
||||
}
|
||||
|
||||
File tmpUnpackedFolder = new File(tmpFolder, zip_fn);
|
||||
|
||||
// Update libs
|
||||
File tgtLibsFolder = new File(sketchbook_path, "libraries");
|
||||
File tmpLibsFolder = new File(tmpUnpackedFolder, "libraries");
|
||||
updateFolder(tmpLibsFolder.listFiles(), tgtLibsFolder);
|
||||
|
||||
// Update tools
|
||||
File tgtToolsFolder = new File(sketchbook_path, "tools");
|
||||
File tmpToolsFolder = new File(tmpUnpackedFolder, "tools");
|
||||
if (tmpToolsFolder.exists()) {
|
||||
updateFolder(tmpToolsFolder.listFiles(), tgtToolsFolder);
|
||||
}
|
||||
|
||||
BaseNoGui.librariesIndexer.rescanLibraries();
|
||||
|
||||
{ // Ask for a star
|
||||
Object[] options = { tr("Yes"), tr("Not now") };
|
||||
int result = JOptionPane.showOptionDialog(editor,
|
||||
"Blynk libraries are succesfully updated!\n\n" +
|
||||
"Would you like to give us a star on github?",
|
||||
tr("Update"),
|
||||
JOptionPane.YES_NO_OPTION,
|
||||
JOptionPane.INFORMATION_MESSAGE,
|
||||
null,
|
||||
options,
|
||||
options[0]);
|
||||
if (result == JOptionPane.YES_OPTION) {
|
||||
Base.openURL(tr("https://github.com/blynkkk/blynk-library/releases/latest"));
|
||||
}
|
||||
}
|
||||
|
||||
editor.statusNotice("Blynk libraries updated.");
|
||||
} catch (IOException e) {
|
||||
JOptionPane.showMessageDialog(editor,
|
||||
tr("Failed to update Blynk libraries! ;(\n\nLibrary may not work properly.\nPlease re-run the update tool later, or try installing update manually."),
|
||||
tr("Update"),
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
throw(e);
|
||||
} finally {
|
||||
// delete zip created temp folder, if exists
|
||||
if (tmpFolder != null) {
|
||||
FileUtils.recursiveDelete(tmpFolder);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
editor.statusError("Blynk update failed");
|
||||
System.err.println(e);
|
||||
//e.printStackTrace(System.err);
|
||||
return;
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
}
|
||||
}
|
||||
157
arduino-cli/libraries/Blynk/extras/ide-tools/BlynkUsbScript.java
Normal file
157
arduino-cli/libraries/Blynk/extras/ide-tools/BlynkUsbScript.java
Normal file
@@ -0,0 +1,157 @@
|
||||
/**
|
||||
* @file BlynkUpdater.java
|
||||
* @author Volodymyr Shymanskyy
|
||||
* @license This project is released under the MIT License (MIT)
|
||||
* @copyright Copyright (c) 2016 Volodymyr Shymanskyy
|
||||
* @date Dec 2016
|
||||
* @brief
|
||||
*
|
||||
* It is not permitted to use this source code for other purposes,
|
||||
* except running scripts of original Blynk library.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.github.blynk.arduino.tools;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.lang.Runnable;
|
||||
import java.lang.Thread;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import processing.app.Editor;
|
||||
import processing.app.PreferencesData;
|
||||
import processing.app.tools.Tool;
|
||||
|
||||
import processing.app.BaseNoGui;
|
||||
import processing.app.I18n;
|
||||
import processing.app.helpers.OSUtils;
|
||||
import processing.app.helpers.FileUtils;
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
import processing.app.Base;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.DefaultCaret;
|
||||
import java.nio.file.*;
|
||||
|
||||
import processing.app.Theme;
|
||||
|
||||
import static processing.app.I18n.tr;
|
||||
import processing.app.I18n;
|
||||
|
||||
public class BlynkUsbScript implements Tool {
|
||||
private Editor editor;
|
||||
|
||||
public void init(Editor editor) {
|
||||
this.editor = editor;
|
||||
}
|
||||
|
||||
public String getMenuTitle() {
|
||||
return "Blynk: Run USB script";
|
||||
}
|
||||
|
||||
private void captureIO(final InputStream src, JTextArea textArea) {
|
||||
new Thread(() -> {
|
||||
Scanner sc = new Scanner(src);
|
||||
while (sc.hasNextLine()) {
|
||||
textArea.append(sc.nextLine() + "\n");
|
||||
}
|
||||
//} catch (IOException e) {
|
||||
}).start();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
Runnable runnable = () -> {
|
||||
try {
|
||||
//this.editor.serialMonitor.suspend();
|
||||
Font consoleFont = Theme.getFont("console.font");
|
||||
Font editorFont = PreferencesData.getFont("editor.font");
|
||||
Font font = Theme.scale(new Font(consoleFont.getName(), consoleFont.getStyle(), editorFont.getSize()));
|
||||
|
||||
String warning = "Ensure that Serial Monitor and Plotter are closed when using this tool.\n" +
|
||||
"It uses same port and speed as Serial Monitor\n\n";
|
||||
|
||||
String serial_port = PreferencesData.get("serial.port");
|
||||
String serial_debug_rate = PreferencesData.get("serial.debug_rate");
|
||||
String sketchbook_path = PreferencesData.get("sketchbook.path");
|
||||
|
||||
Path blynk_path = Paths.get(sketchbook_path, "libraries", "Blynk");
|
||||
|
||||
String full_cmd;
|
||||
if (OSUtils.isWindows()) {
|
||||
String script = "blynk-ser.bat";
|
||||
Path script_path = Paths.get(blynk_path.toString(), "scripts", script);
|
||||
|
||||
String args = " -c " + serial_port + " -b " + serial_debug_rate;
|
||||
full_cmd = "echo." + warning.replace("\n"," & echo.") + " & \"" + script_path.toString() + "\"" + args;
|
||||
full_cmd = "cmd /C start \"Blynk\" cmd /C \"" + full_cmd + "\"";
|
||||
|
||||
//System.err.println(full_cmd);
|
||||
|
||||
final Process p = Runtime.getRuntime().exec(full_cmd);
|
||||
|
||||
p.waitFor();
|
||||
p.destroy();
|
||||
} else {
|
||||
|
||||
String script = "blynk-ser.sh";
|
||||
Path script_path = Paths.get(blynk_path.toString(), "scripts", script);
|
||||
|
||||
String args = " -c " + serial_port + " -b " + serial_debug_rate;
|
||||
full_cmd = script_path.toString() + args;
|
||||
|
||||
//System.err.println(full_cmd);
|
||||
|
||||
JTextArea textArea = new JTextArea(warning);
|
||||
textArea.setRows(16);
|
||||
textArea.setColumns(120);
|
||||
textArea.setEditable(false);
|
||||
textArea.setLineWrap(true);
|
||||
textArea.setFont(font);
|
||||
|
||||
DefaultCaret caret = (DefaultCaret)textArea.getCaret();
|
||||
caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
|
||||
|
||||
textArea.setCaretPosition(textArea.getDocument().getLength());
|
||||
|
||||
JScrollPane scrollPane = new JScrollPane(textArea);
|
||||
//scrollPane.setPreferredSize( new Dimension(textArea.getPreferredSize().width, 500 ) );
|
||||
|
||||
JFrame frame = new JFrame(script + args);
|
||||
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||
frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
|
||||
final Process p = Runtime.getRuntime().exec(full_cmd);
|
||||
|
||||
captureIO(p.getInputStream(), textArea);
|
||||
captureIO(p.getErrorStream(), textArea);
|
||||
|
||||
frame.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent windowEvent) {
|
||||
p.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
p.waitFor();
|
||||
p.destroy();
|
||||
frame.setVisible(false);
|
||||
frame.dispose();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
editor.statusError("Blynk USB script failed");
|
||||
System.err.println(e);
|
||||
//e.printStackTrace(System.err);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
Thread thread = new Thread(runnable);
|
||||
thread.start();
|
||||
}
|
||||
}
|
||||
20
arduino-cli/libraries/Blynk/extras/ide-tools/build.sh
Normal file
20
arduino-cli/libraries/Blynk/extras/ide-tools/build.sh
Normal file
@@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ -z "$ARDUINO_IDE_PATH" ]; then
|
||||
echo "ARDUINO_IDE_PATH not defined"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -d "$ARDUINO_IDE_PATH" ]; then
|
||||
echo "$ARDUINO_IDE_PATH does not exist"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
IDE_LIB_PATH=$ARDUINO_IDE_PATH/lib
|
||||
|
||||
TGT_DIR=./$1/tool/
|
||||
TMP_DIR=./build_$1/
|
||||
rm -rf $TGT_DIR $TMP_DIR
|
||||
mkdir -p $TGT_DIR $TMP_DIR
|
||||
javac -target 1.8 -cp "$IDE_LIB_PATH/pde.jar:$IDE_LIB_PATH/arduino-core.jar" -d $TMP_DIR $1.java && jar cvf $TGT_DIR/$1.jar -C $TMP_DIR .
|
||||
rm -rf $TMP_DIR
|
||||
Reference in New Issue
Block a user