Set I2C input to be toggled by def

-Synced Comp/Vref til #24 is fixed
This commit is contained in:
pyr0ball 2019-04-22 16:52:30 -07:00
parent 37f7d4d085
commit 4c35d52259

View file

@ -56,7 +56,16 @@ The gain STATE is representative of these values:
4 = 11x 4 = 11x
*/ */
//#include <Wire.h>
// Debug output toggle. Uncomment to enable
//#define DEBUG true
// i2c input toggle. Uncomment to enable
//#define I2C true
#ifdef I2C
#include <Wire.h>
#endif
// Set variables for working parameters // Set variables for working parameters
int GAIN_FACTOR = 2; // Gain adjustment factor. 0=3x, 1=3.5x, 2=4.33x, 3=6x, 4=11x int GAIN_FACTOR = 2; // Gain adjustment factor. 0=3x, 1=3.5x, 2=4.33x, 3=6x, 4=11x
@ -68,7 +77,6 @@ int TRG_DUR = 120; // duration of the Z-axis pulse sent, in ms
int Hyst = 20; // Hysteresis value for ADC measurements int Hyst = 20; // Hysteresis value for ADC measurements
#define Vin 5 // input reference voltage #define Vin 5 // input reference voltage
// 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
@ -259,7 +267,8 @@ void serialInput() {
/*------------------------------------------------*/ /*------------------------------------------------*/
/* void i2cInput() { #ifdef I2C
void i2cInput() {
// receive data from Serial and save it into inputBuffer // receive data from Serial and save it into inputBuffer
@ -269,7 +278,8 @@ void serialInput() {
i2cReply(); i2cReply();
} }
} }
*/ #endif
/*------------------------------------------------*/ /*------------------------------------------------*/
void identifyMarkers() { void identifyMarkers() {
@ -296,8 +306,8 @@ void identifyMarkers() {
bytesRecvd = 0; bytesRecvd = 0;
readInProgress = true; readInProgress = true;
} }
#ifdef I2C
/* if (y == endMarker) { if (y == endMarker) {
readInProgress = false; readInProgress = false;
serialIncoming = true; serialIncoming = true;
inputBuffer[bytesRecvd] = 0; inputBuffer[bytesRecvd] = 0;
@ -316,7 +326,7 @@ void identifyMarkers() {
bytesRecvd = 0; bytesRecvd = 0;
readInProgress = true; readInProgress = true;
} }
*/ #endif
} }
/*------------------------------------------------*/ /*------------------------------------------------*/
@ -373,44 +383,18 @@ void updateGainFactor() {
void updateVComp() { void updateVComp() {
if (serialInt >= 0) { if (serialInt >= 0) {
compInt = (serialFloat / 5) * 1024; compInt = (serialFloat / 5) * 1024;
senseInt = compInt; // syncing these params til #24 is fixed
} }
} }
/*------------------------------------------------* /*------------------------------------------------*/
void updateVCompH() {
if (serialInt >= 0) {
compHighThrs = ((float)serialFloat);
}
}
*------------------------------------------------*
void updateVCompL() {
if (serialInt >= 0) {
compLowThrs = ((float)serialFloat);
}
}
*------------------------------------------------*/
void updateVAdj() { void updateVAdj() {
if (serialInt >= 0) { if (serialInt >= 0) {
senseInt = (serialFloat / 5) * 1024; senseInt = (serialFloat / 5) * 1024;
compInt = senseInt; // syncing these params til #24 is fixed
} }
} }
/*------------------------------------------------* /*------------------------------------------------*/
void updateVAdjH() {
if (serialInt >= 0) {
senseHighThrs = ((float)serialFloat);
}
}
*------------------------------------------------*
void updateVAdjL() {
if (serialInt >= 0) {
senseLowThrs = ((float)serialFloat);
}
}
*------------------------------------------------*/
void updateHysteresis() { void updateHysteresis() {
if (serialInt >= 0) { if (serialInt >= 0) {
@ -422,7 +406,7 @@ void updateHysteresis() {
void serialReply() { void serialReply() {
if (serialIncoming) { if (serialIncoming) {
serialIncoming = false; serialIncoming = false;
#ifdef DEBUG
Serial.print("Comp Reference:"); Serial.print("Comp Reference:");
Serial.print(VComp); Serial.print(VComp);
Serial.print(" "); Serial.print(" ");
@ -450,6 +434,7 @@ void serialReply() {
Serial.print(diffAdjL); Serial.print(diffAdjL);
Serial.print(" "); Serial.print(" ");
Serial.println(diffAdjH); Serial.println(diffAdjH);
#endif
Serial.print("Delay:"); Serial.print("Delay:");
Serial.println(TRG_DUR); Serial.println(TRG_DUR);
@ -459,13 +444,13 @@ void serialReply() {
} }
} }
/*------------------------------------------------*/ /*------------------------------------------------*/
/* #ifdef I2C
void i2cReply() { void i2cReply() {
if (serialIncoming) { if (serialIncoming) {
Wire.write("OK"); Wire.write("OK");
} }
} }
*/ #endif
/*------------------------------------------------*/ /*------------------------------------------------*/
void loop() { void loop() {