16 changed files with 879 additions and 0 deletions
@ -0,0 +1,151 @@ |
|||
<?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.mingw.base.1135534147"> |
|||
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.toolchain.gnu.mingw.base.1135534147" moduleId="org.eclipse.cdt.core.settings" name="Sming"> |
|||
<externalSettings/> |
|||
<extensions> |
|||
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/> |
|||
<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"/> |
|||
<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"/> |
|||
</extensions> |
|||
</storageModule> |
|||
<storageModule moduleId="cdtBuildSystem" version="4.0.0"> |
|||
<configuration artifactName="${ProjName}" buildProperties="" description="" id="cdt.managedbuild.toolchain.gnu.mingw.base.1135534147" name="Sming" parent="org.eclipse.cdt.build.core.emptycfg"> |
|||
<folderInfo id="cdt.managedbuild.toolchain.gnu.mingw.base.1135534147.86962463" name="/" resourcePath=""> |
|||
<toolChain id="cdt.managedbuild.toolchain.gnu.cross.base.1164554300" name="Cross GCC" superClass="cdt.managedbuild.toolchain.gnu.cross.base"> |
|||
<option id="cdt.managedbuild.option.gnu.cross.prefix.521205673" name="Prefix" superClass="cdt.managedbuild.option.gnu.cross.prefix"/> |
|||
<option id="cdt.managedbuild.option.gnu.cross.path.393887888" name="Path" superClass="cdt.managedbuild.option.gnu.cross.path"/> |
|||
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.targetPlatform.gnu.cross.712123812" isAbstract="false" osList="all" superClass="cdt.managedbuild.targetPlatform.gnu.cross"/> |
|||
<builder id="cdt.managedbuild.builder.gnu.cross.2110485170" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="cdt.managedbuild.builder.gnu.cross"/> |
|||
<tool id="cdt.managedbuild.tool.gnu.cross.c.compiler.1168221903" name="Cross GCC Compiler" superClass="cdt.managedbuild.tool.gnu.cross.c.compiler"> |
|||
<option id="gnu.c.compiler.option.include.paths.357494572" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath"> |
|||
<listOptionValue builtIn="false" value=""${SMING_HOME}""/> |
|||
<listOptionValue builtIn="false" value=""${SMING_HOME}/system/include""/> |
|||
<listOptionValue builtIn="false" value=""${SMING_HOME}/Libraries""/> |
|||
<listOptionValue builtIn="false" value=""${ESP_HOME}/sdk/include""/> |
|||
</option> |
|||
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.313321806" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/> |
|||
</tool> |
|||
<tool id="cdt.managedbuild.tool.gnu.cross.cpp.compiler.1999763015" name="Cross G++ Compiler" superClass="cdt.managedbuild.tool.gnu.cross.cpp.compiler"> |
|||
<option id="gnu.cpp.compiler.option.include.paths.611746109" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath"> |
|||
<listOptionValue builtIn="false" value=""${SMING_HOME}""/> |
|||
<listOptionValue builtIn="false" value=""${SMING_HOME}/system/include""/> |
|||
<listOptionValue builtIn="false" value=""${SMING_HOME}/Libraries""/> |
|||
<listOptionValue builtIn="false" value=""${ESP_HOME}/sdk/include""/> |
|||
</option> |
|||
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1330530366" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/> |
|||
</tool> |
|||
<tool id="cdt.managedbuild.tool.gnu.cross.c.linker.65193859" name="Cross GCC Linker" superClass="cdt.managedbuild.tool.gnu.cross.c.linker"/> |
|||
<tool id="cdt.managedbuild.tool.gnu.cross.cpp.linker.1795850540" name="Cross G++ Linker" superClass="cdt.managedbuild.tool.gnu.cross.cpp.linker"> |
|||
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.364843833" 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.cross.archiver.525412186" name="Cross GCC Archiver" superClass="cdt.managedbuild.tool.gnu.cross.archiver"/> |
|||
<tool id="cdt.managedbuild.tool.gnu.cross.assembler.587940548" name="Cross GCC Assembler" superClass="cdt.managedbuild.tool.gnu.cross.assembler"> |
|||
<option id="gnu.both.asm.option.include.paths.1067006329" name="Include paths (-I)" superClass="gnu.both.asm.option.include.paths" valueType="includePath"> |
|||
<listOptionValue builtIn="false" value=""${SMING_HOME}""/> |
|||
<listOptionValue builtIn="false" value=""${SMING_HOME}/system/include""/> |
|||
<listOptionValue builtIn="false" value=""${SMING_HOME}/Libraries""/> |
|||
<listOptionValue builtIn="false" value=""${ESP_HOME}/sdk/include""/> |
|||
</option> |
|||
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.651581712" superClass="cdt.managedbuild.tool.gnu.assembler.input"/> |
|||
</tool> |
|||
</toolChain> |
|||
</folderInfo> |
|||
</configuration> |
|||
</storageModule> |
|||
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/> |
|||
</cconfiguration> |
|||
</storageModule> |
|||
<storageModule moduleId="cdtBuildSystem" version="4.0.0"> |
|||
<project id="Basic_Blink.null.1347473968" name="Basic_Blink"/> |
|||
</storageModule> |
|||
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/> |
|||
<storageModule moduleId="refreshScope" versionNumber="2"> |
|||
<configuration configurationName="Sming"> |
|||
<resource resourceType="PROJECT" workspacePath="/Basic_Blink"/> |
|||
</configuration> |
|||
</storageModule> |
|||
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"> |
|||
<buildTargets> |
|||
<target name="all" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder"> |
|||
<buildCommand>make</buildCommand> |
|||
<buildArguments>-f ${ProjDirPath}/Makefile</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>-f ${ProjDirPath}/Makefile</buildArguments> |
|||
<buildTarget>clean</buildTarget> |
|||
<stopOnError>true</stopOnError> |
|||
<useDefaultCommand>true</useDefaultCommand> |
|||
<runAllBuilders>true</runAllBuilders> |
|||
</target> |
|||
<target name="flash" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder"> |
|||
<buildCommand>make</buildCommand> |
|||
<buildArguments>-f ${ProjDirPath}/Makefile</buildArguments> |
|||
<buildTarget>flash</buildTarget> |
|||
<stopOnError>true</stopOnError> |
|||
<useDefaultCommand>true</useDefaultCommand> |
|||
<runAllBuilders>true</runAllBuilders> |
|||
</target> |
|||
<target name="flashonefile" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder"> |
|||
<buildCommand>make</buildCommand> |
|||
<buildArguments>-f ${ProjDirPath}/Makefile</buildArguments> |
|||
<buildTarget>flashonefile</buildTarget> |
|||
<stopOnError>true</stopOnError> |
|||
<useDefaultCommand>true</useDefaultCommand> |
|||
<runAllBuilders>true</runAllBuilders> |
|||
</target> |
|||
<target name="flashinit" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder"> |
|||
<buildCommand>make</buildCommand> |
|||
<buildArguments>-f ${ProjDirPath}/Makefile</buildArguments> |
|||
<buildTarget>flashinit</buildTarget> |
|||
<stopOnError>true</stopOnError> |
|||
<useDefaultCommand>true</useDefaultCommand> |
|||
<runAllBuilders>true</runAllBuilders> |
|||
</target> |
|||
<target name="flashboot" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder"> |
|||
<buildCommand>make</buildCommand> |
|||
<buildArguments>-f ${ProjDirPath}/Makefile</buildArguments> |
|||
<buildTarget>flashboot</buildTarget> |
|||
<stopOnError>true</stopOnError> |
|||
<useDefaultCommand>true</useDefaultCommand> |
|||
<runAllBuilders>true</runAllBuilders> |
|||
</target> |
|||
<target name="rebuild" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder"> |
|||
<buildCommand>make</buildCommand> |
|||
<buildArguments>-f ${ProjDirPath}/Makefile</buildArguments> |
|||
<buildTarget>rebuild</buildTarget> |
|||
<stopOnError>true</stopOnError> |
|||
<useDefaultCommand>true</useDefaultCommand> |
|||
<runAllBuilders>true</runAllBuilders> |
|||
</target> |
|||
</buildTargets> |
|||
</storageModule> |
|||
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/> |
|||
<storageModule moduleId="scannerConfiguration"> |
|||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> |
|||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.mingw.base.1135534147;cdt.managedbuild.toolchain.gnu.mingw.base.1135534147.86962463;cdt.managedbuild.tool.gnu.c.compiler.mingw.base.2032390008;cdt.managedbuild.tool.gnu.c.compiler.input.1700912488"> |
|||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> |
|||
</scannerConfigBuildInfo> |
|||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.mingw.base.1135534147;cdt.managedbuild.toolchain.gnu.mingw.base.1135534147.86962463;cdt.managedbuild.tool.gnu.cross.c.compiler.1168221903;cdt.managedbuild.tool.gnu.c.compiler.input.313321806"> |
|||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> |
|||
</scannerConfigBuildInfo> |
|||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.mingw.base.1135534147;cdt.managedbuild.toolchain.gnu.mingw.base.1135534147.86962463;cdt.managedbuild.tool.gnu.cross.cpp.compiler.1999763015;cdt.managedbuild.tool.gnu.cpp.compiler.input.1330530366"> |
|||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> |
|||
</scannerConfigBuildInfo> |
|||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.mingw.base.1135534147;cdt.managedbuild.toolchain.gnu.mingw.base.1135534147.86962463;cdt.managedbuild.tool.gnu.cpp.compiler.mingw.base.454898447;cdt.managedbuild.tool.gnu.cpp.compiler.input.501261625"> |
|||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> |
|||
</scannerConfigBuildInfo> |
|||
</storageModule> |
|||
</cproject> |
@ -0,0 +1,28 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<projectDescription> |
|||
<name>Basic_Blink</name> |
|||
<comment></comment> |
|||
<projects> |
|||
<project>SmingFramework</project> |
|||
</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.mingw.base.1135534147" name="Sming"> |
|||
<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 copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/> |
|||
<provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="-1336254526216957438" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true"> |
|||
<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,24 @@ |
|||
#####################################################################
|
|||
#### Please don't change this file. Use Makefile-user.mk instead ####
|
|||
#####################################################################
|
|||
# Including user Makefile.
|
|||
# Should be used to set project-specific parameters
|
|||
include ./Makefile-user.mk |
|||
|
|||
# Important parameters check.
|
|||
# We need to make sure SMING_HOME and ESP_HOME variables are set.
|
|||
# You can use Makefile-user.mk in each project or use enviromental variables to set it globally.
|
|||
|
|||
ifndef SMING_HOME |
|||
$(error SMING_HOME is not set. Please configure it in Makefile-user.mk) |
|||
endif |
|||
ifndef ESP_HOME |
|||
$(error ESP_HOME is not set. Please configure it in Makefile-user.mk) |
|||
endif |
|||
|
|||
# Include main Sming Makefile
|
|||
ifeq ($(RBOOT_ENABLED), 1) |
|||
include $(SMING_HOME)/Makefile-rboot.mk |
|||
else |
|||
include $(SMING_HOME)/Makefile-project.mk |
|||
endif |
@ -0,0 +1,39 @@ |
|||
## Local build configuration
|
|||
## Parameters configured here will override default and ENV values.
|
|||
## Uncomment and change examples:
|
|||
|
|||
## Add your source directories here separated by space
|
|||
# MODULES = app
|
|||
# EXTRA_INCDIR = include
|
|||
|
|||
## ESP_HOME sets the path where ESP tools and SDK are located.
|
|||
## Windows:
|
|||
# ESP_HOME = c:/Espressif
|
|||
|
|||
## MacOS / Linux:
|
|||
# ESP_HOME = /opt/esp-open-sdk
|
|||
|
|||
## SMING_HOME sets the path where Sming framework is located.
|
|||
## Windows:
|
|||
# SMING_HOME = c:/tools/sming/Sming
|
|||
|
|||
## MacOS / Linux
|
|||
# SMING_HOME = /opt/sming/Sming
|
|||
|
|||
## COM port parameter is reqruied to flash firmware correctly.
|
|||
## Windows:
|
|||
COM_PORT = COM13 |
|||
|
|||
## MacOS / Linux:
|
|||
# COM_PORT = /dev/tty.usbserial
|
|||
|
|||
## Com port speed
|
|||
COM_SPEED = 460800 |
|||
|
|||
## Configure flash parameters (for ESP12-E and other new boards):
|
|||
# SPI_MODE = dio
|
|||
|
|||
## SPIFFS options
|
|||
DISABLE_SPIFFS = 1 |
|||
# SPIFF_FILES = files
|
|||
|
@ -0,0 +1,27 @@ |
|||
/*
|
|||
* adc.h |
|||
* |
|||
* Created on: Jul 20, 2017 |
|||
* Author: Elmar |
|||
*/ |
|||
|
|||
#ifndef APP_ADC_H_ |
|||
#define APP_ADC_H_ |
|||
|
|||
#include "sensor.h" |
|||
|
|||
namespace rijnfel { |
|||
|
|||
template<typename Sample, typename Voltage> |
|||
class cADC: public cSensor<Sample> { |
|||
public: |
|||
cADC() { |
|||
|
|||
} |
|||
virtual Voltage ConvertSample(Sample & sample) = 0; |
|||
virtual ~cADC() { |
|||
|
|||
} |
|||
}; |
|||
} |
|||
#endif /* APP_ADC_H_ */ |
@ -0,0 +1,167 @@ |
|||
/*
|
|||
* ADS101x.cpp |
|||
* |
|||
* Created on: Jul 20, 2017 |
|||
* Author: Elmar |
|||
*/ |
|||
|
|||
#include "ads101x.h" |
|||
#include <SmingCore/Wire.h> |
|||
|
|||
namespace rijnfel { |
|||
|
|||
namespace ads { |
|||
|
|||
static const uint16_t OS_POS = 15; |
|||
static const uint16_t OS_MASK = 1 << OS_POS; |
|||
static const uint16_t MUX_POS = 12; |
|||
static const uint16_t MUX_MASK = 7 << MUX_POS; |
|||
static const uint16_t PGA_POS = 9; |
|||
static const uint16_t PGA_MASK = 7 << PGA_POS; |
|||
static const uint16_t MODE_POS = 8; |
|||
static const uint16_t MODE_MASK = 1 << MODE_POS; |
|||
static const uint16_t DR_POS = 5; |
|||
static const uint16_t DR_MASK = 7 << DR_POS; |
|||
|
|||
#define OS_BIT(val) ((val << OS_POS) & OS_MASK) |
|||
#define MUX_BIT(val) ((val << MUX_POS) & MUX_MASK) |
|||
#define PGA_BIT(val) ((val << PGA_POS) & PGA_MASK) |
|||
#define MODE_BIT(val) ((val << MODE_POS) & MODE_MASK) |
|||
#define DR_BIT(val) ((val << DR_POS) & DR_MASK) |
|||
|
|||
static const uint8_t REGISTER_CONVERSION = 0; |
|||
static const uint8_t REGISTER_CONFIG = 1; |
|||
static const uint8_t REGISTER_LOW_TRESHOLD = 2; |
|||
static const uint8_t REGISTER_HIGH_TRESHOLD = 2; |
|||
|
|||
cADS101x::cADS101x(uint8_t i_address) : |
|||
m_address(i_address), m_readyPin(0) { |
|||
SetDefaults(); |
|||
} |
|||
cADS101x::cADS101x(uint8_t i_readyPin, uint8_t i_address) : |
|||
m_address(i_address), m_readyPin(i_readyPin) { |
|||
SetDefaults(); |
|||
} |
|||
|
|||
void cADS101x::SetOneShot(bool i_oneShot) { |
|||
m_oneShot = i_oneShot; |
|||
WriteSettings(CreateSettings(0)); |
|||
} |
|||
|
|||
void cADS101x::SetGain(enum eGainAmplifier i_gain) { |
|||
m_gain = i_gain; |
|||
WriteSettings(CreateSettings(0)); |
|||
} |
|||
|
|||
void cADS101x::SetMux(enum eInputMux i_mux) { |
|||
m_mux = i_mux; |
|||
WriteSettings(CreateSettings(0)); |
|||
} |
|||
|
|||
void cADS101x::SetSampleSpeed(enum eSampleSpeed i_sampleSpeed) { |
|||
m_sampleSpeed = i_sampleSpeed; |
|||
WriteSettings(CreateSettings(0)); |
|||
} |
|||
|
|||
void cADS101x::WaitSample(void) { |
|||
OneShot(); |
|||
uint16 readSettings = 0; |
|||
do { |
|||
readSettings = GetSettings(); |
|||
} while (readSettings & OS_MASK != 1); |
|||
} |
|||
|
|||
bool cADS101x::IsReady(void) { |
|||
return (GetSettings() & OS_MASK); |
|||
} |
|||
|
|||
uint16_t cADS101x::CreateSettings(uint8_t start) { |
|||
return OS_BIT(start) | MUX_BIT(m_mux) | PGA_BIT(m_gain) |
|||
| MODE_BIT(m_oneShot) | DR_BIT(m_sampleSpeed); |
|||
} |
|||
|
|||
void cADS101x::WriteSettings(uint16_t i_settings) { |
|||
Wire.beginTransmission(m_address); |
|||
Wire.write(REGISTER_CONFIG); |
|||
Wire.write((uint8_t) (i_settings >> 8)); |
|||
Wire.write((uint8_t) (i_settings & 0xFF)); |
|||
Wire.endTransmission(); |
|||
|
|||
} |
|||
|
|||
void cADS101x::OneShot(void) { |
|||
if (m_oneShot) { |
|||
uint16_t settings = CreateSettings(1); |
|||
WriteSettings(settings); |
|||
} |
|||
} |
|||
|
|||
uint16_t cADS101x::GetSettings(void) { |
|||
uint16_t settings; |
|||
Wire.beginTransmission(m_address); |
|||
Wire.write(REGISTER_CONFIG); |
|||
Wire.endTransmission(); |
|||
Wire.beginTransmission(m_address); |
|||
Wire.requestFrom((int) m_address, 2); //16 bits
|
|||
settings = Wire.read() << 8; |
|||
settings |= Wire.read(); |
|||
return settings; |
|||
} |
|||
ads_voltage_t cADS101x::ConvertSample(ads_sample_t & sample) { |
|||
//Raw sample is in (parts of) millivolts, go to micro to remove fractions
|
|||
ads_voltage_t returnType = (sample.rawSample >> 4) * 1000; //Multiply for extra precision
|
|||
switch (sample.gain) { |
|||
case eGainAmplifier::FSR_0_256: |
|||
//one lsb is 0.256 mv = 256 uv
|
|||
returnType *= 256; |
|||
break; |
|||
case eGainAmplifier::FSR_0_512: |
|||
//one lsb is 0.512 mv = 512 uv
|
|||
returnType *= 512; |
|||
break; |
|||
case eGainAmplifier::FSR_1_024: |
|||
//one lsb is 1.024 mv = 1024 uv
|
|||
returnType *= 1024; |
|||
break; |
|||
case eGainAmplifier::FSR_2_048: |
|||
//one lsb is 2.048 mv = 2048 uv
|
|||
returnType *= 2048; |
|||
break; |
|||
case eGainAmplifier::FSR_4_096: |
|||
//one lsb is 4.096 mv = 4096 uv
|
|||
returnType *= 4096; |
|||
break; |
|||
case eGainAmplifier::FSR_6_144: |
|||
//one lsb is 6.144 mv = 6144 uv
|
|||
returnType *= 6144; |
|||
break; |
|||
} |
|||
return returnType; |
|||
} |
|||
|
|||
ads_sample_t cADS101x::RawSample(void) { |
|||
OneShot(); |
|||
ads_sample_t sample; |
|||
Wire.beginTransmission(m_address); |
|||
Wire.write(REGISTER_CONVERSION); |
|||
Wire.endTransmission(); |
|||
Wire.beginTransmission(m_address); |
|||
Wire.requestFrom((int) m_address, 2); //16 bits
|
|||
sample.rawSample = Wire.read() << 8; |
|||
sample.rawSample |= Wire.read(); |
|||
sample.gain = m_gain; |
|||
sample.mux = m_mux; |
|||
m_latestSample = sample; |
|||
return sample; |
|||
} |
|||
|
|||
void cADS101x::SetDefaults(void) { |
|||
m_mux = eInputMux::AIN_0_1; |
|||
m_gain = eGainAmplifier::FSR_2_048; |
|||
m_sampleSpeed = eSampleSpeed::SPS_1600; |
|||
m_oneShot = true; |
|||
} |
|||
|
|||
} |
|||
|
|||
} |
@ -0,0 +1,70 @@ |
|||
/*
|
|||
* ADS101x.h |
|||
* |
|||
* Created on: Jul 20, 2017 |
|||
* Author: Elmar |
|||
*/ |
|||
|
|||
#ifndef APP_ADS101X_H_ |
|||
#define APP_ADS101X_H_ |
|||
|
|||
#include <stdint.h> |
|||
#include "adc.h" |
|||
|
|||
namespace rijnfel { |
|||
|
|||
namespace ads { |
|||
|
|||
//Voltage in uV
|
|||
typedef int32_t ads_voltage_t; |
|||
|
|||
enum eInputMux { |
|||
AIN_0_1, AIN_0_3, AIN_1_3, AIN_2_3, AIN_0, AIN_1, AIN_2, AIN_3 |
|||
}; |
|||
enum eGainAmplifier { |
|||
FSR_6_144, FSR_4_096, FSR_2_048, FSR_1_024, FSR_0_512, FSR_0_256 |
|||
}; |
|||
enum eSampleSpeed { |
|||
SPS_128, SPS_250, SPS_490, SPS_920, SPS_1600, SPS_2400, SPS_3300 |
|||
}; |
|||
|
|||
struct ads_sample_t { |
|||
int16_t rawSample; |
|||
enum eInputMux mux; |
|||
enum eGainAmplifier gain; |
|||
}; |
|||
|
|||
class cADS101x: cADC<ads_sample_t, ads_voltage_t> { |
|||
public: |
|||
|
|||
cADS101x(uint8_t i_address = 0x48); |
|||
cADS101x(uint8_t i_readyPin, uint8_t i_address = 0x48); |
|||
|
|||
void SetOneShot(bool i_oneShot = true); |
|||
void SetGain(enum eGainAmplifier i_gain); |
|||
void SetMux(enum eInputMux i_mux); |
|||
void SetSampleSpeed(enum eSampleSpeed i_speed); |
|||
virtual void WaitSample(void); |
|||
virtual bool IsReady(void); |
|||
uint16_t GetSettings(void); |
|||
|
|||
virtual ads_sample_t RawSample(void); |
|||
virtual ads_voltage_t ConvertSample(ads_sample_t & sample); |
|||
virtual ~cADS101x() { |
|||
|
|||
} |
|||
private: |
|||
uint16_t CreateSettings(uint8_t i_startSample); |
|||
void WriteSettings(uint16_t i_settings); |
|||
void SetDefaults(void); |
|||
void OneShot(void); |
|||
private: |
|||
uint8_t m_address, m_readyPin; |
|||
bool m_oneShot; |
|||
enum eInputMux m_mux; |
|||
enum eGainAmplifier m_gain; |
|||
enum eSampleSpeed m_sampleSpeed; |
|||
}; |
|||
} |
|||
} |
|||
#endif /* APP_ADS101X_H_ */ |
@ -0,0 +1,66 @@ |
|||
#include <user_config.h> |
|||
#include <SmingCore/SmingCore.h> |
|||
#include <SmingCore/HardwareSerial.h> |
|||
#include "ads101x.h" |
|||
|
|||
#define LED_PIN 2 // GPIO2
|
|||
|
|||
using namespace rijnfel; |
|||
Timer procTimer; |
|||
ads::cADS101x adc; |
|||
bool state = true; |
|||
uint16_t sampless = 1; |
|||
uint8_t channel = 0; |
|||
unsigned int average[4]; |
|||
|
|||
void readAdc() { |
|||
//while (adc.IsReady()) {
|
|||
adc.SetMux(static_cast<ads::eInputMux>(ads::eInputMux::AIN_0 + channel)); |
|||
channel++; |
|||
if (channel > 3) { |
|||
channel = 0; |
|||
} |
|||
uint16_t settings = adc.GetSettings(); |
|||
Serial.printf("Settings = %d;\n\r", settings); |
|||
|
|||
if (false) { |
|||
adc.SetMux( |
|||
static_cast<ads::eInputMux>(ads::eInputMux::AIN_0 + channel)); |
|||
ads::ads_sample_t sample = adc.RawSample(); |
|||
average[channel] += adc.ConvertSample(sample) / 1000; //want it in mv
|
|||
channel++; |
|||
if (channel > 3) { |
|||
channel = 0; |
|||
sampless++; |
|||
if (sampless > 3300) { |
|||
for (uint8_t i = 0; i < 4; i++) { |
|||
Serial.printf("C[%d] = %d; ", i, average[i] / sampless); |
|||
average[i] = 0; |
|||
} |
|||
Serial.printf("\n\r"); |
|||
sampless = 0; |
|||
} |
|||
} |
|||
} |
|||
WDT.alive(); |
|||
//}
|
|||
//Serial.printf("Not ready anymore\n\r");
|
|||
} |
|||
|
|||
void blink() { |
|||
readAdc(); |
|||
} |
|||
|
|||
void init() { |
|||
Serial.begin(460800); |
|||
Wire.pins(5, 4); |
|||
|
|||
Wire.begin(); |
|||
//SET higher CPU freq & disable wifi sleep
|
|||
system_update_cpu_freq(SYS_CPU_160MHZ); |
|||
WDT.enable(false); |
|||
pinMode(LED_PIN, OUTPUT); |
|||
adc.SetMux(ads::eInputMux::AIN_0); |
|||
adc.SetSampleSpeed(ads::eSampleSpeed::SPS_3300); |
|||
procTimer.initializeMs(500, readAdc).start(); |
|||
} |
@ -0,0 +1,60 @@ |
|||
/*
|
|||
* double_buffer.h |
|||
* |
|||
* Created on: Aug 1, 2017 |
|||
* Author: Elmar |
|||
*/ |
|||
|
|||
#ifndef APP_DOUBLE_BUFFER_H_ |
|||
#define APP_DOUBLE_BUFFER_H_ |
|||
|
|||
#include <stdint.h> |
|||
|
|||
namespace rijnfel { |
|||
|
|||
template<typename BufferType> |
|||
class cDoubleBuffer { |
|||
public: |
|||
cDoubleBuffer(int i_size) : |
|||
m_size(i_size) { |
|||
m_writeIndex = 0; |
|||
m_bufferIndex = 0; |
|||
m_buf = new BufferType*[2]; |
|||
m_buf[0] = new BufferType[m_size]; |
|||
m_buf[1] = new BufferType[m_size]; |
|||
} |
|||
|
|||
void Resize(int i_newSize) { |
|||
|
|||
} |
|||
|
|||
bool AddValue(BufferType i_val) { |
|||
m_buf[m_bufferIndex][m_writeIndex] = i_val; |
|||
m_writeIndex++; |
|||
if (m_writeIndex >= m_size) { |
|||
m_bufferIndex = !m_bufferIndex; |
|||
m_writeIndex = 0; |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
BufferType * GetBuffer(int i_index) { |
|||
return m_buf[i_index]; |
|||
} |
|||
|
|||
virtual ~cDoubleBuffer() { |
|||
delete m_buf[0]; |
|||
delete m_buf[1]; |
|||
delete m_buf; |
|||
} |
|||
private: |
|||
int m_size; |
|||
int m_writeIndex; |
|||
int m_bufferIndex; |
|||
BufferType ** m_buf; |
|||
}; |
|||
|
|||
} /* namespace rijnfel */ |
|||
|
|||
#endif /* APP_DOUBLE_BUFFER_H_ */ |
@ -0,0 +1,38 @@ |
|||
/*
|
|||
* sensor.h |
|||
* |
|||
* Created on: Aug 1, 2017 |
|||
* Author: Elmar |
|||
*/ |
|||
|
|||
#ifndef APP_SENSOR_H_ |
|||
#define APP_SENSOR_H_ |
|||
|
|||
#include <stddef.h> |
|||
|
|||
namespace rijnfel { |
|||
template<typename Sample> |
|||
class cSensor { |
|||
public: |
|||
cSensor() { |
|||
m_callback = NULL; |
|||
} |
|||
Sample GetLatestSample(void) { |
|||
return m_latestSample; |
|||
} |
|||
void SetOnSampleCallBack(void (*i_callback)(Sample & o_sample)) { |
|||
m_callback = i_callback; |
|||
} |
|||
virtual void WaitSample(void) = 0; |
|||
virtual bool IsReady(void) = 0; |
|||
virtual Sample RawSample(void) = 0; |
|||
virtual ~cSensor() { |
|||
|
|||
} |
|||
protected: |
|||
Sample m_latestSample; |
|||
void (*m_callback)(Sample & o_sample); |
|||
}; |
|||
} |
|||
|
|||
#endif /* APP_SENSOR_H_ */ |
@ -0,0 +1,47 @@ |
|||
/*
|
|||
* sensor_hub.cpp |
|||
* |
|||
* Created on: Aug 1, 2017 |
|||
* Author: Elmar |
|||
*/ |
|||
|
|||
#include "sensor_hub.h" |
|||
#include <stdint.h> |
|||
|
|||
namespace rijnfel { |
|||
|
|||
cSensorHub::cSensorHub(uint32_t i_updatePeriod) : |
|||
m_updatePeriod(i_updatePeriod) { |
|||
m_adc = new ads::cADS101x(); |
|||
m_adcSettings = NULL; |
|||
m_tempSettings = NULL; |
|||
} |
|||
|
|||
void cSensorHub::Update() { |
|||
if (m_adcSettings) { |
|||
if (m_adcSettings->ShouldSample(m_updatePeriod)) { |
|||
if (m_adcSettings->m_buffer.AddValue(m_adc->RawSample())) { |
|||
m_adcSettings->m_callback(m_adcSettings->m_buffer); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
void cSensorHub::SetAdcSettings( |
|||
cSensorSettings<ads::ads_sample_t> * i_adcSettings) { |
|||
m_adcSettings = i_adcSettings; |
|||
} |
|||
|
|||
void cSensorHub::SetTempSettings(cSensorSettings<uint32_t> * i_tempSettings) { |
|||
m_tempSettings = i_tempSettings; |
|||
} |
|||
|
|||
cSensorHub::~cSensorHub() { |
|||
if (m_adcSettings) |
|||
delete m_adcSettings; |
|||
if (m_tempSettings) |
|||
delete m_tempSettings; |
|||
delete m_adc; |
|||
} |
|||
|
|||
} /* namespace rijnfel */ |
@ -0,0 +1,33 @@ |
|||
/*
|
|||
* sensor_hub.h |
|||
* |
|||
* Created on: Aug 1, 2017 |
|||
* Author: Elmar |
|||
*/ |
|||
|
|||
#ifndef APP_SENSOR_HUB_H_ |
|||
#define APP_SENSOR_HUB_H_ |
|||
|
|||
#include "ads101x.h" |
|||
#include "sensor_settings.h" |
|||
|
|||
namespace rijnfel { |
|||
|
|||
class cSensorHub { |
|||
public: |
|||
//in milliseconds
|
|||
cSensorHub(uint32_t i_updatePeriod); |
|||
void SetAdcSettings(cSensorSettings<ads::ads_sample_t> * i_adcSettings); |
|||
void SetTempSettings(cSensorSettings<uint32_t> * i_tempSettings); |
|||
void Update(); |
|||
virtual ~cSensorHub(); |
|||
private: |
|||
uint32_t m_updatePeriod; |
|||
cSensorSettings<ads::ads_sample_t> * m_adcSettings; |
|||
cSensorSettings<uint32_t> * m_tempSettings; |
|||
ads::cADS101x * m_adc; |
|||
}; |
|||
|
|||
} /* namespace rijnfel */ |
|||
|
|||
#endif /* APP_SENSOR_HUB_H_ */ |
@ -0,0 +1,41 @@ |
|||
/*
|
|||
* sensor_settings.h |
|||
* |
|||
* Created on: Aug 1, 2017 |
|||
* Author: Elmar |
|||
*/ |
|||
|
|||
#ifndef APP_SENSOR_SETTINGS_H_ |
|||
#define APP_SENSOR_SETTINGS_H_ |
|||
|
|||
#include "double_buffer.h" |
|||
|
|||
namespace rijnfel { |
|||
|
|||
template<typename BufferType> |
|||
class cSensorSettings { |
|||
public: |
|||
cSensorSettings(void (*i_callback)(cDoubleBuffer<BufferType> & buffer), |
|||
uint32_t i_periodTimer, uint32_t i_period) : |
|||
m_callback(i_callback), m_periodTimer(i_periodTimer), m_period( |
|||
i_period) { |
|||
m_buffer(1000 / m_period); |
|||
} |
|||
bool ShouldSample(uint32_t i_updatePeriod) { |
|||
m_periodTimer += i_updatePeriod; |
|||
if (m_periodTimer >= m_period) { |
|||
m_periodTimer -= m_period; |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
cDoubleBuffer<BufferType> m_buffer; |
|||
void (*m_callback)(cDoubleBuffer<BufferType> & buffer); |
|||
private: |
|||
uint32_t m_periodTimer; |
|||
uint32_t m_period; |
|||
}; |
|||
|
|||
} |
|||
|
|||
#endif /* APP_SENSOR_SETTINGS_H_ */ |
@ -0,0 +1,28 @@ |
|||
/*
|
|||
* temperature.h |
|||
* |
|||
* Created on: Aug 1, 2017 |
|||
* Author: Elmar |
|||
*/ |
|||
|
|||
#ifndef APP_TEMPERATURE_H_ |
|||
#define APP_TEMPERATURE_H_ |
|||
|
|||
#include "sensor.h" |
|||
|
|||
namespace rijnfel { |
|||
template<typename Sample, typename Temperature> |
|||
class cTemperatureSensor: cSensor<Sample> { |
|||
public: |
|||
cTemperatureSensor() { |
|||
|
|||
} |
|||
virtual Temperature ConvertSample(Sample sample) = 0; |
|||
virtual ~cTemperatureSensor() { |
|||
|
|||
} |
|||
}; |
|||
|
|||
} |
|||
|
|||
#endif /* APP_TEMPERATURE_H_ */ |
@ -0,0 +1,45 @@ |
|||
#ifndef __USER_CONFIG_H__ |
|||
#define __USER_CONFIG_H__ |
|||
|
|||
#ifdef __cplusplus |
|||
extern "C" { |
|||
#endif |
|||
|
|||
// UART config
|
|||
#define SERIAL_BAUD_RATE COM_SPEED_SERIAL |
|||
|
|||
// ESP SDK config
|
|||
#define LWIP_OPEN_SRC |
|||
#define USE_US_TIMER |
|||
|
|||
// Default types
|
|||
#define __CORRECT_ISO_CPP_STDLIB_H_PROTO |
|||
#include <limits.h> |
|||
#include <stdint.h> |
|||
|
|||
// Override c_types.h include and remove buggy espconn
|
|||
#define _C_TYPES_H_ |
|||
#define _NO_ESPCON_ |
|||
|
|||
// Updated, compatible version of c_types.h
|
|||
// Just removed types declared in <stdint.h>
|
|||
#include <espinc/c_types_compatible.h> |
|||
|
|||
// System API declarations
|
|||
#include <esp_systemapi.h> |
|||
|
|||
// C++ Support
|
|||
#include <esp_cplusplus.h> |
|||
// Extended string conversion for compatibility
|
|||
#include <stringconversion.h> |
|||
// Network base API
|
|||
#include <espinc/lwip_includes.h> |
|||
|
|||
// Beta boards
|
|||
#define BOARD_ESP01 |
|||
|
|||
#ifdef __cplusplus |
|||
} |
|||
#endif |
|||
|
|||
#endif |
Loading…
Reference in new issue