Fixed serial command for voltmeter constant, added EEPROM support for it #bugfix
This commit is contained in:
parent
6976b3908d
commit
8d5fb81219
4 changed files with 36 additions and 21 deletions
|
|
@ -8,6 +8,8 @@ int LOOP_DUR = LOOP_DUR_DEFAULT; // duration of time between ADC checks and othe
|
||||||
int TRG_DUR = TRG_DUR_DEFAULT; // duration of the Z-axis pulse sent, in ms
|
int TRG_DUR = TRG_DUR_DEFAULT; // duration of the Z-axis pulse sent, in ms
|
||||||
int Hyst = HYST_DEFAULT; // Hysteresis value for ADC measurements
|
int Hyst = HYST_DEFAULT; // Hysteresis value for ADC measurements
|
||||||
int Debug = 0;
|
int Debug = 0;
|
||||||
|
long voltMeterConstant = VM_CONST_DEFAULT;
|
||||||
|
uint8_t pP_i2c_address = 0xa0;
|
||||||
|
|
||||||
void resetEEPROM() {
|
void resetEEPROM() {
|
||||||
resetConfig();
|
resetConfig();
|
||||||
|
|
@ -65,6 +67,17 @@ void restoreConfig() {
|
||||||
} else {
|
} else {
|
||||||
Hyst = temp;
|
Hyst = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long longTemp;
|
||||||
|
EEPROM.get(VM_CONST_DEFAULT, longTemp);
|
||||||
|
if (longTemp < 1000000L || longTemp > 1200000L)
|
||||||
|
{
|
||||||
|
resetEEPROM();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
voltMeterConstant = longTemp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void resetConfig() {
|
void resetConfig() {
|
||||||
|
|
@ -74,4 +87,5 @@ void resetConfig() {
|
||||||
LOOP_DUR = LOOP_DUR_DEFAULT;
|
LOOP_DUR = LOOP_DUR_DEFAULT;
|
||||||
TRG_DUR = TRG_DUR_DEFAULT;
|
TRG_DUR = TRG_DUR_DEFAULT;
|
||||||
Hyst = HYST_DEFAULT;
|
Hyst = HYST_DEFAULT;
|
||||||
|
voltMeterConstant = VM_CONST_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
@ -48,14 +48,15 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define VM_CONST_ADDRESS 28
|
#define VM_CONST_ADDRESS 28
|
||||||
|
#define VM_CONST_DEFAULT 1125300L
|
||||||
#if !(defined(voltMeterConstant))
|
#if !(defined(voltMeterConstant))
|
||||||
extern long voltMeterConstant = 1125300L; // For fine tuning input voltage sense
|
extern long voltMeterConstant; // For fine tuning input voltage sense
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef I2C_INPUT
|
#ifdef I2C_INPUT
|
||||||
#define I2C_SLAVE_ADDRESS 24
|
#define I2C_SLAVE_ADDRESS 24
|
||||||
#if !(defined(pP_i2c_address))
|
#if !(defined(pP_i2c_address))
|
||||||
extern byte pP_i2c_address = 0xa0; // I2C Bus Address
|
extern uint8_t pP_i2c_address; // I2C Bus Address
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ void parseData() {
|
||||||
strcpy(serialMessageIn, strtokIndx); // copy it to serialMessageIn
|
strcpy(serialMessageIn, strtokIndx); // copy it to serialMessageIn
|
||||||
|
|
||||||
strtokIndx = strtok(NULL, " "); // this continues where the previous call left off
|
strtokIndx = strtok(NULL, " "); // this continues where the previous call left off
|
||||||
serialInt = atoi(strtokIndx); // convert this part to an integer
|
serialLong = atol(strtokIndx); // convert this part to an integer
|
||||||
|
|
||||||
}
|
}
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
@ -60,9 +60,9 @@ void identifyMarkers() {
|
||||||
|
|
||||||
void updateGainFactor()
|
void updateGainFactor()
|
||||||
{
|
{
|
||||||
if (serialInt >= 0)
|
if (serialLong >= 0)
|
||||||
{
|
{
|
||||||
GAIN_FACTOR = serialInt;
|
GAIN_FACTOR = serialLong;
|
||||||
adjustGain();
|
adjustGain();
|
||||||
EEPROM.put(GAIN_FACTOR_ADDRESS, GAIN_FACTOR);
|
EEPROM.put(GAIN_FACTOR_ADDRESS, GAIN_FACTOR);
|
||||||
}
|
}
|
||||||
|
|
@ -71,9 +71,9 @@ void updateGainFactor()
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
void updateVFol() {
|
void updateVFol() {
|
||||||
if (serialInt >= 0)
|
if (serialLong >= 0)
|
||||||
{
|
{
|
||||||
followerThrs = serialInt;
|
followerThrs = serialLong;
|
||||||
adjustFollow();
|
adjustFollow();
|
||||||
EEPROM.put(FOLLOWER_THRESHOLD_ADDRESS, followerThrs);
|
EEPROM.put(FOLLOWER_THRESHOLD_ADDRESS, followerThrs);
|
||||||
}
|
}
|
||||||
|
|
@ -81,9 +81,9 @@ void updateVFol() {
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
void updateVComp() {
|
void updateVComp() {
|
||||||
if (serialInt >= 0)
|
if (serialLong >= 0)
|
||||||
{
|
{
|
||||||
compThrs = serialInt;
|
compThrs = serialLong;
|
||||||
adjustComp();
|
adjustComp();
|
||||||
EEPROM.put(COMP_THRESHOLD_ADDRESS, compThrs);
|
EEPROM.put(COMP_THRESHOLD_ADDRESS, compThrs);
|
||||||
}
|
}
|
||||||
|
|
@ -93,36 +93,36 @@ void updateVComp() {
|
||||||
|
|
||||||
void updateLoopDuration()
|
void updateLoopDuration()
|
||||||
{
|
{
|
||||||
if (serialInt >= 0)
|
if (serialLong >= 0)
|
||||||
{
|
{
|
||||||
LOOP_DUR = serialInt;
|
LOOP_DUR = serialLong;
|
||||||
EEPROM.put(LOOP_DUR_ADDRESS, LOOP_DUR);
|
EEPROM.put(LOOP_DUR_ADDRESS, LOOP_DUR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
void updateTrigDuration() {
|
void updateTrigDuration() {
|
||||||
if (serialInt >= 0)
|
if (serialLong >= 0)
|
||||||
{
|
{
|
||||||
TRG_DUR = serialInt;
|
TRG_DUR = serialLong;
|
||||||
EEPROM.put(TRG_DUR_ADDRESS, TRG_DUR);
|
EEPROM.put(TRG_DUR_ADDRESS, TRG_DUR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
void updateHysteresis() {
|
void updateHysteresis() {
|
||||||
if (serialInt >= 0)
|
if (serialLong >= 0)
|
||||||
{
|
{
|
||||||
Hyst = serialInt;
|
Hyst = serialLong;
|
||||||
EEPROM.put(HYST_ADDRESS, Hyst);
|
EEPROM.put(HYST_ADDRESS, Hyst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
void updateConstant() {
|
void updateConstant() {
|
||||||
if (serialInt >= 0)
|
if (serialLong >= 0)
|
||||||
{
|
{
|
||||||
voltMeterConstant = (long) serialInt;
|
voltMeterConstant = (long) serialLong;
|
||||||
EEPROM.put(VM_CONST_ADDRESS, voltMeterConstant);
|
EEPROM.put(VM_CONST_ADDRESS, voltMeterConstant);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -130,9 +130,9 @@ void updateConstant() {
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
void updateDebug() {
|
void updateDebug() {
|
||||||
if (serialInt > 0) {
|
if (serialLong > 0) {
|
||||||
Debug = 1;
|
Debug = 1;
|
||||||
} else if (serialInt == 0) {
|
} else if (serialLong == 0) {
|
||||||
Debug = 0;
|
Debug = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -218,7 +218,7 @@ void updateParams() {
|
||||||
updateVComp();
|
updateVComp();
|
||||||
}
|
}
|
||||||
else if (strcmp(serialMessageIn, "LOOP_D") == 0) {
|
else if (strcmp(serialMessageIn, "LOOP_D") == 0) {
|
||||||
updateTrigDuration();
|
updateLoopDuration();
|
||||||
}
|
}
|
||||||
else if (strcmp(serialMessageIn, "TRG_D") == 0) {
|
else if (strcmp(serialMessageIn, "TRG_D") == 0) {
|
||||||
updateTrigDuration();
|
updateTrigDuration();
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ char inputBuffer[buffSize];
|
||||||
byte bytesRecvd = 0;
|
byte bytesRecvd = 0;
|
||||||
bool serialIncoming = false;
|
bool serialIncoming = false;
|
||||||
char serialMessageIn[buffSize] = {0};
|
char serialMessageIn[buffSize] = {0};
|
||||||
int serialInt = 0;
|
long serialLong = 0;
|
||||||
|
|
||||||
//#define LOW 0
|
//#define LOW 0
|
||||||
//#define HIGH 1
|
//#define HIGH 1
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue