Formatting
This commit is contained in:
parent
60a26ad3f7
commit
f2c3843668
16 changed files with 343 additions and 433 deletions
|
|
@ -0,0 +1,3 @@
|
||||||
|
BasedOnStyle: LLVM
|
||||||
|
ColumnLimit: 200
|
||||||
|
AllowShortFunctionsOnASingleLine: false
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||||
// for the documentation about the extensions.json format
|
// for the documentation about the extensions.json format
|
||||||
"recommendations": [
|
"recommendations": [
|
||||||
"platformio.platformio-ide"
|
"platformio.platformio-ide"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
@ -32,24 +32,23 @@
|
||||||
#endif
|
#endif
|
||||||
#include "LightChrono.h"
|
#include "LightChrono.h"
|
||||||
|
|
||||||
LightChrono::LightChrono()
|
LightChrono::LightChrono() {
|
||||||
{
|
|
||||||
restart();
|
restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LightChrono::start() { restart(); }
|
void LightChrono::start() {
|
||||||
|
restart();
|
||||||
|
}
|
||||||
|
|
||||||
void LightChrono::restart()
|
void LightChrono::restart() {
|
||||||
{
|
|
||||||
_startTime = millis();
|
_startTime = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
LightChrono::chrono_t LightChrono::elapsed() const {
|
LightChrono::chrono_t LightChrono::elapsed() const {
|
||||||
return (millis() - _startTime);
|
return (millis() - _startTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LightChrono::hasPassed(LightChrono::chrono_t timeout) const
|
bool LightChrono::hasPassed(LightChrono::chrono_t timeout) const {
|
||||||
{
|
|
||||||
return (elapsed() >= timeout);
|
return (elapsed() >= timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -58,10 +57,7 @@ bool LightChrono::hasPassed(LightChrono::chrono_t timeout, bool restartIfPassed)
|
||||||
if (restartIfPassed)
|
if (restartIfPassed)
|
||||||
restart();
|
restart();
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,8 +39,7 @@
|
||||||
* // do something
|
* // do something
|
||||||
* // ...
|
* // ...
|
||||||
*/
|
*/
|
||||||
class LightChrono
|
class LightChrono {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
#if defined(ARDUINO_ARC32_TOOLS)
|
#if defined(ARDUINO_ARC32_TOOLS)
|
||||||
typedef uint64_t chrono_t;
|
typedef uint64_t chrono_t;
|
||||||
|
|
@ -68,5 +67,3 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -85,39 +85,39 @@ update the voltMeterConstant variable in pP_config.h with the correct value
|
||||||
------------------------------------------------------------*/
|
------------------------------------------------------------*/
|
||||||
|
|
||||||
// Headers, variables, and functions
|
// Headers, variables, and functions
|
||||||
#include <Arduino.h>
|
|
||||||
#include <EEPROM.h>
|
|
||||||
#include "LightChrono.h"
|
#include "LightChrono.h"
|
||||||
#include "pP_pins.h"
|
#include "pP_pins.h"
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <EEPROM.h>
|
||||||
// #include "pP_config.h"
|
// #include "pP_config.h"
|
||||||
#include "pP_volatile.h"
|
|
||||||
#include "pP_function.h"
|
#include "pP_function.h"
|
||||||
#include "pP_serial.h"
|
#include "pP_serial.h"
|
||||||
|
#include "pP_volatile.h"
|
||||||
|
|
||||||
// i2c input toggle. Uncomment to enable
|
// i2c input toggle. Uncomment to enable
|
||||||
#define I2C_INPUT
|
#define I2C_INPUT
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
//Setup PWM on voltage follower (PD3)
|
// Setup PWM on voltage follower (PD3)
|
||||||
TCCR2A = (1 << COM2B1) | (0 << COM2B0) | (0 << WGM21) | (1 << WGM20);
|
TCCR2A = (1 << COM2B1) | (0 << COM2B0) | (0 << WGM21) | (1 << WGM20);
|
||||||
TCCR2B = (0 << WGM22) | (0 << CS22) | (0 << CS21) | (1 << CS20);
|
TCCR2B = (0 << WGM22) | (0 << CS22) | (0 << CS21) | (1 << CS20);
|
||||||
DDRD |= (1 << DDD3);
|
DDRD |= (1 << DDD3);
|
||||||
|
|
||||||
//Setup PWM on comparator (PB1)
|
// Setup PWM on comparator (PB1)
|
||||||
TCCR1A = (1 << COM1A1) | (0 << COM1A0) | (1 << WGM11) | (1 << WGM10);
|
TCCR1A = (1 << COM1A1) | (0 << COM1A0) | (1 << WGM11) | (1 << WGM10);
|
||||||
TCCR1B = (0 << WGM13) | (0 << WGM12) | (0 << CS12) | (0 << CS11) | (1 << CS10);
|
TCCR1B = (0 << WGM13) | (0 << WGM12) | (0 << CS12) | (0 << CS11) | (1 << CS10);
|
||||||
DDRB |= (1 << DDB1);
|
DDRB |= (1 << DDB1);
|
||||||
|
|
||||||
pinMode(TRG_OUT, OUTPUT); // declare the Trigger as as OUTPUT
|
pinMode(TRG_OUT, OUTPUT); // declare the Trigger as as OUTPUT
|
||||||
pinMode(ERR_LED, OUTPUT);
|
pinMode(ERR_LED, OUTPUT);
|
||||||
pinMode(PZDET_PIN, INPUT_PULLUP);
|
pinMode(PZDET_PIN, INPUT_PULLUP);
|
||||||
pinMode(Z_TRG, INPUT_PULLUP); // declare z-sense input with pullup
|
pinMode(Z_TRG, INPUT_PULLUP); // declare z-sense input with pullup
|
||||||
pinMode(V_FOLLOW_PIN, INPUT);
|
pinMode(V_FOLLOW_PIN, INPUT);
|
||||||
pinMode(VCOMP_SENSE_PIN, INPUT);
|
pinMode(VCOMP_SENSE_PIN, INPUT);
|
||||||
pinMode(GADJ_R0, INPUT); // declare input to set high impedance
|
pinMode(GADJ_R0, INPUT); // declare input to set high impedance
|
||||||
pinMode(GADJ_R1, INPUT); // declare input to set high impedance
|
pinMode(GADJ_R1, INPUT); // declare input to set high impedance
|
||||||
pinMode(GADJ_R2, INPUT); // declare input to set high impedance
|
pinMode(GADJ_R2, INPUT); // declare input to set high impedance
|
||||||
pinMode(GADJ_R3, INPUT); // declare input to set high impedance
|
pinMode(GADJ_R3, INPUT); // declare input to set high impedance
|
||||||
|
|
||||||
attachInterrupt(digitalPinToInterrupt(Z_TRG), pulse, FALLING);
|
attachInterrupt(digitalPinToInterrupt(Z_TRG), pulse, FALLING);
|
||||||
|
|
||||||
|
|
@ -140,7 +140,7 @@ void loop() {
|
||||||
if (BlinkCount > 0) {
|
if (BlinkCount > 0) {
|
||||||
BlinkState = !BlinkState;
|
BlinkState = !BlinkState;
|
||||||
digitalWriteFast(ERR_LED, BlinkState);
|
digitalWriteFast(ERR_LED, BlinkState);
|
||||||
//digitalWriteFast(TRG_OUT, BlinkState);
|
// digitalWriteFast(TRG_OUT, BlinkState);
|
||||||
--BlinkCount;
|
--BlinkCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -162,11 +162,11 @@ void loop() {
|
||||||
|
|
||||||
VLast = VOld - Vin;
|
VLast = VOld - Vin;
|
||||||
if (VLast > Hyst || VLast < -Hyst) {
|
if (VLast > Hyst || VLast < -Hyst) {
|
||||||
// Voltage Follower adjustment
|
// Voltage Follower adjustment
|
||||||
adjustFollow();
|
adjustFollow();
|
||||||
// Voltage Comparator adjustment
|
// Voltage Comparator adjustment
|
||||||
adjustComp();
|
adjustComp();
|
||||||
// Alert the user that auto-calibration is ongoing
|
// Alert the user that auto-calibration is ongoing
|
||||||
ERR_STATE = 1;
|
ERR_STATE = 1;
|
||||||
} else {
|
} else {
|
||||||
ERR_STATE = 0;
|
ERR_STATE = 0;
|
||||||
|
|
@ -179,11 +179,11 @@ void loop() {
|
||||||
if (BlinkCount > 0) {
|
if (BlinkCount > 0) {
|
||||||
BlinkState = !BlinkState;
|
BlinkState = !BlinkState;
|
||||||
digitalWriteFast(ERR_LED, BlinkState);
|
digitalWriteFast(ERR_LED, BlinkState);
|
||||||
// digitalWriteFast(TRG_OUT, BlinkState);
|
// digitalWriteFast(TRG_OUT, BlinkState);
|
||||||
--BlinkCount;
|
--BlinkCount;
|
||||||
// } else {
|
// } else {
|
||||||
// Check for error state
|
// Check for error state
|
||||||
// checkError();
|
// checkError();
|
||||||
} else {
|
} else {
|
||||||
digitalWriteFast(ERR_LED, 0);
|
digitalWriteFast(ERR_LED, 0);
|
||||||
}
|
}
|
||||||
|
|
@ -193,7 +193,7 @@ void loop() {
|
||||||
serialPrintState();
|
serialPrintState();
|
||||||
}
|
}
|
||||||
// Sets trigger output state to false after completing loop
|
// Sets trigger output state to false after completing loop
|
||||||
//digitalWriteFast(TRG_OUT, HIGH);
|
// digitalWriteFast(TRG_OUT, HIGH);
|
||||||
sensorHReading = 0;
|
sensorHReading = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,119 +1,97 @@
|
||||||
#ifndef PP_CMD_H
|
#ifndef PP_CMD_H
|
||||||
#define PP_CMD_H
|
#define PP_CMD_H
|
||||||
|
|
||||||
|
#include "EEPROM.h"
|
||||||
#include "pP_config.h"
|
#include "pP_config.h"
|
||||||
#include "pP_function.h"
|
#include "pP_function.h"
|
||||||
#include "EEPROM.h"
|
|
||||||
|
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
void updateGainFactor(int value)
|
void updateGainFactor(int value) {
|
||||||
{
|
if (value >= 0) {
|
||||||
if (value >= 0)
|
GAIN_FACTOR = value;
|
||||||
{
|
adjustGain();
|
||||||
GAIN_FACTOR = value;
|
EEPROM.put(GAIN_FACTOR_ADDRESS, GAIN_FACTOR);
|
||||||
adjustGain();
|
}
|
||||||
EEPROM.put(GAIN_FACTOR_ADDRESS, GAIN_FACTOR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
void updateVFol(int value)
|
void updateVFol(int value) {
|
||||||
{
|
if (value >= 0) {
|
||||||
if (value >= 0)
|
followerThrs = value;
|
||||||
{
|
adjustFollow();
|
||||||
followerThrs = value;
|
EEPROM.put(FOLLOWER_THRESHOLD_ADDRESS, followerThrs);
|
||||||
adjustFollow();
|
}
|
||||||
EEPROM.put(FOLLOWER_THRESHOLD_ADDRESS, followerThrs);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
void updateVComp(int value)
|
void updateVComp(int value) {
|
||||||
{
|
if (value >= 0) {
|
||||||
if (value >= 0)
|
compThrs = value;
|
||||||
{
|
adjustComp();
|
||||||
compThrs = value;
|
EEPROM.put(COMP_THRESHOLD_ADDRESS, compThrs);
|
||||||
adjustComp();
|
}
|
||||||
EEPROM.put(COMP_THRESHOLD_ADDRESS, compThrs);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
void updateLoopDuration(int value)
|
void updateLoopDuration(int value) {
|
||||||
{
|
if (value >= 0) {
|
||||||
if (value >= 0)
|
LOOP_DUR = value;
|
||||||
{
|
EEPROM.put(LOOP_DUR_ADDRESS, LOOP_DUR);
|
||||||
LOOP_DUR = value;
|
}
|
||||||
EEPROM.put(LOOP_DUR_ADDRESS, LOOP_DUR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
void updateTrigDuration(int value)
|
void updateTrigDuration(int value) {
|
||||||
{
|
if (value >= 0) {
|
||||||
if (value >= 0)
|
TRG_DUR = value;
|
||||||
{
|
EEPROM.put(TRG_DUR_ADDRESS, TRG_DUR);
|
||||||
TRG_DUR = value;
|
}
|
||||||
EEPROM.put(TRG_DUR_ADDRESS, TRG_DUR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
void updateHysteresis(int value)
|
void updateHysteresis(int value) {
|
||||||
{
|
if (value >= 0) {
|
||||||
if (value >= 0)
|
Hyst = value;
|
||||||
{
|
EEPROM.put(HYST_ADDRESS, Hyst);
|
||||||
Hyst = value;
|
}
|
||||||
EEPROM.put(HYST_ADDRESS, Hyst);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
void updateLogic(int value)
|
void updateLogic(int value) {
|
||||||
{
|
if (value >= 0) {
|
||||||
if (value >= 0)
|
LOGIC = value;
|
||||||
{
|
EEPROM.put(LOGIC_ADDRESS, LOGIC);
|
||||||
LOGIC = value;
|
pulse();
|
||||||
EEPROM.put(LOGIC_ADDRESS, LOGIC);
|
}
|
||||||
pulse();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
void updatePzDet(int value)
|
void updatePzDet(int value) {
|
||||||
{
|
if (value >= 0) {
|
||||||
if (value >= 0)
|
PZDET = value;
|
||||||
{
|
EEPROM.put(PZDET_ADDRESS, PZDET);
|
||||||
PZDET = value;
|
}
|
||||||
EEPROM.put(PZDET_ADDRESS, PZDET);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
void updateConstant(long value)
|
void updateConstant(long value) {
|
||||||
{
|
if (value >= 0) {
|
||||||
if (value >= 0)
|
voltMeterConstant = value;
|
||||||
{
|
EEPROM.put(VM_CONST_ADDRESS, voltMeterConstant);
|
||||||
voltMeterConstant = value;
|
}
|
||||||
EEPROM.put(VM_CONST_ADDRESS, voltMeterConstant);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
void updateDebug(int value)
|
void updateDebug(int value) {
|
||||||
{
|
if (value > 0) {
|
||||||
if (value > 0)
|
Debug = 1;
|
||||||
{
|
} else if (value == 0) {
|
||||||
Debug = 1;
|
Debug = 0;
|
||||||
}
|
}
|
||||||
else if (value == 0)
|
|
||||||
{
|
|
||||||
Debug = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //PP_CMD_H
|
#endif // PP_CMD_H
|
||||||
|
|
@ -16,107 +16,107 @@ long voltMeterConstant = VM_CONST_DEFAULT;
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
void eraseEEPROM() {
|
void eraseEEPROM() {
|
||||||
|
|
||||||
setDefaultConfig();
|
setDefaultConfig();
|
||||||
|
|
||||||
EEPROM.put(GAIN_FACTOR_ADDRESS, GAIN_FACTOR);
|
EEPROM.put(GAIN_FACTOR_ADDRESS, GAIN_FACTOR);
|
||||||
EEPROM.put(FOLLOWER_THRESHOLD_ADDRESS, followerThrs);
|
EEPROM.put(FOLLOWER_THRESHOLD_ADDRESS, followerThrs);
|
||||||
EEPROM.put(COMP_THRESHOLD_ADDRESS, compThrs);
|
EEPROM.put(COMP_THRESHOLD_ADDRESS, compThrs);
|
||||||
EEPROM.put(LOOP_DUR_ADDRESS, LOOP_DUR);
|
EEPROM.put(LOOP_DUR_ADDRESS, LOOP_DUR);
|
||||||
EEPROM.put(TRG_DUR_ADDRESS, TRG_DUR);
|
EEPROM.put(TRG_DUR_ADDRESS, TRG_DUR);
|
||||||
EEPROM.put(HYST_ADDRESS, Hyst);
|
EEPROM.put(HYST_ADDRESS, Hyst);
|
||||||
EEPROM.put(PZDET_ADDRESS, PZDET);
|
EEPROM.put(PZDET_ADDRESS, PZDET);
|
||||||
EEPROM.put(LOGIC_ADDRESS, LOGIC);
|
EEPROM.put(LOGIC_ADDRESS, LOGIC);
|
||||||
EEPROM.put(VM_CONST_ADDRESS, voltMeterConstant);
|
EEPROM.put(VM_CONST_ADDRESS, voltMeterConstant);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore config from EEPROM, otherwise erase config and write to EEPROM
|
// Restore config from EEPROM, otherwise erase config and write to EEPROM
|
||||||
void restoreConfig() {
|
void restoreConfig() {
|
||||||
int temp;
|
int temp;
|
||||||
|
|
||||||
bool erase = false;
|
bool erase = false;
|
||||||
|
|
||||||
EEPROM.get(GAIN_FACTOR_ADDRESS, temp);
|
EEPROM.get(GAIN_FACTOR_ADDRESS, temp);
|
||||||
if (temp < 0 || temp > 4) {
|
if (temp < 0 || temp > 4) {
|
||||||
erase = true;
|
erase = true;
|
||||||
} else {
|
} else {
|
||||||
GAIN_FACTOR = temp;
|
GAIN_FACTOR = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
EEPROM.get(FOLLOWER_THRESHOLD_ADDRESS, temp);
|
EEPROM.get(FOLLOWER_THRESHOLD_ADDRESS, temp);
|
||||||
if (temp < 0 || temp > 5000) {
|
if (temp < 0 || temp > 5000) {
|
||||||
erase = true;
|
erase = true;
|
||||||
} else {
|
} else {
|
||||||
followerThrs = temp;
|
followerThrs = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
EEPROM.get(COMP_THRESHOLD_ADDRESS, temp);
|
EEPROM.get(COMP_THRESHOLD_ADDRESS, temp);
|
||||||
if (temp < 0 || temp > 5000) {
|
if (temp < 0 || temp > 5000) {
|
||||||
erase = true;
|
erase = true;
|
||||||
} else {
|
} else {
|
||||||
compThrs = temp;
|
compThrs = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
EEPROM.get(LOOP_DUR_ADDRESS, temp);
|
EEPROM.get(LOOP_DUR_ADDRESS, temp);
|
||||||
if (temp < 0 && temp > 1000) {
|
if (temp < 0 && temp > 1000) {
|
||||||
erase = true;
|
erase = true;
|
||||||
} else {
|
} else {
|
||||||
LOOP_DUR = temp;
|
LOOP_DUR = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
EEPROM.get(TRG_DUR_ADDRESS, temp);
|
EEPROM.get(TRG_DUR_ADDRESS, temp);
|
||||||
if (temp < 0 || temp > 1000) {
|
if (temp < 0 || temp > 1000) {
|
||||||
erase = true;
|
erase = true;
|
||||||
} else {
|
} else {
|
||||||
TRG_DUR = temp;
|
TRG_DUR = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
EEPROM.get(HYST_ADDRESS, temp);
|
EEPROM.get(HYST_ADDRESS, temp);
|
||||||
if (temp < 0 || temp > 1000) {
|
if (temp < 0 || temp > 1000) {
|
||||||
erase = true;
|
erase = true;
|
||||||
} else {
|
} else {
|
||||||
Hyst = temp;
|
Hyst = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
EEPROM.get(PZDET_ADDRESS, temp);
|
EEPROM.get(PZDET_ADDRESS, temp);
|
||||||
if (temp < 0 || temp > 1) {
|
if (temp < 0 || temp > 1) {
|
||||||
erase = true;
|
erase = true;
|
||||||
} else {
|
} else {
|
||||||
PZDET = temp;
|
PZDET = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
EEPROM.get(LOGIC_ADDRESS, temp);
|
EEPROM.get(LOGIC_ADDRESS, temp);
|
||||||
if (temp < 0 || temp > 1) {
|
if (temp < 0 || temp > 1) {
|
||||||
erase = true;
|
erase = true;
|
||||||
} else {
|
} else {
|
||||||
LOGIC = temp;
|
LOGIC = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
long longTemp;
|
long longTemp;
|
||||||
EEPROM.get(VM_CONST_ADDRESS, longTemp);
|
EEPROM.get(VM_CONST_ADDRESS, longTemp);
|
||||||
if (longTemp < 1000000L || longTemp > 1200000L) {
|
if (longTemp < 1000000L || longTemp > 1200000L) {
|
||||||
erase = true;
|
erase = true;
|
||||||
} else {
|
} else {
|
||||||
voltMeterConstant = longTemp;
|
voltMeterConstant = longTemp;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (erase) {
|
if (erase) {
|
||||||
eraseEEPROM();
|
eraseEEPROM();
|
||||||
}
|
}
|
||||||
|
|
||||||
adjustFollow();
|
adjustFollow();
|
||||||
adjustComp();
|
adjustComp();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setDefaultConfig() {
|
void setDefaultConfig() {
|
||||||
GAIN_FACTOR = GAIN_FACTOR_DEFAULT;
|
GAIN_FACTOR = GAIN_FACTOR_DEFAULT;
|
||||||
followerThrs = FOLLOWER_THRESHOLD_DEFAULT;
|
followerThrs = FOLLOWER_THRESHOLD_DEFAULT;
|
||||||
compThrs = COMP_THRESHOLD_DEFAULT;
|
compThrs = COMP_THRESHOLD_DEFAULT;
|
||||||
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;
|
||||||
PZDET = PZDET_DEFAULT;
|
PZDET = PZDET_DEFAULT;
|
||||||
LOGIC = LOGIC_DEFAULT;
|
LOGIC = LOGIC_DEFAULT;
|
||||||
voltMeterConstant = VM_CONST_DEFAULT;
|
voltMeterConstant = VM_CONST_DEFAULT;
|
||||||
adjustFollow();
|
adjustFollow();
|
||||||
adjustComp();
|
adjustComp();
|
||||||
}
|
}
|
||||||
|
|
@ -48,7 +48,7 @@ extern long voltMeterConstant; // For fine tuning input voltage sense
|
||||||
#ifdef I2C_INPUT
|
#ifdef I2C_INPUT
|
||||||
#define I2C_SLAVE_ADDRESS 24
|
#define I2C_SLAVE_ADDRESS 24
|
||||||
uint8_t pP_i2c_address = 0xa0; // I2C Bus Address
|
uint8_t pP_i2c_address = 0xa0; // I2C Bus Address
|
||||||
#endif // I2C_INPUT
|
#endif // I2C_INPUT
|
||||||
|
|
||||||
void eraseEEPROM();
|
void eraseEEPROM();
|
||||||
void setDefaultConfig();
|
void setDefaultConfig();
|
||||||
|
|
|
||||||
|
|
@ -9,24 +9,19 @@
|
||||||
#include "pP_function.h"
|
#include "pP_function.h"
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include "pP_config.h"
|
#include "pP_config.h"
|
||||||
#include "pP_volatile.h"
|
|
||||||
#include "pP_pins.h"
|
#include "pP_pins.h"
|
||||||
|
#include "pP_volatile.h"
|
||||||
#include "stdint.h"
|
#include "stdint.h"
|
||||||
|
|
||||||
void digitalWriteFast(uint8_t pin, uint8_t x)
|
void digitalWriteFast(uint8_t pin, uint8_t x) {
|
||||||
{
|
if (pin / 8) { // pin >= 8
|
||||||
if (pin / 8)
|
|
||||||
{ // pin >= 8
|
|
||||||
PORTB ^= (-x ^ PORTB) & (1 << (pin % 8));
|
PORTB ^= (-x ^ PORTB) & (1 << (pin % 8));
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
PORTD ^= (-x ^ PORTD) & (1 << (pin % 8));
|
PORTD ^= (-x ^ PORTD) & (1 << (pin % 8));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int analogReadFast(uint8_t ADCpin)
|
int analogReadFast(uint8_t ADCpin) {
|
||||||
{
|
|
||||||
byte ADCSRAoriginal = ADCSRA;
|
byte ADCSRAoriginal = ADCSRA;
|
||||||
ADCSRA = (ADCSRA & B11111000) | 4;
|
ADCSRA = (ADCSRA & B11111000) | 4;
|
||||||
int adc = analogRead(ADCpin);
|
int adc = analogRead(ADCpin);
|
||||||
|
|
@ -36,15 +31,13 @@ int analogReadFast(uint8_t ADCpin)
|
||||||
|
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
void doubleFlash()
|
void doubleFlash() {
|
||||||
{
|
|
||||||
BlinkCount = 4;
|
BlinkCount = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
void pulse()
|
void pulse() {
|
||||||
{
|
|
||||||
digitalWriteFast(TRG_OUT, LOGIC);
|
digitalWriteFast(TRG_OUT, LOGIC);
|
||||||
sensorHReading = 1;
|
sensorHReading = 1;
|
||||||
delay(TRG_DUR);
|
delay(TRG_DUR);
|
||||||
|
|
@ -55,8 +48,7 @@ void pulse()
|
||||||
|
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
long readVcc()
|
long readVcc() {
|
||||||
{
|
|
||||||
// Read 1.1V reference against AVcc
|
// Read 1.1V reference against AVcc
|
||||||
|
|
||||||
// Atmega's Secret Voltmeter setup:
|
// Atmega's Secret Voltmeter setup:
|
||||||
|
|
@ -103,8 +95,7 @@ If the scale_constant calculated is different from the default 1125300,
|
||||||
update the voltMeterConstant variable in pP_config.h with the correct value
|
update the voltMeterConstant variable in pP_config.h with the correct value
|
||||||
--------------------------------------------------*/
|
--------------------------------------------------*/
|
||||||
|
|
||||||
void readVin()
|
void readVin() {
|
||||||
{
|
|
||||||
VOld = Vin;
|
VOld = Vin;
|
||||||
Vin = readVcc();
|
Vin = readVcc();
|
||||||
followerLong = followerThrs * 1023L;
|
followerLong = followerThrs * 1023L;
|
||||||
|
|
@ -117,8 +108,7 @@ void readVin()
|
||||||
|
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
void adjustFollow()
|
void adjustFollow() {
|
||||||
{
|
|
||||||
/* Compares diffs of threshold vs read value
|
/* Compares diffs of threshold vs read value
|
||||||
if positive, adjusts the follower to within
|
if positive, adjusts the follower to within
|
||||||
the range set above*/
|
the range set above*/
|
||||||
|
|
@ -133,8 +123,7 @@ void adjustFollow()
|
||||||
|
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
void adjustComp()
|
void adjustComp() {
|
||||||
{
|
|
||||||
compLong = compThrs * 1023L;
|
compLong = compThrs * 1023L;
|
||||||
compInt = (long long)compLong / Vin;
|
compInt = (long long)compLong / Vin;
|
||||||
compInt = (int)compInt;
|
compInt = (int)compInt;
|
||||||
|
|
@ -143,21 +132,17 @@ void adjustComp()
|
||||||
|
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
void calibrateAlert()
|
void calibrateAlert() {
|
||||||
{
|
|
||||||
VLast = VOld - Vin;
|
VLast = VOld - Vin;
|
||||||
if (VLast > Hyst || VLast < -Hyst)
|
if (VLast > Hyst || VLast < -Hyst) {
|
||||||
{
|
|
||||||
ERR_STATE = 1;
|
ERR_STATE = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
void adjustGain()
|
void adjustGain() {
|
||||||
{
|
switch (GAIN_FACTOR) {
|
||||||
switch (GAIN_FACTOR)
|
|
||||||
{
|
|
||||||
case 4:
|
case 4:
|
||||||
pinMode(GADJ_R0, OUTPUT);
|
pinMode(GADJ_R0, OUTPUT);
|
||||||
digitalWriteFast(GADJ_R0, LOW);
|
digitalWriteFast(GADJ_R0, LOW);
|
||||||
|
|
@ -192,7 +177,7 @@ void adjustGain()
|
||||||
|
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
//void checkError () {
|
// void checkError () {
|
||||||
// if (ERR_STATE == 1) {
|
// if (ERR_STATE == 1) {
|
||||||
// digitalWriteFast(ERR_LED, BlinkState);
|
// digitalWriteFast(ERR_LED, BlinkState);
|
||||||
// BlinkState = !BlinkState;
|
// BlinkState = !BlinkState;
|
||||||
|
|
@ -205,12 +190,10 @@ void adjustGain()
|
||||||
|
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
void pzConCheck()
|
void pzConCheck() {
|
||||||
{
|
|
||||||
PZ_STATE = digitalRead(PZDET_PIN);
|
PZ_STATE = digitalRead(PZDET_PIN);
|
||||||
if (PZ_STATE == PZDET)
|
if (PZ_STATE == PZDET) {
|
||||||
{
|
// digitalWriteFast(TRG_OUT, LOGIC);
|
||||||
//digitalWriteFast(TRG_OUT, LOGIC);
|
|
||||||
ERR_STATE = 1;
|
ERR_STATE = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -38,7 +38,7 @@ void adjustFollow();
|
||||||
void adjustComp();
|
void adjustComp();
|
||||||
void calibrateAlert();
|
void calibrateAlert();
|
||||||
void adjustGain();
|
void adjustGain();
|
||||||
//void checkError () {
|
// void checkError () {
|
||||||
// if (ERR_STATE == 1) {
|
// if (ERR_STATE == 1) {
|
||||||
// digitalWriteFast(ERR_LED, BlinkState);
|
// digitalWriteFast(ERR_LED, BlinkState);
|
||||||
// BlinkState = !BlinkState;
|
// BlinkState = !BlinkState;
|
||||||
|
|
@ -50,4 +50,4 @@ void adjustGain();
|
||||||
//}
|
//}
|
||||||
void pzConCheck();
|
void pzConCheck();
|
||||||
|
|
||||||
#endif //PP_FUNCTION_H
|
#endif // PP_FUNCTION_H
|
||||||
|
|
@ -1,16 +1,15 @@
|
||||||
#ifdef I2C_INPUT
|
#ifdef I2C_INPUT
|
||||||
|
|
||||||
#include <Arduino.h>
|
|
||||||
#include "pP_config.h"
|
|
||||||
#include "pP_i2c.h"
|
#include "pP_i2c.h"
|
||||||
|
#include "pP_config.h"
|
||||||
|
#include <Arduino.h>
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
|
|
||||||
byte registerMap[regMapSize];
|
byte registerMap[regMapSize];
|
||||||
byte registerMapTemp[regMapSize - 1];
|
byte registerMapTemp[regMapSize - 1];
|
||||||
byte receivedCommands[maxBytes];
|
byte receivedCommands[maxBytes];
|
||||||
|
|
||||||
pP_i2c::pP_i2c(){
|
pP_i2c::pP_i2c() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void pP_i2c::init() {
|
void pP_i2c::init() {
|
||||||
|
|
@ -24,19 +23,15 @@ void pP_i2c::i2cReportStatus() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void pP_i2c::i2cReportVersion() {
|
void pP_i2c::i2cReportVersion() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void pP_i2c::i2cReportConfig() {
|
void pP_i2c::i2cReportConfig() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void pP_i2c::i2cReportIdentity() {
|
void pP_i2c::i2cReportIdentity() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void pP_i2c::i2cRequestInput() {
|
void pP_i2c::i2cRequestInput() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void pP_i2c::i2cReply() {
|
void pP_i2c::i2cReply() {
|
||||||
|
|
@ -68,64 +63,64 @@ void pP_i2c::i2cInput(int bytesReceived) {
|
||||||
|
|
||||||
// Parse commands and apply changes or actions
|
// Parse commands and apply changes or actions
|
||||||
switch (cmdRcvd[0]) {
|
switch (cmdRcvd[0]) {
|
||||||
case 0x00:
|
case 0x00:
|
||||||
i2cReportStatus();
|
i2cReportStatus();
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
case 0x01:
|
case 0x01:
|
||||||
followerInt = (int) cmdRcvd[1];
|
followerInt = (int)cmdRcvd[1];
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
case 0x02:
|
case 0x02:
|
||||||
compInt = (int) cmdRcvd[1];
|
compInt = (int)cmdRcvd[1];
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
case 0x03:
|
case 0x03:
|
||||||
GAIN_FACTOR = (int) cmdRcvd[1];
|
GAIN_FACTOR = (int)cmdRcvd[1];
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
case 0x04:
|
case 0x04:
|
||||||
Hyst = (int) cmdRcvd[1];
|
Hyst = (int)cmdRcvd[1];
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
case 0x05:
|
case 0x05:
|
||||||
LOOP_DUR = (int) cmdRcvd[1];
|
LOOP_DUR = (int)cmdRcvd[1];
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
case 0x06:
|
case 0x06:
|
||||||
LOGIC = (int) cmdRcvd[1];
|
LOGIC = (int)cmdRcvd[1];
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
case 0x07:
|
case 0x07:
|
||||||
PZDET = (int) cmdRcvd[1];
|
PZDET = (int)cmdRcvd[1];
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
case 0x08:
|
case 0x08:
|
||||||
TRG_DUR = (int) cmdRcvd[1];
|
TRG_DUR = (int)cmdRcvd[1];
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
case 0x09:
|
case 0x09:
|
||||||
DEBUG = (int) cmdRcvd[1];
|
DEBUG = (int)cmdRcvd[1];
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
case 0x0a:
|
case 0x0a:
|
||||||
voltMeterConstant = longRcvd[0]*65536+longRcvd[1]*256+longRcvd[2];
|
voltMeterConstant = longRcvd[0] * 65536 + longRcvd[1] * 256 + longRcvd[2];
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
case 0x0b:
|
case 0x0b:
|
||||||
reportVersion();
|
reportVersion();
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
case 0x0c:
|
case 0x0c:
|
||||||
reportConfig();
|
reportConfig();
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
case 0x0d:
|
case 0x0d:
|
||||||
reportIdentity();
|
reportIdentity();
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -2,23 +2,23 @@
|
||||||
#define _pP_i2c_h_
|
#define _pP_i2c_h_
|
||||||
#ifdef I2C_INPUT
|
#ifdef I2C_INPUT
|
||||||
|
|
||||||
#define status_Offset 0x00 // Status register
|
#define status_Offset 0x00 // Status register
|
||||||
#define senseInt_Offset 0x01 // Integer of sense threshold in millivolts
|
#define senseInt_Offset 0x01 // Integer of sense threshold in millivolts
|
||||||
#define compInt_Offset 0x02 // Integer of comparator threshold in millivolts
|
#define compInt_Offset 0x02 // Integer of comparator threshold in millivolts
|
||||||
#define gainFactor_Offset 0x03 // Gain adjustment factor. 0=3x, 1=3.5x, 2=4.33x, 3=6x, 4=11x
|
#define gainFactor_Offset 0x03 // Gain adjustment factor. 0=3x, 1=3.5x, 2=4.33x, 3=6x, 4=11x
|
||||||
#define hysteresis_Offset 0x04 // Hysteresis value for ADC measurements
|
#define hysteresis_Offset 0x04 // Hysteresis value for ADC measurements
|
||||||
#define loopDuration_Offset 0x05 // duration of time between ADC checks and other loop functions
|
#define loopDuration_Offset 0x05 // duration of time between ADC checks and other loop functions
|
||||||
#define logicLevel_Offset 0x06
|
#define logicLevel_Offset 0x06
|
||||||
#define piezoDetect_Offset 0x07
|
#define piezoDetect_Offset 0x07
|
||||||
#define triggerDuration_Offset 0x08 // duration of the Z-axis pulse sent, in ms
|
#define triggerDuration_Offset 0x08 // duration of the Z-axis pulse sent, in ms
|
||||||
#define debugEnable_Offset 0x09
|
#define debugEnable_Offset 0x09
|
||||||
#define voltMeterLong_Offset 0x0a // For fine-tuning the input volt master
|
#define voltMeterLong_Offset 0x0a // For fine-tuning the input volt master
|
||||||
#define versionRegister_Offset 0x0b
|
#define versionRegister_Offset 0x0b
|
||||||
#define configRegister_Offset 0x0c
|
#define configRegister_Offset 0x0c
|
||||||
#define identRegister_Offset 0x0d
|
#define identRegister_Offset 0x0d
|
||||||
|
|
||||||
/*-------------------------Variables------------------------*/
|
/*-------------------------Variables------------------------*/
|
||||||
#define regMapSize 14
|
#define regMapSize 14
|
||||||
#define maxBytes 2
|
#define maxBytes 2
|
||||||
#define longBytes 4
|
#define longBytes 4
|
||||||
byte regMap[regMapSize];
|
byte regMap[regMapSize];
|
||||||
|
|
@ -26,16 +26,16 @@ byte regMapTemp[regMapSize];
|
||||||
byte cmdRcvd[maxBytes];
|
byte cmdRcvd[maxBytes];
|
||||||
byte longRcvd[longBytes];
|
byte longRcvd[longBytes];
|
||||||
|
|
||||||
|
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
class pP_i2c {
|
class pP_i2c {
|
||||||
public:
|
public:
|
||||||
pP_i2c(uint8_t address=pP_i2c_address);
|
pP_i2c(uint8_t address = pP_i2c_address);
|
||||||
void init();
|
void init();
|
||||||
void i2cInput(int bytesReceived);
|
void i2cInput(int bytesReceived);
|
||||||
private:
|
|
||||||
char _i2cResponse;
|
private:
|
||||||
|
char _i2cResponse;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // I2C_INPUT
|
#endif // I2C_INPUT
|
||||||
|
|
|
||||||
|
|
@ -16,18 +16,18 @@ Default pins (based on Rev.2.x.xPCB layout)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Analog Pin Assignments
|
// Analog Pin Assignments
|
||||||
#define V_FOLLOW_PIN A0 // Sense pin to check Voltage Follower stage
|
#define V_FOLLOW_PIN A0 // Sense pin to check Voltage Follower stage
|
||||||
#define VCOMP_SENSE_PIN A1 // Sense pin to check comparator stage voltage
|
#define VCOMP_SENSE_PIN A1 // Sense pin to check comparator stage voltage
|
||||||
|
|
||||||
// Digital Pin Assignments
|
// Digital Pin Assignments
|
||||||
#define TRG_OUT 7 // LED and Z-Min trigger output connected to digital pin 7
|
#define TRG_OUT 7 // LED and Z-Min trigger output connected to digital pin 7
|
||||||
//#define TRG_OUT 13 // For testing on Atmega328/2560, Output is moved to onboard LED pin
|
//#define TRG_OUT 13 // For testing on Atmega328/2560, Output is moved to onboard LED pin
|
||||||
#define Z_TRG 2 // the piezo is connected to INT0 / digital pin 2
|
#define Z_TRG 2 // the piezo is connected to INT0 / digital pin 2
|
||||||
#define ERR_LED 4 // LED will blink if optimal voltage range cannot be achieved
|
#define ERR_LED 4 // LED will blink if optimal voltage range cannot be achieved
|
||||||
#define GADJ_R0 20 // Auto-adjust ladder pin assignments
|
#define GADJ_R0 20 // Auto-adjust ladder pin assignments
|
||||||
#define GADJ_R1 21 // "
|
#define GADJ_R1 21 // "
|
||||||
#define GADJ_R2 5 // "
|
#define GADJ_R2 5 // "
|
||||||
#define GADJ_R3 6 // "
|
#define GADJ_R3 6 // "
|
||||||
#define V_FOL_PWM 3 // PWM analog output pin for voltage follower adjustment
|
#define V_FOL_PWM 3 // PWM analog output pin for voltage follower adjustment
|
||||||
#define VCOMP_PWM 9 // PWM analog output pin for comparator adjustment
|
#define VCOMP_PWM 9 // PWM analog output pin for comparator adjustment
|
||||||
#define PZDET_PIN 16 // Digital input pin for detecting piezo connection
|
#define PZDET_PIN 16 // Digital input pin for detecting piezo connection
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#include "pP_cmd.h"
|
#include "pP_cmd.h"
|
||||||
|
#include "pP_volatile.h"
|
||||||
|
|
||||||
void parseData()
|
void parseData() {
|
||||||
{
|
|
||||||
|
|
||||||
// split the data into its parts
|
// split the data into its parts
|
||||||
|
|
||||||
|
|
@ -15,45 +15,36 @@ void parseData()
|
||||||
}
|
}
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
void identifyMarkers()
|
void identifyMarkers() {
|
||||||
{
|
|
||||||
|
|
||||||
char x = Serial.read();
|
char x = Serial.read();
|
||||||
#ifdef I2C_INPUT
|
#ifdef I2C_INPUT
|
||||||
char y = Wire.read();
|
char y = Wire.read();
|
||||||
#endif // I2C_INPUT
|
#endif // I2C_INPUT
|
||||||
|
|
||||||
if (x == '\n' || x == '\r')
|
if (x == '\n' || x == '\r') {
|
||||||
{
|
|
||||||
serialIncoming = true;
|
serialIncoming = true;
|
||||||
inputBuffer[bytesRecvd] = 0;
|
inputBuffer[bytesRecvd] = 0;
|
||||||
parseData();
|
parseData();
|
||||||
bytesRecvd = 0;
|
bytesRecvd = 0;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
inputBuffer[bytesRecvd] = x;
|
inputBuffer[bytesRecvd] = x;
|
||||||
bytesRecvd++;
|
bytesRecvd++;
|
||||||
if (bytesRecvd == buffSize)
|
if (bytesRecvd == buffSize) {
|
||||||
{
|
|
||||||
bytesRecvd = buffSize - 1;
|
bytesRecvd = buffSize - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef I2C_INPUT
|
#ifdef I2C_INPUT
|
||||||
if (y == '\n' || y == '\r')
|
if (y == '\n' || y == '\r') {
|
||||||
{
|
|
||||||
serialIncoming = true;
|
serialIncoming = true;
|
||||||
inputBuffer[bytesRecvd] = 0;
|
inputBuffer[bytesRecvd] = 0;
|
||||||
parseData();
|
parseData();
|
||||||
bytesRecvd = 0;
|
bytesRecvd = 0;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
inputBuffer[bytesRecvd] = y;
|
inputBuffer[bytesRecvd] = y;
|
||||||
bytesRecvd++;
|
bytesRecvd++;
|
||||||
if (bytesRecvd == buffSize)
|
if (bytesRecvd == buffSize) {
|
||||||
{
|
|
||||||
bytesRecvd = buffSize - 1;
|
bytesRecvd = buffSize - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -62,12 +53,10 @@ void identifyMarkers()
|
||||||
|
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
void serialPrintConfig()
|
void serialPrintConfig() {
|
||||||
{
|
|
||||||
Serial.print("GAIN_F ");
|
Serial.print("GAIN_F ");
|
||||||
Serial.print(GAIN_FACTOR);
|
Serial.print(GAIN_FACTOR);
|
||||||
switch (GAIN_FACTOR)
|
switch (GAIN_FACTOR) {
|
||||||
{
|
|
||||||
case 0:
|
case 0:
|
||||||
Serial.println(" 3x");
|
Serial.println(" 3x");
|
||||||
break;
|
break;
|
||||||
|
|
@ -116,8 +105,7 @@ void serialPrintConfig()
|
||||||
Serial.println(PP_VERSION);
|
Serial.println(PP_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
void serialPrintState()
|
void serialPrintState() {
|
||||||
{
|
|
||||||
Serial.print("{");
|
Serial.print("{");
|
||||||
|
|
||||||
Serial.print("\"Vcc\":");
|
Serial.print("\"Vcc\":");
|
||||||
|
|
@ -147,64 +135,36 @@ void serialPrintState()
|
||||||
Serial.println("}");
|
Serial.println("}");
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateParams()
|
void updateParams() {
|
||||||
{
|
|
||||||
serialIncoming = false;
|
serialIncoming = false;
|
||||||
if (strcmp(serialMessageIn, "GAIN_F") == 0)
|
if (strcmp(serialMessageIn, "GAIN_F") == 0) {
|
||||||
{
|
|
||||||
updateGainFactor(serialLong);
|
updateGainFactor(serialLong);
|
||||||
}
|
} else if (strcmp(serialMessageIn, "VFOL") == 0) {
|
||||||
else if (strcmp(serialMessageIn, "VFOL") == 0)
|
|
||||||
{
|
|
||||||
updateVFol(serialLong);
|
updateVFol(serialLong);
|
||||||
}
|
} else if (strcmp(serialMessageIn, "VCOMP") == 0) {
|
||||||
else if (strcmp(serialMessageIn, "VCOMP") == 0)
|
|
||||||
{
|
|
||||||
updateVComp(serialLong);
|
updateVComp(serialLong);
|
||||||
}
|
} else if (strcmp(serialMessageIn, "LOOP_D") == 0) {
|
||||||
else if (strcmp(serialMessageIn, "LOOP_D") == 0)
|
|
||||||
{
|
|
||||||
updateLoopDuration(serialLong);
|
updateLoopDuration(serialLong);
|
||||||
}
|
} else if (strcmp(serialMessageIn, "TRG_D") == 0) {
|
||||||
else if (strcmp(serialMessageIn, "TRG_D") == 0)
|
|
||||||
{
|
|
||||||
updateTrigDuration(serialLong);
|
updateTrigDuration(serialLong);
|
||||||
}
|
} else if (strcmp(serialMessageIn, "HYST") == 0) {
|
||||||
else if (strcmp(serialMessageIn, "HYST") == 0)
|
|
||||||
{
|
|
||||||
updateHysteresis(serialLong);
|
updateHysteresis(serialLong);
|
||||||
}
|
} else if (strcmp(serialMessageIn, "LOGIC") == 0) {
|
||||||
else if (strcmp(serialMessageIn, "LOGIC") == 0)
|
|
||||||
{
|
|
||||||
updateLogic(serialLong);
|
updateLogic(serialLong);
|
||||||
}
|
} else if (strcmp(serialMessageIn, "PZDET") == 0) {
|
||||||
else if (strcmp(serialMessageIn, "PZDET") == 0)
|
|
||||||
{
|
|
||||||
updatePzDet(serialLong);
|
updatePzDet(serialLong);
|
||||||
}
|
} else if (strcmp(serialMessageIn, "CONST") == 0) {
|
||||||
else if (strcmp(serialMessageIn, "CONST") == 0)
|
|
||||||
{
|
|
||||||
updateConstant(serialLong);
|
updateConstant(serialLong);
|
||||||
}
|
} else if (strcmp(serialMessageIn, "DEBUG") == 0) {
|
||||||
else if (strcmp(serialMessageIn, "DEBUG") == 0)
|
|
||||||
{
|
|
||||||
updateDebug(serialLong);
|
updateDebug(serialLong);
|
||||||
}
|
} else if (strcmp(serialMessageIn, "CONFIG") == 0) {
|
||||||
else if (strcmp(serialMessageIn, "CONFIG") == 0)
|
|
||||||
{
|
|
||||||
serialPrintConfig();
|
serialPrintConfig();
|
||||||
}
|
} else if (strcmp(serialMessageIn, "ERASE") == 0) {
|
||||||
else if (strcmp(serialMessageIn, "ERASE") == 0)
|
|
||||||
{
|
|
||||||
eraseEEPROM();
|
eraseEEPROM();
|
||||||
serialPrintConfig();
|
serialPrintConfig();
|
||||||
}
|
} else if (strcmp(serialMessageIn, "STATE") == 0) {
|
||||||
else if (strcmp(serialMessageIn, "STATE") == 0)
|
|
||||||
{
|
|
||||||
serialPrintState();
|
serialPrintState();
|
||||||
}
|
} else if (strcmp(serialMessageIn, "HELP") == 0) {
|
||||||
else if (strcmp(serialMessageIn, "HELP") == 0)
|
|
||||||
{
|
|
||||||
#if defined(ARDUINO_AVR_ATmega328PB)
|
#if defined(ARDUINO_AVR_ATmega328PB)
|
||||||
Serial.println("To change gain factor: GAIN_F [integer for gain state - see note*]");
|
Serial.println("To change gain factor: GAIN_F [integer for gain state - see note*]");
|
||||||
Serial.println("To change voltage follower voltage (low threshold): VFOL [float value]");
|
Serial.println("To change voltage follower voltage (low threshold): VFOL [float value]");
|
||||||
|
|
@ -235,11 +195,9 @@ void updateParams()
|
||||||
parseData();
|
parseData();
|
||||||
}
|
}
|
||||||
|
|
||||||
void serialInput()
|
void serialInput() {
|
||||||
{
|
|
||||||
// receive data from Serial and save it into inputBuffer
|
// receive data from Serial and save it into inputBuffer
|
||||||
if (Serial.available() > 0)
|
if (Serial.available() > 0) {
|
||||||
{
|
|
||||||
|
|
||||||
// the order of these IF clauses is significant
|
// the order of these IF clauses is significant
|
||||||
identifyMarkers();
|
identifyMarkers();
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,14 @@
|
||||||
#include "stdint.h"
|
#include "stdint.h"
|
||||||
|
|
||||||
// these variables will change on their own. Do not edit ANYTHING below this line
|
// these variables will change on their own. Do not edit ANYTHING below this line
|
||||||
volatile int sensorHReading = 0; // variable to store the value read from the sensor pin
|
volatile int sensorHReading = 0; // variable to store the value read from the sensor pin
|
||||||
volatile int ADJ_FOLLOW = 0; // Variable for Follower adjustment
|
volatile int ADJ_FOLLOW = 0; // Variable for Follower adjustment
|
||||||
volatile int ADJ_COMP = 0; // Variable for Comparator adjustment
|
volatile int ADJ_COMP = 0; // Variable for Comparator adjustment
|
||||||
volatile int ERR_STATE = 0;
|
volatile int ERR_STATE = 0;
|
||||||
volatile int PZ_STATE = 0;
|
volatile int PZ_STATE = 0;
|
||||||
|
|
||||||
int Vin = 5000; // input reference voltage in millivolts (multiply V by 1000)
|
int Vin = 5000; // input reference voltage in millivolts (multiply V by 1000)
|
||||||
int VOld = 5000; // Variable to store previous cycle's Vin
|
int VOld = 5000; // Variable to store previous cycle's Vin
|
||||||
int VLast = 0;
|
int VLast = 0;
|
||||||
|
|
||||||
// Convert threshold values based on the input voltage
|
// Convert threshold values based on the input voltage
|
||||||
|
|
@ -29,7 +29,7 @@ int VFol = 0;
|
||||||
// Error blink parameters
|
// Error blink parameters
|
||||||
|
|
||||||
int BlinkState = 0;
|
int BlinkState = 0;
|
||||||
int BlinkCount = (InitCount * 2) + 1; // Multiply Blink count by 2 to handle toggle state, add one extra to make sure light is on after
|
int BlinkCount = (InitCount * 2) + 1; // Multiply Blink count by 2 to handle toggle state, add one extra to make sure light is on after
|
||||||
|
|
||||||
// Serial Input Parsing Variables
|
// Serial Input Parsing Variables
|
||||||
char inputBuffer[buffSize];
|
char inputBuffer[buffSize];
|
||||||
|
|
|
||||||
|
|
@ -5,14 +5,14 @@
|
||||||
#include "stdint.h"
|
#include "stdint.h"
|
||||||
|
|
||||||
// these variables will change on their own. Do not edit ANYTHING below this line
|
// these variables will change on their own. Do not edit ANYTHING below this line
|
||||||
extern volatile int sensorHReading; // variable to store the value read from the sensor pin
|
extern volatile int sensorHReading; // variable to store the value read from the sensor pin
|
||||||
extern volatile int ADJ_FOLLOW; // Variable for Follower adjustment
|
extern volatile int ADJ_FOLLOW; // Variable for Follower adjustment
|
||||||
extern volatile int ADJ_COMP; // Variable for Comparator adjustment
|
extern volatile int ADJ_COMP; // Variable for Comparator adjustment
|
||||||
extern volatile int ERR_STATE;
|
extern volatile int ERR_STATE;
|
||||||
extern volatile int PZ_STATE;
|
extern volatile int PZ_STATE;
|
||||||
|
|
||||||
extern int Vin; // input reference voltage in millivolts (multiply V by 1000)
|
extern int Vin; // input reference voltage in millivolts (multiply V by 1000)
|
||||||
extern int VOld; // Variable to store previous cycle's Vin
|
extern int VOld; // Variable to store previous cycle's Vin
|
||||||
extern int VLast;
|
extern int VLast;
|
||||||
|
|
||||||
// Convert threshold values based on the input voltage
|
// Convert threshold values based on the input voltage
|
||||||
|
|
@ -31,7 +31,7 @@ extern int VFol;
|
||||||
// Error blink parameters
|
// Error blink parameters
|
||||||
|
|
||||||
extern int BlinkState;
|
extern int BlinkState;
|
||||||
extern int BlinkCount; // Multiply Blink count by 2 to handle toggle state, add one extra to make sure light is on after
|
extern int BlinkCount; // Multiply Blink count by 2 to handle toggle state, add one extra to make sure light is on after
|
||||||
|
|
||||||
// Serial Input Parsing Variables
|
// Serial Input Parsing Variables
|
||||||
#define buffSize 40
|
#define buffSize 40
|
||||||
|
|
@ -48,4 +48,4 @@ extern long serialLong;
|
||||||
// Task scheduler instances
|
// Task scheduler instances
|
||||||
extern LightChrono mainLoop;
|
extern LightChrono mainLoop;
|
||||||
|
|
||||||
#endif //PP_VOLATILE_H
|
#endif // PP_VOLATILE_H
|
||||||
Loading…
Reference in a new issue