Added voice control
Former-commit-id: f03cb75d99a1f2719387a782331c2d0b3f4a6256
This commit is contained in:
parent
12f2c3eeee
commit
35c92407a3
96 changed files with 74167 additions and 10 deletions
58
src/se/koc/hal/bot/AliceBot.java
Normal file
58
src/se/koc/hal/bot/AliceBot.java
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright (c) 2015 Ziver
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package se.koc.hal.bot;
|
||||
|
||||
import org.alicebot.ab.Bot;
|
||||
import org.alicebot.ab.Chat;
|
||||
import org.alicebot.ab.MagicBooleans;
|
||||
import se.koc.hal.intf.HalBot;
|
||||
import zutil.io.file.FileUtil;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2015-05-07.
|
||||
*/
|
||||
public class AliceBot implements HalBot{
|
||||
private Chat chatSession;
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
MagicBooleans.trace_mode = false;
|
||||
|
||||
File path = FileUtil.find("resource");
|
||||
if(path == null || !path.exists()){
|
||||
System.err.println("Bot folder does not exist");
|
||||
System.exit(1);
|
||||
}
|
||||
Bot bot = new Bot(
|
||||
"super",
|
||||
path.getAbsolutePath());
|
||||
chatSession = new Chat(bot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String respond(String question) {
|
||||
return chatSession.multisentenceRespond(question);
|
||||
}
|
||||
}
|
||||
33
src/se/koc/hal/intf/HalBot.java
Normal file
33
src/se/koc/hal/intf/HalBot.java
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright (c) 2015 Ziver
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package se.koc.hal.intf;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2015-05-07.
|
||||
*/
|
||||
public interface HalBot {
|
||||
|
||||
public void initialize();
|
||||
|
||||
public String respond(String question);
|
||||
}
|
||||
31
src/se/koc/hal/plugin/tellstick/TellstickChangeListener.java
Normal file
31
src/se/koc/hal/plugin/tellstick/TellstickChangeListener.java
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (c) 2015 Ziver
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package se.koc.hal.plugin.tellstick;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2015-05-08.
|
||||
*/
|
||||
public interface TellstickChangeListener {
|
||||
|
||||
public void stateChange(TellstickProtocol protocol);
|
||||
}
|
||||
|
|
@ -38,8 +38,9 @@ public class TellstickParser {
|
|||
}
|
||||
|
||||
|
||||
private TellstickProtocol previus;
|
||||
|
||||
public void decode(String data) {
|
||||
public TellstickProtocol decode(String data) {
|
||||
if (data.startsWith("+W")) {
|
||||
data = data.substring(2);
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
|
|
@ -56,7 +57,11 @@ public class TellstickParser {
|
|||
TellstickProtocol protocol = protClass.newInstance();
|
||||
String binData = map.get("data");
|
||||
protocol.decode(Converter.hexToByte(binData));
|
||||
System.out.println("Decoded: " + protocol);
|
||||
if(!protocol.equals(previus)) {
|
||||
previus = protocol;
|
||||
System.out.println("Decoded: " + protocol);
|
||||
return protocol;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
@ -68,6 +73,8 @@ public class TellstickParser {
|
|||
}else {
|
||||
System.out.println("Unknown prefix: " + data);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -33,10 +33,13 @@ import java.io.*;
|
|||
* This version of the TwoWaySerialComm example makes use of the
|
||||
* SerialPortEventListener to avoid polling.
|
||||
*/
|
||||
public class TwoWaySerialComm extends Thread{
|
||||
public class TellstickSerialComm extends Thread{
|
||||
public static TellstickSerialComm instance;
|
||||
|
||||
private BufferedReader in;
|
||||
private OutputStream out;
|
||||
private TellstickParser parser = new TellstickParser();
|
||||
private TellstickChangeListener listener;
|
||||
|
||||
public void connect(String portName) throws Exception {
|
||||
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
|
||||
|
|
@ -66,16 +69,29 @@ public class TwoWaySerialComm extends Thread{
|
|||
try {
|
||||
String data;
|
||||
while ((data = in.readLine()) != null) {
|
||||
System.out.println("> "+data);
|
||||
parser.decode(data);
|
||||
System.out.println("> " + data);
|
||||
TellstickProtocol protocol = parser.decode(data);
|
||||
if (protocol == null && (data.startsWith("+S") || data.startsWith("+T"))) {
|
||||
synchronized (this) {
|
||||
this.notifyAll();
|
||||
}
|
||||
}
|
||||
else if(listener != null){
|
||||
listener.stateChange(protocol);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void write(TellstickProtocol prot) {
|
||||
public synchronized void write(TellstickProtocol prot) {
|
||||
write(prot.encode());
|
||||
try {
|
||||
this.wait();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void write(String data) {
|
||||
|
|
@ -89,29 +105,58 @@ public class TwoWaySerialComm extends Thread{
|
|||
}
|
||||
}
|
||||
|
||||
public void setListener(TellstickChangeListener listener){
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
|
||||
public static TellstickSerialComm getInstance(){
|
||||
if(instance == null){
|
||||
try {
|
||||
instance = new TellstickSerialComm();
|
||||
instance.connect("COM6");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
// http://developer.telldus.com/doxygen/TellStick.html
|
||||
TwoWaySerialComm comm = new TwoWaySerialComm();
|
||||
TellstickSerialComm comm = new TellstickSerialComm();
|
||||
comm.connect("COM6");
|
||||
|
||||
try{Thread.sleep(1000);}catch(Exception e){}
|
||||
|
||||
NexaSelfLearning nexa = new NexaSelfLearning();
|
||||
nexa.setHouse(11772006);
|
||||
//nexa.setHouse(11772006);
|
||||
nexa.setHouse(15087918);
|
||||
nexa.setGroup(0);
|
||||
nexa.setUnit(1);
|
||||
nexa.setUnit(0);
|
||||
|
||||
|
||||
while(true) {
|
||||
nexa.setEnable(true);
|
||||
nexa.setUnit(0);
|
||||
comm.write(nexa);
|
||||
Thread.sleep(2000);
|
||||
nexa.setUnit(1);
|
||||
comm.write(nexa);
|
||||
Thread.sleep(2000);
|
||||
|
||||
|
||||
nexa.setEnable(false);
|
||||
nexa.setUnit(0);
|
||||
comm.write(nexa);
|
||||
Thread.sleep(4000);
|
||||
Thread.sleep(2000);
|
||||
nexa.setUnit(1);
|
||||
comm.write(nexa);
|
||||
Thread.sleep(2000);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
@ -152,4 +152,11 @@ public class NexaSelfLearning implements TellstickProtocol {
|
|||
";unit:"+unit+
|
||||
";method:"+enable;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj){
|
||||
if(obj instanceof NexaSelfLearning)
|
||||
return ((NexaSelfLearning) obj).house == house &&
|
||||
((NexaSelfLearning)obj).unit == unit;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
29
src/se/koc/hal/struct/Dimmer.java
Normal file
29
src/se/koc/hal/struct/Dimmer.java
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright (c) 2015 Ziver
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package se.koc.hal.struct;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2015-05-07.
|
||||
*/
|
||||
public class Dimmer {
|
||||
}
|
||||
65
src/se/koc/hal/struct/Switch.java
Normal file
65
src/se/koc/hal/struct/Switch.java
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright (c) 2015 Ziver
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package se.koc.hal.struct;
|
||||
|
||||
import se.koc.hal.plugin.tellstick.TellstickSerialComm;
|
||||
import se.koc.hal.plugin.tellstick.protocols.NexaSelfLearning;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2015-05-07.
|
||||
*/
|
||||
public class Switch {
|
||||
private String name;
|
||||
private NexaSelfLearning nexa;
|
||||
|
||||
|
||||
public Switch(String name, NexaSelfLearning nexa){
|
||||
this.name = name;
|
||||
this.nexa = nexa;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
public boolean isOn(){
|
||||
return nexa.isEnabled();
|
||||
}
|
||||
public void turnOn(){
|
||||
nexa.setEnable(true);
|
||||
TellstickSerialComm.getInstance().write(nexa);
|
||||
}
|
||||
public void turnOff(){
|
||||
nexa.setEnable(false);
|
||||
TellstickSerialComm.getInstance().write(nexa);
|
||||
}
|
||||
|
||||
public boolean equals(Object obj){
|
||||
if(obj instanceof String)
|
||||
return name.equals(obj);
|
||||
if(obj instanceof NexaSelfLearning)
|
||||
return nexa.equals(obj);
|
||||
return this == obj;
|
||||
}
|
||||
}
|
||||
30
src/se/koc/hal/struct/Trigger.java
Normal file
30
src/se/koc/hal/struct/Trigger.java
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright (c) 2015 Ziver
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package se.koc.hal.struct;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2015-05-07.
|
||||
*/
|
||||
public interface Trigger {
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue