piloter_un_apn_lumix_depuis_son_ordinateur
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédente | Prochaine révisionLes deux révisions suivantes | ||
piloter_un_apn_lumix_depuis_son_ordinateur [2020/04/11 13:25] – Mushussu | piloter_un_apn_lumix_depuis_son_ordinateur [2020/04/11 13:27] – Mushussu | ||
---|---|---|---|
Ligne 3: | Ligne 3: | ||
Sélectionner le réseau Wi-Fi adéquat : | Sélectionner le réseau Wi-Fi adéquat : | ||
MENU -> [Config.] -> Wi-Fi -> Fonction Wi-Fi -> Nouvelle connexion -> Prise de vue et affichage à distance -> DISP. Changer de mode -> Par réseau -> Dans la liste | MENU -> [Config.] -> Wi-Fi -> Fonction Wi-Fi -> Nouvelle connexion -> Prise de vue et affichage à distance -> DISP. Changer de mode -> Par réseau -> Dans la liste | ||
+ | ===== Processing ===== | ||
+ | <code java> | ||
+ | // http:// | ||
+ | import controlP5.*; | ||
+ | import java.awt.image.*; | ||
+ | import javax.imageio.*; | ||
+ | import java.net.*; | ||
+ | import java.io.*; | ||
+ | ControlP5 cp5; | ||
+ | ReceiverThread thread; | ||
+ | |||
+ | XML xml; | ||
+ | String adresse; | ||
+ | int port; | ||
+ | PImage video; | ||
+ | |||
+ | void setup() { | ||
+ | size(1000, 600); | ||
+ | noStroke(); | ||
+ | video = createImage(640, | ||
+ | thread = new ReceiverThread(video.width, | ||
+ | thread.start(); | ||
+ | |||
+ | cp5 = new ControlP5(this); | ||
+ | |||
+ | |||
+ | cp5.addToggle(" | ||
+ | .setPosition(40, | ||
+ | .setSize(50, | ||
+ | .setValue(false) | ||
+ | .setMode(ControlP5.SWITCH) | ||
+ | ; | ||
+ | |||
+ | cp5.addToggle(" | ||
+ | .setPosition(120, | ||
+ | .setSize(50, | ||
+ | .setValue(false) | ||
+ | .setMode(ControlP5.SWITCH) | ||
+ | ; | ||
+ | |||
+ | cp5.addButton(" | ||
+ | .setValue(0) | ||
+ | .setPosition(100, | ||
+ | .setSize(120, | ||
+ | ; | ||
+ | |||
+ | cp5.addButton(" | ||
+ | .setValue(0) | ||
+ | .setPosition(100, | ||
+ | .setSize(80, | ||
+ | ; | ||
+ | adresse = ""; | ||
+ | port = 49152; | ||
+ | } | ||
+ | |||
+ | void draw() { | ||
+ | background(0); | ||
+ | if (thread.available()) { | ||
+ | video = thread.getImage(); | ||
+ | } | ||
+ | image(video, | ||
+ | } | ||
+ | |||
+ | void Connexion(int valeur) { | ||
+ | println(valeur); | ||
+ | adresse = " | ||
+ | xml = loadXML(adresse | ||
+ | println(" | ||
+ | println(xml); | ||
+ | } | ||
+ | |||
+ | void Mode(boolean drapeau) { | ||
+ | if (!drapeau && !adresse.equals("" | ||
+ | xml = loadXML(adresse | ||
+ | println(" | ||
+ | } else { | ||
+ | xml = loadXML(adresse | ||
+ | println(" | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void Diffusion(boolean drapeau) { | ||
+ | println(adresse); | ||
+ | if (!drapeau && !adresse.equals("" | ||
+ | xml = loadXML(adresse | ||
+ | println(" | ||
+ | } else { | ||
+ | xml = loadXML(adresse | ||
+ | println(" | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void keyPressed() { | ||
+ | println(byte(key)); | ||
+ | if (byte(key) == 10) { | ||
+ | Photo(0); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | void Photo(int valeur) { | ||
+ | xml = loadXML(adresse | ||
+ | println(xml); | ||
+ | } | ||
+ | |||
+ | // Daniel Shiffman | ||
+ | // < | ||
+ | |||
+ | class ReceiverThread extends Thread { | ||
+ | |||
+ | // Port we are receiving. | ||
+ | int port = 49152; | ||
+ | DatagramSocket ds; | ||
+ | // A byte array to read into (max size of 65536, could be smaller) | ||
+ | byte[] buffer = new byte[40000]; | ||
+ | |||
+ | boolean running; | ||
+ | boolean available; | ||
+ | |||
+ | // Start with something | ||
+ | PImage img; | ||
+ | |||
+ | ReceiverThread (int w, int h) { | ||
+ | img = createImage(w, | ||
+ | running = false; | ||
+ | available = true; // We start with " | ||
+ | |||
+ | try { | ||
+ | ds = new DatagramSocket(port); | ||
+ | } | ||
+ | catch (SocketException e) { | ||
+ | e.printStackTrace(); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | PImage getImage() { | ||
+ | // We set available equal to false now that we've gotten the data | ||
+ | available = false; | ||
+ | return img; | ||
+ | } | ||
+ | |||
+ | boolean available() { | ||
+ | return available; | ||
+ | } | ||
+ | |||
+ | // Overriding " | ||
+ | void start () { | ||
+ | running = true; | ||
+ | super.start(); | ||
+ | } | ||
+ | |||
+ | // We must implement run, this gets triggered by start() | ||
+ | void run () { | ||
+ | while (running) { | ||
+ | checkForImage(); | ||
+ | // New data is available! | ||
+ | available = true; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void checkForImage() { | ||
+ | DatagramPacket p = new DatagramPacket(buffer, | ||
+ | try { | ||
+ | ds.receive(p); | ||
+ | } | ||
+ | catch (IOException e) { | ||
+ | e.printStackTrace(); | ||
+ | } | ||
+ | byte[] data = p.getData(); | ||
+ | int debutTrame = 0; | ||
+ | for (int i = 0; i < 200; i++) { | ||
+ | if ((int(data[i]) == 0xff) && (int(data[i + 1]) == 0xD8)) { | ||
+ | debutTrame = i; | ||
+ | } | ||
+ | } | ||
+ | // println(" | ||
+ | data = subset(data, | ||
+ | // Read incoming data into a ByteArrayInputStream | ||
+ | ByteArrayInputStream bais = new ByteArrayInputStream( data ); | ||
+ | // We need to unpack JPG and put it in the PImage img | ||
+ | img.loadPixels(); | ||
+ | try { | ||
+ | // Make a BufferedImage out of the incoming bytes | ||
+ | BufferedImage bimg = ImageIO.read(bais); | ||
+ | // Put the pixels into the PImage | ||
+ | bimg.getRGB(0, | ||
+ | } | ||
+ | catch (Exception e) { | ||
+ | e.printStackTrace(); | ||
+ | } | ||
+ | // Update the PImage pixels | ||
+ | img.updatePixels(); | ||
+ | } | ||
+ | |||
+ | |||
+ | // Our method that quits the thread | ||
+ | void quit() { | ||
+ | System.out.println(" | ||
+ | running = false; // Setting running to false ends the loop in run() | ||
+ | // In case the thread is waiting. . . | ||
+ | interrupt(); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
===== Sources ===== | ===== Sources ===== | ||
{{ : | {{ : |
piloter_un_apn_lumix_depuis_son_ordinateur.txt · Dernière modification : 2023/08/31 22:16 de Mushussu