From 4cb0910910a0f23d64ab887e3398d0e486f2c119 Mon Sep 17 00:00:00 2001 From: Rik Veenboer Date: Thu, 11 Jun 2015 23:10:08 +0100 Subject: [PATCH] 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)); + } +}