diff --git a/java/exec.connected/.gitignore b/java/exec.connected/.gitignore new file mode 100644 index 0000000..05f98b2 --- /dev/null +++ b/java/exec.connected/.gitignore @@ -0,0 +1,6 @@ +/.gradle +/.settings +/.classpath +/.project +/bin +/build diff --git a/java/exec.connected/build.gradle b/java/exec.connected/build.gradle new file mode 100644 index 0000000..b605a2e --- /dev/null +++ b/java/exec.connected/build.gradle @@ -0,0 +1,14 @@ +apply plugin: 'java' +apply plugin: 'eclipse' + +task wrapper(type: Wrapper) { + gradleVersion = '2.2' +} + +repositories { + mavenCentral() +} + +dependencies { + compile 'com.esotericsoftware.yamlbeans:yamlbeans:1.09' +} \ No newline at end of file diff --git a/java/exec.connected/out.yml b/java/exec.connected/out.yml new file mode 100644 index 0000000..fd8ab02 --- /dev/null +++ b/java/exec.connected/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/java/exec.connected/src/main/java/connected/TestFromYaml.java b/java/exec.connected/src/main/java/connected/TestFromYaml.java new file mode 100644 index 0000000..8398a5c --- /dev/null +++ b/java/exec.connected/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/java/exec.connected/src/main/java/connected/TestTcpCommunication.java b/java/exec.connected/src/main/java/connected/TestTcpCommunication.java new file mode 100644 index 0000000..8b64ec1 --- /dev/null +++ b/java/exec.connected/src/main/java/connected/TestTcpCommunication.java @@ -0,0 +1,46 @@ +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/java/exec.connected/src/main/java/dummy/Dummy.java b/java/exec.connected/src/main/java/dummy/Dummy.java new file mode 100644 index 0000000..f541e08 --- /dev/null +++ b/java/exec.connected/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/java/exec.connected/src/main/java/extra/LircTaskMapCycle.java b/java/exec.connected/src/main/java/extra/LircTaskMapCycle.java new file mode 100644 index 0000000..f188084 --- /dev/null +++ b/java/exec.connected/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/java/exec.connected/src/main/java/extra/Task.java b/java/exec.connected/src/main/java/extra/Task.java new file mode 100644 index 0000000..0e33685 --- /dev/null +++ b/java/exec.connected/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/java/exec.connected/src/main/java/map/DenonRC176EventMap.java b/java/exec.connected/src/main/java/map/DenonRC176EventMap.java new file mode 100644 index 0000000..11015b9 --- /dev/null +++ b/java/exec.connected/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/java/exec.connected/src/main/java/map/PhiliphsRCLE011EventMap.java b/java/exec.connected/src/main/java/map/PhiliphsRCLE011EventMap.java new file mode 100644 index 0000000..3f8725e --- /dev/null +++ b/java/exec.connected/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/java/exec.connected/src/main/java/map/SamsungBN5901015AEventMap.java b/java/exec.connected/src/main/java/map/SamsungBN5901015AEventMap.java new file mode 100644 index 0000000..a3385a6 --- /dev/null +++ b/java/exec.connected/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)); + } +} diff --git a/java/exec.connected/src/main/java/yaml/Contact.java b/java/exec.connected/src/main/java/yaml/Contact.java new file mode 100644 index 0000000..11c2c5c --- /dev/null +++ b/java/exec.connected/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/java/exec.connected/src/main/java/yaml/Phone.java b/java/exec.connected/src/main/java/yaml/Phone.java new file mode 100644 index 0000000..a32d6f2 --- /dev/null +++ b/java/exec.connected/src/main/java/yaml/Phone.java @@ -0,0 +1,6 @@ +package yaml; + +public class Phone { + public String name; + public String number; +} diff --git a/java/exec.connected/src/main/java/yaml/TestParsing.java b/java/exec.connected/src/main/java/yaml/TestParsing.java new file mode 100644 index 0000000..b292463 --- /dev/null +++ b/java/exec.connected/src/main/java/yaml/TestParsing.java @@ -0,0 +1,68 @@ +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/java/exec.connected/test.yml b/java/exec.connected/test.yml new file mode 100644 index 0000000..801e11c --- /dev/null +++ b/java/exec.connected/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