Initial commit.
This commit is contained in:
@@ -0,0 +1,203 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<?fileVersion 4.0.0?>
|
||||
|
||||
<cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
|
||||
<storageModule moduleId="org.eclipse.cdt.core.settings">
|
||||
<cconfiguration id="cdt.managedbuild.toolchain.gnu.base.2045375629">
|
||||
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.toolchain.gnu.base.2045375629" moduleId="org.eclipse.cdt.core.settings" name="Default">
|
||||
<externalSettings/>
|
||||
<extensions>
|
||||
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
|
||||
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
</extensions>
|
||||
</storageModule>
|
||||
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||
<configuration artifactName="${ProjName}" buildProperties="" description="" id="cdt.managedbuild.toolchain.gnu.base.2045375629" name="Default" parent="org.eclipse.cdt.build.core.emptycfg">
|
||||
<folderInfo id="cdt.managedbuild.toolchain.gnu.base.2045375629.345717916" name="/" resourcePath="">
|
||||
<toolChain id="cdt.managedbuild.toolchain.gnu.base.45267683" name="cdt.managedbuild.toolchain.gnu.base" superClass="cdt.managedbuild.toolchain.gnu.base">
|
||||
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.target.gnu.platform.base.451391214" name="Debug Platform" osList="linux,hpux,aix,qnx" superClass="cdt.managedbuild.target.gnu.platform.base"/>
|
||||
<builder id="cdt.managedbuild.target.gnu.builder.base.1001917549" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="cdt.managedbuild.target.gnu.builder.base"/>
|
||||
<tool id="cdt.managedbuild.tool.gnu.archiver.base.103602143" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
|
||||
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.base.514423684" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.base">
|
||||
<option id="gnu.cpp.compiler.option.include.paths.1968643116" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/TinkerforgeCPPsimple/lib/tinkerforge/include}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/TinkerforgeCPPsimple/lib/log4cpp/include}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/TinkerforgeCPPsimple/include}""/>
|
||||
</option>
|
||||
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1250728170" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
|
||||
</tool>
|
||||
<tool id="cdt.managedbuild.tool.gnu.c.compiler.base.1057495097" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.base">
|
||||
<option id="gnu.c.compiler.option.include.paths.2145657280" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/TinkerforgeCPPsimple/lib/tinkerforge/include}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/TinkerforgeCPPsimple/lib/log4cpp/include}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/TinkerforgeCPPsimple/include}""/>
|
||||
</option>
|
||||
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.734558176" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
|
||||
</tool>
|
||||
<tool id="cdt.managedbuild.tool.gnu.c.linker.base.726225854" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.base"/>
|
||||
<tool id="cdt.managedbuild.tool.gnu.cpp.linker.base.1699573124" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.base">
|
||||
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1972564706" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
|
||||
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
|
||||
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
|
||||
</inputType>
|
||||
</tool>
|
||||
<tool id="cdt.managedbuild.tool.gnu.assembler.base.2044825375" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.base">
|
||||
<option id="gnu.both.asm.option.include.paths.1865303662" name="Include paths (-I)" superClass="gnu.both.asm.option.include.paths" valueType="includePath">
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/TinkerforgeCPPsimple/include}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/TinkerforgeCPPsimple/third-party/tinkerforge/include}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/TinkerforgeCPPsimple/third-party/log4cpp/include}""/>
|
||||
</option>
|
||||
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.437019266" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
|
||||
</tool>
|
||||
</toolChain>
|
||||
</folderInfo>
|
||||
<sourceEntries>
|
||||
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="include"/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="src"/>
|
||||
</sourceEntries>
|
||||
</configuration>
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
|
||||
</cconfiguration>
|
||||
</storageModule>
|
||||
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||
<project id="TinkerforgeSimpleCPP.null.1772554978" name="TinkerforgeSimpleCPP"/>
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
|
||||
<storageModule moduleId="refreshScope" versionNumber="2">
|
||||
<configuration configurationName="Default">
|
||||
<resource resourceType="PROJECT" workspacePath="/TinkerforgeCPPsimple"/>
|
||||
</configuration>
|
||||
</storageModule>
|
||||
<storageModule moduleId="scannerConfiguration">
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.base.2045375629;cdt.managedbuild.toolchain.gnu.base.2045375629.345717916;cdt.managedbuild.tool.gnu.c.compiler.base.1057495097;cdt.managedbuild.tool.gnu.c.compiler.input.734558176">
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
</scannerConfigBuildInfo>
|
||||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.base.2045375629;cdt.managedbuild.toolchain.gnu.base.2045375629.345717916;cdt.managedbuild.tool.gnu.cpp.compiler.base.514423684;cdt.managedbuild.tool.gnu.cpp.compiler.input.1250728170">
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
</scannerConfigBuildInfo>
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets">
|
||||
<buildTargets>
|
||||
<target name="all" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildArguments/>
|
||||
<buildTarget>all</buildTarget>
|
||||
<stopOnError>true</stopOnError>
|
||||
<useDefaultCommand>true</useDefaultCommand>
|
||||
<runAllBuilders>true</runAllBuilders>
|
||||
</target>
|
||||
<target name="clean" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildArguments/>
|
||||
<buildTarget>clean</buildTarget>
|
||||
<stopOnError>true</stopOnError>
|
||||
<useDefaultCommand>true</useDefaultCommand>
|
||||
<runAllBuilders>true</runAllBuilders>
|
||||
</target>
|
||||
<target name="distclean" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildArguments/>
|
||||
<buildTarget>distclean</buildTarget>
|
||||
<stopOnError>true</stopOnError>
|
||||
<useDefaultCommand>true</useDefaultCommand>
|
||||
<runAllBuilders>true</runAllBuilders>
|
||||
</target>
|
||||
<target name="log4cpp-dist" path="third-party" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildArguments/>
|
||||
<buildTarget>log4cpp-dist</buildTarget>
|
||||
<stopOnError>true</stopOnError>
|
||||
<useDefaultCommand>true</useDefaultCommand>
|
||||
<runAllBuilders>true</runAllBuilders>
|
||||
</target>
|
||||
<target name="tinkerforge-dist" path="third-party" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildArguments/>
|
||||
<buildTarget>tinkerforge-dist</buildTarget>
|
||||
<stopOnError>true</stopOnError>
|
||||
<useDefaultCommand>true</useDefaultCommand>
|
||||
<runAllBuilders>true</runAllBuilders>
|
||||
</target>
|
||||
<target name="log4cpp-distclean" path="third-party" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildArguments/>
|
||||
<buildTarget>log4cpp-distclean</buildTarget>
|
||||
<stopOnError>true</stopOnError>
|
||||
<useDefaultCommand>true</useDefaultCommand>
|
||||
<runAllBuilders>true</runAllBuilders>
|
||||
</target>
|
||||
<target name="tinkerforge-distclean" path="third-party" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildArguments/>
|
||||
<buildTarget>tinkerforge-distclean</buildTarget>
|
||||
<stopOnError>true</stopOnError>
|
||||
<useDefaultCommand>true</useDefaultCommand>
|
||||
<runAllBuilders>true</runAllBuilders>
|
||||
</target>
|
||||
<target name="all" path="third-party" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildArguments/>
|
||||
<buildTarget>all</buildTarget>
|
||||
<stopOnError>true</stopOnError>
|
||||
<useDefaultCommand>true</useDefaultCommand>
|
||||
<runAllBuilders>true</runAllBuilders>
|
||||
</target>
|
||||
<target name="clean" path="third-party" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildArguments/>
|
||||
<buildTarget>clean</buildTarget>
|
||||
<stopOnError>true</stopOnError>
|
||||
<useDefaultCommand>true</useDefaultCommand>
|
||||
<runAllBuilders>true</runAllBuilders>
|
||||
</target>
|
||||
<target name="tinkerforge-dist" path="lib" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildTarget>tinkerforge-dist</buildTarget>
|
||||
<stopOnError>true</stopOnError>
|
||||
<useDefaultCommand>true</useDefaultCommand>
|
||||
<runAllBuilders>true</runAllBuilders>
|
||||
</target>
|
||||
<target name="tinkerforge-distclean" path="lib" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildTarget>tinkerforge-distclean</buildTarget>
|
||||
<stopOnError>true</stopOnError>
|
||||
<useDefaultCommand>true</useDefaultCommand>
|
||||
<runAllBuilders>true</runAllBuilders>
|
||||
</target>
|
||||
<target name="log4cpp-dist" path="lib" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildTarget>log4cpp-dist</buildTarget>
|
||||
<stopOnError>true</stopOnError>
|
||||
<useDefaultCommand>true</useDefaultCommand>
|
||||
<runAllBuilders>true</runAllBuilders>
|
||||
</target>
|
||||
<target name="log4cpp-distclean" path="lib" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildTarget>log4cpp-distclean</buildTarget>
|
||||
<stopOnError>true</stopOnError>
|
||||
<useDefaultCommand>true</useDefaultCommand>
|
||||
<runAllBuilders>true</runAllBuilders>
|
||||
</target>
|
||||
<target name="all" path="lib" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildTarget>all</buildTarget>
|
||||
<stopOnError>true</stopOnError>
|
||||
<useDefaultCommand>true</useDefaultCommand>
|
||||
<runAllBuilders>true</runAllBuilders>
|
||||
</target>
|
||||
<target name="clean" path="lib" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildTarget>clean</buildTarget>
|
||||
<stopOnError>true</stopOnError>
|
||||
<useDefaultCommand>true</useDefaultCommand>
|
||||
<runAllBuilders>true</runAllBuilders>
|
||||
</target>
|
||||
</buildTargets>
|
||||
</storageModule>
|
||||
</cproject>
|
||||
@@ -0,0 +1,7 @@
|
||||
syntax: regexp
|
||||
|
||||
^bin/
|
||||
^build/
|
||||
^lib/
|
||||
^third-party/log4cpp/
|
||||
^third-party/tinkerforge/
|
||||
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>TinkerforgeCPPsimple</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
|
||||
<triggers>clean,full,incremental,</triggers>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
|
||||
<triggers>full,incremental,</triggers>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.cdt.core.cnature</nature>
|
||||
<nature>org.eclipse.cdt.core.ccnature</nature>
|
||||
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
|
||||
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<project>
|
||||
<configuration id="cdt.managedbuild.toolchain.gnu.base.2045375629" name="Default">
|
||||
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
|
||||
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
||||
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
||||
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuildCommandParser" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser" keep-relative-paths="false" name="CDT GCC Build Output Parser" parameter="(gcc)|([gc]\+\+)|(clang)" prefer-non-shared="true"/>
|
||||
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-1226846246929179048" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}" -std=c++11">
|
||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||
</provider>
|
||||
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
||||
</extension>
|
||||
</configuration>
|
||||
</project>
|
||||
@@ -0,0 +1,25 @@
|
||||
|
||||
include Makefile.local
|
||||
|
||||
SRC_FILES =
|
||||
|
||||
include src/config.mk
|
||||
|
||||
OBJS = $(SRC_FILES:src/%.cpp=build/%.o)
|
||||
|
||||
all : lib/libtfcppsimple.a
|
||||
|
||||
lib/libtfcppsimple.a : lib $(OBJS)
|
||||
mkdir -p lib
|
||||
$(AR) rc $@ $(OBJS)
|
||||
$(RANLIB) $@
|
||||
|
||||
$(OBJS) : build/%.o : src/%.cpp
|
||||
mkdir -p $(dir $@)
|
||||
$(CXX) $(CXX_FLAGS) -I include -I third-party/tinkerforge/include -I third-party/log4cpp/include -c $< -o $@
|
||||
|
||||
clean :
|
||||
rm -rf build
|
||||
|
||||
distclean : clean
|
||||
rm -rf lib/libtfcppsimple.a
|
||||
@@ -0,0 +1,28 @@
|
||||
|
||||
|
||||
|
||||
CXX_FLAGS = -O0 -g3 -Wall -std=c++11
|
||||
|
||||
TINKERFORGE_CXX_FLAGS =
|
||||
|
||||
|
||||
|
||||
GCC_HOME =
|
||||
GCC_PREFIX =
|
||||
|
||||
GCC = ${GCC_PREFIX}-gcc
|
||||
CXX = ${GCC_PREFIX}-g++
|
||||
CPP = ${GCC_PREFIX}-cpp
|
||||
AR = ${GCC_PREFIX}-ar
|
||||
OBJDUMP = ${GCC_PREFIX}-objdump
|
||||
RANLIB = ${GCC_PREFIX}-ranlib
|
||||
SIZE = ${GCC_PREFIX}-size
|
||||
|
||||
#GCC = ${GCC_HOME}/bin/${GCC_PREFIX}-gcc
|
||||
#CXX = ${GCC_HOME}/bin/${GCC_PREFIX}-g++
|
||||
#CPP = ${GCC_HOME}/bin/${GCC_PREFIX}-cpp
|
||||
#AR = ${GCC_HOME}/bin/${GCC_PREFIX}-ar
|
||||
#OBJDUMP = ${GCC_HOME}/bin/${GCC_PREFIX}-objdump
|
||||
#RANLIB = ${GCC_HOME}/bin/${GCC_PREFIX}-ranlib
|
||||
#SIZE = ${GCC_HOME}/bin/${GCC_PREFIX}-size
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* TfCPPsimple.h
|
||||
*
|
||||
* Created on: 11.06.2014
|
||||
* Author: matzman
|
||||
*/
|
||||
|
||||
#ifndef TFCPPSIMPLE_H_
|
||||
#define TFCPPSIMPLE_H_
|
||||
|
||||
#include <tfcppsimple/TfException.h>
|
||||
#include <tfcppsimple/TfConnection.h>
|
||||
#include <tfcppsimple/TfUtils.h>
|
||||
#include <tfcppsimple/TfDevice.h>
|
||||
#include <tfcppsimple/devices/TfMasterBrick.h>
|
||||
#include <tfcppsimple/devices/TfHumidityBricklet.h>
|
||||
#include <tfcppsimple/devices/TfIO16Bricklet.h>
|
||||
#include <tfcppsimple/devices/TfLCD20x4Bricklet.h>
|
||||
#include <tfcppsimple/devices/TfTemperatureBricklet.h>
|
||||
#include <tfcppsimple/devices/TfUnknownBrick.h>
|
||||
#include <tfcppsimple/devices/TfUnknownBricklet.h>
|
||||
|
||||
|
||||
|
||||
#endif /* TFCPPSIMPLE_H_ */
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* ObservableTemplate.h
|
||||
*
|
||||
* Created on: 11.06.2014
|
||||
* Author: matzman
|
||||
*/
|
||||
|
||||
#ifndef OBSERVABLETEMPLATE_H_
|
||||
#define OBSERVABLETEMPLATE_H_
|
||||
|
||||
#include <set>
|
||||
#include <mutex>
|
||||
#include <functional>
|
||||
#include <cstdint>
|
||||
|
||||
namespace tfcppsimple {
|
||||
|
||||
template<class C>
|
||||
class ObservableTemplate {
|
||||
protected:
|
||||
std::mutex observableLock;
|
||||
std::set<C*> listeners;
|
||||
public:
|
||||
bool addListener(C& listener) {
|
||||
std::lock_guard<std::mutex> lock(observableLock);
|
||||
return listeners.insert(&listener).second;
|
||||
}
|
||||
bool removeListener(C& listener) {
|
||||
std::lock_guard<std::mutex> lock(observableLock);
|
||||
return listeners.erase(&listener) == 1;
|
||||
}
|
||||
uint32_t notifyListeners(std::function<bool(C& listener)> visitor) {
|
||||
std::lock_guard<std::mutex> lock(observableLock);
|
||||
uint32_t count = 0;
|
||||
for (auto l : listeners) {
|
||||
count++;
|
||||
if (!visitor(*l)) break;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif /* OBSERVABLETEMPLATE_H_ */
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* TfBrick.h
|
||||
*
|
||||
* Created on: 12.06.2014
|
||||
* Author: matzman
|
||||
*/
|
||||
|
||||
#ifndef TFBRICK_H_
|
||||
#define TFBRICK_H_
|
||||
|
||||
#include <tfcppsimple/TfDevice.h>
|
||||
|
||||
namespace tfcppsimple {
|
||||
|
||||
class TfBrick: public TfDevice {
|
||||
public:
|
||||
TfBrick(TfConnection& connection,
|
||||
std::string uid,
|
||||
std::string connected_uid,
|
||||
TfDevicePosition position,
|
||||
TfVersion hardware_version,
|
||||
TfVersion firmware_version,
|
||||
uint16_t raw_device_identifier,
|
||||
TfDeviceIdentifier device_identifier,
|
||||
TfDevice* parent
|
||||
);
|
||||
virtual ~TfBrick();
|
||||
};
|
||||
|
||||
} /* namespace tfcppsimple */
|
||||
|
||||
#endif /* TFBRICK_H_ */
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* TfBricklet.h
|
||||
*
|
||||
* Created on: 12.06.2014
|
||||
* Author: matzman
|
||||
*/
|
||||
|
||||
#ifndef TFBRICKLET_H_
|
||||
#define TFBRICKLET_H_
|
||||
|
||||
#include <tfcppsimple/TfDevice.h>
|
||||
|
||||
namespace tfcppsimple {
|
||||
|
||||
class TfBricklet: public TfDevice {
|
||||
public:
|
||||
TfBricklet(TfConnection& connection,
|
||||
std::string uid,
|
||||
std::string connected_uid,
|
||||
TfDevicePosition position,
|
||||
TfVersion hardware_version,
|
||||
TfVersion firmware_version,
|
||||
uint16_t raw_device_identifier,
|
||||
TfDeviceIdentifier device_identifier,
|
||||
TfDevice* parent
|
||||
);
|
||||
virtual ~TfBricklet();
|
||||
};
|
||||
|
||||
} /* namespace tfcppsimple */
|
||||
|
||||
#endif /* TFBRICKLET_H_ */
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* TFConnection.h
|
||||
*
|
||||
* Created on: 10.06.2014
|
||||
* Author: matzman
|
||||
*/
|
||||
|
||||
#ifndef TFCONNECTION_H_
|
||||
#define TFCONNECTION_H_
|
||||
|
||||
#include <tfcppsimple/TfTypes.h>
|
||||
#include <tfcppsimple/ObservableTemplate.h>
|
||||
#include <tfcppsimple/TfDevice.h>
|
||||
#include <log4cpp/Category.hh>
|
||||
#include <ip_connection.h>
|
||||
#include <string>
|
||||
#include <mutex>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace tfcppsimple {
|
||||
|
||||
|
||||
class TfDevice;
|
||||
class TfConnection;
|
||||
|
||||
enum class TfConnectionState : int {
|
||||
NOTCONFIGURED = 0,
|
||||
PENDING = 1,
|
||||
CONNECTED = 2,
|
||||
CONNECTION_LOST = 3,
|
||||
DISCONNECTED = 4,
|
||||
ERROR = 5
|
||||
};
|
||||
|
||||
|
||||
class TfConnectionListener {
|
||||
public:
|
||||
virtual ~TfConnectionListener() {}
|
||||
|
||||
virtual void stateChangeCallback(TfConnection& conn, TfConnectionState oldstate, TfConnectionState newstate) {}
|
||||
virtual void connectCallback(TfConnection& conn, TfCallbackConnectReason reason) {}
|
||||
virtual void disconnectCallback(TfConnection& conn, TfCallbackDisconnectReason reason) {}
|
||||
virtual void newDeviceCallback(TfConnection& conn, TfDevice& device) {}
|
||||
virtual void shutdownCallback(TfConnection& conn) {}
|
||||
};
|
||||
|
||||
|
||||
class TfConnection : public ObservableTemplate<TfConnectionListener> {
|
||||
public:
|
||||
|
||||
private:
|
||||
static log4cpp::Category& logger;
|
||||
|
||||
static void __enumerateCallback( const char *uid,
|
||||
const char *connected_uid,
|
||||
char position,
|
||||
uint8_t hardware_version[3],
|
||||
uint8_t firmware_version[3],
|
||||
uint16_t device_identifier,
|
||||
uint8_t enumeration_type,
|
||||
void *user_data);
|
||||
static void __connectedCallback(uint8_t connect_reason, void *user_data);
|
||||
static void __disconnectedCallback(uint8_t disconnect_reason, void *user_data);
|
||||
|
||||
void enumerateCallback(
|
||||
const char *uid,
|
||||
const char *connected_uid,
|
||||
char position,
|
||||
uint8_t hardware_version[3],
|
||||
uint8_t firmware_version[3],
|
||||
uint16_t device_identifier,
|
||||
TfCallbackEnumerationType enumeration_type);
|
||||
void connectedCallback(TfCallbackConnectReason connect_reason);
|
||||
void disconnectedCallback(TfCallbackDisconnectReason disconnect_reason);
|
||||
|
||||
bool stateChange(TfConnectionState newstate);
|
||||
|
||||
|
||||
std::mutex objLock;
|
||||
IPConnection tfIpConnection;
|
||||
std::string host;
|
||||
uint16_t port = 0;
|
||||
bool okFlag = false;
|
||||
TfConnectionState state = TfConnectionState::NOTCONFIGURED;
|
||||
std::map<std::string, TfDevice*> devices;
|
||||
std::vector<TfDevice*> rootDevices;
|
||||
|
||||
|
||||
public:
|
||||
TfConnection();
|
||||
virtual ~TfConnection();
|
||||
|
||||
bool connect(std::string host = "localhost", uint16_t port = 4223,
|
||||
bool autoReconnect = true, uint32_t timeout = 2500);
|
||||
bool disconnect();
|
||||
|
||||
IPConnection& getTfIpConnection() { return tfIpConnection; }
|
||||
|
||||
const std::map<std::string, TfDevice*>& getDeviceMap() { return devices; }
|
||||
const std::vector<TfDevice*>& getRootDevices() { return rootDevices; }
|
||||
|
||||
|
||||
bool isOk() { return okFlag; }
|
||||
|
||||
bool isAutoReconnect() { return ipcon_get_auto_reconnect(&tfIpConnection); }
|
||||
void setAutoReconnect(bool flag) { return ipcon_set_auto_reconnect(&tfIpConnection, flag); }
|
||||
|
||||
uint32_t getResponseTimeout() { return ipcon_get_timeout(&tfIpConnection); }
|
||||
void setResponseTimeout(uint32_t timeout) { ipcon_set_timeout(&tfIpConnection, timeout); }
|
||||
|
||||
TfConnectionState getStatus() { return state; }
|
||||
|
||||
void startDeviceQuery(uint32_t usec);
|
||||
|
||||
void wait() { ipcon_wait(&tfIpConnection); }
|
||||
void unwait() { ipcon_unwait(&tfIpConnection); }
|
||||
|
||||
const std::string& getHost() { return host; }
|
||||
|
||||
uint16_t getPort() { return port; }
|
||||
};
|
||||
|
||||
} /* namespace growcontrol */
|
||||
|
||||
#endif /* TFCONNECTION_H_ */
|
||||
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
* TfAbstractDevice.h
|
||||
*
|
||||
* Created on: 12.06.2014
|
||||
* Author: matzman
|
||||
*/
|
||||
|
||||
#ifndef TFABSTRACTDEVICE_H_
|
||||
#define TFABSTRACTDEVICE_H_
|
||||
|
||||
#include <tfcppsimple/TfTypes.h>
|
||||
#include <tfcppsimple/TfConnection.h>
|
||||
#include <log4cpp/Category.hh>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
|
||||
namespace tfcppsimple {
|
||||
|
||||
class TfConnection;
|
||||
class TfDevice;
|
||||
|
||||
|
||||
enum class TfDevicePosition : char {
|
||||
//'0' - '8' (Position in Stapel). Für Bricklets: 'a' - 'd' (Position an Brick).
|
||||
BRICK0 = '0',
|
||||
BRICK1 = '1',
|
||||
BRICK2 = '2',
|
||||
BRICK3 = '3',
|
||||
BRICK4 = '4',
|
||||
BRICK5 = '5',
|
||||
BRICK6 = '6',
|
||||
BRICK7 = '7',
|
||||
BRICK8 = '8',
|
||||
|
||||
BRICKLET0 = 'a',
|
||||
BRICKLET1 = 'b',
|
||||
BRICKLET2 = 'c',
|
||||
BRICKLET3 = 'd',
|
||||
};
|
||||
|
||||
|
||||
enum class TfDeviceIdentifier : uint16_t {
|
||||
UNKNOWN = 0,
|
||||
UNKNOWN_BRICK = 0,
|
||||
UNKNOWN_BRICKLET = 0,
|
||||
MASTER = 13,
|
||||
LCD20x4 = 212,
|
||||
HUMIDITY = 27,
|
||||
IO16 = 28,
|
||||
TEMPERATURE = 216
|
||||
};
|
||||
|
||||
|
||||
enum class TfDeviceType : int {
|
||||
UNKNOWN = 0,
|
||||
BRICK = 1,
|
||||
BRICKLET = 2
|
||||
};
|
||||
|
||||
enum class TfDeviceState : int {
|
||||
UNKNOWN,
|
||||
AVAILABLE,
|
||||
CONNECTED,
|
||||
DISCONNECTED,
|
||||
CONNECTION_LOST
|
||||
};
|
||||
|
||||
struct TfVersion {
|
||||
uint8_t _major;
|
||||
uint8_t _minor;
|
||||
uint8_t _release;
|
||||
} __attribute__((packed));
|
||||
|
||||
|
||||
class TfDeviceStateListener {
|
||||
public:
|
||||
virtual ~TfDeviceStateListener() {}
|
||||
|
||||
virtual void stateChangeCallback(TfDevice& device, TfDeviceState oldstate, TfDeviceState newstate) {}
|
||||
virtual void shutdownCallback(TfDevice& device) {}
|
||||
};
|
||||
|
||||
|
||||
class TfDevice : public ObservableTemplate<TfDeviceStateListener> {
|
||||
friend class TfDeviceFactory;
|
||||
friend class TfConnection;
|
||||
public:
|
||||
|
||||
protected:
|
||||
static log4cpp::Category& logger;
|
||||
|
||||
TfConnection& connection;
|
||||
std::string uid;
|
||||
std::string connected_uid;
|
||||
TfDevicePosition position;
|
||||
TfVersion hardware_version;
|
||||
TfVersion firmware_version;
|
||||
uint16_t raw_device_identifier;
|
||||
TfDeviceIdentifier device_identifier;
|
||||
TfDevice* parent;
|
||||
std::map<TfDevicePosition, TfDevice*> children;
|
||||
TfDeviceType deviceType;
|
||||
TfDeviceState state = TfDeviceState::UNKNOWN;
|
||||
bool configuredFlag = false;
|
||||
|
||||
TfDevice(TfConnection& connection,
|
||||
std::string uid,
|
||||
std::string connected_uid,
|
||||
TfDevicePosition position,
|
||||
TfVersion hardware_version,
|
||||
TfVersion firmware_version,
|
||||
uint16_t raw_device_identifier,
|
||||
TfDeviceIdentifier device_identifier,
|
||||
TfDevice* parent,
|
||||
TfDeviceType deviceType
|
||||
);
|
||||
|
||||
virtual bool changeDeviceState(TfDeviceState newstate);
|
||||
virtual void doConfigureDevice();
|
||||
virtual void doReconfigureDevice();
|
||||
virtual void doUnconfigureDevice();
|
||||
virtual void doConnectionLost();
|
||||
virtual void doShutdown();
|
||||
|
||||
void signalEnumerationCallback(TfCallbackEnumerationType enumeration_type);
|
||||
void signalConnectedCallback(TfCallbackConnectReason connect_reason);
|
||||
void signalDisconnectedCallback(TfCallbackDisconnectReason disconnect_reason);
|
||||
void signalShutdown();
|
||||
|
||||
public:
|
||||
virtual ~TfDevice();
|
||||
|
||||
bool connect();
|
||||
bool disconnect();
|
||||
|
||||
const std::string& getConnectedUid() {
|
||||
return connected_uid;
|
||||
}
|
||||
|
||||
TfDeviceIdentifier getDeviceIdentifier() {
|
||||
return device_identifier;
|
||||
}
|
||||
|
||||
const TfVersion& getFirmwareVersion() {
|
||||
return firmware_version;
|
||||
}
|
||||
|
||||
const TfVersion& getHardwareVersion() {
|
||||
return hardware_version;
|
||||
}
|
||||
|
||||
TfDevicePosition getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
uint16_t getRawDeviceIdentifier() {
|
||||
return raw_device_identifier;
|
||||
}
|
||||
|
||||
const std::string& getUid() {
|
||||
return uid;
|
||||
}
|
||||
|
||||
const std::map<TfDevicePosition, TfDevice*>& getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
TfDevice* getChild(TfDevicePosition pos) {
|
||||
auto ret = children.find(pos);
|
||||
return ret == children.end() ? nullptr : ret->second;
|
||||
}
|
||||
|
||||
TfDevice* getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
TfDeviceType getDeviceType() {
|
||||
return deviceType;
|
||||
}
|
||||
|
||||
TfConnection& getConnection() {
|
||||
return connection;
|
||||
}
|
||||
|
||||
TfDeviceState getDeviceState() { return state; }
|
||||
|
||||
bool isConfigured() { return configuredFlag; }
|
||||
|
||||
virtual std::string getDeviceName(bool extended = true);
|
||||
};
|
||||
|
||||
|
||||
} /* namespace tfcppsimple */
|
||||
|
||||
|
||||
#endif /* TFABSTRACTDEVICE_H_ */
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* DeviceFactory.h
|
||||
*
|
||||
* Created on: 12.06.2014
|
||||
* Author: matzman
|
||||
*/
|
||||
|
||||
#ifndef TFDEVICEFACTORY_H_
|
||||
#define TFDEVICEFACTORY_H_
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace tfcppsimple {
|
||||
|
||||
class TfDevice;
|
||||
class TfConnection;
|
||||
|
||||
class TfDeviceFactory {
|
||||
public:
|
||||
static TfDevice* createNewDevice(
|
||||
TfConnection& conn,
|
||||
const char *uid,
|
||||
const char *connected_uid,
|
||||
char position,
|
||||
uint8_t hardware_version[3],
|
||||
uint8_t firmware_version[3],
|
||||
uint16_t device_identifier,
|
||||
TfDevice* parent);
|
||||
};
|
||||
|
||||
} /* namespace tfcppsimple */
|
||||
|
||||
#endif /* DEVICEFACTORY_H_ */
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* TfException.h
|
||||
*
|
||||
* Created on: 11.06.2014
|
||||
* Author: matzman
|
||||
*/
|
||||
|
||||
#ifndef TFEXCEPTION_H_
|
||||
#define TFEXCEPTION_H_
|
||||
|
||||
|
||||
#include <tfcppsimple/TfTypes.h>
|
||||
#include <exception>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace tfcppsimple {
|
||||
|
||||
class TfException : public std::runtime_error {
|
||||
public:
|
||||
TfException(std::string message)
|
||||
: std::runtime_error(message) {}
|
||||
};
|
||||
|
||||
class TfError : public TfException {
|
||||
private:
|
||||
TfErrorCode errorCode;
|
||||
public:
|
||||
TfError(std::string message, TfErrorCode code)
|
||||
: TfException(message), errorCode(code) {}
|
||||
|
||||
TfErrorCode getErrorCode() { return errorCode; }
|
||||
};
|
||||
|
||||
|
||||
} // end namespace tfcppsimple
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* TFEXCEPTION_H_ */
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* TfTypes.h
|
||||
*
|
||||
* Created on: 11.06.2014
|
||||
* Author: matzman
|
||||
*/
|
||||
|
||||
#ifndef TFTYPES_H_
|
||||
#define TFTYPES_H_
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace tfcppsimple {
|
||||
|
||||
enum class TfErrorCode : int {
|
||||
E_OK = 0,
|
||||
E_TIMEOUT = -1,
|
||||
E_NO_STREAM_SOCKET = -2,
|
||||
E_HOSTNAME_INVALID = -3,
|
||||
E_NO_CONNECT = -4,
|
||||
E_NO_THREAD = -5,
|
||||
E_NOT_ADDED = -6, // (seit Bindings Version 2.0.0 nicht mehr verwendet)
|
||||
E_ALREADY_CONNECTED = -7,
|
||||
E_NOT_CONNECTED = -8,
|
||||
E_INVALID_PARAMETER = -9,
|
||||
E_NOT_SUPPORTED = -10,
|
||||
E_UNKNOWN_ERROR_CODE = -11
|
||||
};
|
||||
|
||||
enum class TfCallbackConnectReason : uint8_t {
|
||||
REQUEST = 0, // Verbindung aufgebaut nach Anfrage vom Benutzer.
|
||||
RECONNECT = 1 // Verbindung aufgebaut nach durch Auto-Reconnect.
|
||||
};
|
||||
|
||||
enum class TfCallbackDisconnectReason : uint8_t {
|
||||
REQUEST =0, // Trennung wurde vom Benutzer angefragt.
|
||||
ERROR = 1, // Trennung aufgrund eines unlösbaren Problems.
|
||||
SHUTDOWN = 2, // Trennung wurde vom Brick Daemon oder WIFI/Ethernet Extension eingeleitet.
|
||||
};
|
||||
|
||||
|
||||
enum class TfCallbackEnumerationType : uint8_t {
|
||||
AVAILABLE = 0, // Gerät ist verfügbar (Enumerierung vom Benutzer ausgelöst).
|
||||
CONNECTED = 1, // Gerät wurde neu verbunden (Automatisch vom Brick gesendet nachdem die Kommunikation aufgebaut wurde). Dies kann bedeuten, dass das Gerät die vorher eingestellte Konfiguration verloren hat und neu konfiguriert werden muss.
|
||||
DISCONNECTED = 2, // Gerät wurde getrennt (Nur bei USB-Verbindungen möglich). In diesem Fall haben nur uid und enumeration_type einen gültigen Wert.
|
||||
};
|
||||
|
||||
|
||||
} // end namespace tfcppsimple
|
||||
|
||||
|
||||
|
||||
#endif /* TFTYPES_H_ */
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* TfUtils.h
|
||||
*
|
||||
* Created on: 11.06.2014
|
||||
* Author: matzman
|
||||
*/
|
||||
|
||||
#ifndef TFUTILS_H_
|
||||
#define TFUTILS_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace tfcppsimple {
|
||||
|
||||
class TfUtils {
|
||||
public:
|
||||
static void configureLog4CPP(std::string configFile);
|
||||
static void configureLog4CPP(); // Default Config
|
||||
};
|
||||
|
||||
} /* namespace tfcppsimple */
|
||||
|
||||
#endif /* TFUTILS_H_ */
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* TfHumidityBricklet.h
|
||||
*
|
||||
* Created on: 12.06.2014
|
||||
* Author: matzman
|
||||
*/
|
||||
|
||||
#ifndef TFHUMIDITYBRICKLET_H_
|
||||
#define TFHUMIDITYBRICKLET_H_
|
||||
|
||||
#include <tfcppsimple/TfBricklet.h>
|
||||
#include <bricklet_humidity.h>
|
||||
|
||||
namespace tfcppsimple {
|
||||
|
||||
class TfHumidityBricklet: public TfBricklet {
|
||||
friend class TfDeviceFactory;
|
||||
private:
|
||||
Humidity humidityObj;
|
||||
|
||||
TfHumidityBricklet(TfConnection& connection,
|
||||
std::string uid,
|
||||
std::string connected_uid,
|
||||
TfDevicePosition position,
|
||||
TfVersion hardware_version,
|
||||
TfVersion firmware_version,
|
||||
TfDevice* parent
|
||||
);
|
||||
|
||||
virtual void doConfigureDevice();
|
||||
virtual void doReconfigureDevice();
|
||||
virtual void doConnectionLost();
|
||||
virtual void doShutdown();
|
||||
|
||||
public:
|
||||
virtual ~TfHumidityBricklet();
|
||||
|
||||
virtual std::string getDeviceName(bool extended = true);
|
||||
|
||||
uint16_t getHumidity();
|
||||
|
||||
uint16_t getHumidityRaw();
|
||||
};
|
||||
|
||||
} /* namespace tfcppsimple */
|
||||
|
||||
#endif /* TFHUMIDITYBRICKLET_H_ */
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* TfIO16Bricklet.h
|
||||
*
|
||||
* Created on: 12.06.2014
|
||||
* Author: matzman
|
||||
*/
|
||||
|
||||
#ifndef TFIO16BRICKLET_H_
|
||||
#define TFIO16BRICKLET_H_
|
||||
|
||||
#include <tfcppsimple/TfBricklet.h>
|
||||
|
||||
namespace tfcppsimple {
|
||||
|
||||
class TfIO16Bricklet: public TfBricklet {
|
||||
public:
|
||||
TfIO16Bricklet(TfConnection& connection,
|
||||
std::string uid,
|
||||
std::string connected_uid,
|
||||
TfDevicePosition position,
|
||||
TfVersion hardware_version,
|
||||
TfVersion firmware_version,
|
||||
TfDevice* parent
|
||||
);
|
||||
virtual ~TfIO16Bricklet();
|
||||
|
||||
virtual std::string getDeviceName(bool extended = true);
|
||||
};
|
||||
|
||||
} /* namespace tfcppsimple */
|
||||
|
||||
#endif /* TFIO16BRICKLET_H_ */
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* TfLCD204Bricklet.h
|
||||
*
|
||||
* Created on: 12.06.2014
|
||||
* Author: matzman
|
||||
*/
|
||||
|
||||
#ifndef TFLCD20X4BRICKLET_H_
|
||||
#define TFLCD20X4BRICKLET_H_
|
||||
|
||||
#include <tfcppsimple/TfBricklet.h>
|
||||
#include <bricklet_lcd_20x4.h>
|
||||
|
||||
namespace tfcppsimple {
|
||||
|
||||
class TfLCD20x4Bricklet;
|
||||
|
||||
class TfLCD20x4Listener {
|
||||
public:
|
||||
virtual ~TfLCD20x4Listener() {}
|
||||
|
||||
virtual void buttonStateCallback(TfLCD20x4Bricklet& lcd, uint8_t button, bool state) {}
|
||||
};
|
||||
|
||||
class TfLCD20x4Bricklet: public TfBricklet {
|
||||
friend class TfDeviceFactory;
|
||||
private:
|
||||
LCD20x4 lcdObj;
|
||||
bool backlightFlag = false;
|
||||
bool cursorFlag = false;
|
||||
bool blinkingFlag = false;
|
||||
ObservableTemplate<TfLCD20x4Listener> lcdListeners;
|
||||
|
||||
TfLCD20x4Bricklet(TfConnection& connection,
|
||||
std::string uid,
|
||||
std::string connected_uid,
|
||||
TfDevicePosition position,
|
||||
TfVersion hardware_version,
|
||||
TfVersion firmware_version,
|
||||
TfDevice* parent
|
||||
);
|
||||
|
||||
virtual void doConfigureDevice();
|
||||
virtual void doReconfigureDevice();
|
||||
virtual void doConnectionLost();
|
||||
virtual void doShutdown();
|
||||
|
||||
static void __buttonPressed(uint8_t button, void *user_data);
|
||||
static void __buttonReleased(uint8_t button, void *user_data);
|
||||
void buttonStateCallBack(uint8_t button, bool state);
|
||||
|
||||
public:
|
||||
virtual ~TfLCD20x4Bricklet();
|
||||
|
||||
virtual std::string getDeviceName(bool extended = true);
|
||||
|
||||
void writeLine(uint8_t line, uint8_t position, std::string txt);
|
||||
|
||||
void clearDisplay();
|
||||
|
||||
void setBacklight(bool backlight);
|
||||
|
||||
bool getBacklight() { return false; }
|
||||
|
||||
void setCursor(bool cursor, bool blinking = false);
|
||||
|
||||
bool addLcdListener(TfLCD20x4Listener& listener);
|
||||
|
||||
bool removeLcdListener(TfLCD20x4Listener& listener);
|
||||
};
|
||||
|
||||
} /* namespace tfcppsimple */
|
||||
|
||||
#endif /* TFLCD20X4BRICKLET_H_ */
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* TfMasterBrick.h
|
||||
*
|
||||
* Created on: 12.06.2014
|
||||
* Author: matzman
|
||||
*/
|
||||
|
||||
#ifndef TFMASTERBRICK_H_
|
||||
#define TFMASTERBRICK_H_
|
||||
|
||||
#include <brick_master.h>
|
||||
#include <tfcppsimple/TfBrick.h>
|
||||
|
||||
namespace tfcppsimple {
|
||||
|
||||
class TfMasterBrick: public TfBrick {
|
||||
friend class TfDeviceFactory;
|
||||
private:
|
||||
Master masterObj;
|
||||
|
||||
TfMasterBrick(TfConnection& connection,
|
||||
std::string uid,
|
||||
std::string connected_uid,
|
||||
TfDevicePosition position,
|
||||
TfVersion hardware_version,
|
||||
TfVersion firmware_version,
|
||||
TfDevice* parent
|
||||
);
|
||||
|
||||
virtual void doConfigureDevice();
|
||||
virtual void doReconfigureDevice();
|
||||
virtual void doConnectionLost();
|
||||
virtual void doShutdown();
|
||||
|
||||
public:
|
||||
virtual ~TfMasterBrick();
|
||||
|
||||
virtual std::string getDeviceName(bool extended = true);
|
||||
|
||||
uint16_t getStackVoltage();
|
||||
|
||||
uint16_t getStackCurrent();
|
||||
|
||||
uint16_t getUSBVoltage();
|
||||
|
||||
int16_t getChipTemperature();
|
||||
};
|
||||
|
||||
} /* namespace tfcppsimple */
|
||||
|
||||
#endif /* TFMASTERBRICK_H_ */
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* TfTemperatureBricklet.h
|
||||
*
|
||||
* Created on: 12.06.2014
|
||||
* Author: matzman
|
||||
*/
|
||||
|
||||
#ifndef TFTEMPERATUREBRICKLET_H_
|
||||
#define TFTEMPERATUREBRICKLET_H_
|
||||
|
||||
#include <tfcppsimple/TfBricklet.h>
|
||||
#include <bricklet_temperature.h>
|
||||
|
||||
namespace tfcppsimple {
|
||||
|
||||
enum class TfTemperatureI2Cmode : uint8_t {
|
||||
FAST = 0, // Fast (400kHz, default)
|
||||
SLOW = 1 // Slow (100kHz)
|
||||
};
|
||||
|
||||
class TfTemperatureBricklet: public TfBricklet {
|
||||
friend class TfDeviceFactory;
|
||||
private:
|
||||
Temperature temperatureObj;
|
||||
TfTemperatureI2Cmode i2cMode = TfTemperatureI2Cmode::FAST;
|
||||
|
||||
TfTemperatureBricklet(TfConnection& connection,
|
||||
std::string uid,
|
||||
std::string connected_uid,
|
||||
TfDevicePosition position,
|
||||
TfVersion hardware_version,
|
||||
TfVersion firmware_version,
|
||||
TfDevice* parent
|
||||
);
|
||||
|
||||
virtual void doConfigureDevice();
|
||||
virtual void doReconfigureDevice();
|
||||
virtual void doConnectionLost();
|
||||
virtual void doShutdown();
|
||||
|
||||
public:
|
||||
virtual ~TfTemperatureBricklet();
|
||||
|
||||
virtual std::string getDeviceName(bool extended = true);
|
||||
|
||||
int16_t getTemperature();
|
||||
|
||||
void setI2Cmode(TfTemperatureI2Cmode mode);
|
||||
TfTemperatureI2Cmode getI2Cmode();
|
||||
};
|
||||
|
||||
} /* namespace tfcppsimple */
|
||||
|
||||
#endif /* TFTEMPERATUREBRICKLET_H_ */
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* TfUnknownBrick.h
|
||||
*
|
||||
* Created on: 13.06.2014
|
||||
* Author: matzman
|
||||
*/
|
||||
|
||||
#ifndef TFUNKNOWNBRICK_H_
|
||||
#define TFUNKNOWNBRICK_H_
|
||||
|
||||
#include <tfcppsimple/TfBrick.h>
|
||||
|
||||
namespace tfcppsimple {
|
||||
|
||||
class TfUnknownBrick: public TfBrick {
|
||||
friend class TfDeviceFactory;
|
||||
private:
|
||||
TfUnknownBrick(TfConnection& connection,
|
||||
std::string uid,
|
||||
std::string connected_uid,
|
||||
TfDevicePosition position,
|
||||
TfVersion hardware_version,
|
||||
TfVersion firmware_version,
|
||||
uint16_t raw_device_identifier,
|
||||
TfDevice* parent
|
||||
);
|
||||
|
||||
public:
|
||||
virtual ~TfUnknownBrick();
|
||||
|
||||
virtual std::string getDeviceName(bool extended = true);
|
||||
};
|
||||
|
||||
} /* namespace tfcppsimple */
|
||||
|
||||
#endif /* TFUNKNOWNBRICK_H_ */
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* TfUnknownBricklet.h
|
||||
*
|
||||
* Created on: 13.06.2014
|
||||
* Author: matzman
|
||||
*/
|
||||
|
||||
#ifndef TFUNKNOWNBRICKLET_H_
|
||||
#define TFUNKNOWNBRICKLET_H_
|
||||
|
||||
#include <tfcppsimple/TfBricklet.h>
|
||||
|
||||
namespace tfcppsimple {
|
||||
|
||||
class TfUnknownBricklet: public TfBricklet {
|
||||
friend class TfDeviceFactory;
|
||||
private:
|
||||
TfUnknownBricklet(TfConnection& connection,
|
||||
std::string uid,
|
||||
std::string connected_uid,
|
||||
TfDevicePosition position,
|
||||
TfVersion hardware_version,
|
||||
TfVersion firmware_version,
|
||||
uint16_t raw_device_identifier,
|
||||
TfDevice* parent
|
||||
);
|
||||
|
||||
public:
|
||||
virtual ~TfUnknownBricklet();
|
||||
|
||||
virtual std::string getDeviceName(bool extended = true);
|
||||
};
|
||||
|
||||
} /* namespace tfcppsimple */
|
||||
|
||||
#endif /* TFUNKNOWNBRICKLET_H_ */
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* TfBrick.cpp
|
||||
*
|
||||
* Created on: 12.06.2014
|
||||
* Author: matzman
|
||||
*/
|
||||
|
||||
#include <tfcppsimple/TfBrick.h>
|
||||
|
||||
namespace tfcppsimple {
|
||||
|
||||
TfBrick::TfBrick(TfConnection& connection,
|
||||
std::string uid,
|
||||
std::string connected_uid,
|
||||
TfDevicePosition position,
|
||||
TfVersion hardware_version,
|
||||
TfVersion firmware_version,
|
||||
uint16_t raw_device_identifier,
|
||||
TfDeviceIdentifier device_identifier,
|
||||
TfDevice* parent
|
||||
)
|
||||
: TfDevice(connection, uid, connected_uid, position, hardware_version, firmware_version,
|
||||
raw_device_identifier, device_identifier, parent, TfDeviceType::BRICK ) {
|
||||
|
||||
}
|
||||
|
||||
TfBrick::~TfBrick() {
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
||||
} /* namespace tfcppsimple */
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* TfBricklet.cpp
|
||||
*
|
||||
* Created on: 12.06.2014
|
||||
* Author: matzman
|
||||
*/
|
||||
|
||||
#include <tfcppsimple/TfBricklet.h>
|
||||
|
||||
namespace tfcppsimple {
|
||||
|
||||
TfBricklet::TfBricklet(TfConnection& connection,
|
||||
std::string uid,
|
||||
std::string connected_uid,
|
||||
TfDevicePosition position,
|
||||
TfVersion hardware_version,
|
||||
TfVersion firmware_version,
|
||||
uint16_t raw_device_identifier,
|
||||
TfDeviceIdentifier device_identifier,
|
||||
TfDevice* parent
|
||||
)
|
||||
: TfDevice(connection, uid, connected_uid, position, hardware_version, firmware_version,
|
||||
raw_device_identifier, device_identifier, parent, TfDeviceType::BRICKLET ) {
|
||||
|
||||
}
|
||||
|
||||
TfBricklet::~TfBricklet() {
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
||||
} /* namespace tfcppsimple */
|
||||
@@ -0,0 +1,288 @@
|
||||
/*
|
||||
* TfConnection.cpp
|
||||
*
|
||||
* Created on: 10.06.2014
|
||||
* Author: matzman
|
||||
*/
|
||||
|
||||
#include <tfcppsimple/TfConnection.h>
|
||||
#include <tfcppsimple/TfException.h>
|
||||
#include <tfcppsimple/TfDeviceFactory.h>
|
||||
#include <sstream>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
namespace tfcppsimple {
|
||||
|
||||
|
||||
|
||||
|
||||
log4cpp::Category& TfConnection::logger = log4cpp::Category::getInstance("tfcppsimple.tfconnection");
|
||||
|
||||
|
||||
|
||||
TfConnection::TfConnection() {
|
||||
}
|
||||
|
||||
TfConnection::~TfConnection() {
|
||||
logger.debug("TfConnection::~TfConnection() begin");
|
||||
if (okFlag) {
|
||||
ipcon_destroy(&tfIpConnection); // Calls ipcon_disconnect internally
|
||||
okFlag = false;
|
||||
|
||||
ipcon_register_callback(&tfIpConnection, IPCON_CALLBACK_ENUMERATE,
|
||||
nullptr, nullptr);
|
||||
ipcon_register_callback(&tfIpConnection, IPCON_CALLBACK_CONNECTED,
|
||||
nullptr, nullptr);
|
||||
ipcon_register_callback(&tfIpConnection, IPCON_CALLBACK_DISCONNECTED,
|
||||
nullptr, nullptr);
|
||||
}
|
||||
logger.debug("TfConnection::~TfConnection() end");
|
||||
}
|
||||
|
||||
|
||||
bool TfConnection::connect(std::string host , uint16_t port, bool autoReconnect, uint32_t timeout) {
|
||||
logger.debug("TfConnection::connect(\"%s\" , %d, %d, %d) begin", host.c_str(), port, autoReconnect, timeout);
|
||||
if (!okFlag && state == TfConnectionState::NOTCONFIGURED) {
|
||||
// Create IP Connection
|
||||
ipcon_create(&tfIpConnection);
|
||||
|
||||
ipcon_set_auto_reconnect(&tfIpConnection, autoReconnect);
|
||||
|
||||
ipcon_register_callback(&tfIpConnection, IPCON_CALLBACK_ENUMERATE,
|
||||
(void*)TfConnection::__enumerateCallback, this);
|
||||
|
||||
ipcon_register_callback(&tfIpConnection, IPCON_CALLBACK_CONNECTED,
|
||||
(void*)TfConnection::__connectedCallback, this);
|
||||
|
||||
ipcon_register_callback(&tfIpConnection, IPCON_CALLBACK_DISCONNECTED,
|
||||
(void*)TfConnection::__disconnectedCallback, this);
|
||||
|
||||
// Connect to brickd
|
||||
TfErrorCode errorCode;
|
||||
if((errorCode = (TfErrorCode)ipcon_connect(&tfIpConnection, host.c_str(), port)) != TfErrorCode::E_OK) {
|
||||
std::ostringstream msg;
|
||||
msg << "Could not connect to brickd (" << host <<":" << port << "): Error " << (int)errorCode;
|
||||
throw TfError(msg.str(), errorCode);
|
||||
}
|
||||
|
||||
okFlag = true;
|
||||
}
|
||||
logger.debug("TfConnection::connect() end");
|
||||
return okFlag;
|
||||
}
|
||||
|
||||
bool TfConnection::disconnect() {
|
||||
logger.debug("TfConnection::disconnect() begin");
|
||||
if (okFlag && state != TfConnectionState::NOTCONFIGURED) {
|
||||
notifyListeners([this](TfConnectionListener& l)->bool {
|
||||
l.shutdownCallback(*this);
|
||||
return true;
|
||||
}
|
||||
);
|
||||
for (auto d : devices) {
|
||||
d.second->signalShutdown();
|
||||
delete d.second;
|
||||
}
|
||||
ipcon_destroy(&tfIpConnection); // Calls ipcon_disconnect internally
|
||||
okFlag = false;
|
||||
stateChange(TfConnectionState::NOTCONFIGURED);
|
||||
ipcon_register_callback(&tfIpConnection, IPCON_CALLBACK_ENUMERATE,
|
||||
nullptr, nullptr);
|
||||
ipcon_register_callback(&tfIpConnection, IPCON_CALLBACK_CONNECTED,
|
||||
nullptr, nullptr);
|
||||
ipcon_register_callback(&tfIpConnection, IPCON_CALLBACK_DISCONNECTED,
|
||||
nullptr, nullptr);
|
||||
devices.clear();
|
||||
rootDevices.clear();
|
||||
}
|
||||
logger.debug("TfConnection::disconnect() end");
|
||||
return state == TfConnectionState::NOTCONFIGURED;
|
||||
}
|
||||
|
||||
void TfConnection::__enumerateCallback( const char *uid,
|
||||
const char *connected_uid,
|
||||
char position,
|
||||
uint8_t hardware_version[3],
|
||||
uint8_t firmware_version[3],
|
||||
uint16_t device_identifier,
|
||||
uint8_t enumeration_type,
|
||||
void *user_data) {
|
||||
logger << log4cpp::Priority::DEBUG << "TfConnection::__enumerateCallback(\""
|
||||
<< uid << "\", \"" << connected_uid <<"\", '" << (unsigned)position << "', "
|
||||
<< (unsigned)hardware_version[0] << "." << (unsigned)hardware_version[1] << "." << (unsigned)hardware_version[2] << ", "
|
||||
<< (unsigned)firmware_version[0] << "." << (unsigned)firmware_version[1] << "." << (unsigned)firmware_version[2] << ", "
|
||||
<< device_identifier << ", " << (unsigned)enumeration_type << ", " << user_data << ") begin";
|
||||
if (user_data != nullptr) {
|
||||
TfConnection& conn = *(TfConnection*)user_data;
|
||||
conn.enumerateCallback(uid, connected_uid, position, hardware_version, firmware_version,
|
||||
device_identifier, (TfCallbackEnumerationType)enumeration_type);
|
||||
}
|
||||
logger.debug("TfConnection::__enumerateCallback() end");
|
||||
}
|
||||
|
||||
void TfConnection::__connectedCallback(uint8_t connect_reason, void *user_data) {
|
||||
logger << log4cpp::Priority::DEBUG << "TfConnection::__connectedCallback("
|
||||
<< (unsigned)connect_reason << ", " << user_data << ") begin";
|
||||
if (user_data != nullptr) {
|
||||
TfConnection& conn = *(TfConnection*)user_data;
|
||||
conn.connectedCallback((TfCallbackConnectReason)connect_reason);
|
||||
}
|
||||
logger.debug("TfConnection::__connectedCallback() end");
|
||||
}
|
||||
|
||||
void TfConnection::__disconnectedCallback(uint8_t disconnect_reason, void *user_data) {
|
||||
logger << log4cpp::Priority::DEBUG << "TfConnection::__disconnectedCallback("
|
||||
<< (unsigned)disconnect_reason << ", " << user_data << ") begin";
|
||||
if (user_data != nullptr) {
|
||||
TfConnection& conn = *(TfConnection*)user_data;
|
||||
conn.disconnectedCallback((TfCallbackDisconnectReason)disconnect_reason);
|
||||
}
|
||||
logger.debug("TfConnection::__disconnectedCallback() end");
|
||||
}
|
||||
|
||||
void TfConnection::enumerateCallback(
|
||||
const char *uid,
|
||||
const char *connected_uid,
|
||||
char position,
|
||||
uint8_t hardware_version[3],
|
||||
uint8_t firmware_version[3],
|
||||
uint16_t device_identifier,
|
||||
TfCallbackEnumerationType enumeration_type) {
|
||||
logger << log4cpp::Priority::DEBUG << "TfConnection[" << this << "]::enumerateCallback(\""
|
||||
<< uid << "\", \"" << connected_uid <<"\", '" << (unsigned)position << "', "
|
||||
<< (unsigned)hardware_version[0] << "." << (unsigned)hardware_version[1] << "." << (unsigned)hardware_version[2] << ", "
|
||||
<< (unsigned)firmware_version[0] << "." << (unsigned)firmware_version[1] << "." << (unsigned)firmware_version[2] << ", "
|
||||
<< device_identifier << ", " << (unsigned)enumeration_type << ") begin";
|
||||
|
||||
auto dev = devices.find(uid);
|
||||
if (dev != devices.end()) {
|
||||
dev->second->signalEnumerationCallback(enumeration_type);
|
||||
} else {
|
||||
if ( enumeration_type == TfCallbackEnumerationType::CONNECTED
|
||||
|| enumeration_type == TfCallbackEnumerationType::AVAILABLE ) {
|
||||
TfDevice* parent = nullptr;
|
||||
bool errorFlag = false;
|
||||
if (strcmp(connected_uid, "0") != 0) {
|
||||
auto pdev = devices.find(connected_uid);
|
||||
if (pdev != devices.end()) {
|
||||
parent = pdev->second;
|
||||
} else {
|
||||
errorFlag = true;
|
||||
logger << log4cpp::Priority::ERROR << "TfConnection[" << this
|
||||
<< "]::enumerateCallback: Could not find parent device \""
|
||||
<< connected_uid << "\".";
|
||||
}
|
||||
}
|
||||
if (!errorFlag) {
|
||||
TfDevice* ndev = TfDeviceFactory::createNewDevice(*this, uid, connected_uid,
|
||||
position, hardware_version, firmware_version, device_identifier, parent);
|
||||
devices.insert({ndev->getUid(), ndev});
|
||||
if (ndev->getParent() == nullptr) {
|
||||
rootDevices.push_back(ndev);
|
||||
} else {
|
||||
ndev->getParent()->children.insert({ndev->getPosition(), ndev});
|
||||
}
|
||||
logger << log4cpp::Priority::INFO << "Found device \"" << ndev->getDeviceName(true) << "\".";
|
||||
notifyListeners([ndev, this](TfConnectionListener& l)->bool {
|
||||
l.newDeviceCallback(*this, *ndev);
|
||||
return true;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("TfConnection::enumerateCallback() end");
|
||||
}
|
||||
|
||||
void TfConnection::connectedCallback(TfCallbackConnectReason connect_reason) {
|
||||
logger << log4cpp::Priority::DEBUG << "TfConnection[" << this << "]::connectedCallback("
|
||||
<< (unsigned)connect_reason << ") begin";
|
||||
switch (connect_reason) {
|
||||
case TfCallbackConnectReason::REQUEST:
|
||||
logger << log4cpp::Priority::INFO << "TfConnection[" << this << "]: Connection established.";
|
||||
break;
|
||||
case TfCallbackConnectReason::RECONNECT:
|
||||
logger << log4cpp::Priority::WARN << "TfConnection[" << this << "]: Connection reestablished.";
|
||||
break;
|
||||
default:
|
||||
logger << log4cpp::Priority::FATAL << "TfConnection[" << this << "]: Unknown Connection Reason! What to do?";
|
||||
break;
|
||||
}
|
||||
stateChange(TfConnectionState::CONNECTED);
|
||||
try {
|
||||
startDeviceQuery(0);
|
||||
} catch (TfError& e) {
|
||||
logger << log4cpp::Priority::FATAL << "TfConnection[" << this << "]: " << e.what();
|
||||
}
|
||||
notifyListeners([connect_reason, this](TfConnectionListener& l)->bool {
|
||||
l.connectCallback(*this, connect_reason);
|
||||
return true;
|
||||
}
|
||||
);
|
||||
for (auto d : devices) {
|
||||
d.second->signalConnectedCallback(connect_reason);
|
||||
}
|
||||
logger.debug("TfConnection::connectedCallback() end");
|
||||
}
|
||||
|
||||
void TfConnection::disconnectedCallback(TfCallbackDisconnectReason disconnect_reason) {
|
||||
logger << log4cpp::Priority::DEBUG << "TfConnection[" << this << "]::disconnectedCallback("
|
||||
<< (unsigned)disconnect_reason << ") begin";
|
||||
switch (disconnect_reason) {
|
||||
case TfCallbackDisconnectReason::SHUTDOWN:
|
||||
stateChange(TfConnectionState::CONNECTION_LOST);
|
||||
logger << log4cpp::Priority::WARN << "TfConnection[" << this << "]: Connection shutdown by peer.";
|
||||
break;
|
||||
case TfCallbackDisconnectReason::REQUEST:
|
||||
stateChange(TfConnectionState::DISCONNECTED);
|
||||
logger << log4cpp::Priority::INFO << "TfConnection[" << this << "]: Connection shutdown by user request.";
|
||||
break;
|
||||
case TfCallbackDisconnectReason::ERROR:
|
||||
stateChange(TfConnectionState::ERROR);
|
||||
logger << log4cpp::Priority::FATAL << "TfConnection[" << this << "]: Connection Error! What to do?";
|
||||
break;
|
||||
default:
|
||||
stateChange(TfConnectionState::ERROR);
|
||||
logger << log4cpp::Priority::FATAL << "TfConnection[" << this << "]: Unknown Disconnection Reason! What to do?";
|
||||
break;
|
||||
}
|
||||
notifyListeners([disconnect_reason, this](TfConnectionListener& l)->bool {
|
||||
l.disconnectCallback(*this, disconnect_reason);
|
||||
return true;
|
||||
}
|
||||
);
|
||||
for (auto d : devices) {
|
||||
d.second->signalDisconnectedCallback(disconnect_reason);
|
||||
}
|
||||
logger.debug("TfConnection::disconnectedCallback() end");
|
||||
}
|
||||
|
||||
void TfConnection::startDeviceQuery(uint32_t usec) {
|
||||
logger << log4cpp::Priority::DEBUG << "TfConnection::startDeviceQuery(" << usec << ") begin";
|
||||
TfErrorCode errorCode;
|
||||
if((errorCode = (TfErrorCode)ipcon_enumerate(&tfIpConnection)) != TfErrorCode::E_OK) {
|
||||
std::ostringstream msg;
|
||||
msg << "Error while trying to enumerate devices: " << (int)errorCode;
|
||||
throw TfError(msg.str(), errorCode);
|
||||
}
|
||||
if (usec > 0) {
|
||||
usleep(usec);
|
||||
}
|
||||
logger.debug("TfConnection::startDeviceQuery() end");
|
||||
}
|
||||
|
||||
bool TfConnection::stateChange(TfConnectionState newstate) {
|
||||
TfConnectionState oldstate = state;
|
||||
state = newstate;
|
||||
notifyListeners([oldstate, newstate, this](TfConnectionListener& l)->bool {
|
||||
l.stateChangeCallback(*this, oldstate, newstate);
|
||||
return true;
|
||||
}
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
} /* namespace growcontrol */
|
||||
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
* TfAbstractDevice.cpp
|
||||
*
|
||||
* Created on: 12.06.2014
|
||||
* Author: matzman
|
||||
*/
|
||||
|
||||
#include <tfcppsimple/TfDevice.h>
|
||||
#include <tfcppsimple/TfException.h>
|
||||
#include <sstream>
|
||||
|
||||
namespace tfcppsimple {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
log4cpp::Category& TfDevice::logger = log4cpp::Category::getInstance("tfcppsimple.tfdevice");
|
||||
|
||||
TfDevice::TfDevice(TfConnection& connection,
|
||||
std::string uid,
|
||||
std::string connected_uid,
|
||||
TfDevicePosition position,
|
||||
TfVersion hardware_version,
|
||||
TfVersion firmware_version,
|
||||
uint16_t raw_device_identifier,
|
||||
TfDeviceIdentifier device_identifier,
|
||||
TfDevice* parent,
|
||||
TfDeviceType deviceType
|
||||
)
|
||||
: connection(connection), uid(uid), connected_uid(connected_uid), position(position),
|
||||
hardware_version(hardware_version), firmware_version(firmware_version),
|
||||
raw_device_identifier(raw_device_identifier), device_identifier(device_identifier),
|
||||
parent(parent), deviceType(deviceType) {
|
||||
|
||||
}
|
||||
|
||||
TfDevice::~TfDevice() {
|
||||
}
|
||||
|
||||
bool TfDevice::connect() {
|
||||
try {
|
||||
changeDeviceState(TfDeviceState::CONNECTED);
|
||||
} catch (TfException &e) {
|
||||
logger << log4cpp::Priority::ERROR << getDeviceName(true) << ": exception during connect: " << e.what();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TfDevice::disconnect() {
|
||||
try {
|
||||
if (state == TfDeviceState::CONNECTED) {
|
||||
changeDeviceState(TfDeviceState::AVAILABLE);
|
||||
} else {
|
||||
doUnconfigureDevice();
|
||||
}
|
||||
} catch (TfException &e) {
|
||||
logger << log4cpp::Priority::ERROR << getDeviceName(true) << ": exception during disconnect: " << e.what();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool TfDevice::changeDeviceState(TfDeviceState newstate) {
|
||||
bool validFlag = false;
|
||||
if (state != newstate) {
|
||||
if (state == TfDeviceState::UNKNOWN && newstate == TfDeviceState::AVAILABLE) {
|
||||
validFlag = true;
|
||||
} else if (state == TfDeviceState::AVAILABLE && newstate == TfDeviceState::CONNECTED) {
|
||||
try {
|
||||
doConfigureDevice();
|
||||
validFlag = true;
|
||||
} catch (TfException &e) {
|
||||
logger << log4cpp::Priority::ERROR << getDeviceName(true) << ": exception during state change: " << e.what();
|
||||
}
|
||||
} else if (state == TfDeviceState::AVAILABLE && (newstate == TfDeviceState::DISCONNECTED || newstate == TfDeviceState::CONNECTION_LOST)) {
|
||||
validFlag = true;
|
||||
} else if (state == TfDeviceState::CONNECTED && (newstate == TfDeviceState::DISCONNECTED || newstate == TfDeviceState::CONNECTION_LOST)) {
|
||||
try {
|
||||
doConnectionLost();
|
||||
} catch (TfException &e) {
|
||||
logger << log4cpp::Priority::ERROR << getDeviceName(true) << ": exception during state change: " << e.what();
|
||||
}
|
||||
validFlag = true;
|
||||
} else if ((state == TfDeviceState::DISCONNECTED || state == TfDeviceState::CONNECTION_LOST) && newstate == TfDeviceState::AVAILABLE) {
|
||||
validFlag = true;
|
||||
} else if ((state == TfDeviceState::DISCONNECTED || state == TfDeviceState::CONNECTION_LOST) && newstate == TfDeviceState::CONNECTED) {
|
||||
try {
|
||||
doReconfigureDevice();
|
||||
validFlag = true;
|
||||
} catch (TfException &e) {
|
||||
logger << log4cpp::Priority::ERROR << getDeviceName(true) << ": exception during state change: " << e.what();
|
||||
}
|
||||
} else {
|
||||
logger << log4cpp::Priority::ERROR << getDeviceName(true) << ": invalid state changed from "
|
||||
<< (int)state << " to "<< (int)newstate << ".";
|
||||
}
|
||||
if (validFlag) {
|
||||
logger << log4cpp::Priority::DEBUG << getDeviceName(true) << ": state changed from "
|
||||
<< (int)state << " to "<< (int)newstate << ".";
|
||||
TfDeviceState oldstate = state;
|
||||
state = newstate;
|
||||
notifyListeners([oldstate, newstate, this](TfDeviceStateListener& l)->bool {
|
||||
l.stateChangeCallback(*this, oldstate, newstate);
|
||||
return true;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
return validFlag;
|
||||
}
|
||||
|
||||
void TfDevice::doConfigureDevice() {
|
||||
configuredFlag = true;
|
||||
}
|
||||
|
||||
void TfDevice::doReconfigureDevice() {
|
||||
configuredFlag = true;
|
||||
}
|
||||
|
||||
void TfDevice::doUnconfigureDevice() {
|
||||
configuredFlag = false;
|
||||
}
|
||||
|
||||
void TfDevice::doConnectionLost() {
|
||||
}
|
||||
|
||||
void TfDevice::doShutdown() {
|
||||
configuredFlag = false;
|
||||
}
|
||||
|
||||
std::string TfDevice::getDeviceName(bool extended) {
|
||||
std::ostringstream ss;
|
||||
ss << "Unknown Device (" << raw_device_identifier << ")";
|
||||
if (extended) {
|
||||
ss << " [" << uid << "]";
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
void TfDevice::signalEnumerationCallback(TfCallbackEnumerationType enumeration_type) {
|
||||
if (enumeration_type == TfCallbackEnumerationType::DISCONNECTED) {
|
||||
auto prio = log4cpp::Priority::INFO;
|
||||
if (state == TfDeviceState::CONNECTED) {
|
||||
prio = log4cpp::Priority::ERROR;
|
||||
}
|
||||
if (changeDeviceState(TfDeviceState::DISCONNECTED)) {
|
||||
logger << prio << "Device \"" << getDeviceName(true) << "\" disconnected.";
|
||||
}
|
||||
} else {
|
||||
switch (state) {
|
||||
case TfDeviceState::AVAILABLE:
|
||||
case TfDeviceState::CONNECTED:
|
||||
// do nothing
|
||||
break;
|
||||
case TfDeviceState::DISCONNECTED:
|
||||
case TfDeviceState::CONNECTION_LOST:
|
||||
if (configuredFlag) {
|
||||
if (changeDeviceState(TfDeviceState::CONNECTED)) {
|
||||
logger << log4cpp::Priority::ERROR << "Device \"" << getDeviceName(true) << "\" reconnected.";
|
||||
}
|
||||
} else {
|
||||
if (changeDeviceState(TfDeviceState::AVAILABLE)) {
|
||||
logger << log4cpp::Priority::INFO << "Device \"" << getDeviceName(true) << "\" reconnected.";
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
void TfDevice::signalConnectedCallback(TfCallbackConnectReason connect_reason) {}
|
||||
|
||||
void TfDevice::signalDisconnectedCallback(TfCallbackDisconnectReason disconnect_reason) {
|
||||
auto prio = log4cpp::Priority::INFO;
|
||||
if (state == TfDeviceState::CONNECTED) {
|
||||
prio = log4cpp::Priority::ERROR;
|
||||
}
|
||||
if (changeDeviceState(TfDeviceState::CONNECTION_LOST)) {
|
||||
logger << prio << "Connection to device \"" << getDeviceName(true) << "\" lost.";
|
||||
}
|
||||
}
|
||||
|
||||
void TfDevice::signalShutdown() {
|
||||
notifyListeners([this](TfDeviceStateListener& l)->bool {
|
||||
l.shutdownCallback(*this);
|
||||
return true;
|
||||
}
|
||||
);
|
||||
doShutdown();
|
||||
}
|
||||
|
||||
} /* namespace tfcppsimple */
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* TfDeviceFactory.cpp
|
||||
*
|
||||
* Created on: 12.06.2014
|
||||
* Author: matzman
|
||||
*/
|
||||
|
||||
#include <tfcppsimple/TfDeviceFactory.h>
|
||||
#include <tfcppsimple/TfDevice.h>
|
||||
#include <tfcppsimple/TfException.h>
|
||||
#include <tfcppsimple/devices/TfMasterBrick.h>
|
||||
#include <tfcppsimple/devices/TfHumidityBricklet.h>
|
||||
#include <tfcppsimple/devices/TfIO16Bricklet.h>
|
||||
#include <tfcppsimple/devices/TfLCD20x4Bricklet.h>
|
||||
#include <tfcppsimple/devices/TfTemperatureBricklet.h>
|
||||
#include <tfcppsimple/devices/TfUnknownBrick.h>
|
||||
#include <tfcppsimple/devices/TfUnknownBricklet.h>
|
||||
|
||||
namespace tfcppsimple {
|
||||
|
||||
TfDevice* TfDeviceFactory::createNewDevice(
|
||||
TfConnection& conn,
|
||||
const char *uid,
|
||||
const char *connected_uid,
|
||||
char position,
|
||||
uint8_t hardware_version[3],
|
||||
uint8_t firmware_version[3],
|
||||
uint16_t device_identifier,
|
||||
TfDevice* parent) {
|
||||
TfDevice* ret = nullptr;
|
||||
switch ((TfDeviceIdentifier)device_identifier) {
|
||||
case TfDeviceIdentifier::MASTER:
|
||||
ret = new TfMasterBrick(conn, std::string(uid), std::string(connected_uid),
|
||||
(TfDevicePosition)position,
|
||||
{hardware_version[0], hardware_version[1], hardware_version[2]},
|
||||
{firmware_version[0], firmware_version[1], firmware_version[2]},
|
||||
parent);
|
||||
ret->changeDeviceState(TfDeviceState::AVAILABLE);
|
||||
break;
|
||||
case TfDeviceIdentifier::TEMPERATURE:
|
||||
ret = new TfTemperatureBricklet(conn, std::string(uid), std::string(connected_uid),
|
||||
(TfDevicePosition)position,
|
||||
{hardware_version[0], hardware_version[1], hardware_version[2]},
|
||||
{firmware_version[0], firmware_version[1], firmware_version[2]},
|
||||
parent);
|
||||
ret->changeDeviceState(TfDeviceState::AVAILABLE);
|
||||
break;
|
||||
case TfDeviceIdentifier::HUMIDITY:
|
||||
ret = new TfHumidityBricklet(conn, std::string(uid), std::string(connected_uid),
|
||||
(TfDevicePosition)position,
|
||||
{hardware_version[0], hardware_version[1], hardware_version[2]},
|
||||
{firmware_version[0], firmware_version[1], firmware_version[2]},
|
||||
parent);
|
||||
ret->changeDeviceState(TfDeviceState::AVAILABLE);
|
||||
break;
|
||||
case TfDeviceIdentifier::LCD20x4:
|
||||
ret = new TfLCD20x4Bricklet(conn, std::string(uid), std::string(connected_uid),
|
||||
(TfDevicePosition)position,
|
||||
{hardware_version[0], hardware_version[1], hardware_version[2]},
|
||||
{firmware_version[0], firmware_version[1], firmware_version[2]},
|
||||
parent);
|
||||
ret->changeDeviceState(TfDeviceState::AVAILABLE);
|
||||
break;
|
||||
case TfDeviceIdentifier::IO16:
|
||||
ret = new TfIO16Bricklet(conn, std::string(uid), std::string(connected_uid),
|
||||
(TfDevicePosition)position,
|
||||
{hardware_version[0], hardware_version[1], hardware_version[2]},
|
||||
{firmware_version[0], firmware_version[1], firmware_version[2]},
|
||||
parent);
|
||||
ret->changeDeviceState(TfDeviceState::AVAILABLE);
|
||||
break;
|
||||
default:
|
||||
if (position >= (uint16_t)TfDevicePosition::BRICK0 && position <= (uint16_t)TfDevicePosition::BRICK8) {
|
||||
ret = new TfUnknownBrick(conn, std::string(uid), std::string(connected_uid),
|
||||
(TfDevicePosition)position,
|
||||
{hardware_version[0], hardware_version[1], hardware_version[2]},
|
||||
{firmware_version[0], firmware_version[1], firmware_version[2]},
|
||||
device_identifier, parent);
|
||||
ret->changeDeviceState(TfDeviceState::AVAILABLE);
|
||||
} else if (position >= (uint16_t)TfDevicePosition::BRICKLET0 && position <= (uint16_t)TfDevicePosition::BRICKLET3) {
|
||||
ret = new TfUnknownBricklet(conn, std::string(uid), std::string(connected_uid),
|
||||
(TfDevicePosition)position,
|
||||
{hardware_version[0], hardware_version[1], hardware_version[2]},
|
||||
{firmware_version[0], firmware_version[1], firmware_version[2]},
|
||||
device_identifier, parent);
|
||||
ret->changeDeviceState(TfDeviceState::AVAILABLE);
|
||||
} else {
|
||||
std::ostringstream ss;
|
||||
ss << "Unknown device (" << device_identifier << ") at unknown position " << position;
|
||||
throw TfException(ss.str());
|
||||
}
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
} /* namespace tfcppsimple */
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* TfUtils.cpp
|
||||
*
|
||||
* Created on: 11.06.2014
|
||||
* Author: matzman
|
||||
*/
|
||||
|
||||
#include <tfcppsimple/TfUtils.h>
|
||||
#include <log4cpp/PropertyConfigurator.hh>
|
||||
#include <log4cpp/Appender.hh>
|
||||
#include <log4cpp/BasicLayout.hh>
|
||||
#include <log4cpp/Category.hh>
|
||||
#include <log4cpp/OstreamAppender.hh>
|
||||
#include <iostream>
|
||||
|
||||
namespace tfcppsimple {
|
||||
|
||||
void TfUtils::configureLog4CPP(std::string configFile) {
|
||||
try {
|
||||
log4cpp::PropertyConfigurator::configure( configFile );
|
||||
} catch( log4cpp::ConfigureFailure &e ) {
|
||||
std::cerr << "[log4cpp::ConfigureFailure catched] while reading "
|
||||
<< configFile << ": " << e.what() << std::endl;
|
||||
configureLog4CPP();
|
||||
}
|
||||
}
|
||||
|
||||
void TfUtils::configureLog4CPP() {
|
||||
log4cpp::Appender *appender = new log4cpp::OstreamAppender("console", &std::cerr);
|
||||
appender->setLayout(new log4cpp::BasicLayout());
|
||||
log4cpp::Category& root = log4cpp::Category::getRoot();
|
||||
root.setPriority(log4cpp::Priority::INFO);
|
||||
root.addAppender(appender);
|
||||
}
|
||||
|
||||
} /* namespace tfcppsimple */
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
SRC_FILES += src/TfConnection.cpp src/TfUtils.cpp src/TfDevice.cpp src/TfBrick.cpp src/TfBricklet.cpp src/TfDeviceFactory.cpp
|
||||
|
||||
include src/devices/config.mk
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* TfHumidityBricklet.cpp
|
||||
*
|
||||
* Created on: 12.06.2014
|
||||
* Author: matzman
|
||||
*/
|
||||
|
||||
#include <tfcppsimple/devices/TfHumidityBricklet.h>
|
||||
#include <tfcppsimple/TfException.h>
|
||||
|
||||
namespace tfcppsimple {
|
||||
|
||||
TfHumidityBricklet::TfHumidityBricklet(TfConnection& connection,
|
||||
std::string uid,
|
||||
std::string connected_uid,
|
||||
TfDevicePosition position,
|
||||
TfVersion hardware_version,
|
||||
TfVersion firmware_version,
|
||||
TfDevice* parent
|
||||
)
|
||||
: TfBricklet(connection, uid, connected_uid, position, hardware_version, firmware_version,
|
||||
(uint16_t)TfDeviceIdentifier::HUMIDITY, TfDeviceIdentifier::HUMIDITY, parent) {
|
||||
|
||||
}
|
||||
|
||||
TfHumidityBricklet::~TfHumidityBricklet() {
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
||||
|
||||
std::string TfHumidityBricklet::getDeviceName(bool extended) {
|
||||
std::ostringstream ss;
|
||||
ss << "Humidity Bricklet";
|
||||
if (extended) {
|
||||
ss << " [" << uid << "]";
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
void TfHumidityBricklet::doConfigureDevice() {
|
||||
humidity_create(&humidityObj, uid.c_str(), &connection.getTfIpConnection());
|
||||
int ret = humidity_set_response_expected_all(&humidityObj, true);
|
||||
if (ret != E_OK) {
|
||||
std::ostringstream ss;
|
||||
ss << "Error while configuring: " << ret << ".";
|
||||
throw TfError(ss.str(), (TfErrorCode)ret);
|
||||
} else {
|
||||
TfDevice::doConfigureDevice();
|
||||
}
|
||||
}
|
||||
|
||||
void TfHumidityBricklet::doReconfigureDevice() {
|
||||
humidity_destroy(&humidityObj);
|
||||
humidity_create(&humidityObj, uid.c_str(), &connection.getTfIpConnection());
|
||||
int ret = humidity_set_response_expected_all(&humidityObj, true);
|
||||
if (ret != E_OK) {
|
||||
std::ostringstream ss;
|
||||
ss << "Error while reconfiguring: " << ret << ".";
|
||||
throw TfError(ss.str(), (TfErrorCode)ret);
|
||||
} else {
|
||||
TfDevice::doReconfigureDevice();
|
||||
}
|
||||
}
|
||||
|
||||
void TfHumidityBricklet::doConnectionLost() {
|
||||
TfDevice::doConnectionLost();
|
||||
}
|
||||
|
||||
void TfHumidityBricklet::doShutdown() {
|
||||
humidity_destroy(&humidityObj);
|
||||
TfDevice::doShutdown();
|
||||
}
|
||||
|
||||
|
||||
uint16_t TfHumidityBricklet::getHumidity() {
|
||||
uint16_t retval;
|
||||
int ret = humidity_get_humidity(&humidityObj, &retval);
|
||||
if (ret != E_OK) {
|
||||
std::ostringstream ss;
|
||||
ss << "Error while reading humidity: " << ret << ".";
|
||||
throw TfError(ss.str(), (TfErrorCode)ret);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
uint16_t TfHumidityBricklet::getHumidityRaw() {
|
||||
uint16_t retval;
|
||||
int ret = humidity_get_analog_value(&humidityObj, &retval);
|
||||
if (ret != E_OK) {
|
||||
std::ostringstream ss;
|
||||
ss << "Error while reading raw humidity: " << ret << ".";
|
||||
throw TfError(ss.str(), (TfErrorCode)ret);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
} /* namespace tfcppsimple */
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* TfIO16Bricklet.cpp
|
||||
*
|
||||
* Created on: 12.06.2014
|
||||
* Author: matzman
|
||||
*/
|
||||
|
||||
#include <tfcppsimple/devices/TfIO16Bricklet.h>
|
||||
|
||||
namespace tfcppsimple {
|
||||
|
||||
TfIO16Bricklet::TfIO16Bricklet(TfConnection& connection,
|
||||
std::string uid,
|
||||
std::string connected_uid,
|
||||
TfDevicePosition position,
|
||||
TfVersion hardware_version,
|
||||
TfVersion firmware_version,
|
||||
TfDevice* parent
|
||||
)
|
||||
: TfBricklet(connection, uid, connected_uid, position, hardware_version, firmware_version,
|
||||
(uint16_t)TfDeviceIdentifier::IO16, TfDeviceIdentifier::IO16, parent) {
|
||||
|
||||
}
|
||||
|
||||
TfIO16Bricklet::~TfIO16Bricklet() {
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
||||
|
||||
std::string TfIO16Bricklet::getDeviceName(bool extended) {
|
||||
std::ostringstream ss;
|
||||
ss << "IO16 Bricklet";
|
||||
if (extended) {
|
||||
ss << " [" << uid << "]";
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
} /* namespace tfcppsimple */
|
||||
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
* TfLCD204Bricklet.cpp
|
||||
*
|
||||
* Created on: 12.06.2014
|
||||
* Author: matzman
|
||||
*/
|
||||
|
||||
#include <tfcppsimple/devices/TfLCD20x4Bricklet.h>
|
||||
#include <tfcppsimple/TfException.h>
|
||||
|
||||
namespace tfcppsimple {
|
||||
|
||||
|
||||
|
||||
|
||||
TfLCD20x4Bricklet::TfLCD20x4Bricklet(TfConnection& connection,
|
||||
std::string uid,
|
||||
std::string connected_uid,
|
||||
TfDevicePosition position,
|
||||
TfVersion hardware_version,
|
||||
TfVersion firmware_version,
|
||||
TfDevice* parent
|
||||
)
|
||||
: TfBricklet(connection, uid, connected_uid, position, hardware_version, firmware_version,
|
||||
(uint16_t)TfDeviceIdentifier::LCD20x4, TfDeviceIdentifier::LCD20x4, parent) {
|
||||
|
||||
}
|
||||
|
||||
TfLCD20x4Bricklet::~TfLCD20x4Bricklet() {
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
||||
|
||||
std::string TfLCD20x4Bricklet::getDeviceName(bool extended) {
|
||||
std::ostringstream ss;
|
||||
ss << "LCD 20x4 Bricklet";
|
||||
if (extended) {
|
||||
ss << " [" << uid << "]";
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
void TfLCD20x4Bricklet::doConfigureDevice() {
|
||||
lcd_20x4_create(&lcdObj, uid.c_str(), &connection.getTfIpConnection());
|
||||
int ret = lcd_20x4_set_response_expected_all(&lcdObj, true);
|
||||
if (ret != E_OK) {
|
||||
std::ostringstream ss;
|
||||
ss << "Error while configuring: " << ret << ".";
|
||||
throw TfError(ss.str(), (TfErrorCode)ret);
|
||||
} else {
|
||||
clearDisplay();
|
||||
setBacklight(backlightFlag);
|
||||
setCursor(cursorFlag, blinkingFlag);
|
||||
lcd_20x4_register_callback(&lcdObj, LCD_20X4_CALLBACK_BUTTON_PRESSED, (void*)__buttonPressed, (void*)this);
|
||||
lcd_20x4_register_callback(&lcdObj, LCD_20X4_CALLBACK_BUTTON_RELEASED, (void*)__buttonReleased, (void*)this);
|
||||
TfDevice::doConfigureDevice();
|
||||
}
|
||||
}
|
||||
|
||||
void TfLCD20x4Bricklet::doReconfigureDevice() {
|
||||
lcd_20x4_destroy(&lcdObj);
|
||||
lcd_20x4_create(&lcdObj, uid.c_str(), &connection.getTfIpConnection());
|
||||
int ret = lcd_20x4_set_response_expected_all(&lcdObj, true);
|
||||
if (ret != E_OK) {
|
||||
std::ostringstream ss;
|
||||
ss << "Error while reconfiguring: " << ret << ".";
|
||||
throw TfError(ss.str(), (TfErrorCode)ret);
|
||||
} else {
|
||||
setBacklight(backlightFlag);
|
||||
setCursor(cursorFlag, blinkingFlag);
|
||||
lcd_20x4_register_callback(&lcdObj, LCD_20X4_CALLBACK_BUTTON_PRESSED, (void*)__buttonPressed, (void*)this);
|
||||
lcd_20x4_register_callback(&lcdObj, LCD_20X4_CALLBACK_BUTTON_RELEASED, (void*)__buttonReleased, (void*)this);
|
||||
TfDevice::doReconfigureDevice();
|
||||
}
|
||||
}
|
||||
|
||||
void TfLCD20x4Bricklet::doConnectionLost() {
|
||||
TfDevice::doConnectionLost();
|
||||
}
|
||||
|
||||
void TfLCD20x4Bricklet::doShutdown() {
|
||||
lcd_20x4_destroy(&lcdObj);
|
||||
lcd_20x4_register_callback(&lcdObj, LCD_20X4_CALLBACK_BUTTON_PRESSED, nullptr, this);
|
||||
lcd_20x4_register_callback(&lcdObj, LCD_20X4_CALLBACK_BUTTON_RELEASED, nullptr, this);
|
||||
TfDevice::doShutdown();
|
||||
}
|
||||
|
||||
void TfLCD20x4Bricklet::writeLine(uint8_t line, uint8_t position, std::string txt) {
|
||||
int ret = lcd_20x4_write_line(&lcdObj, line, position, txt.c_str());
|
||||
if (ret != E_OK) {
|
||||
std::ostringstream ss;
|
||||
ss << "Error while writing line: " << ret << ".";
|
||||
throw TfError(ss.str(), (TfErrorCode)ret);
|
||||
}
|
||||
}
|
||||
|
||||
void TfLCD20x4Bricklet::clearDisplay() {
|
||||
int ret = lcd_20x4_clear_display(&lcdObj);
|
||||
if (ret != E_OK) {
|
||||
std::ostringstream ss;
|
||||
ss << "Error while clearing display: " << ret << ".";
|
||||
throw TfError(ss.str(), (TfErrorCode)ret);
|
||||
}
|
||||
}
|
||||
|
||||
void TfLCD20x4Bricklet::setBacklight(bool backlight) {
|
||||
backlightFlag = backlight;
|
||||
int ret;
|
||||
if (backlightFlag) {
|
||||
ret = lcd_20x4_backlight_on(&lcdObj);
|
||||
} else {
|
||||
ret = lcd_20x4_backlight_off(&lcdObj);
|
||||
}
|
||||
if (ret != E_OK) {
|
||||
std::ostringstream ss;
|
||||
ss << "Error while setting backlight: " << ret << ".";
|
||||
throw TfError(ss.str(), (TfErrorCode)ret);
|
||||
}
|
||||
}
|
||||
|
||||
void TfLCD20x4Bricklet::setCursor(bool cursor, bool blinking) {
|
||||
cursorFlag = cursor;
|
||||
blinkingFlag = blinking;
|
||||
int ret = lcd_20x4_set_config(&lcdObj, cursorFlag, blinkingFlag);
|
||||
if (ret != E_OK) {
|
||||
std::ostringstream ss;
|
||||
ss << "Error while setting cursor: " << ret << ".";
|
||||
throw TfError(ss.str(), (TfErrorCode)ret);
|
||||
}
|
||||
}
|
||||
|
||||
void TfLCD20x4Bricklet::__buttonPressed(uint8_t button, void *user_data) {
|
||||
if (user_data != nullptr) {
|
||||
((TfLCD20x4Bricklet*)user_data)->buttonStateCallBack(button, true);
|
||||
}
|
||||
}
|
||||
|
||||
void TfLCD20x4Bricklet::__buttonReleased(uint8_t button, void *user_data) {
|
||||
if (user_data != nullptr) {
|
||||
((TfLCD20x4Bricklet*)user_data)->buttonStateCallBack(button, false);
|
||||
}
|
||||
}
|
||||
|
||||
void TfLCD20x4Bricklet::buttonStateCallBack(uint8_t button, bool state) {
|
||||
lcdListeners.notifyListeners([button, state, this](TfLCD20x4Listener& l)->bool {
|
||||
l.buttonStateCallback(*this, button, state);
|
||||
return true;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
bool TfLCD20x4Bricklet::addLcdListener(TfLCD20x4Listener& listener) {
|
||||
return lcdListeners.addListener(listener);
|
||||
}
|
||||
|
||||
bool TfLCD20x4Bricklet::removeLcdListener(TfLCD20x4Listener& listener) {
|
||||
return lcdListeners.removeListener(listener);
|
||||
}
|
||||
|
||||
|
||||
} /* namespace tfcppsimple */
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* TfMasterBrick.cpp
|
||||
*
|
||||
* Created on: 12.06.2014
|
||||
* Author: matzman
|
||||
*/
|
||||
|
||||
#include <tfcppsimple/devices/TfMasterBrick.h>
|
||||
#include <tfcppsimple/TfException.h>
|
||||
#include <sstream>
|
||||
|
||||
namespace tfcppsimple {
|
||||
|
||||
TfMasterBrick::TfMasterBrick(TfConnection& connection,
|
||||
std::string uid,
|
||||
std::string connected_uid,
|
||||
TfDevicePosition position,
|
||||
TfVersion hardware_version,
|
||||
TfVersion firmware_version,
|
||||
TfDevice* parent
|
||||
)
|
||||
: TfBrick(connection, uid, connected_uid, position, hardware_version, firmware_version,
|
||||
(uint16_t)TfDeviceIdentifier::MASTER, TfDeviceIdentifier::MASTER, parent) {
|
||||
|
||||
}
|
||||
|
||||
TfMasterBrick::~TfMasterBrick() {
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
||||
|
||||
std::string TfMasterBrick::getDeviceName(bool extended) {
|
||||
std::ostringstream ss;
|
||||
ss << "Master Brick";
|
||||
if (extended) {
|
||||
ss << " [" << uid << "]";
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
void TfMasterBrick::doConfigureDevice() {
|
||||
master_create(&masterObj, uid.c_str(), &connection.getTfIpConnection());
|
||||
int ret = master_set_response_expected_all(&masterObj, true);
|
||||
if (ret != E_OK) {
|
||||
std::ostringstream ss;
|
||||
ss << "Error while configuring: " << ret << ".";
|
||||
throw TfError(ss.str(), (TfErrorCode)ret);
|
||||
} else {
|
||||
TfDevice::doConfigureDevice();
|
||||
}
|
||||
}
|
||||
|
||||
void TfMasterBrick::doReconfigureDevice() {
|
||||
master_destroy(&masterObj);
|
||||
master_create(&masterObj, uid.c_str(), &connection.getTfIpConnection());
|
||||
int ret = master_set_response_expected_all(&masterObj, true);
|
||||
if (ret != E_OK) {
|
||||
std::ostringstream ss;
|
||||
ss << "Error while reconfiguring: " << ret << ".";
|
||||
throw TfError(ss.str(), (TfErrorCode)ret);
|
||||
} else {
|
||||
TfDevice::doReconfigureDevice();
|
||||
}
|
||||
}
|
||||
|
||||
void TfMasterBrick::doConnectionLost() {
|
||||
TfDevice::doConnectionLost();
|
||||
}
|
||||
|
||||
void TfMasterBrick::doShutdown() {
|
||||
master_destroy(&masterObj);
|
||||
TfDevice::doShutdown();
|
||||
}
|
||||
|
||||
|
||||
uint16_t TfMasterBrick::getStackVoltage() {
|
||||
uint16_t ret_voltage;
|
||||
int ret = master_get_stack_voltage(&masterObj, &ret_voltage);
|
||||
if (ret != E_OK) {
|
||||
std::ostringstream ss;
|
||||
ss << "Error while reading stack voltage: " << ret << ".";
|
||||
throw TfError(ss.str(), (TfErrorCode)ret);
|
||||
}
|
||||
return ret_voltage;
|
||||
}
|
||||
|
||||
uint16_t TfMasterBrick::getStackCurrent() {
|
||||
uint16_t ret_current;
|
||||
int ret = master_get_stack_current(&masterObj, &ret_current);
|
||||
if (ret != E_OK) {
|
||||
std::ostringstream ss;
|
||||
ss << "Error while reading stack current: " << ret << ".";
|
||||
throw TfError(ss.str(), (TfErrorCode)ret);
|
||||
}
|
||||
return ret_current;
|
||||
}
|
||||
|
||||
uint16_t TfMasterBrick::getUSBVoltage() {
|
||||
uint16_t ret_voltage;
|
||||
int ret = master_get_usb_voltage(&masterObj, &ret_voltage);
|
||||
if (ret != E_OK) {
|
||||
std::ostringstream ss;
|
||||
ss << "Error while reading usb voltage: " << ret << ".";
|
||||
throw TfError(ss.str(), (TfErrorCode)ret);
|
||||
}
|
||||
return ret_voltage;
|
||||
}
|
||||
|
||||
int16_t TfMasterBrick::getChipTemperature(){
|
||||
int16_t ret_temperature;
|
||||
int ret = master_get_chip_temperature(&masterObj, &ret_temperature);
|
||||
if (ret != E_OK) {
|
||||
std::ostringstream ss;
|
||||
ss << "Error while reading chip temperature: " << ret << ".";
|
||||
throw TfError(ss.str(), (TfErrorCode)ret);
|
||||
}
|
||||
return ret_temperature;
|
||||
}
|
||||
|
||||
|
||||
} /* namespace tfcppsimple */
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* TfTemperatureBricklet.cpp
|
||||
*
|
||||
* Created on: 12.06.2014
|
||||
* Author: matzman
|
||||
*/
|
||||
|
||||
#include <tfcppsimple/devices/TfTemperatureBricklet.h>
|
||||
#include <tfcppsimple/TfException.h>
|
||||
|
||||
namespace tfcppsimple {
|
||||
|
||||
TfTemperatureBricklet::TfTemperatureBricklet(TfConnection& connection,
|
||||
std::string uid,
|
||||
std::string connected_uid,
|
||||
TfDevicePosition position,
|
||||
TfVersion hardware_version,
|
||||
TfVersion firmware_version,
|
||||
TfDevice* parent
|
||||
)
|
||||
: TfBricklet(connection, uid, connected_uid, position, hardware_version, firmware_version,
|
||||
(uint16_t)TfDeviceIdentifier::TEMPERATURE, TfDeviceIdentifier::TEMPERATURE, parent) {
|
||||
|
||||
}
|
||||
|
||||
TfTemperatureBricklet::~TfTemperatureBricklet() {
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
||||
|
||||
std::string TfTemperatureBricklet::getDeviceName(bool extended) {
|
||||
std::ostringstream ss;
|
||||
ss << "Temperature Bricklet";
|
||||
if (extended) {
|
||||
ss << " [" << uid << "]";
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
void TfTemperatureBricklet::doConfigureDevice() {
|
||||
temperature_create(&temperatureObj, uid.c_str(), &connection.getTfIpConnection());
|
||||
int ret = temperature_set_response_expected_all(&temperatureObj, true);
|
||||
if (ret != E_OK) {
|
||||
std::ostringstream ss;
|
||||
ss << "Error while configuring: " << ret << ".";
|
||||
throw TfError(ss.str(), (TfErrorCode)ret);
|
||||
} else {
|
||||
TfDevice::doConfigureDevice();
|
||||
}
|
||||
}
|
||||
|
||||
void TfTemperatureBricklet::doReconfigureDevice() {
|
||||
temperature_destroy(&temperatureObj);
|
||||
temperature_create(&temperatureObj, uid.c_str(), &connection.getTfIpConnection());
|
||||
int ret = temperature_set_response_expected_all(&temperatureObj, true);
|
||||
if (ret != E_OK) {
|
||||
std::ostringstream ss;
|
||||
ss << "Error while reconfiguring: " << ret << ".";
|
||||
throw TfError(ss.str(), (TfErrorCode)ret);
|
||||
} else {
|
||||
TfDevice::doReconfigureDevice();
|
||||
}
|
||||
}
|
||||
|
||||
void TfTemperatureBricklet::doConnectionLost() {
|
||||
TfDevice::doConnectionLost();
|
||||
}
|
||||
|
||||
void TfTemperatureBricklet::doShutdown() {
|
||||
temperature_destroy(&temperatureObj);
|
||||
TfDevice::doShutdown();
|
||||
}
|
||||
|
||||
|
||||
int16_t TfTemperatureBricklet::getTemperature() {
|
||||
int16_t retval;
|
||||
int ret = temperature_get_temperature(&temperatureObj, &retval);
|
||||
if (ret != E_OK) {
|
||||
std::ostringstream ss;
|
||||
ss << "Error while reading temperature: " << ret << ".";
|
||||
throw TfError(ss.str(), (TfErrorCode)ret);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
void TfTemperatureBricklet::setI2Cmode(TfTemperatureI2Cmode mode) {
|
||||
int ret = temperature_set_i2c_mode(&temperatureObj, (uint8_t)mode);
|
||||
if (ret != E_OK) {
|
||||
std::ostringstream ss;
|
||||
ss << "Error while setting i2c mode: " << ret << ".";
|
||||
throw TfError(ss.str(), (TfErrorCode)ret);
|
||||
} else {
|
||||
i2cMode = mode;
|
||||
}
|
||||
}
|
||||
|
||||
TfTemperatureI2Cmode TfTemperatureBricklet::getI2Cmode() {
|
||||
return i2cMode;
|
||||
}
|
||||
|
||||
} /* namespace tfcppsimple */
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* TfUnknownBrick.cpp
|
||||
*
|
||||
* Created on: 13.06.2014
|
||||
* Author: matzman
|
||||
*/
|
||||
|
||||
#include <tfcppsimple/devices/TfUnknownBrick.h>
|
||||
|
||||
namespace tfcppsimple {
|
||||
|
||||
TfUnknownBrick::TfUnknownBrick(TfConnection& connection,
|
||||
std::string uid,
|
||||
std::string connected_uid,
|
||||
TfDevicePosition position,
|
||||
TfVersion hardware_version,
|
||||
TfVersion firmware_version,
|
||||
uint16_t raw_device_identifier,
|
||||
TfDevice* parent
|
||||
)
|
||||
: TfBrick(connection, uid, connected_uid, position, hardware_version, firmware_version,
|
||||
raw_device_identifier, TfDeviceIdentifier::UNKNOWN_BRICK, parent) {
|
||||
|
||||
}
|
||||
|
||||
TfUnknownBrick::~TfUnknownBrick() {
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
||||
|
||||
std::string TfUnknownBrick::getDeviceName(bool extended) {
|
||||
std::ostringstream ss;
|
||||
ss << "Unknown Brick (" << raw_device_identifier << ")";
|
||||
if (extended) {
|
||||
ss << " [" << uid << "]";
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
} /* namespace tfcppsimple */
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* TfUnknownBricklet.cpp
|
||||
*
|
||||
* Created on: 13.06.2014
|
||||
* Author: matzman
|
||||
*/
|
||||
|
||||
#include <tfcppsimple/devices/TfUnknownBricklet.h>
|
||||
|
||||
namespace tfcppsimple {
|
||||
|
||||
TfUnknownBricklet::TfUnknownBricklet(TfConnection& connection,
|
||||
std::string uid,
|
||||
std::string connected_uid,
|
||||
TfDevicePosition position,
|
||||
TfVersion hardware_version,
|
||||
TfVersion firmware_version,
|
||||
uint16_t raw_device_identifier,
|
||||
TfDevice* parent
|
||||
)
|
||||
: TfBricklet(connection, uid, connected_uid, position, hardware_version, firmware_version,
|
||||
raw_device_identifier, TfDeviceIdentifier::UNKNOWN_BRICKLET, parent) {
|
||||
|
||||
}
|
||||
|
||||
TfUnknownBricklet::~TfUnknownBricklet() {
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
||||
|
||||
std::string TfUnknownBricklet::getDeviceName(bool extended) {
|
||||
std::ostringstream ss;
|
||||
ss << "Unknown Bricklet (" << raw_device_identifier << ")";
|
||||
if (extended) {
|
||||
ss << " [" << uid << "]";
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
} /* namespace tfcppsimple */
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
SRC_FILES += src/devices/TfMasterBrick.cpp \
|
||||
src/devices/TfHumidityBricklet.cpp \
|
||||
src/devices/TfIO16Bricklet.cpp \
|
||||
src/devices/TfLCD20x4Bricklet.cpp \
|
||||
src/devices/TfTemperatureBricklet.cpp \
|
||||
src/devices/TfUnknownBrick.cpp \
|
||||
src/devices/TfUnknownBricklet.cpp
|
||||
|
||||
Vendored
+70
@@ -0,0 +1,70 @@
|
||||
|
||||
include ../Makefile.local
|
||||
|
||||
TINKERFORGE_FILES=$(shell cat tinkerforge-filelist)
|
||||
TINKERFORGE_OBJS=$(TINKERFORGE_FILES:%.cpp=tinkerforge/build/%.o)
|
||||
|
||||
|
||||
all: tinkerforge-dist log4cpp-dist
|
||||
|
||||
clean: log4cpp-distclean tinkerforge-distclean
|
||||
|
||||
tinkerforge-dist : tinkerforge-unzip tinkerforge/lib/libtinkerforge.a tinkerforge-copy-libs tinkerforge-clean
|
||||
|
||||
tinkerforge-unzip : tinkerforge-distclean
|
||||
unzip tinkerforge_c_bindings_*.zip -d tinkerforge
|
||||
cd tinkerforge/bindings; for i in *.c; do mv $$i $${i%.c}.cpp; done
|
||||
mkdir tinkerforge/include
|
||||
cd tinkerforge/bindings; for i in *.h; do mv $$i ../include/$$i; done
|
||||
|
||||
tinkerforge-copy-libs :
|
||||
mkdir -p ../lib
|
||||
cp tinkerforge/lib/libtinkerforge.a ../lib
|
||||
|
||||
tinkerforge-generate-filelist :
|
||||
cd tinkerforge/bindings; ls -1 *.cpp > ../../tinkerforge-filelist
|
||||
|
||||
tinkerforge-distclean :
|
||||
rm -rf tinkerforge tinkerforge/lib/libtinkerforge.a
|
||||
|
||||
tinkerforge-clean :
|
||||
rm -rf tinkerforge/build
|
||||
|
||||
tinkerforge/lib :
|
||||
mkdir -p $@
|
||||
|
||||
tinkerforge/build :
|
||||
mkdir -p $@
|
||||
|
||||
tinkerforge/lib/libtinkerforge.a : tinkerforge/lib $(TINKERFORGE_OBJS)
|
||||
$(AR) rc $@ tinkerforge/build/*.o
|
||||
$(RANLIB) $@
|
||||
|
||||
$(TINKERFORGE_OBJS) : tinkerforge/build/%.o : tinkerforge/bindings/%.cpp tinkerforge/build
|
||||
$(CXX) $(CXX_FLAGS) $(TINKERFORGE_CXX_FLAGS) -I tinkerforge/include -c $< -o $@
|
||||
|
||||
|
||||
log4cpp-dist : log4cpp-unzip log4cpp-build log4cpp-copy-libs log4cpp-clean
|
||||
|
||||
log4cpp-unzip : log4cpp-distclean
|
||||
tar xvfz log4cpp-*.tar.gz
|
||||
mv log4cpp log4cpp-src
|
||||
mkdir log4cpp
|
||||
mv log4cpp-src log4cpp/src
|
||||
|
||||
log4cpp-build :
|
||||
cd log4cpp/src; \
|
||||
./configure --prefix $(realpath log4cpp) --libdir $(realpath log4cpp)/lib
|
||||
make -C log4cpp/src
|
||||
make -C log4cpp/src install
|
||||
|
||||
log4cpp-copy-libs :
|
||||
mkdir -p ../lib
|
||||
cp log4cpp/lib/liblog4cpp.a ../lib
|
||||
|
||||
log4cpp-distclean :
|
||||
rm -rf log4cpp log4cpp/lib/liblog4cpp.a
|
||||
|
||||
log4cpp-clean :
|
||||
rm -rf log4cpp/src
|
||||
|
||||
Vendored
BIN
Binary file not shown.
Vendored
+47
@@ -0,0 +1,47 @@
|
||||
brick_dc.cpp
|
||||
brick_imu.cpp
|
||||
bricklet_ambient_light.cpp
|
||||
bricklet_analog_in.cpp
|
||||
bricklet_analog_out.cpp
|
||||
bricklet_barometer.cpp
|
||||
bricklet_current12.cpp
|
||||
bricklet_current25.cpp
|
||||
bricklet_distance_ir.cpp
|
||||
bricklet_distance_us.cpp
|
||||
bricklet_dual_button.cpp
|
||||
bricklet_dual_relay.cpp
|
||||
bricklet_gps.cpp
|
||||
bricklet_hall_effect.cpp
|
||||
bricklet_humidity.cpp
|
||||
bricklet_industrial_digital_in_4.cpp
|
||||
bricklet_industrial_digital_out_4.cpp
|
||||
bricklet_industrial_dual_0_20ma.cpp
|
||||
bricklet_industrial_quad_relay.cpp
|
||||
bricklet_io16.cpp
|
||||
bricklet_io4.cpp
|
||||
bricklet_joystick.cpp
|
||||
bricklet_lcd_16x2.cpp
|
||||
bricklet_lcd_20x4.cpp
|
||||
bricklet_led_strip.cpp
|
||||
bricklet_linear_poti.cpp
|
||||
bricklet_line.cpp
|
||||
bricklet_moisture.cpp
|
||||
bricklet_motion_detector.cpp
|
||||
bricklet_multi_touch.cpp
|
||||
bricklet_piezo_buzzer.cpp
|
||||
bricklet_piezo_speaker.cpp
|
||||
bricklet_ptc.cpp
|
||||
bricklet_remote_switch.cpp
|
||||
bricklet_rotary_encoder.cpp
|
||||
bricklet_rotary_poti.cpp
|
||||
bricklet_segment_display_4x7.cpp
|
||||
bricklet_sound_intensity.cpp
|
||||
bricklet_temperature.cpp
|
||||
bricklet_temperature_ir.cpp
|
||||
bricklet_tilt.cpp
|
||||
bricklet_voltage.cpp
|
||||
bricklet_voltage_current.cpp
|
||||
brick_master.cpp
|
||||
brick_servo.cpp
|
||||
brick_stepper.cpp
|
||||
ip_connection.cpp
|
||||
BIN
Binary file not shown.
Reference in New Issue
Block a user