more stuff
This commit is contained in:
parent
bc8a9023aa
commit
7c2ff00bc4
20
.cproject
20
.cproject
@ -18,19 +18,27 @@
|
||||
<folderInfo id="it.baeyens.arduino.core.toolChain.release.1766021206.928550470" name="/" resourcePath="">
|
||||
<toolChain id="it.baeyens.arduino.core.toolChain.release.1379005045" name="it.baeyens.arduino.core.toolChain.release" superClass="it.baeyens.arduino.core.toolChain.release">
|
||||
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="it.baeyens.arduino.targetplatform.2135596349" name="Arduino Target" osList="all" superClass="it.baeyens.arduino.targetplatform"/>
|
||||
<builder buildPath="${workspace_loc:/ThermometerPro}/Release" id="it.baeyens.arduino.sketch.builder.92079915" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Arduino sketch builder" superClass="it.baeyens.arduino.sketch.builder"/>
|
||||
<builder buildPath="${workspace_loc:/ThermometerPro}/Release" id="it.baeyens.arduino.sketch.builder.92079915" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Arduino sketch builder" superClass="it.baeyens.arduino.sketch.builder">
|
||||
<outputEntries>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="outputPath" name="Release"/>
|
||||
</outputEntries>
|
||||
</builder>
|
||||
<tool id="it.baeyens.arduino.tool.sketch.compiler.cpp.1453728045" name="Arduino C++ Compiler" superClass="it.baeyens.arduino.tool.sketch.compiler.cpp">
|
||||
<option id="it.baeyens.arduino.compiler.cpp.sketch.option.incpath.1409263842" name="Include Paths (-I)" superClass="it.baeyens.arduino.compiler.cpp.sketch.option.incpath" valueType="includePath">
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/ThermometerPro/arduino/core}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/ThermometerPro/arduino/variant}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/ThermometerPro/ThermometerPro/arduino/core}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/ThermometerPro/ThermometerPro/arduino/variant}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/ThermometerPro/ThermometerPro/Libraries/SPI}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/ThermometerPro/Libraries/EEPROM}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/ThermometerPro/Libraries/SPI}""/>
|
||||
</option>
|
||||
<inputType id="it.baeyens.arduino.compiler.cpp.sketch.input.2020703864" name="CPP source files" superClass="it.baeyens.arduino.compiler.cpp.sketch.input"/>
|
||||
</tool>
|
||||
<tool id="it.baeyens.arduino.tool.compiler.c.1433100019" name="Arduino C Compiler" superClass="it.baeyens.arduino.tool.compiler.c">
|
||||
<option id="it.baeyens.arduino.compiler.c.sketch.option.incpath.14050020" name="Include Paths (-I)" superClass="it.baeyens.arduino.compiler.c.sketch.option.incpath" valueType="includePath">
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/ThermometerPro/arduino/core}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/ThermometerPro/arduino/variant}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/ThermometerPro/ThermometerPro/arduino/core}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/ThermometerPro/ThermometerPro/arduino/variant}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/ThermometerPro/ThermometerPro/Libraries/SPI}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/ThermometerPro/Libraries/EEPROM}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/ThermometerPro/Libraries/SPI}""/>
|
||||
</option>
|
||||
<inputType id="it.baeyens.arduino.compiler.c.sketch.input.1030697818" name="C Source Files" superClass="it.baeyens.arduino.compiler.c.sketch.input"/>
|
||||
@ -43,7 +51,7 @@
|
||||
</toolChain>
|
||||
</folderInfo>
|
||||
<sourceEntries>
|
||||
<entry excluding="Libraries/*/?xamples" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name=""/>
|
||||
<entry excluding="Libraries/*/?xamples|NilRTOS" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
|
||||
</sourceEntries>
|
||||
</configuration>
|
||||
</storageModule>
|
||||
|
5
.project
5
.project
@ -26,6 +26,11 @@
|
||||
<nature>it.baeyens.arduinonature</nature>
|
||||
</natures>
|
||||
<linkedResources>
|
||||
<link>
|
||||
<name>Libraries/EEPROM</name>
|
||||
<type>2</type>
|
||||
<locationURI>ArduinoHardwareLibPath/EEPROM</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>Libraries/SPI</name>
|
||||
<type>2</type>
|
||||
|
@ -305,7 +305,7 @@ void AD7190_RangeSetup(unsigned char polarity, unsigned char range)
|
||||
oldRegValue = AD7190_GetRegisterValue(AD7190_REG_CONF,3, 1);
|
||||
oldRegValue &= ~(AD7190_CONF_UNIPOLAR |
|
||||
AD7190_CONF_GAIN(0x7));
|
||||
newRegValue = oldRegValue |
|
||||
newRegValue = oldRegValue |
|
||||
(polarity * AD7190_CONF_UNIPOLAR) |
|
||||
AD7190_CONF_GAIN(range);
|
||||
AD7190_SetRegisterValue(AD7190_REG_CONF, newRegValue, 3, 1);
|
||||
@ -323,7 +323,8 @@ unsigned long AD7190_SingleConversion(void)
|
||||
|
||||
command = AD7190_MODE_SEL(AD7190_MODE_SINGLE) |
|
||||
AD7190_MODE_CLKSRC(AD7190_CLK_INT) |
|
||||
AD7190_MODE_RATE(0x060);
|
||||
AD7190_MODE_REJ60 |
|
||||
AD7190_MODE_RATE(0x360);
|
||||
|
||||
//ADI_PART_CS_LOW;
|
||||
SPI_Enable(AD7190_SLAVE_ID);
|
||||
|
@ -1,8 +1,25 @@
|
||||
#include "ThermometerPro.h"
|
||||
|
||||
|
||||
#include "AD7190.h"
|
||||
#include "cmd.h"
|
||||
#include "test.h"
|
||||
#include "uptime.h"
|
||||
|
||||
|
||||
static CmdServer cmdServer(&Serial);
|
||||
static TestCmd testCmd;
|
||||
static Uptime uptime;
|
||||
|
||||
|
||||
|
||||
void setup() {
|
||||
cmdServer.begin();
|
||||
testCmd.registerYourself(&cmdServer);
|
||||
uptime.begin(&cmdServer);
|
||||
|
||||
|
||||
|
||||
Serial.begin(9600);
|
||||
|
||||
delay(5000);
|
||||
@ -11,6 +28,7 @@ void setup() {
|
||||
unsigned char ad7190Status = AD7190_Init();
|
||||
Serial.print(String("ad7190Status: ") + ad7190Status + "\n");
|
||||
|
||||
AD7190_RangeSetup(1, AD7190_CONF_GAIN_1);
|
||||
|
||||
AD7190_Calibrate(AD7190_MODE_CAL_INT_ZERO, AD7190_CH_AIN4P_AINCOM);
|
||||
AD7190_Calibrate(AD7190_MODE_CAL_INT_FULL, AD7190_CH_AIN4P_AINCOM);
|
||||
@ -24,10 +42,11 @@ void setup() {
|
||||
AD7190_Calibrate(AD7190_MODE_CAL_INT_ZERO, AD7190_CH_AIN1P_AINCOM);
|
||||
AD7190_Calibrate(AD7190_MODE_CAL_INT_FULL, AD7190_CH_AIN1P_AINCOM);
|
||||
|
||||
AD7190_RangeSetup(1, AD7190_CONF_GAIN_1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
unsigned long T() {
|
||||
AD7190_ChannelSelect(AD7190_CH_AIN4P_AINCOM);
|
||||
unsigned long t = AD7190_SingleConversion();
|
||||
@ -43,41 +62,66 @@ float pt1000(float r) {
|
||||
|
||||
|
||||
void loop() {
|
||||
cmdServer.exec();
|
||||
uptime.exec();
|
||||
|
||||
|
||||
|
||||
Serial.print("Tick\n");
|
||||
|
||||
AD7190_ChannelSelect(AD7190_CH_AIN4P_AINCOM);
|
||||
unsigned long n4 = AD7190_SingleConversion();
|
||||
n4 &= 0xffff00;
|
||||
AD7190_ChannelSelect(AD7190_CH_AIN3P_AINCOM);
|
||||
unsigned long n3x = AD7190_SingleConversion();
|
||||
n3x &= 0xffff00;
|
||||
AD7190_ChannelSelect(AD7190_CH_AIN2P_AINCOM);
|
||||
unsigned long n2x = AD7190_SingleConversion();
|
||||
n2x &= 0xffff00;
|
||||
AD7190_ChannelSelect(AD7190_CH_AIN1P_AINCOM);
|
||||
unsigned long n1x = AD7190_SingleConversion();
|
||||
|
||||
|
||||
n1x &= 0xffff00;
|
||||
|
||||
|
||||
unsigned long n_max = 0xffffff;
|
||||
float r_ref = 6000.0;
|
||||
|
||||
float r_m4 = (((float)n4) / ((float)n_max)) * r_ref;
|
||||
|
||||
float r_m4 = (((float)n4) / ((float)n_max)) * r_ref * 1.0010705;
|
||||
float t4 = pt1000(r_m4);
|
||||
Serial.print(n4); Serial.print(", "); Serial.print(r_m4, 4); Serial.print(", "); Serial.println(t4, 2);
|
||||
Serial.print(n4); Serial.print(", "); Serial.print(r_m4, 4); Serial.print(", "); Serial.print(t4, 2);
|
||||
Serial.println();
|
||||
|
||||
unsigned long n3 = n3x - n4;
|
||||
float r_m3 = (((float)n3) / ((float)n_max)) * r_ref;
|
||||
float r_m3 = (((float)n3) / ((float)n_max)) * r_ref * 1.000794;
|
||||
float t3 = pt1000(r_m3);
|
||||
Serial.print(n3x); Serial.print(", "); Serial.print(n3); Serial.print(", "); Serial.print(r_m3, 4); Serial.print(", "); Serial.println(t3, 2);
|
||||
Serial.print(n3x); Serial.print(", "); Serial.print(n3); Serial.print(", "); Serial.print(r_m3, 4); Serial.print(", "); Serial.print(t3, 2);
|
||||
// float d = r_m4 - r_m3;
|
||||
// Serial.print(", "); Serial.print(d, 2);
|
||||
// unsigned long dd = n4 - n3;
|
||||
// Serial.print(", "); Serial.print(dd);
|
||||
Serial.println();
|
||||
|
||||
unsigned long n2 = n2x - n3x;
|
||||
float r_m2 = (((float)n2) / ((float)n_max)) * r_ref;
|
||||
float r_m2 = (((float)n2) / ((float)n_max)) * r_ref * 1.001804;
|
||||
float t2 = pt1000(r_m2);
|
||||
Serial.print(n2x); Serial.print(", "); Serial.print(n2); Serial.print(", "); Serial.print(r_m2, 4); Serial.print(", "); Serial.println(t2, 2);
|
||||
Serial.print(n2x); Serial.print(", "); Serial.print(n2); Serial.print(", "); Serial.print(r_m2, 4); Serial.print(", "); Serial.print(t2, 2);
|
||||
// d = r_m3 - r_m2;
|
||||
// Serial.print(", "); Serial.print(d, 2);
|
||||
// dd = n3 - n2;
|
||||
// Serial.print(", "); Serial.print(dd);
|
||||
Serial.println();
|
||||
|
||||
unsigned long n1 = n1x - n2x;
|
||||
float r_m1 = (((float)n1) / ((float)n_max)) * r_ref;
|
||||
float r_m1 = (((float)n1) / ((float)n_max)) * r_ref * 1.002999;
|
||||
float t1 = pt1000(r_m1);
|
||||
Serial.print(n1x); Serial.print(", "); Serial.print(n1); Serial.print(", "); Serial.print(r_m1, 4); Serial.print(", "); Serial.println(t1, 2);
|
||||
Serial.print(n1x); Serial.print(", "); Serial.print(n1); Serial.print(", "); Serial.print(r_m1, 4); Serial.print(", "); Serial.print(t1, 2);
|
||||
// d = r_m2 - r_m1;
|
||||
// Serial.print(", "); Serial.print(d, 2);
|
||||
// dd = n2 - n1;
|
||||
// Serial.print(", "); Serial.print(dd);
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
|
||||
|
||||
delay(1000);
|
||||
|
97
cmd.cpp
Normal file
97
cmd.cpp
Normal file
@ -0,0 +1,97 @@
|
||||
#include <HardwareSerial.h>
|
||||
|
||||
#include "cmd.h"
|
||||
#include "fatal.h"
|
||||
|
||||
|
||||
void Cmd::registerYourself(CmdServer *cmdServer) {
|
||||
cmdServer->registerCmd(this);
|
||||
}
|
||||
|
||||
|
||||
CmdServer::CmdServer(Stream *p_stream) :
|
||||
m_stream(p_stream), cmd(""), params(""), cmdListIdx(0)
|
||||
{
|
||||
}
|
||||
|
||||
void CmdServer::begin() {
|
||||
((Serial_*)m_stream)->begin(9600);
|
||||
}
|
||||
|
||||
void CmdServer::exec() {
|
||||
static uint8_t state = 0;
|
||||
bool done = false;
|
||||
|
||||
if (m_stream->available()) {
|
||||
char ch;
|
||||
while ((ch = m_stream->read()) != -1) {
|
||||
switch (state) {
|
||||
case 0:
|
||||
if ((ch != ' ') && (ch != '\n')) {
|
||||
cmd += ch;
|
||||
} else if (ch == '\n') {
|
||||
done = true;
|
||||
} else {
|
||||
state = 1;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (ch != '\n') {
|
||||
params += ch;
|
||||
} else {
|
||||
done = true;
|
||||
state = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (done) {
|
||||
m_stream->println("Cmd: " + cmd);
|
||||
parseCommand();
|
||||
cmd = "";
|
||||
params = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CmdServer::registerCmd(Cmd *cmdObj) {
|
||||
if (cmdListIdx < NUM_OF_COMMANDS) {
|
||||
cmdList[cmdListIdx] = cmdObj;
|
||||
cmdListIdx++;
|
||||
} else {
|
||||
fatal(FATAL_NOT_ENOUGH_CMD_SLOTS);
|
||||
}
|
||||
}
|
||||
|
||||
void CmdServer::parseCommand() {
|
||||
//m_client.println("cmd: " + cmd);
|
||||
//m_client.println("params: " + params);
|
||||
|
||||
if (cmd.equalsIgnoreCase("help")) {
|
||||
for (uint8_t i = 0; i < cmdListIdx; i++) {
|
||||
Cmd *c = cmdList[i];
|
||||
m_stream->println(c->getCmdName() + " " + c->getHelp());
|
||||
}
|
||||
m_stream->println("HELP List this help for all commands");
|
||||
} else {
|
||||
bool found = false;
|
||||
for (uint8_t i = 0; i < cmdListIdx; i++) {
|
||||
// m_client.println("Check: " + cmdList[i]->getCmdName());
|
||||
if (cmdList[i]->getCmdName().equalsIgnoreCase(cmd)) {
|
||||
found = true;
|
||||
// m_client.println("cmd found");
|
||||
cmdList[i]->setClient(m_stream);
|
||||
String res = cmdList[i]->exec(params);
|
||||
m_stream->println(res);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (! found)
|
||||
m_stream->println("command not found");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
46
cmd.h
Normal file
46
cmd.h
Normal file
@ -0,0 +1,46 @@
|
||||
#ifndef CMD_H_
|
||||
#define CMD_H_
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <stdint.h>
|
||||
#include <WString.h>
|
||||
#include <Print.h>
|
||||
#include <Stream.h>
|
||||
|
||||
static const uint8_t NUM_OF_COMMANDS = 10;
|
||||
|
||||
class CmdServer;
|
||||
|
||||
class Cmd {
|
||||
public:
|
||||
virtual ~Cmd() {};
|
||||
void setClient(Stream *p_stream) { m_stream = p_stream; };
|
||||
virtual String exec(String params) =0;
|
||||
virtual String getCmdName() =0;
|
||||
virtual String getHelp() =0;
|
||||
virtual void registerYourself(CmdServer *cmdServer);
|
||||
protected:
|
||||
Stream *m_stream;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class CmdServer {
|
||||
public:
|
||||
CmdServer(Stream *p_stream);
|
||||
void begin();
|
||||
void exec();
|
||||
void registerCmd(Cmd *cmdObj);
|
||||
private:
|
||||
void parseCommand();
|
||||
Stream *m_stream;
|
||||
String cmd;
|
||||
String params;
|
||||
uint8_t cmdListIdx;
|
||||
Cmd *cmdList[NUM_OF_COMMANDS];
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* CMD_H_ */
|
11
fatal.cpp
Normal file
11
fatal.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
#include <avr/interrupt.h>
|
||||
#include"fatal.h"
|
||||
|
||||
|
||||
void fatal(uint8_t code) {
|
||||
cli();
|
||||
// do something with the code and somehow show that there is a problem
|
||||
while (1);
|
||||
}
|
||||
|
||||
|
15
fatal.h
Normal file
15
fatal.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef FATAL_H_
|
||||
#define FATAL_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
const uint8_t FATAL_UNKNOWN = 1;
|
||||
const uint8_t FATAL_NOT_ENOUGH_CMD_SLOTS = 2;
|
||||
|
||||
const uint8_t FATAL_BUFFER_OVERFLOW = 10;
|
||||
|
||||
|
||||
void fatal(uint8_t code);
|
||||
|
||||
|
||||
#endif /* FATAL_H_ */
|
7
test.cpp
Normal file
7
test.cpp
Normal file
@ -0,0 +1,7 @@
|
||||
#include <WString.h>
|
||||
#include "test.h"
|
||||
|
||||
String TestCmd::exec(String params) {
|
||||
return "Result of testCmd";
|
||||
}
|
||||
|
14
test.h
Normal file
14
test.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef TEST_H_
|
||||
#define TEST_H_
|
||||
|
||||
#include "cmd.h"
|
||||
|
||||
class TestCmd : public Cmd {
|
||||
public:
|
||||
virtual String getCmdName() { return "TEST"; }
|
||||
virtual String getHelp() { return "Just a test command"; }
|
||||
virtual String exec(String params);
|
||||
};
|
||||
|
||||
|
||||
#endif /* TEST_H_ */
|
45
uptime.cpp
Normal file
45
uptime.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
#include <WString.h>
|
||||
#include "uptime.h"
|
||||
|
||||
|
||||
UptimeCmd::UptimeCmd(Uptime *uptime) : m_uptime(uptime) {
|
||||
|
||||
}
|
||||
|
||||
String UptimeCmd::exec(String params) {
|
||||
return m_uptime->getDays() + String(" ") +
|
||||
m_uptime->getHours() + String(":") + m_uptime->getMinutes() + String(":") + m_uptime->getSeconds();
|
||||
}
|
||||
|
||||
Uptime::Uptime() : m_uptimeCmd(this), m_seconds(0), m_minutes(0), m_hours(0), m_days(0) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Uptime::begin(CmdServer *cmdServer) {
|
||||
m_uptimeCmd.registerYourself(cmdServer);
|
||||
}
|
||||
|
||||
|
||||
void Uptime::exec() {
|
||||
static unsigned long lastMillis = 0;
|
||||
|
||||
unsigned long currentMillis = millis();
|
||||
if (currentMillis >= (lastMillis + 1000)) {
|
||||
m_seconds += ((currentMillis - lastMillis) / 1000);
|
||||
if (m_seconds >= 60) {
|
||||
m_seconds -= 60;
|
||||
m_minutes++;
|
||||
if (m_minutes >= 60) {
|
||||
m_minutes -= 60;
|
||||
m_hours++;
|
||||
if (m_hours >= 24) {
|
||||
m_hours -= 24;
|
||||
m_days++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lastMillis = currentMillis;
|
||||
}
|
||||
}
|
39
uptime.h
Normal file
39
uptime.h
Normal file
@ -0,0 +1,39 @@
|
||||
#ifndef UPTIME_H_
|
||||
#define UPTIME_H_
|
||||
|
||||
#include "cmd.h"
|
||||
|
||||
|
||||
class Uptime;
|
||||
|
||||
|
||||
class UptimeCmd : public Cmd {
|
||||
public:
|
||||
UptimeCmd(Uptime *uptime);
|
||||
virtual String getCmdName() { return "UP"; }
|
||||
virtual String getHelp() { return "Uptime"; }
|
||||
virtual String exec(String params);
|
||||
private:
|
||||
Uptime *m_uptime;
|
||||
};
|
||||
|
||||
|
||||
class Uptime {
|
||||
public:
|
||||
Uptime();
|
||||
void begin(CmdServer *cmdServer);
|
||||
void exec();
|
||||
uint8_t getSeconds() { return m_seconds; };
|
||||
uint8_t getMinutes() { return m_minutes; };
|
||||
uint8_t getHours() { return m_hours; };
|
||||
uint8_t getDays() { return m_days; };
|
||||
private:
|
||||
UptimeCmd m_uptimeCmd;
|
||||
uint8_t m_seconds;
|
||||
uint8_t m_minutes;
|
||||
uint8_t m_hours;
|
||||
uint16_t m_days;
|
||||
};
|
||||
|
||||
|
||||
#endif /* TEST_H_ */
|
Loading…
x
Reference in New Issue
Block a user