Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Saving settings to EEPROM and other IMO sensible changes
- Loading branch information
Showing
9 changed files
with
430 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_config.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#include "pP_config.h" | ||
#include <EEPROM.h> | ||
|
||
int GAIN_FACTOR = GAIN_FACTOR_DEFAULT; // Gain adjustment factor. 0=3x, 1=3.5x, 2=4.33x, 3=6x, 4=11x | ||
int followerThrs = FOLLOWER_THRESHOLD_DEFAULT; | ||
int compThrs = COMP_THRESHOLD_DEFAULT; | ||
int LOOP_DUR = LOOP_DUR_DEFAULT; // duration of time between ADC checks and other loop functions | ||
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 Debug = 0; | ||
long voltMeterConstant = 1125300L; // For fine tuning input voltage sense | ||
// byte pP_i2c_address = 0xa0; // I2C Bus Address | ||
|
||
void resetEEPROM() | ||
{ | ||
resetConfig(); | ||
EEPROM.put(GAIN_FACTOR_ADDRESS, GAIN_FACTOR); | ||
EEPROM.put(FOLLOWER_THRESHOLD_ADDRESS, followerThrs); | ||
EEPROM.put(COMP_THRESHOLD_ADDRESS, compThrs); | ||
EEPROM.put(LOOP_DUR_ADDRESS, LOOP_DUR); | ||
EEPROM.put(TRG_DUR_ADDRESS, TRG_DUR); | ||
EEPROM.put(HYST_ADDRESS, Hyst); | ||
} | ||
|
||
// Restore config from EEPROM, otherwise reset config and write to EEPROM | ||
void restoreConfig() | ||
{ | ||
int temp; | ||
|
||
EEPROM.get(GAIN_FACTOR_ADDRESS, temp); | ||
if (temp < 0 || temp > 4) | ||
{ | ||
resetEEPROM(); | ||
} | ||
else | ||
{ | ||
GAIN_FACTOR = temp; | ||
} | ||
|
||
EEPROM.get(FOLLOWER_THRESHOLD_ADDRESS, temp); | ||
if (temp < 0 || temp > 5000) | ||
{ | ||
resetEEPROM(); | ||
} | ||
else | ||
{ | ||
followerThrs = temp; | ||
} | ||
|
||
EEPROM.get(COMP_THRESHOLD_ADDRESS, temp); | ||
if (temp < 0 || temp > 5000) | ||
{ | ||
resetEEPROM(); | ||
} | ||
else | ||
{ | ||
compThrs = temp; | ||
} | ||
|
||
EEPROM.get(LOOP_DUR_ADDRESS, temp); | ||
if (temp < 0 && temp > 1000) | ||
{ | ||
resetEEPROM(); | ||
} | ||
else | ||
{ | ||
LOOP_DUR = temp; | ||
} | ||
|
||
EEPROM.get(TRG_DUR_ADDRESS, temp); | ||
if (temp < 0 || temp > 1000) | ||
{ | ||
resetEEPROM(); | ||
} | ||
else | ||
{ | ||
TRG_DUR = temp; | ||
} | ||
|
||
EEPROM.get(HYST_ADDRESS, temp); | ||
if (temp < 0 || temp > 1000) | ||
{ | ||
resetEEPROM(); | ||
} | ||
else | ||
{ | ||
Hyst = temp; | ||
} | ||
} | ||
|
||
void resetConfig() | ||
{ | ||
GAIN_FACTOR = GAIN_FACTOR_DEFAULT; | ||
followerThrs = FOLLOWER_THRESHOLD_DEFAULT; | ||
compThrs = COMP_THRESHOLD_DEFAULT; | ||
LOOP_DUR = LOOP_DUR_DEFAULT; | ||
TRG_DUR = TRG_DUR_DEFAULT; | ||
Hyst = HYST_DEFAULT; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,63 @@ | ||
#ifndef PP_CONFIG_H | ||
#define PP_CONFIG_H | ||
|
||
// Configurable settings: | ||
|
||
#define GAIN_FACTOR_DEFAULT 2 | ||
#define GAIN_FACTOR_ADDRESS 0 | ||
#if !(defined(GAIN_FACTOR)) | ||
int GAIN_FACTOR = 2; // Gain adjustment factor. 0=3x, 1=3.5x, 2=4.33x, 3=6x, 4=11x | ||
extern int GAIN_FACTOR; // Gain adjustment factor. 0=3x, 1=3.5x, 2=4.33x, 3=6x, 4=11x | ||
#endif | ||
|
||
#ifndef senseThrs | ||
#define senseThrs 1450 | ||
#define FOLLOWER_THRESHOLD_DEFAULT 1450 | ||
#define FOLLOWER_THRESHOLD_ADDRESS 4 | ||
#if !(defined(followerThrs)) | ||
extern int followerThrs; | ||
#endif | ||
|
||
#ifndef compThrs | ||
#define compThrs 2850 | ||
#define COMP_THRESHOLD_DEFAULT 2850 | ||
#define COMP_THRESHOLD_ADDRESS 8 | ||
#if !(defined(compThrs)) | ||
extern int compThrs; | ||
#endif | ||
|
||
#ifndef InitCount | ||
#define InitCount 6 // Number of times to blink the LED on start | ||
#define InitCount 6 // Number of times to blink the LED on start | ||
#endif | ||
|
||
#define LOOP_DUR_DEFAULT 50 | ||
#define LOOP_DUR_ADDRESS 12 | ||
#if !(defined(LOOP_DUR)) | ||
int LOOP_DUR = 50; // duration of time between ADC checks and other loop functions | ||
extern int LOOP_DUR; // duration of time between ADC checks and other loop functions | ||
#endif | ||
|
||
#define TRG_DUR_DEFAULT 20 | ||
#define TRG_DUR_ADDRESS 16 | ||
#if !(defined(TRG_DUR)) | ||
int TRG_DUR = 20; // duration of the Z-axis pulse sent, in ms | ||
extern int TRG_DUR; // duration of the Z-axis pulse sent, in ms | ||
#endif | ||
|
||
#define HYST_DEFAULT 20 | ||
#define HYST_ADDRESS 20 | ||
#if !(defined(Hyst)) | ||
int Hyst = 20; // Hysteresis value for ADC measurements | ||
extern int Hyst; // Hysteresis value for ADC measurements | ||
#endif | ||
|
||
#if !(defined(voldMeterConstant)) | ||
long voltMeterConstant = 1125300L; // For fine tuning input voltage sense | ||
#if !(defined(Debug)) | ||
extern int Debug; | ||
#endif | ||
|
||
#ifdef I2C_INPUT | ||
#if !(defined(pP_i2c_address)) | ||
byte pP_i2c_address = 0xa0; // I2C Bus Address | ||
#endif | ||
#if !(defined(voldMeterConstant)) | ||
extern long voltMeterConstant; // For fine tuning input voltage sense | ||
#endif | ||
|
||
|
||
// #ifdef I2C_INPUT | ||
// #if !(defined(pP_i2c_address)) | ||
// extern byte pP_i2c_address = 0xa0; // I2C Bus Address | ||
// #endif | ||
// #endif | ||
|
||
void restoreConfig(); | ||
void resetConfig(); | ||
|
||
#endif |
Oops, something went wrong.