Compare commits
3 Commits
MeterBusNo
...
deadEnd24
Author | SHA1 | Date | |
---|---|---|---|
08ab509dc8 | |||
317899fe43 | |||
d3d2c75541 |
55
Config.cpp
55
Config.cpp
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
#include "Resources.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -83,29 +84,47 @@ void Config::setULong(int pos, unsigned long value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned char Config::getUChar(int pos) {
|
||||||
|
u_uchar u;
|
||||||
|
for (unsigned int i = 0; i < sizeof(unsigned char); i++) {
|
||||||
|
u.e[i] = EEPROM.read(pos + i);
|
||||||
|
}
|
||||||
|
return u.c;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Config::setUChar(int pos, unsigned char value) {
|
||||||
|
u_uchar u;
|
||||||
|
u.c = value;
|
||||||
|
for (unsigned int i = 0; i < sizeof(unsigned char); i++) {
|
||||||
|
EEPROM.write(pos + i, u.e[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Config::initialize() {
|
||||||
|
if (! Config::isInitialized()) {
|
||||||
|
Serial.println(getResource(CONFIG_INIT_KEY));
|
||||||
|
Config::setFloat(Config::THERMOMETER_ALPHA, 1.0);
|
||||||
|
Config::setULong(Config::THERMOMETER_PERIOD, 1000);
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
Config::setFloat(Config::THERMOMETER_CAL[i], 1.0);
|
||||||
|
}
|
||||||
|
Config::setBool(Config::THERMOMETER_DEBUG, true);
|
||||||
|
Config::setBool(Config::THERMOMETER_INFO, true);
|
||||||
|
|
||||||
|
|
||||||
|
Config::setUChar(Config::METERBUSCLIENT_ADDRESS, 0);
|
||||||
|
|
||||||
|
Config::setMagic();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Config::isInitialized() {
|
bool Config::isInitialized() {
|
||||||
unsigned int magic = getUInt(MAGIC);
|
unsigned int magic = getUInt(MAGIC);
|
||||||
return magic == MAGIC_TOKEN;
|
return magic == MAGIC_TOKEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Config::initialize() {
|
|
||||||
if (! isInitialized()) {
|
|
||||||
//Serial.println(getResource(CONFIG_INIT_KEY));
|
|
||||||
setFloat(THERMOMETER_ALPHA, 1.0);
|
|
||||||
setULong(THERMOMETER_PERIOD, 1000);
|
|
||||||
for (int i = 0; i < 4; i++) {
|
|
||||||
setFloat(THERMOMETER_CAL[i], 1.0);
|
|
||||||
}
|
|
||||||
setBool(THERMOMETER_DEBUG, true);
|
|
||||||
setBool(THERMOMETER_INFO, true);
|
|
||||||
|
|
||||||
|
|
||||||
//Config::setUChar(Config::METERBUSCLIENT_ADDRESS, 0);
|
|
||||||
|
|
||||||
setMagic();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Config::setMagic() {
|
void Config::setMagic() {
|
||||||
setUInt(MAGIC, MAGIC_TOKEN);
|
setUInt(MAGIC, MAGIC_TOKEN);
|
||||||
}
|
}
|
||||||
|
9
Config.h
9
Config.h
@ -39,6 +39,11 @@ typedef union {
|
|||||||
uint8_t e[sizeof(bool)];
|
uint8_t e[sizeof(bool)];
|
||||||
} u_bool;
|
} u_bool;
|
||||||
|
|
||||||
|
typedef union {
|
||||||
|
unsigned char c;
|
||||||
|
uint8_t e[sizeof(unsigned char)];
|
||||||
|
} u_uchar;
|
||||||
|
|
||||||
|
|
||||||
namespace Config {
|
namespace Config {
|
||||||
const unsigned int MAGIC_TOKEN = 0xDEADBEEF;
|
const unsigned int MAGIC_TOKEN = 0xDEADBEEF;
|
||||||
@ -51,6 +56,7 @@ namespace Config {
|
|||||||
const int THERMOMETER_INFO = 29; // 1
|
const int THERMOMETER_INFO = 29; // 1
|
||||||
const int METERBUSCLIENT_ADDRESS = 30; // 1
|
const int METERBUSCLIENT_ADDRESS = 30; // 1
|
||||||
|
|
||||||
|
|
||||||
bool getBool(int pos);
|
bool getBool(int pos);
|
||||||
void setBool(int pos, bool value);
|
void setBool(int pos, bool value);
|
||||||
float getFloat(int pos);
|
float getFloat(int pos);
|
||||||
@ -59,10 +65,11 @@ namespace Config {
|
|||||||
void setUInt(int pos, unsigned int value);
|
void setUInt(int pos, unsigned int value);
|
||||||
unsigned long getULong(int pos);
|
unsigned long getULong(int pos);
|
||||||
void setULong(int pos, unsigned long value);
|
void setULong(int pos, unsigned long value);
|
||||||
|
unsigned char getUChar(int pos);
|
||||||
|
void setUChar(int pos, unsigned char value);
|
||||||
|
|
||||||
void initialize();
|
void initialize();
|
||||||
|
|
||||||
|
|
||||||
bool isInitialized();
|
bool isInitialized();
|
||||||
|
|
||||||
void setMagic();
|
void setMagic();
|
||||||
|
@ -12,62 +12,6 @@
|
|||||||
|
|
||||||
//String TEXT;
|
//String TEXT;
|
||||||
|
|
||||||
const String TEXT_RESOURCES[] = {
|
|
||||||
"Text1",
|
|
||||||
"PeriodMeasure (ms): ",
|
|
||||||
"Alpha: ",
|
|
||||||
"Calibration: ",
|
|
||||||
"Info: ",
|
|
||||||
"Debug: ",
|
|
||||||
"COMPILE_TIME_DEBUG: ",
|
|
||||||
"TimeOuts: ",
|
|
||||||
"Cycles: ",
|
|
||||||
"Period (ms): ",
|
|
||||||
"Alpha: ",
|
|
||||||
"index: ",
|
|
||||||
"cal: ",
|
|
||||||
"t: ",
|
|
||||||
"ts: ",
|
|
||||||
", ",
|
|
||||||
" enable : enable the calibration mode",
|
|
||||||
" disable : disable the calibration mode",
|
|
||||||
" show : show parameters for calibration process",
|
|
||||||
" r : set value of calibration resistor",
|
|
||||||
" start <0..3>: start calibration on channel",
|
|
||||||
" stop <0..3>: stop calibration on channel",
|
|
||||||
" enabled : ",
|
|
||||||
" r_cal : ",
|
|
||||||
"setTemperature: i=",
|
|
||||||
"t=",
|
|
||||||
"t_smoothed=",
|
|
||||||
"CONF: ",
|
|
||||||
"MODE: ",
|
|
||||||
"Initializing EEPROM",
|
|
||||||
"State 0",
|
|
||||||
"Switching to State 1",
|
|
||||||
"Switching to State 10",
|
|
||||||
"State 9",
|
|
||||||
"Timeout: ",
|
|
||||||
"State 10",
|
|
||||||
"No, no, we are in calibration high mode, so directly switch to state 20",
|
|
||||||
"Switching to state 11",
|
|
||||||
"r_avg on channel ",
|
|
||||||
"calibration factor: ",
|
|
||||||
"Calibration stopped",
|
|
||||||
"Save calibration factor for channel ",
|
|
||||||
": ",
|
|
||||||
"HELP List this help for all commands",
|
|
||||||
"command not found",
|
|
||||||
"Thermometer configuration operations",
|
|
||||||
"Show thermometer measurement values",
|
|
||||||
"Thermometer calibration operations",
|
|
||||||
"No, no, we are in calibration zero mode, so directly switch to state 20",
|
|
||||||
"MeterBus Client Configuration",
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const String& getResource(uint8_t key) {
|
const String& getResource(uint8_t key) {
|
||||||
//TEXT = String("T") + key + String(": ");
|
//TEXT = String("T") + key + String(": ");
|
||||||
|
56
Resources.h
56
Resources.h
@ -41,7 +41,7 @@ const uint8_t SET_TEMPERATURE_DEBUG_2_KEY = 25;
|
|||||||
const uint8_t SET_TEMPERATURE_DEBUG_3_KEY = 26;
|
const uint8_t SET_TEMPERATURE_DEBUG_3_KEY = 26;
|
||||||
const uint8_t CONF_COLON_KEY = 27;
|
const uint8_t CONF_COLON_KEY = 27;
|
||||||
const uint8_t MODE_COLON_KEY = 28;
|
const uint8_t MODE_COLON_KEY = 28;
|
||||||
const uint8_t THERMOMETER_BEGIN_1_KEY = 29;
|
const uint8_t CONFIG_INIT_KEY = 29;
|
||||||
const uint8_t STATE_0_KEY = 30;
|
const uint8_t STATE_0_KEY = 30;
|
||||||
const uint8_t TO_STATE_1_KEY = 31;
|
const uint8_t TO_STATE_1_KEY = 31;
|
||||||
const uint8_t TO_STATE_10_KEY = 32;
|
const uint8_t TO_STATE_10_KEY = 32;
|
||||||
@ -64,6 +64,60 @@ const uint8_t CALIBRATION_ZEOR_MODE_HINT_KEY = 48;
|
|||||||
const uint8_t MBC_CONFIG_HELP_KEY = 49;
|
const uint8_t MBC_CONFIG_HELP_KEY = 49;
|
||||||
|
|
||||||
|
|
||||||
|
const String TEXT_RESOURCES[] = {
|
||||||
|
"Text1",
|
||||||
|
"PeriodMeasure (ms): ",
|
||||||
|
"Alpha: ",
|
||||||
|
"Calibration: ",
|
||||||
|
"Info: ",
|
||||||
|
"Debug: ",
|
||||||
|
"COMPILE_TIME_DEBUG: ",
|
||||||
|
"TimeOuts: ",
|
||||||
|
"Cycles: ",
|
||||||
|
"Period (ms): ",
|
||||||
|
"Alpha: ",
|
||||||
|
"index: ",
|
||||||
|
"cal: ",
|
||||||
|
"t: ",
|
||||||
|
"ts: ",
|
||||||
|
", ",
|
||||||
|
" enable : enable the calibration mode",
|
||||||
|
" disable : disable the calibration mode",
|
||||||
|
" show : show parameters for calibration process",
|
||||||
|
" r : set value of calibration resistor",
|
||||||
|
" start <0..3>: start calibration on channel",
|
||||||
|
" stop <0..3>: stop calibration on channel",
|
||||||
|
" enabled : ",
|
||||||
|
" r_cal : ",
|
||||||
|
"setTemperature: i=",
|
||||||
|
"t=",
|
||||||
|
"t_smoothed=",
|
||||||
|
"CONF: ",
|
||||||
|
"MODE: ",
|
||||||
|
"Initializing EEPROM",
|
||||||
|
"State 0",
|
||||||
|
"Switching to State 1",
|
||||||
|
"Switching to State 10",
|
||||||
|
"State 9",
|
||||||
|
"Timeout: ",
|
||||||
|
"State 10",
|
||||||
|
"No, no, we are in calibration high mode, so directly switch to state 20",
|
||||||
|
"Switching to state 11",
|
||||||
|
"r_avg on channel ",
|
||||||
|
"calibration factor: ",
|
||||||
|
"Calibration stopped",
|
||||||
|
"Save calibration factor for channel ",
|
||||||
|
": ",
|
||||||
|
"HELP List this help for all commands",
|
||||||
|
"command not found",
|
||||||
|
"Thermometer configuration operations",
|
||||||
|
"Show thermometer measurement values",
|
||||||
|
"Thermometer calibration operations",
|
||||||
|
"No, no, we are in calibration zero mode, so directly switch to state 20",
|
||||||
|
"MeterBus Client Configuration",
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const String& getResource(uint8_t key);
|
const String& getResource(uint8_t key);
|
||||||
|
@ -7,37 +7,39 @@
|
|||||||
#include "spi.h"
|
#include "spi.h"
|
||||||
|
|
||||||
|
|
||||||
// #define ENABLE_CONFIGURATION_INVALID_CMD 1
|
#define ENABLE_CONFIGURATION_INVALID_CMD 1
|
||||||
|
|
||||||
|
|
||||||
static CmdServer cmdServer(&Serial);
|
//static CmdServer cmdServer(&Serial);
|
||||||
#ifdef ENABLE_CONFIGURATION_INVALID_CMD
|
#ifdef ENABLE_CONFIGURATION_INVALID_CMD
|
||||||
static ConfigInvalidateCmd configInvalidateCmd;
|
// static ConfigInvalidateCmd configInvalidateCmd;
|
||||||
#endif
|
#endif
|
||||||
static Uptime uptime;
|
//static Uptime uptime;
|
||||||
static Thermometer thermometer;
|
//static Thermometer thermometer;
|
||||||
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
|
||||||
|
|
||||||
Config::initialize();
|
//Config::initialize();
|
||||||
|
|
||||||
|
//spiInit();
|
||||||
|
|
||||||
spiInit();
|
//cmdServer.begin();
|
||||||
|
|
||||||
cmdServer.begin();
|
|
||||||
#ifdef ENABLE_CONFIGURATION_INVALID_CMD
|
#ifdef ENABLE_CONFIGURATION_INVALID_CMD
|
||||||
configInvalidateCmd.registerYourself(&cmdServer);
|
//configInvalidateCmd.registerYourself(&cmdServer);
|
||||||
#endif
|
#endif
|
||||||
uptime.begin(&cmdServer);
|
//uptime.begin(&cmdServer);
|
||||||
thermometer.begin(&cmdServer);
|
//thermometer.begin(&cmdServer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
cmdServer.exec();
|
//cmdServer.exec();
|
||||||
uptime.exec();
|
//uptime.exec();
|
||||||
thermometer.exec();
|
//thermometer.exec();
|
||||||
|
|
||||||
|
Serial.println("Tick");
|
||||||
|
delay(1000);
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
* MeterBusClient.cpp
|
* meterBusClient.cpp
|
||||||
*
|
*
|
||||||
* Created on: 08.03.2014
|
* Created on: 08.03.2014
|
||||||
* Author: wn
|
* Author: wn
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "MeterBusClient.h"
|
#include "meterBusClient.h"
|
||||||
|
|
||||||
|
|
||||||
MeterBusClient::MeterBusClient() : m_address(0) {
|
MeterBusClient::MeterBusClient() : m_address(0) {
|
||||||
@ -18,11 +18,11 @@ void MeterBusClient::begin(CmdServer *cmdServer) {
|
|||||||
Serial3.begin(1200);
|
Serial3.begin(1200);
|
||||||
|
|
||||||
|
|
||||||
//setAddress(Config::getUChar(Config::METERBUSCLIENT_ADDRESS));
|
setAddress(Config::getUChar(Config::METERBUSCLIENT_ADDRESS));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MeterBusClient::setAddress(unsigned char a) {
|
void MeterBusClient::setAddress(unsigned char a) {
|
||||||
//Config::setUChar(Config::METERBUSCLIENT_ADDRESS, a);
|
Config::setUChar(Config::METERBUSCLIENT_ADDRESS, a);
|
||||||
m_address = a;
|
m_address = a;
|
||||||
}
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* MeterBusClient.h
|
* meterBusClient.h
|
||||||
*
|
*
|
||||||
* Created on: 08.03.2014
|
* Created on: 08.03.2014
|
||||||
* Author: wn
|
* Author: wn
|
||||||
@ -8,11 +8,11 @@
|
|||||||
#ifndef METERBUSCLIENT_H_
|
#ifndef METERBUSCLIENT_H_
|
||||||
#define METERBUSCLIENT_H_
|
#define METERBUSCLIENT_H_
|
||||||
|
|
||||||
|
|
||||||
#include "cmd.h"
|
#include "cmd.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "Resources.h"
|
#include "Resources.h"
|
||||||
|
|
||||||
|
|
||||||
class MeterBusClient;
|
class MeterBusClient;
|
||||||
|
|
||||||
|
|
||||||
@ -43,5 +43,4 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* METERBUSCLIENT_H_ */
|
#endif /* METERBUSCLIENT_H_ */
|
@ -252,19 +252,7 @@ void Thermometer::begin(CmdServer *cmdServer) {
|
|||||||
AD7190_Calibrate(AD7190_MODE_CAL_INT_ZERO, AD7190_CH_AIN1P_AINCOM);
|
AD7190_Calibrate(AD7190_MODE_CAL_INT_ZERO, AD7190_CH_AIN1P_AINCOM);
|
||||||
AD7190_Calibrate(AD7190_MODE_CAL_INT_FULL, AD7190_CH_AIN1P_AINCOM);
|
AD7190_Calibrate(AD7190_MODE_CAL_INT_FULL, AD7190_CH_AIN1P_AINCOM);
|
||||||
|
|
||||||
/*
|
|
||||||
if (! Config::isInitialized()) {
|
|
||||||
Serial.println(getResource(THERMOMETER_BEGIN_1_KEY));
|
|
||||||
Config::setFloat(Config::THERMOMETER_ALPHA, 1.0);
|
|
||||||
Config::setULong(Config::THERMOMETER_PERIOD, 1000);
|
|
||||||
for (int i = 0; i < 4; i++) {
|
|
||||||
Config::setFloat(Config::THERMOMETER_CAL[i], 1.0);
|
|
||||||
}
|
|
||||||
Config::setBool(Config::THERMOMETER_DEBUG, true);
|
|
||||||
Config::setBool(Config::THERMOMETER_INFO, true);
|
|
||||||
Config::setMagic();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
setAlpha(Config::getFloat(Config::THERMOMETER_ALPHA));
|
setAlpha(Config::getFloat(Config::THERMOMETER_ALPHA));
|
||||||
setPeriodMeasure(Config::getULong(Config::THERMOMETER_PERIOD));
|
setPeriodMeasure(Config::getULong(Config::THERMOMETER_PERIOD));
|
||||||
@ -274,12 +262,7 @@ void Thermometer::begin(CmdServer *cmdServer) {
|
|||||||
setDebug(Config::getBool(Config::THERMOMETER_DEBUG));
|
setDebug(Config::getBool(Config::THERMOMETER_DEBUG));
|
||||||
setInfo(Config::getBool(Config::THERMOMETER_INFO));
|
setInfo(Config::getBool(Config::THERMOMETER_INFO));
|
||||||
|
|
||||||
//setCalibrateFactor(0, 1.002999);
|
|
||||||
//setCalibrateFactor(1, 1.001804);
|
|
||||||
//setCalibrateFactor(2, 1.000794);
|
|
||||||
//setCalibrateFactor(3, 1.001071);
|
|
||||||
|
|
||||||
// prepare
|
|
||||||
prepareAdc();
|
prepareAdc();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -391,6 +374,7 @@ void Thermometer::exec() {
|
|||||||
if (currentMillis >= (lastMillis + getPeriodMeasure())) {
|
if (currentMillis >= (lastMillis + getPeriodMeasure())) {
|
||||||
lastMillis = currentMillis;
|
lastMillis = currentMillis;
|
||||||
state = 0;
|
state = 0;
|
||||||
|
Serial3.println("Tick");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user