This repository has been archived by the owner on May 17, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2143 from theoweiss/TF-2015-1
TinkerForge Binding enhancements
- Loading branch information
Showing
91 changed files
with
27,060 additions
and
5,799 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> | ||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> | ||
<classpathentry kind="src" output="target/classes" path="src/main/java"/> | ||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/> | ||
<classpathentry kind="output" path="target/classes"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>org.openhab.action.tinkerforge</name> | ||
<comment>This is the ${binding-name} binding of the open Home Automation Bus (openHAB)</comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.pde.ManifestBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.pde.SchemaBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.pde.ds.core.builder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
<nature>org.eclipse.pde.PluginNature</nature> | ||
</natures> | ||
</projectDescription> |
7 changes: 7 additions & 0 deletions
7
bundles/action/org.openhab.action.tinkerforge/.settings/org.eclipse.jdt.core.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 | ||
org.eclipse.jdt.core.compiler.compliance=1.7 | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.source=1.7 |
29 changes: 29 additions & 0 deletions
29
bundles/action/org.openhab.action.tinkerforge/META-INF/MANIFEST.MF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Manifest-Version: 1.0 | ||
Private-Package: org.openhab.action.tinkerforge.internal | ||
Ignore-Package: org.openhab.action.tinkerforge.internal | ||
Bundle-License: http://www.eclipse.org/legal/epl-v10.html | ||
Bundle-Name: openHAB TinkerForge Action | ||
Bundle-SymbolicName: org.openhab.action.tinkerforge | ||
Bundle-Vendor: openHAB.org | ||
Bundle-Version: 1.7.0.qualifier | ||
Bundle-Activator: org.openhab.action.tinkerforge.internal.TinkerForgeActivator | ||
Bundle-ManifestVersion: 2 | ||
Bundle-Description: This is the TinkerForge action of the open Home Aut | ||
omation Bus (openHAB) | ||
Import-Package: org.apache.commons.lang, | ||
org.openhab.core.scriptengine.action, | ||
org.openhab.core.items, | ||
org.openhab.core.library.items, | ||
org.openhab.core.library.types, | ||
org.openhab.core.types, | ||
org.osgi.framework, | ||
org.osgi.service.cm, | ||
org.osgi.service.component, | ||
org.slf4j | ||
Bundle-DocURL: http://www.openhab.org | ||
Bundle-RequiredExecutionEnvironment: JavaSE-1.7 | ||
Service-Component: OSGI-INF/action.xml | ||
Bundle-ClassPath: . | ||
Bundle-ActivationPolicy: lazy | ||
Require-Bundle: org.openhab.binding.tinkerforge;bundle-version="1.7.0", | ||
org.eclipse.emf.ecore |
20 changes: 20 additions & 0 deletions
20
bundles/action/org.openhab.action.tinkerforge/OSGI-INF/action.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2010-2015, openHAB.org and others. | ||
All rights reserved. This program and the accompanying materials | ||
are made available under the terms of the Eclipse Public License v1.0 | ||
which accompanies this distribution, and is available at | ||
http://www.eclipse.org/legal/epl-v10.html | ||
--> | ||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="activate" deactivate="deactivate" immediate="true" name="org.openhab.action.tinkerforge"> | ||
<implementation class="org.openhab.action.tinkerforge.internal.TinkerForgeActionService" /> | ||
|
||
<service> | ||
<provide interface="org.openhab.core.scriptengine.action.ActionService" /> | ||
</service> | ||
|
||
|
||
</scr:component> |
6 changes: 6 additions & 0 deletions
6
bundles/action/org.openhab.action.tinkerforge/build.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
source.. = src/main/java/,\ | ||
src/main/resources/ | ||
bin.includes = META-INF/,\ | ||
.,\ | ||
OSGI-INF/ | ||
output.. = target/classes/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
|
||
<parent> | ||
<groupId>org.openhab.bundles</groupId> | ||
<artifactId>action</artifactId> | ||
<version>1.7.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<properties> | ||
<bundle.symbolicName>org.openhab.action.tinkerforge</bundle.symbolicName> | ||
<bundle.namespace>org.openhab.action.tinkerforge</bundle.namespace> | ||
<deb.name>openhab-addon-action-tinkerforge</deb.name> | ||
<deb.description>openhab addon action for TinkerForge devices</deb.description> | ||
</properties> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.openhab.action</groupId> | ||
<artifactId>org.openhab.action.tinkerforge</artifactId> | ||
|
||
<name>openHAB TinkerForge Action</name> | ||
|
||
<packaging>eclipse-plugin</packaging> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.vafer</groupId> | ||
<artifactId>jdeb</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
116 changes: 116 additions & 0 deletions
116
...action.tinkerforge/src/main/java/org/openhab/action/tinkerforge/internal/TinkerForge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/** | ||
* Copyright (c) 2010-2015, openHAB.org and others. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
package org.openhab.action.tinkerforge.internal; | ||
|
||
import org.openhab.binding.tinkerforge.ecosystem.TinkerforgeContext; | ||
import org.openhab.binding.tinkerforge.internal.model.MBaseDevice; | ||
import org.openhab.binding.tinkerforge.internal.model.MBrickDC; | ||
import org.openhab.binding.tinkerforge.internal.model.MBrickletLCD20x4; | ||
import org.openhab.binding.tinkerforge.internal.model.MServo; | ||
import org.openhab.core.scriptengine.action.ActionDoc; | ||
import org.openhab.core.scriptengine.action.ParamDoc; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
|
||
/** | ||
* This class contains the methods that are made available in scripts and rules for TinkerForge. | ||
* | ||
* @author Theo Weiss | ||
* @since 1.7.0 | ||
*/ | ||
public class TinkerForge { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(TinkerForge.class); | ||
private static TinkerforgeContext context = TinkerforgeContext.getInstance(); | ||
|
||
@ActionDoc(text = "clears a TinkerForge LCD", returns = "<code>true</code>, if successful and <code>false</code> otherwise.") | ||
public static boolean tfClearLCD(@ParamDoc(name = "uid", text = "the device uid") String uid) { | ||
if (context.getEcosystem() != null) { | ||
MBaseDevice mDevice = context.getEcosystem().getDevice(uid, null); | ||
if (mDevice instanceof MBrickletLCD20x4) { | ||
return ((MBrickletLCD20x4) mDevice).clear(); | ||
} else { | ||
logger.error("no lcd device found with uid {}", uid); | ||
return false; | ||
} | ||
} else { | ||
logger.warn("ecosystem was null"); | ||
return false; | ||
} | ||
} | ||
|
||
@ActionDoc(text = "sets the position of a TinkerForge servo", returns = "<code>true</code>, if successful and <code>false</code> otherwise.") | ||
public static boolean tfServoSetposition(@ParamDoc(name = "uid", text = "servo uid") String uid, | ||
@ParamDoc(name = "num", text = "servo number 0-6") String num, | ||
@ParamDoc(name = "position", text = "servo postion -9000 - 9000") String position, | ||
@ParamDoc(name = "velocity", text = "servo velocity") String velocity, | ||
@ParamDoc(name = "acceleration", text = "servo acceleration") String acceleration) { | ||
if (context.getEcosystem() != null) { | ||
MBaseDevice mDevice = context.getEcosystem().getDevice(uid, num); | ||
if (mDevice instanceof MServo) { | ||
logger.trace("servo setPoint action"); | ||
return ((MServo) mDevice).setPoint(Short.parseShort(position), Integer.parseInt(velocity), | ||
Integer.parseInt(acceleration)); | ||
} else { | ||
logger.trace("no servo device found with uid {}, num {}", uid, num); | ||
return false; | ||
} | ||
} else { | ||
logger.error("Action failed ecosystem is null"); | ||
} | ||
return false; | ||
|
||
} | ||
|
||
@ActionDoc(text = "sets the speed of a TinkerForge DC motor", returns = "<code>true</code>, if successful and <code>false</code> otherwise.") | ||
public static boolean tfDCMotorSetspeed( | ||
@ParamDoc(name = "uid", text = "Brick DC uid") String uid, | ||
@ParamDoc(name = "speed", text = "speed -32767 - 32767") Short speed, | ||
@ParamDoc(name = "acceleration", text = "motor acceleration") Integer acceleration, | ||
@ParamDoc(name = "drivemode", text = "drive mode \"break\" or \"coast\"") String drivemode) { | ||
if (context.getEcosystem() != null) { | ||
MBaseDevice mDevice = context.getEcosystem().getDevice(uid, null); | ||
if (mDevice instanceof MBrickDC) { | ||
logger.trace("servo setPoint action"); | ||
return ((MBrickDC) mDevice).setSpeed(speed, acceleration, drivemode); | ||
} else { | ||
logger.trace("no Brick DC device found with uid {}, num {}", uid); | ||
return false; | ||
} | ||
} else { | ||
logger.error("Action failed ecosystem is null"); | ||
} | ||
return false; | ||
|
||
} | ||
|
||
@ActionDoc(text = "sets the speed of a TinkerForge DC motor", returns = "<code>true</code>, if successful and <code>false</code> otherwise.") | ||
public static boolean tfDCMotorSetspeed( | ||
@ParamDoc(name = "uid", text = "Brick DC uid") String uid, | ||
@ParamDoc(name = "speed", text = "speed -32767 - 32767") String speed, | ||
@ParamDoc(name = "acceleration", text = "motor acceleration") String acceleration, | ||
@ParamDoc(name = "drivemode", text = "drive mode \"break\" or \"coast\"") String drivemode) { | ||
if (context.getEcosystem() != null) { | ||
MBaseDevice mDevice = context.getEcosystem().getDevice(uid, null); | ||
if (mDevice instanceof MBrickDC) { | ||
logger.trace("servo setPoint action"); | ||
return ((MBrickDC) mDevice).setSpeed(Short.parseShort(speed), | ||
Integer.parseInt(acceleration), drivemode); | ||
} else { | ||
logger.trace("no Brick DC device found with uid {}, num {}", uid); | ||
return false; | ||
} | ||
} else { | ||
logger.error("Action failed ecosystem is null"); | ||
} | ||
return false; | ||
|
||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...forge/src/main/java/org/openhab/action/tinkerforge/internal/TinkerForgeActionService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* Copyright (c) 2010-2015, openHAB.org and others. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
package org.openhab.action.tinkerforge.internal; | ||
|
||
import org.openhab.core.scriptengine.action.ActionService; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
|
||
/** | ||
* This class registers an OSGi service for the TinkerForge action. | ||
* | ||
* @author Theo Weiss | ||
* @since 1.7.0 | ||
*/ | ||
public class TinkerForgeActionService implements ActionService { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(TinkerForgeActionService.class); | ||
|
||
/** | ||
* Indicates whether this action is properly configured which means all necessary configurations | ||
* are set. This flag can be checked by the action methods before executing code. | ||
*/ | ||
/* default */static boolean isProperlyConfigured = false; | ||
|
||
public TinkerForgeActionService() { | ||
} | ||
|
||
public void activate() { | ||
logger.debug("TinkerForge action activated"); | ||
} | ||
|
||
public void deactivate() { | ||
logger.debug("TinkerForge action deactivated"); | ||
} | ||
|
||
@Override | ||
public String getActionClassName() { | ||
return TinkerForge.class.getCanonicalName(); | ||
} | ||
|
||
@Override | ||
public Class<?> getActionClass() { | ||
return TinkerForge.class; | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
...nkerforge/src/main/java/org/openhab/action/tinkerforge/internal/TinkerForgeActivator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* Copyright (c) 2010-2015, openHAB.org and others. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
package org.openhab.action.tinkerforge.internal; | ||
|
||
import org.osgi.framework.BundleActivator; | ||
import org.osgi.framework.BundleContext; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
|
||
/** | ||
* Extension of the default OSGi bundle activator | ||
* | ||
* @author Theo Weiss | ||
* @since 1.7.0 | ||
*/ | ||
public final class TinkerForgeActivator implements BundleActivator { | ||
|
||
private static Logger logger = LoggerFactory.getLogger(TinkerForgeActivator.class); | ||
|
||
private static BundleContext context; | ||
|
||
/** | ||
* Called whenever the OSGi framework starts our bundle | ||
*/ | ||
public void start(BundleContext bc) throws Exception { | ||
context = bc; | ||
logger.debug("TinkerForge action has been started."); | ||
} | ||
|
||
/** | ||
* Called whenever the OSGi framework stops our bundle | ||
*/ | ||
public void stop(BundleContext bc) throws Exception { | ||
context = null; | ||
logger.debug("TinkerForge action has been stopped."); | ||
} | ||
|
||
/** | ||
* Returns the bundle context of this bundle | ||
* @return the bundle context | ||
*/ | ||
public static BundleContext getContext() { | ||
return context; | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
bundles/action/org.openhab.action.tinkerforge/src/main/resources/readme.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Bundle resources go in here! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.