From 4cb0910910a0f23d64ab887e3398d0e486f2c119 Mon Sep 17 00:00:00 2001 From: Rik Veenboer Date: Thu, 11 Jun 2015 23:10:08 +0100 Subject: [PATCH 1/3] Snapshot of project to connect drivers for lirc (https://github.com/Boukefalos/jliblirc) and ibuddy (https://github.com/Boukefalos/jlibibuddy) towards pluggable successor of mimis (https://github.com/Boukefalos/mimis) --- .gitignore | 6 ++ build.gradle | 14 +++ src/main/java/connected/TestParsing.java | 68 +++++++++++++ .../java/connected/TestTcpCommunication.java | 54 +++++++++++ src/main/java/dummy/Dummy.java | 97 +++++++++++++++++++ src/main/java/extra/LircTaskMapCycle.java | 36 +++++++ src/main/java/extra/Task.java | 65 +++++++++++++ src/main/java/map/DenonRC176EventMap.java | 50 ++++++++++ .../java/map/PhiliphsRCLE011EventMap.java | 50 ++++++++++ .../java/map/SamsungBN5901015AEventMap.java | 32 ++++++ 10 files changed, 472 insertions(+) create mode 100644 .gitignore create mode 100644 build.gradle create mode 100644 src/main/java/connected/TestParsing.java create mode 100644 src/main/java/connected/TestTcpCommunication.java create mode 100644 src/main/java/dummy/Dummy.java create mode 100644 src/main/java/extra/LircTaskMapCycle.java create mode 100644 src/main/java/extra/Task.java create mode 100644 src/main/java/map/DenonRC176EventMap.java create mode 100644 src/main/java/map/PhiliphsRCLE011EventMap.java create mode 100644 src/main/java/map/SamsungBN5901015AEventMap.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..05f98b2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +/.gradle +/.settings +/.classpath +/.project +/bin +/build diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..b44bee4 --- /dev/null +++ b/build.gradle @@ -0,0 +1,14 @@ +apply plugin: 'java' +apply plugin: 'eclipse' + +task wrapper(type: Wrapper) { + gradleVersion = '2.2' +} + +repositories { + mavenCentral() +} + +dependencies { + +} \ No newline at end of file diff --git a/src/main/java/connected/TestParsing.java b/src/main/java/connected/TestParsing.java new file mode 100644 index 0000000..abb73da --- /dev/null +++ b/src/main/java/connected/TestParsing.java @@ -0,0 +1,68 @@ +package connected; + +import java.util.HashMap; + +import lirc.Lirc; +import base.work.Listen; + +import com.github.boukefalos.lirc.LircButton; +import com.github.boukefalos.lirc.implementation.LocalImplementation; +import com.github.boukefalos.lirc.util.SignalObject; +public class TestParsing extends Listen> { + public static void main(String[] args) { + new TestParsing().start(); + } + + protected HashMap buttonMap; + //protected LircTaskMapCycle taskMapCycle; + //buttonMap = new HashMap(); + + public void start() { + LocalImplementation lirc = new LocalImplementation(); + + /*public void put(String name, LircButton[] LircButtonArray) { + buttonMap.put(name, LircButtonArray); + }*/ + + + /*public LircButton parseButton(Scanner scanner) throws UnknownButtonException { + try { + + LircButton[] buttonArray = buttonMap.get(remote); + f (buttonArray != null) { + for (LircButton button : buttonArray) { + if (button.getCode().equals(code)) { + return button; + } + } + } + } catch (InputMismatchException e) { + logger.error("", e); + } catch (NoSuchElementException e) { + logger.error("", e); + } + throw new UnknownButtonException(); +}*/ + + /*put(PhiliphsRCLE011Button.NAME, PhiliphsRCLE011Button.values()); + put(DenonRC176Button.NAME, DenonRC176Button.values()); + put(SamsungBN5901015AButton.NAME, SamsungBN5901015AButton.values());*/ + + lirc.Lirc.Signal x = Lirc.Signal.BEGIN; + //lirc.put(PhiliphsRCLE011Button.NAME, PhiliphsRCLE011Button.values()); + lirc.start(); + super.start(); + + try { + Thread.sleep(100000000); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + public void put(String name, LircButton[] LircButtonArray) { + buttonMap.put(name, LircButtonArray); + } +} diff --git a/src/main/java/connected/TestTcpCommunication.java b/src/main/java/connected/TestTcpCommunication.java new file mode 100644 index 0000000..bfb1437 --- /dev/null +++ b/src/main/java/connected/TestTcpCommunication.java @@ -0,0 +1,54 @@ +package connected; + +import java.util.Properties; + +import base.work.Work; + +import com.github.boukefalos.ibuddy.iBuddy; +import com.github.boukefalos.lirc.Lirc; +import com.github.boukefalos.lirc.Loader; + +import dummy.Dummy; + +public class TestTcpCommunication { + public static void main(String[] args) { + try { + Properties localProperties = new Properties(); + localProperties.setProperty("implementation", "local"); + localProperties.setProperty("server", "true"); + localProperties.setProperty("server.port", "8883"); + localProperties.setProperty("server.protocol", "tcp"); + + Properties remoteProperties = new Properties(); + remoteProperties.setProperty("implementation", "remote"); + remoteProperties.setProperty("protocol", "tcp"); + remoteProperties.setProperty("remote.host", "localhost"); + remoteProperties.setProperty("remote.port", "8883"); + + Loader localLoader = new Loader(localProperties); + Loader remoteLoader = new Loader(remoteProperties); + + //Lirc localLirc = localLoader.getLirc(); + Lirc remoteLirc = remoteLoader.getLirc(); + + Properties iBuddyProperties = new Properties(); + iBuddyProperties.setProperty("implementation", "local"); + iBuddy iBuddy = new com.github.boukefalos.ibuddy.Loader(iBuddyProperties).getiBuddy(); + Dummy dummy = new Dummy(remoteLirc, iBuddy); + + Work server = localLoader.getServer(); + + // Can we reuse the same Thread for all Listens? + //localLirc.start(); + remoteLirc.start(); + server.start(); + dummy.start(); + + + Thread.sleep(10000); + //server.exit(); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/dummy/Dummy.java b/src/main/java/dummy/Dummy.java new file mode 100644 index 0000000..8775160 --- /dev/null +++ b/src/main/java/dummy/Dummy.java @@ -0,0 +1,97 @@ +package dummy; + +import lirc.Lirc.Color; +import lirc.Lirc.Direction; +import lirc.Lirc.Number; +import lirc.Lirc.Signal; +import base.work.Listen; + +import com.github.boukefalos.ibuddy.iBuddy; +import com.github.boukefalos.lirc.Lirc; +import com.github.boukefalos.lirc.LircButton; +import com.github.boukefalos.lirc.util.SignalObject; + +public class Dummy extends Listen { + protected Lirc lirc; + protected iBuddy iBuddy; + + public Dummy(Lirc lirc, iBuddy iBuddy) { + this.lirc = lirc; + this.iBuddy = iBuddy; + lirc.register(this); + } + + public void start() { + lirc.start(); + super.start(); + } + + public void input(SignalObject signalObject) { + Signal signal = signalObject.signal; + Object object = signalObject.object; + System.out.println(object); + try { + // Move these mappings to config file? + if (object instanceof LircButton) { + LircButton lircButton = (LircButton) object; + String code = lircButton.code; + logger.error(signal.name() + " : " + code + " @ " + lircButton.remote); + } else if (object instanceof Color) { + Color color = (Color) object; + System.err.println("Color: " + color); + try { + switch (color) { + case RED: + iBuddy.setHeadRed(signal.equals(Signal.BEGIN)); + break; + case GREEN: + iBuddy.setHeadGreen(signal.equals(Signal.BEGIN)); + break; + case YELLOW: + if (signal.equals(Signal.BEGIN)) { + iBuddy.setHead(proto.Ibuddy.Color.YELLOW); + } else { + iBuddy.setHead(proto.Ibuddy.Color.NONE); + } + break; + case BLUE: + iBuddy.setHeadBlue(signal.equals(Signal.BEGIN)); + break; + default: + break; + } + } catch (Exception e) {} + } else if (object instanceof Number) { + Number number = (Number) object; + // Find way to reuse enum? + proto.Ibuddy.Color color = proto.Ibuddy.Color.valueOf(number.getNumber()); + if (signal.equals(Signal.BEGIN)) { + System.err.println("Number: " + number + " Color: " + color); + iBuddy.setHead(color); + } else { + iBuddy.setHead(proto.Ibuddy.Color.NONE); + } + } else if (object instanceof Direction && signal.equals(Signal.BEGIN)) { + Direction direction = (Direction) object; + System.err.println("Direction: " + direction); + switch (direction) { + case LEFT: + iBuddy.setRotateLeft(); + break; + case RIGHT: + iBuddy.setRotateRight(); + break; + case UP: + iBuddy.setWingsUp(); + break; + case DOWN: + iBuddy.setWingsDown(); + default: + iBuddy.setRotateCenter(); + iBuddy.setWingsCenter(); + break; + } + } + } catch (Exception e) {} + } +} diff --git a/src/main/java/extra/LircTaskMapCycle.java b/src/main/java/extra/LircTaskMapCycle.java new file mode 100644 index 0000000..f188084 --- /dev/null +++ b/src/main/java/extra/LircTaskMapCycle.java @@ -0,0 +1,36 @@ +/** + * Copyright (C) 2015 Rik Veenboer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package extra; + +import map.DenonRC176EventMap; +import map.PhiliphsRCLE011EventMap; +import map.SamsungBN5901015AEventMap; + +import com.github.boukefalos.lirc.state.TaskMap; +import com.github.boukefalos.lirc.state.TaskMapCycle; + +public class LircTaskMapCycle extends TaskMapCycle { + protected static final long serialVersionUID = 1L; + + public TaskMap denonRC176, philiphsRCLE011, samsungBN5901015A; + + public LircTaskMapCycle() { + register(denonRC176 = new DenonRC176EventMap()); + register(philiphsRCLE011 = new PhiliphsRCLE011EventMap()); + register(samsungBN5901015A = new SamsungBN5901015AEventMap()); + } +} \ No newline at end of file diff --git a/src/main/java/extra/Task.java b/src/main/java/extra/Task.java new file mode 100644 index 0000000..8ba8d93 --- /dev/null +++ b/src/main/java/extra/Task.java @@ -0,0 +1,65 @@ +/** + * Copyright (C) 2015 Rik Veenboer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package extra; + +import com.github.boukefalos.lirc.input.Input; +import com.github.boukefalos.lirc.util.Signal; +import com.github.boukefalos.lirc.value.Action; +import com.github.boukefalos.lirc.value.Target; + +import extra.Task; + +public class Task implements Input { + protected static final long serialVersionUID = 1L; + + public static final Target TARGET = Target.ALL; + public static final Signal SIGNAL = Signal.NONE; + + protected Target target; + protected Action action; + protected Signal signal; + + public Task(Action action) { + this(action, TARGET); + } + + public Task(Action action, Target target) { + this(action, target, SIGNAL); + } + + public Task(Action action, Target target, Signal signal) { + this.target = target; + this.action = action; + this.signal = signal; + } + + public Target getTarget() { + return target; + } + + public Action getAction() { + return action; + } + + public Signal getSignal() { + return signal; + } + + public Task setSignal(Signal signal) { + return new Task(action, target, signal); + } +} diff --git a/src/main/java/map/DenonRC176EventMap.java b/src/main/java/map/DenonRC176EventMap.java new file mode 100644 index 0000000..11015b9 --- /dev/null +++ b/src/main/java/map/DenonRC176EventMap.java @@ -0,0 +1,50 @@ +/** + * Copyright (C) 2015 Rik Veenboer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package map; + +import com.github.boukefalos.lirc.button.remote.DenonRC176Button; +import com.github.boukefalos.lirc.state.TaskMap; +import com.github.boukefalos.lirc.value.Action; +import com.github.boukefalos.lirc.value.Target; + +import extra.Task; + +public class DenonRC176EventMap extends TaskMap { + protected static final long serialVersionUID = 1L; + + public DenonRC176EventMap() { + /* Mimis */ + receive(DenonRC176Button.TUNER_UP, new Task(Action.NEXT, Target.MAIN)); + receive(DenonRC176Button.TUNER_DOWN, new Task(Action.PREVIOUS, Target.MAIN)); + + /* Application */ + receive(DenonRC176Button.AMP_POWER, new Task(Action.START, Target.CURRENT)); + receive(DenonRC176Button.CD_NEXT, new Task(Action.NEXT, Target.CURRENT)); + receive(DenonRC176Button.CD_PREVIOUS, new Task(Action.PREVIOUS, Target.CURRENT)); + receive(DenonRC176Button.TAPE_REWIND, new Task(Action.REWIND, Target.CURRENT)); + receive(DenonRC176Button.CD_PLAY, new Task(Action.PLAY, Target.CURRENT)); + receive(DenonRC176Button.CD_PAUSE, new Task(Action.PLAY, Target.CURRENT)); + receive(DenonRC176Button.TAPE_FORWARD, new Task(Action.FORWARD, Target.CURRENT)); + receive(DenonRC176Button.AMP_MUTE, new Task(Action.MUTE, Target.CURRENT)); + receive(DenonRC176Button.AMP_VOLUME_UP, new Task(Action.VOLUME_UP, Target.CURRENT)); + receive(DenonRC176Button.AMP_VOLUME_DOWN, new Task(Action.VOLUME_DOWN, Target.CURRENT)); + receive(DenonRC176Button.CD_REPEAT, new Task(Action.REPEAT, Target.CURRENT)); + receive(DenonRC176Button.CD_SHUFFLE, new Task(Action.SHUFFLE, Target.CURRENT)); + receive(DenonRC176Button.TAPE_AB, new Task(Action.LIKE, Target.CURRENT)); + receive(DenonRC176Button.TAPE_REC, new Task(Action.DISLIKE, Target.CURRENT)); + } +} diff --git a/src/main/java/map/PhiliphsRCLE011EventMap.java b/src/main/java/map/PhiliphsRCLE011EventMap.java new file mode 100644 index 0000000..3f8725e --- /dev/null +++ b/src/main/java/map/PhiliphsRCLE011EventMap.java @@ -0,0 +1,50 @@ +/** + * Copyright (C) 2015 Rik Veenboer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package map; + +import com.github.boukefalos.lirc.button.remote.PhiliphsRCLE011Button; +import com.github.boukefalos.lirc.state.TaskMap; +import com.github.boukefalos.lirc.value.Action; +import com.github.boukefalos.lirc.value.Target; + +import extra.Task; + +public class PhiliphsRCLE011EventMap extends TaskMap { + protected static final long serialVersionUID = 1L; + + public PhiliphsRCLE011EventMap() { + /* Mimis */ + receive(PhiliphsRCLE011Button.UP, new Task(Action.NEXT, Target.MAIN)); + receive(PhiliphsRCLE011Button.DOWN, new Task(Action.PREVIOUS, Target.MAIN)); + + /* Application */ + receive(PhiliphsRCLE011Button.POWER, new Task(Action.START, Target.CURRENT)); + receive(PhiliphsRCLE011Button.PROGRAM_UP, new Task(Action.NEXT, Target.CURRENT)); + receive(PhiliphsRCLE011Button.PROGRAM_DOWN, new Task(Action.PREVIOUS, Target.CURRENT)); + receive(PhiliphsRCLE011Button.LEFT, new Task(Action.REWIND, Target.CURRENT)); + receive(PhiliphsRCLE011Button.TUNE, new Task(Action.PLAY, Target.CURRENT)); + receive(PhiliphsRCLE011Button.RIGHT, new Task(Action.FORWARD, Target.CURRENT)); + receive(PhiliphsRCLE011Button.VOLUME_DOWN, new Task(Action.VOLUME_DOWN, Target.CURRENT)); + receive(PhiliphsRCLE011Button.MUTE, new Task(Action.MUTE, Target.CURRENT)); + receive(PhiliphsRCLE011Button.VOLUME_UP, new Task(Action.VOLUME_UP, Target.CURRENT)); + receive(PhiliphsRCLE011Button.CLOCK, new Task(Action.REPEAT, Target.CURRENT)); + receive(PhiliphsRCLE011Button.OUT, new Task(Action.SHUFFLE, Target.CURRENT)); + receive(PhiliphsRCLE011Button.SQUARE, new Task(Action.FULLSCREEN, Target.CURRENT)); + receive(PhiliphsRCLE011Button.RED, new Task(Action.DISLIKE, Target.CURRENT)); + receive(PhiliphsRCLE011Button.GREEN, new Task(Action.LIKE, Target.CURRENT)); + } +} diff --git a/src/main/java/map/SamsungBN5901015AEventMap.java b/src/main/java/map/SamsungBN5901015AEventMap.java new file mode 100644 index 0000000..a3385a6 --- /dev/null +++ b/src/main/java/map/SamsungBN5901015AEventMap.java @@ -0,0 +1,32 @@ +/** + * Copyright (C) 2015 Rik Veenboer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package map; + +import com.github.boukefalos.lirc.button.remote.SamsungBN5901015AButton; +import com.github.boukefalos.lirc.state.TaskMap; +import com.github.boukefalos.lirc.value.Action; +import com.github.boukefalos.lirc.value.Target; + +import extra.Task; + +public class SamsungBN5901015AEventMap extends TaskMap { + protected static final long serialVersionUID = 1L; + + public SamsungBN5901015AEventMap() { + receive(SamsungBN5901015AButton.VOLUME_UP, new Task(Action.VOLUME_UP, Target.CURRENT)); + } +} From c521ef3215c1763925dff714653a3b48c42e1bed Mon Sep 17 00:00:00 2001 From: Rik Veenboer Date: Sun, 3 Jul 2016 12:18:59 +0100 Subject: [PATCH 2/3] Snapshot --- build.gradle | 2 +- out.yml | 8 ++ src/main/java/connected/TestFromYaml.java | 52 +++++++ .../java/connected/TestTcpCommunication.java | 100 ++++++------- src/main/java/yaml/Contact.java | 14 ++ src/main/java/yaml/Phone.java | 6 + .../java/{connected => yaml}/TestParsing.java | 136 +++++++++--------- test.yml | 11 ++ 8 files changed, 206 insertions(+), 123 deletions(-) create mode 100644 out.yml create mode 100644 src/main/java/connected/TestFromYaml.java create mode 100644 src/main/java/yaml/Contact.java create mode 100644 src/main/java/yaml/Phone.java rename src/main/java/{connected => yaml}/TestParsing.java (91%) create mode 100644 test.yml diff --git a/build.gradle b/build.gradle index b44bee4..b605a2e 100644 --- a/build.gradle +++ b/build.gradle @@ -10,5 +10,5 @@ repositories { } dependencies { - + compile 'com.esotericsoftware.yamlbeans:yamlbeans:1.09' } \ No newline at end of file diff --git a/out.yml b/out.yml new file mode 100644 index 0000000..fd8ab02 --- /dev/null +++ b/out.yml @@ -0,0 +1,8 @@ +address: 4011 16th Ave S +phone numbers: +- number: 206-555-5138 + name: Home +- number: 425-555-2306 + name: Work +name: Nathan Sweet +age: 28 diff --git a/src/main/java/connected/TestFromYaml.java b/src/main/java/connected/TestFromYaml.java new file mode 100644 index 0000000..8398a5c --- /dev/null +++ b/src/main/java/connected/TestFromYaml.java @@ -0,0 +1,52 @@ +package connected; + +import java.io.FileReader; +import java.io.OutputStreamWriter; +import java.lang.reflect.Field; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.Collection; +import java.util.Map; + +import yaml.Contact; + +import com.esotericsoftware.yamlbeans.YamlReader; +import com.esotericsoftware.yamlbeans.YamlWriter; + +public class TestFromYaml { + + + + public static void main(String[] args) throws Exception { + YamlReader reader = new YamlReader(new FileReader("test.yml")); + + // while (true) { + //Map contact = (Map) reader.read(); + //if (contact == null) break; + //System.out.println(contact.get("age")); + Class clazz = Contact.class; + for (Field field : clazz.getDeclaredFields()) { + Class type = field.getType(); + if (Collection.class.isAssignableFrom(type) || Map.class.isAssignableFrom(type)) { + System.out.println(field.getName()); + ParameterizedType listType = (ParameterizedType) field.getGenericType(); + Class x = (Class) listType.getActualTypeArguments()[0]; + System.out.println(x); + reader.getConfig().setPropertyElementType(clazz, field.getName(), x); + } + } + //reader.getConfig().setPropertyElementType(Contact.class, "phoneNumbers", Phone.class); + + Contact x = reader.read(Contact.class); + System.out.println(x.phoneNumbers.get(0)); + System.out.println(x.phoneNumbers.get(0).number); + //System.out.println(x.phoneNumbers.get(0).get("number")); + YamlWriter writer = new YamlWriter(new OutputStreamWriter(System.out)); + //writer.write(contact); + //writer.close(); + // } + + } + +} + diff --git a/src/main/java/connected/TestTcpCommunication.java b/src/main/java/connected/TestTcpCommunication.java index bfb1437..8b64ec1 100644 --- a/src/main/java/connected/TestTcpCommunication.java +++ b/src/main/java/connected/TestTcpCommunication.java @@ -1,54 +1,46 @@ -package connected; - -import java.util.Properties; - -import base.work.Work; - -import com.github.boukefalos.ibuddy.iBuddy; -import com.github.boukefalos.lirc.Lirc; -import com.github.boukefalos.lirc.Loader; - -import dummy.Dummy; - -public class TestTcpCommunication { - public static void main(String[] args) { - try { - Properties localProperties = new Properties(); - localProperties.setProperty("implementation", "local"); - localProperties.setProperty("server", "true"); - localProperties.setProperty("server.port", "8883"); - localProperties.setProperty("server.protocol", "tcp"); - - Properties remoteProperties = new Properties(); - remoteProperties.setProperty("implementation", "remote"); - remoteProperties.setProperty("protocol", "tcp"); - remoteProperties.setProperty("remote.host", "localhost"); - remoteProperties.setProperty("remote.port", "8883"); - - Loader localLoader = new Loader(localProperties); - Loader remoteLoader = new Loader(remoteProperties); - - //Lirc localLirc = localLoader.getLirc(); - Lirc remoteLirc = remoteLoader.getLirc(); - - Properties iBuddyProperties = new Properties(); - iBuddyProperties.setProperty("implementation", "local"); - iBuddy iBuddy = new com.github.boukefalos.ibuddy.Loader(iBuddyProperties).getiBuddy(); - Dummy dummy = new Dummy(remoteLirc, iBuddy); - - Work server = localLoader.getServer(); - - // Can we reuse the same Thread for all Listens? - //localLirc.start(); - remoteLirc.start(); - server.start(); - dummy.start(); - - - Thread.sleep(10000); - //server.exit(); - } catch (Exception e) { - e.printStackTrace(); - } - } -} +package connected; + +import java.util.Properties; + +import base.Control; + +import com.github.boukefalos.ibuddy.iBuddy; +import com.github.boukefalos.lirc.Lirc; +import com.github.boukefalos.lirc.Loader; + +import dummy.Dummy; + +public class TestTcpCommunication { + public static void main(String[] args) throws Exception { + Properties localProperties = new Properties(); + localProperties.setProperty("implementation", "local"); + localProperties.setProperty("server", "true"); + localProperties.setProperty("server.port", "8883"); + localProperties.setProperty("server.protocol", "tcp"); + + Properties remoteProperties = new Properties(); + remoteProperties.setProperty("implementation", "remote"); + remoteProperties.setProperty("protocol", "tcp"); + remoteProperties.setProperty("remote.host", "localhost"); + remoteProperties.setProperty("remote.port", "8883"); + + Loader localLoader = new Loader(localProperties); + Loader remoteLoader = new Loader(remoteProperties); + + Lirc localLirc = localLoader.getLirc(); + Lirc remoteLirc = remoteLoader.getLirc(); + + Properties iBuddyProperties = new Properties(); + iBuddyProperties.setProperty("implementation", "local"); + iBuddy iBuddy = new com.github.boukefalos.ibuddy.Loader(iBuddyProperties).getiBuddy(); + Dummy dummy = new Dummy(localLirc, iBuddy); + + Control server = localLoader.getServer(); + + remoteLirc.start(); + server.start(); + dummy.start(); + + Thread.sleep(10000); + } +} diff --git a/src/main/java/yaml/Contact.java b/src/main/java/yaml/Contact.java new file mode 100644 index 0000000..11c2c5c --- /dev/null +++ b/src/main/java/yaml/Contact.java @@ -0,0 +1,14 @@ +package yaml; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class Contact { + public String name; + public int age; + public String address; + public List phoneNumbers; // HashMap + public Map other; + //public HashMap x; +} diff --git a/src/main/java/yaml/Phone.java b/src/main/java/yaml/Phone.java new file mode 100644 index 0000000..a32d6f2 --- /dev/null +++ b/src/main/java/yaml/Phone.java @@ -0,0 +1,6 @@ +package yaml; + +public class Phone { + public String name; + public String number; +} diff --git a/src/main/java/connected/TestParsing.java b/src/main/java/yaml/TestParsing.java similarity index 91% rename from src/main/java/connected/TestParsing.java rename to src/main/java/yaml/TestParsing.java index abb73da..b292463 100644 --- a/src/main/java/connected/TestParsing.java +++ b/src/main/java/yaml/TestParsing.java @@ -1,68 +1,68 @@ -package connected; - -import java.util.HashMap; - -import lirc.Lirc; -import base.work.Listen; - -import com.github.boukefalos.lirc.LircButton; -import com.github.boukefalos.lirc.implementation.LocalImplementation; -import com.github.boukefalos.lirc.util.SignalObject; -public class TestParsing extends Listen> { - public static void main(String[] args) { - new TestParsing().start(); - } - - protected HashMap buttonMap; - //protected LircTaskMapCycle taskMapCycle; - //buttonMap = new HashMap(); - - public void start() { - LocalImplementation lirc = new LocalImplementation(); - - /*public void put(String name, LircButton[] LircButtonArray) { - buttonMap.put(name, LircButtonArray); - }*/ - - - /*public LircButton parseButton(Scanner scanner) throws UnknownButtonException { - try { - - LircButton[] buttonArray = buttonMap.get(remote); - f (buttonArray != null) { - for (LircButton button : buttonArray) { - if (button.getCode().equals(code)) { - return button; - } - } - } - } catch (InputMismatchException e) { - logger.error("", e); - } catch (NoSuchElementException e) { - logger.error("", e); - } - throw new UnknownButtonException(); -}*/ - - /*put(PhiliphsRCLE011Button.NAME, PhiliphsRCLE011Button.values()); - put(DenonRC176Button.NAME, DenonRC176Button.values()); - put(SamsungBN5901015AButton.NAME, SamsungBN5901015AButton.values());*/ - - lirc.Lirc.Signal x = Lirc.Signal.BEGIN; - //lirc.put(PhiliphsRCLE011Button.NAME, PhiliphsRCLE011Button.values()); - lirc.start(); - super.start(); - - try { - Thread.sleep(100000000); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - } - - public void put(String name, LircButton[] LircButtonArray) { - buttonMap.put(name, LircButtonArray); - } -} +package yaml; + +import java.util.HashMap; + +import lirc.Lirc; +import base.work.Listen; + +import com.github.boukefalos.lirc.LircButton; +import com.github.boukefalos.lirc.implementation.Local; +import com.github.boukefalos.lirc.util.SignalObject; +public class TestParsing extends Listen> { + public static void main(String[] args) { + new TestParsing().start(); + } + + protected HashMap buttonMap; + //protected LircTaskMapCycle taskMapCycle; + //buttonMap = new HashMap(); + + public void start() { + Local lirc = new Local(); + + /*public void put(String name, LircButton[] LircButtonArray) { + buttonMap.put(name, LircButtonArray); + }*/ + + + /*public LircButton parseButton(Scanner scanner) throws UnknownButtonException { + try { + + LircButton[] buttonArray = buttonMap.get(remote); + f (buttonArray != null) { + for (LircButton button : buttonArray) { + if (button.getCode().equals(code)) { + return button; + } + } + } + } catch (InputMismatchException e) { + logger.error("", e); + } catch (NoSuchElementException e) { + logger.error("", e); + } + throw new UnknownButtonException(); +}*/ + + /*put(PhiliphsRCLE011Button.NAME, PhiliphsRCLE011Button.values()); + put(DenonRC176Button.NAME, DenonRC176Button.values()); + put(SamsungBN5901015AButton.NAME, SamsungBN5901015AButton.values());*/ + + lirc.Lirc.Signal x = Lirc.Signal.BEGIN; + //lirc.put(PhiliphsRCLE011Button.NAME, PhiliphsRCLE011Button.values()); + lirc.start(); + super.start(); + + try { + Thread.sleep(100000000); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + public void put(String name, LircButton[] LircButtonArray) { + buttonMap.put(name, LircButtonArray); + } +} diff --git a/test.yml b/test.yml new file mode 100644 index 0000000..801e11c --- /dev/null +++ b/test.yml @@ -0,0 +1,11 @@ +name: Nathan Sweet +age: 28 +address: 4011 16th Ave S +phoneNumbers: + - name: Home + number: 206-555-5138 + - name: Work + number: 425-555-2306 +other: + name: Home + number: 206-555-5138 \ No newline at end of file From bed95fa91cf5b92f986a15cddd7496efdfe2d24d Mon Sep 17 00:00:00 2001 From: Rik Veenboer Date: Sun, 3 Jul 2016 12:23:04 +0100 Subject: [PATCH 3/3] Prepare merge to module exec.connected in mimis --- .gitignore => java/exec.connected/.gitignore | 0 .../exec.connected/build.gradle | 0 out.yml => java/exec.connected/out.yml | 0 .../main/java/connected/TestFromYaml.java | 0 .../java/connected/TestTcpCommunication.java | 0 .../src}/main/java/dummy/Dummy.java | 194 +++++++++--------- .../main/java/extra/LircTaskMapCycle.java | 0 .../src}/main/java/extra/Task.java | 130 ++++++------ .../main/java/map/DenonRC176EventMap.java | 0 .../java/map/PhiliphsRCLE011EventMap.java | 0 .../java/map/SamsungBN5901015AEventMap.java | 0 .../src}/main/java/yaml/Contact.java | 0 .../src}/main/java/yaml/Phone.java | 0 .../src}/main/java/yaml/TestParsing.java | 0 test.yml => java/exec.connected/test.yml | 0 15 files changed, 162 insertions(+), 162 deletions(-) rename .gitignore => java/exec.connected/.gitignore (100%) rename build.gradle => java/exec.connected/build.gradle (100%) rename out.yml => java/exec.connected/out.yml (100%) rename {src => java/exec.connected/src}/main/java/connected/TestFromYaml.java (100%) rename {src => java/exec.connected/src}/main/java/connected/TestTcpCommunication.java (100%) rename {src => java/exec.connected/src}/main/java/dummy/Dummy.java (96%) rename {src => java/exec.connected/src}/main/java/extra/LircTaskMapCycle.java (100%) rename {src => java/exec.connected/src}/main/java/extra/Task.java (96%) rename {src => java/exec.connected/src}/main/java/map/DenonRC176EventMap.java (100%) rename {src => java/exec.connected/src}/main/java/map/PhiliphsRCLE011EventMap.java (100%) rename {src => java/exec.connected/src}/main/java/map/SamsungBN5901015AEventMap.java (100%) rename {src => java/exec.connected/src}/main/java/yaml/Contact.java (100%) rename {src => java/exec.connected/src}/main/java/yaml/Phone.java (100%) rename {src => java/exec.connected/src}/main/java/yaml/TestParsing.java (100%) rename test.yml => java/exec.connected/test.yml (100%) diff --git a/.gitignore b/java/exec.connected/.gitignore similarity index 100% rename from .gitignore rename to java/exec.connected/.gitignore diff --git a/build.gradle b/java/exec.connected/build.gradle similarity index 100% rename from build.gradle rename to java/exec.connected/build.gradle diff --git a/out.yml b/java/exec.connected/out.yml similarity index 100% rename from out.yml rename to java/exec.connected/out.yml diff --git a/src/main/java/connected/TestFromYaml.java b/java/exec.connected/src/main/java/connected/TestFromYaml.java similarity index 100% rename from src/main/java/connected/TestFromYaml.java rename to java/exec.connected/src/main/java/connected/TestFromYaml.java diff --git a/src/main/java/connected/TestTcpCommunication.java b/java/exec.connected/src/main/java/connected/TestTcpCommunication.java similarity index 100% rename from src/main/java/connected/TestTcpCommunication.java rename to java/exec.connected/src/main/java/connected/TestTcpCommunication.java diff --git a/src/main/java/dummy/Dummy.java b/java/exec.connected/src/main/java/dummy/Dummy.java similarity index 96% rename from src/main/java/dummy/Dummy.java rename to java/exec.connected/src/main/java/dummy/Dummy.java index 8775160..f541e08 100644 --- a/src/main/java/dummy/Dummy.java +++ b/java/exec.connected/src/main/java/dummy/Dummy.java @@ -1,97 +1,97 @@ -package dummy; - -import lirc.Lirc.Color; -import lirc.Lirc.Direction; -import lirc.Lirc.Number; -import lirc.Lirc.Signal; -import base.work.Listen; - -import com.github.boukefalos.ibuddy.iBuddy; -import com.github.boukefalos.lirc.Lirc; -import com.github.boukefalos.lirc.LircButton; -import com.github.boukefalos.lirc.util.SignalObject; - -public class Dummy extends Listen { - protected Lirc lirc; - protected iBuddy iBuddy; - - public Dummy(Lirc lirc, iBuddy iBuddy) { - this.lirc = lirc; - this.iBuddy = iBuddy; - lirc.register(this); - } - - public void start() { - lirc.start(); - super.start(); - } - - public void input(SignalObject signalObject) { - Signal signal = signalObject.signal; - Object object = signalObject.object; - System.out.println(object); - try { - // Move these mappings to config file? - if (object instanceof LircButton) { - LircButton lircButton = (LircButton) object; - String code = lircButton.code; - logger.error(signal.name() + " : " + code + " @ " + lircButton.remote); - } else if (object instanceof Color) { - Color color = (Color) object; - System.err.println("Color: " + color); - try { - switch (color) { - case RED: - iBuddy.setHeadRed(signal.equals(Signal.BEGIN)); - break; - case GREEN: - iBuddy.setHeadGreen(signal.equals(Signal.BEGIN)); - break; - case YELLOW: - if (signal.equals(Signal.BEGIN)) { - iBuddy.setHead(proto.Ibuddy.Color.YELLOW); - } else { - iBuddy.setHead(proto.Ibuddy.Color.NONE); - } - break; - case BLUE: - iBuddy.setHeadBlue(signal.equals(Signal.BEGIN)); - break; - default: - break; - } - } catch (Exception e) {} - } else if (object instanceof Number) { - Number number = (Number) object; - // Find way to reuse enum? - proto.Ibuddy.Color color = proto.Ibuddy.Color.valueOf(number.getNumber()); - if (signal.equals(Signal.BEGIN)) { - System.err.println("Number: " + number + " Color: " + color); - iBuddy.setHead(color); - } else { - iBuddy.setHead(proto.Ibuddy.Color.NONE); - } - } else if (object instanceof Direction && signal.equals(Signal.BEGIN)) { - Direction direction = (Direction) object; - System.err.println("Direction: " + direction); - switch (direction) { - case LEFT: - iBuddy.setRotateLeft(); - break; - case RIGHT: - iBuddy.setRotateRight(); - break; - case UP: - iBuddy.setWingsUp(); - break; - case DOWN: - iBuddy.setWingsDown(); - default: - iBuddy.setRotateCenter(); - iBuddy.setWingsCenter(); - break; - } - } - } catch (Exception e) {} - } -} +package dummy; + +import lirc.Lirc.Color; +import lirc.Lirc.Direction; +import lirc.Lirc.Number; +import lirc.Lirc.Signal; +import base.work.Listen; + +import com.github.boukefalos.ibuddy.iBuddy; +import com.github.boukefalos.lirc.Lirc; +import com.github.boukefalos.lirc.LircButton; +import com.github.boukefalos.lirc.util.SignalObject; + +public class Dummy extends Listen { + protected Lirc lirc; + protected iBuddy iBuddy; + + public Dummy(Lirc lirc, iBuddy iBuddy) { + this.lirc = lirc; + this.iBuddy = iBuddy; + lirc.register(this); + } + + public void start() { + lirc.start(); + super.start(); + } + + public void input(SignalObject signalObject) { + Signal signal = signalObject.signal; + Object object = signalObject.object; + System.out.println(object); + try { + // Move these mappings to config file? + if (object instanceof LircButton) { + LircButton lircButton = (LircButton) object; + String code = lircButton.code; + logger.error(signal.name() + " : " + code + " @ " + lircButton.remote); + } else if (object instanceof Color) { + Color color = (Color) object; + System.err.println("Color: " + color); + try { + switch (color) { + case RED: + iBuddy.setHeadRed(signal.equals(Signal.BEGIN)); + break; + case GREEN: + iBuddy.setHeadGreen(signal.equals(Signal.BEGIN)); + break; + case YELLOW: + if (signal.equals(Signal.BEGIN)) { + iBuddy.setHead(proto.Ibuddy.Color.YELLOW); + } else { + iBuddy.setHead(proto.Ibuddy.Color.NONE); + } + break; + case BLUE: + iBuddy.setHeadBlue(signal.equals(Signal.BEGIN)); + break; + default: + break; + } + } catch (Exception e) {} + } else if (object instanceof Number) { + Number number = (Number) object; + // Find way to reuse enum? + proto.Ibuddy.Color color = proto.Ibuddy.Color.valueOf(number.getNumber()); + if (signal.equals(Signal.BEGIN)) { + System.err.println("Number: " + number + " Color: " + color); + iBuddy.setHead(color); + } else { + iBuddy.setHead(proto.Ibuddy.Color.NONE); + } + } else if (object instanceof Direction && signal.equals(Signal.BEGIN)) { + Direction direction = (Direction) object; + System.err.println("Direction: " + direction); + switch (direction) { + case LEFT: + iBuddy.setRotateLeft(); + break; + case RIGHT: + iBuddy.setRotateRight(); + break; + case UP: + iBuddy.setWingsUp(); + break; + case DOWN: + iBuddy.setWingsDown(); + default: + iBuddy.setRotateCenter(); + iBuddy.setWingsCenter(); + break; + } + } + } catch (Exception e) {} + } +} diff --git a/src/main/java/extra/LircTaskMapCycle.java b/java/exec.connected/src/main/java/extra/LircTaskMapCycle.java similarity index 100% rename from src/main/java/extra/LircTaskMapCycle.java rename to java/exec.connected/src/main/java/extra/LircTaskMapCycle.java diff --git a/src/main/java/extra/Task.java b/java/exec.connected/src/main/java/extra/Task.java similarity index 96% rename from src/main/java/extra/Task.java rename to java/exec.connected/src/main/java/extra/Task.java index 8ba8d93..0e33685 100644 --- a/src/main/java/extra/Task.java +++ b/java/exec.connected/src/main/java/extra/Task.java @@ -1,65 +1,65 @@ -/** - * Copyright (C) 2015 Rik Veenboer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package extra; - -import com.github.boukefalos.lirc.input.Input; -import com.github.boukefalos.lirc.util.Signal; -import com.github.boukefalos.lirc.value.Action; -import com.github.boukefalos.lirc.value.Target; - -import extra.Task; - -public class Task implements Input { - protected static final long serialVersionUID = 1L; - - public static final Target TARGET = Target.ALL; - public static final Signal SIGNAL = Signal.NONE; - - protected Target target; - protected Action action; - protected Signal signal; - - public Task(Action action) { - this(action, TARGET); - } - - public Task(Action action, Target target) { - this(action, target, SIGNAL); - } - - public Task(Action action, Target target, Signal signal) { - this.target = target; - this.action = action; - this.signal = signal; - } - - public Target getTarget() { - return target; - } - - public Action getAction() { - return action; - } - - public Signal getSignal() { - return signal; - } - - public Task setSignal(Signal signal) { - return new Task(action, target, signal); - } -} +/** + * Copyright (C) 2015 Rik Veenboer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package extra; + +import com.github.boukefalos.lirc.input.Input; +import com.github.boukefalos.lirc.util.Signal; +import com.github.boukefalos.lirc.value.Action; +import com.github.boukefalos.lirc.value.Target; + +import extra.Task; + +public class Task implements Input { + protected static final long serialVersionUID = 1L; + + public static final Target TARGET = Target.ALL; + public static final Signal SIGNAL = Signal.NONE; + + protected Target target; + protected Action action; + protected Signal signal; + + public Task(Action action) { + this(action, TARGET); + } + + public Task(Action action, Target target) { + this(action, target, SIGNAL); + } + + public Task(Action action, Target target, Signal signal) { + this.target = target; + this.action = action; + this.signal = signal; + } + + public Target getTarget() { + return target; + } + + public Action getAction() { + return action; + } + + public Signal getSignal() { + return signal; + } + + public Task setSignal(Signal signal) { + return new Task(action, target, signal); + } +} diff --git a/src/main/java/map/DenonRC176EventMap.java b/java/exec.connected/src/main/java/map/DenonRC176EventMap.java similarity index 100% rename from src/main/java/map/DenonRC176EventMap.java rename to java/exec.connected/src/main/java/map/DenonRC176EventMap.java diff --git a/src/main/java/map/PhiliphsRCLE011EventMap.java b/java/exec.connected/src/main/java/map/PhiliphsRCLE011EventMap.java similarity index 100% rename from src/main/java/map/PhiliphsRCLE011EventMap.java rename to java/exec.connected/src/main/java/map/PhiliphsRCLE011EventMap.java diff --git a/src/main/java/map/SamsungBN5901015AEventMap.java b/java/exec.connected/src/main/java/map/SamsungBN5901015AEventMap.java similarity index 100% rename from src/main/java/map/SamsungBN5901015AEventMap.java rename to java/exec.connected/src/main/java/map/SamsungBN5901015AEventMap.java diff --git a/src/main/java/yaml/Contact.java b/java/exec.connected/src/main/java/yaml/Contact.java similarity index 100% rename from src/main/java/yaml/Contact.java rename to java/exec.connected/src/main/java/yaml/Contact.java diff --git a/src/main/java/yaml/Phone.java b/java/exec.connected/src/main/java/yaml/Phone.java similarity index 100% rename from src/main/java/yaml/Phone.java rename to java/exec.connected/src/main/java/yaml/Phone.java diff --git a/src/main/java/yaml/TestParsing.java b/java/exec.connected/src/main/java/yaml/TestParsing.java similarity index 100% rename from src/main/java/yaml/TestParsing.java rename to java/exec.connected/src/main/java/yaml/TestParsing.java diff --git a/test.yml b/java/exec.connected/test.yml similarity index 100% rename from test.yml rename to java/exec.connected/test.yml